Merge pull request #900 from betrusted-io/pddb-erase

factory utilities
This commit is contained in:
bunnie 2026-06-15 23:17:35 +08:00 committed by GitHub
commit 515dd586b3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 581 additions and 0 deletions

View file

@ -249,6 +249,72 @@ pub fn early_init(mut board_type: bao1x_api::BoardTypeCoding) -> (bao1x_api::Boa
// power on
iox.set_gpio_pin_value(oled_on_port, oled_on_pin, IoxValue::High);
#[cfg(feature = "alt-boot1")]
{
crate::println!("entering pddb_erase");
// setup all the board pins to a known state
let iox = Iox::new(utra::iox::HW_IOX_BASE as *mut u32);
bao1x_hal::board::setup_memory_pins(&iox);
// this routine is used to initialize baosec products - sets the board type and
// erases the off-chip FLASH
use bao1x_api::baosec::PDDB_ORIGIN;
use bao1x_hal::{
board::SPINOR_BULK_ERASE_SIZE,
ifram::IframRange,
iox::Iox,
udma::{Spim, *},
};
let perclk = 100_000_000;
let udma_global = GlobalConfig::new();
// setup the I/O pins
let channel = bao1x_hal::board::setup_memory_pins(&iox);
udma_global.clock_on(bao1x_api::PeriphId::from(channel));
// safety: this is safe because clocks have been set up
let mut flash_spim = unsafe {
Spim::new_with_ifram(
channel,
// has to be half the clock frequency reaching the block, but
// run it as fast
// as we can run perclk
perclk / 4,
perclk / 2,
SpimClkPol::LeadingEdgeRise,
SpimClkPha::CaptureOnLeading,
SpimCs::Cs0,
0,
0,
None,
256 + 16, /* just enough space to send commands + programming
* page */
4096,
Some(6),
Some(SpimMode::Standard), // guess Standard
IframRange::from_raw_parts(
bao1x_hal::board::SPIM_FLASH_IFRAM_ADDR,
bao1x_hal::board::SPIM_FLASH_IFRAM_ADDR,
4096 * 2,
),
)
};
flash_spim.identify_flash_reset_qpi();
let flash_id = flash_spim.mem_read_id_flash();
crate::println!("flash ID (init): {:x}", flash_id);
if bao1x_api::SPI_FLASH_IDS.contains(&(flash_id & 0xFF_FF_FF)) {
let pddb_erase_len = SPINOR_BULK_ERASE_SIZE as usize * 2;
for addr in
(PDDB_ORIGIN..PDDB_ORIGIN + pddb_erase_len).step_by(SPINOR_BULK_ERASE_SIZE as usize)
{
crate::println!(" {:x}...", addr);
flash_spim.flash_erase_block(addr, SPINOR_BULK_ERASE_SIZE as usize);
}
crate::println!("...done!");
} else {
crate::println!("...skipped, couldn't find FLASH part");
}
}
}
#[cfg(not(feature = "oem"))]
BoardTypeCoding::Oem => {

View file

@ -79,6 +79,7 @@ dabao-selftest = [
"xous-bio-bdma/baremetal",
"xous-bio-bdma/bao1x",
]
factory-utils = ["ux-api/loader-baosec"]
ci-security = []
spim-tests = []
redteam = ["bao1x-hal/redteam"]

View file

@ -99,6 +99,8 @@ pub unsafe extern "C" fn rust_entry() -> ! {
#[cfg(feature = "dabao-selftest")]
let mut self_test_ran = false;
#[cfg(feature = "factory-utils")]
let mut factory_util_run = false;
#[cfg(feature = "bao1x-usb")]
// do the main loop through either USB interface or serial port
@ -110,6 +112,13 @@ pub unsafe extern "C" fn rust_entry() -> ! {
self_test_ran = true;
}
}
#[cfg(feature = "factory-utils")]
{
if !factory_util_run {
crate::factory_utils::pddb_erase();
factory_util_run = true;
}
}
let (new_usb_state, new_portsc) = glue::usb_status();

View file

@ -4,9 +4,13 @@ pub use bao1x::*;
pub mod avtrng;
#[cfg(feature = "bao1x-bio")]
pub mod bio;
#[cfg(feature = "factory-utils")]
pub mod bitmaps;
#[cfg(feature = "dabao-selftest")]
pub mod dabao_selftest;
pub mod debug;
#[cfg(feature = "factory-utils")]
pub mod factory_utils;
pub mod irq;
#[cfg(feature = "bao1x-usb")]
pub mod usb;

View file

@ -0,0 +1,24 @@
#!/bin/bash
# export.sh - run as part of build or manually
set -e
for svg in *.svg; do
base=$(basename "$svg" .svg)
# Export at native 128x128 — no scaling = no interpolation
inkscape "$svg" \
--export-type=png \
--export-width=128 \
--export-height=128 \
--export-text-to-path \
-o "/tmp/${base}.png"
# Hard threshold to pure 1-bit B&W — no dithering
convert "/tmp/${base}.png" \
-threshold 50% \
-monochrome \
-depth 1 \
"${base}.png"
python3 ./pngtorust.py -f "${base}.png" -o "${base}.rs"
done

Binary file not shown.

After

Width:  |  Height:  |  Size: 591 B

View file

@ -0,0 +1,132 @@
#![cfg_attr(rustfmt, rustfmt_skip)]
pub const BITMAP: [u32; 512] = [
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0x0fffffff, 0x0383f8f0, 0xc601f078, 0xffffffe3,
0x0fffffff, 0x0301f870, 0x8c01c038, 0xfffffff3,
0xcfffffff, 0x3e38f07f, 0x8cf9c71f, 0xfffffff1,
0xcfffffff, 0x3e7c707f, 0x9cf98f8f, 0xfffffff9,
0x8fffffff, 0x3ffc723f, 0x3cf99f8f, 0xfffffff8,
0x0fffffff, 0x3ffc6338, 0x3e019fcf, 0xfffffffc,
0x0fffffff, 0x3ffc6738, 0x7e019fcf, 0xfffffffc,
0xcfffffff, 0x3ffc601f, 0x7c798f8f, 0xfffffffe,
0xcfffffff, 0x3e7cc01f, 0x7cf98f8f, 0xfffffffe,
0xcfffffff, 0x3e38c79f, 0x7cf9c71f, 0xfffffffe,
0xcfffffff, 0x3f01cf8f, 0x7cf9e03f, 0xfffffffe,
0xcfffffff, 0x3f83cfcf, 0x7cf9f07f, 0xfffffffe,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xe3f1f3ff, 0xff807f07, 0xffffffff,
0xffffffff, 0x80f1e1ff, 0xff807807, 0xffffffff,
0xffffffff, 0x1870e1ff, 0xfffe70c7, 0xffffffff,
0xffffffff, 0x3e70e1ff, 0xfffe73e6, 0xffffffff,
0xffffffff, 0x3e30c1ff, 0xfffe63e6, 0xffffffff,
0xffffffff, 0x7e32c9ff, 0xff8063e6, 0xffffffff,
0xffffffff, 0x7f32c9ff, 0xff8063e6, 0xffffffff,
0xffffffff, 0x7e3259ff, 0xfffe63e6, 0xffffffff,
0xffffffff, 0x3e3219ff, 0xfffe73e6, 0xffffffff,
0xffffffff, 0x3e7219ff, 0xfffe71e7, 0xffffffff,
0xffffffff, 0x007319ff, 0xff807807, 0xffffffff,
0xffffffff, 0x80f319ff, 0xff807c07, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xf80007ff, 0x4fffee7d, 0xfffffffe,
0x007fffff, 0xf8000780, 0xcfff001d, 0xfffffffc,
0x3fffffff, 0xffffe7ff, 0xcfff801d, 0xffffffff,
0x3fffffff, 0x3fffe7ff, 0x0003ee70, 0xfffffff8,
0x3fffffff, 0x3fffe7ff, 0x00078030, 0xfffffff8,
0x3fffffff, 0xffffe7ff, 0xcfff9fbc, 0xffffffff,
0x3fffffff, 0xffffe7ff, 0xcfff9fb8, 0xffffffff,
0x3fffffff, 0xffffe7ff, 0xcfff8038, 0xffffffff,
0x3fffffff, 0x7fffe7ff, 0xd8079fb0, 0xffffffff,
0x3fffffff, 0x7fffe7ff, 0xdf3f8034, 0xffffffff,
0x3fffffff, 0x7fffe7ff, 0x9f3ff9fd, 0xffffffff,
0x3fffffff, 0x3ffff7ff, 0x9f3ff9fd, 0xffffffff,
0x3fffffff, 0xbffff7ff, 0xbf3f001d, 0xfffffffb,
0x3fffffff, 0xfffff3ff, 0x3f3ff0fd, 0xfffffff3,
0x3fffffff, 0xfffff3ff, 0x303fe4fd, 0xfffffffb,
0x3fffffff, 0xfffff3ff, 0x7e03ce3d, 0xfffffff8,
0x003fffff, 0xfffffb00, 0xffff1f8d, 0xfffffff8,
0xffffffff, 0xffffffff, 0xfffffffd, 0xfffffffd,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
];

View file

@ -0,0 +1,174 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="128"
height="128"
viewBox="0 0 128 128"
version="1.1"
id="svg5"
shape-rendering="crispEdges"
inkscape:version="1.1.2 (0a00cf5339, 2022-02-04)"
sodipodi:docname="factory_mode.svg"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview7"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:document-units="px"
showgrid="true"
units="px"
width="128px"
inkscape:zoom="5.1241863"
inkscape:cx="51.910681"
inkscape:cy="67.718069"
inkscape:window-width="1906"
inkscape:window-height="1366"
inkscape:window-x="26"
inkscape:window-y="23"
inkscape:window-maximized="0"
inkscape:current-layer="layer2"
inkscape:snap-grids="true">
<inkscape:grid
type="xygrid"
id="grid19724"
dotted="false" />
</sodipodi:namedview>
<defs
id="defs2">
<marker
style="overflow:visible"
id="Arrow1Sstart"
refX="0.0"
refY="0.0"
orient="auto"
inkscape:stockid="Arrow1Sstart"
inkscape:isstock="true">
<path
transform="scale(0.2) translate(6,0)"
style="fill-rule:evenodd;fill:context-stroke;stroke:context-stroke;stroke-width:1.0pt"
d="M 0.0,0.0 L 5.0,-5.0 L -12.5,0.0 L 5.0,5.0 L 0.0,0.0 z "
id="path16778" />
</marker>
<marker
style="overflow:visible"
id="Arrow2Mstart"
refX="0.0"
refY="0.0"
orient="auto"
inkscape:stockid="Arrow2Mstart"
inkscape:isstock="true">
<path
transform="scale(0.6) translate(0,0)"
d="M 8.7185878,4.0337352 L -2.2072895,0.016013256 L 8.7185884,-4.0017078 C 6.9730900,-1.6296469 6.9831476,1.6157441 8.7185878,4.0337352 z "
style="stroke:context-stroke;fill-rule:evenodd;fill:context-stroke;stroke-width:0.62500000;stroke-linejoin:round"
id="path16790" />
</marker>
<marker
style="overflow:visible"
id="marker17044"
refX="0.0"
refY="0.0"
orient="auto"
inkscape:stockid="Arrow2Lstart"
inkscape:isstock="true">
<path
transform="scale(1.1) translate(1,0)"
d="M 8.7185878,4.0337352 L -2.2072895,0.016013256 L 8.7185884,-4.0017078 C 6.9730900,-1.6296469 6.9831476,1.6157441 8.7185878,4.0337352 z "
style="stroke:context-stroke;fill-rule:evenodd;fill:context-stroke;stroke-width:0.62500000;stroke-linejoin:round"
id="path17042" />
</marker>
<marker
style="overflow:visible"
id="Arrow1Lstart"
refX="0.0"
refY="0.0"
orient="auto"
inkscape:stockid="Arrow1Lstart"
inkscape:isstock="true">
<path
transform="scale(0.8) translate(12.5,0)"
style="fill-rule:evenodd;fill:context-stroke;stroke:context-stroke;stroke-width:1.0pt"
d="M 0.0,0.0 L 5.0,-5.0 L -12.5,0.0 L 5.0,5.0 L 0.0,0.0 z "
id="path16766" />
</marker>
<marker
style="overflow:visible"
id="Arrow2Lstart"
refX="0.0"
refY="0.0"
orient="auto"
inkscape:stockid="Arrow2Lstart"
inkscape:isstock="true">
<path
transform="scale(1.1) translate(1,0)"
d="M 8.7185878,4.0337352 L -2.2072895,0.016013256 L 8.7185884,-4.0017078 C 6.9730900,-1.6296469 6.9831476,1.6157441 8.7185878,4.0337352 z "
style="stroke:context-stroke;fill-rule:evenodd;fill:context-stroke;stroke-width:0.62500000;stroke-linejoin:round"
id="path16784" />
</marker>
</defs>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
sodipodi:insensitive="true">
<rect
style="fill:#000000;fill-opacity:1;fill-rule:evenodd"
id="rect31"
width="128.60579"
height="127.82517"
x="-0.19515294"
y="0.19515294" />
</g>
<g
inkscape:groupmode="layer"
id="layer2"
inkscape:label="Layer 2">
<text
xml:space="preserve"
style="font-size:15.2508px;line-height:1.25;font-family:sans-serif;stroke-width:1.69454"
x="15.28901"
y="28.262556"
id="text8125"
transform="scale(1.0088222,0.99125496)"><tspan
sodipodi:role="line"
id="tspan8123"
x="15.28901"
y="28.262556"
style="fill:#ffffff;fill-opacity:1;stroke-width:1.69454" /></text>
<text
xml:space="preserve"
style="font-size:16px;line-height:1.25;font-family:sans-serif"
x="64.027405"
y="36.634319"
id="text5523"><tspan
sodipodi:role="line"
x="64.027405"
y="36.634319"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:16px;font-family:'Liberation Sans';-inkscape-font-specification:'Liberation Sans, Bold';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;text-align:center;text-anchor:middle;fill:#ffffff;fill-opacity:1"
id="tspan43884">FACTORY</tspan><tspan
sodipodi:role="line"
x="64.027405"
y="57.126568"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:16px;font-family:'Liberation Sans';-inkscape-font-specification:'Liberation Sans, Bold';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;text-align:center;text-anchor:middle;fill:#ffffff;fill-opacity:1"
id="tspan898">MODE</tspan></text>
<text
xml:space="preserve"
style="font-size:20px;line-height:1.25;font-family:sans-serif"
x="60.802094"
y="88.838028"
id="text5523-3"><tspan
sodipodi:role="line"
x="60.802094"
y="88.838028"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:20px;font-family:'Liberation Sans';-inkscape-font-specification:'Liberation Sans, Bold';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;text-align:center;text-anchor:middle;fill:#ffffff;fill-opacity:1"
id="tspan13947">工厂模式</tspan></text>
</g>
</svg>

After

Width:  |  Height:  |  Size: 6.5 KiB

View file

@ -0,0 +1 @@
pub mod factory_mode;

View file

@ -0,0 +1,79 @@
#!/usr/bin/python3
import argparse
import numpy as np
from PIL import Image
def bitflip(data_block, bitwidth=32):
if bitwidth == 0:
return data_block
bytewidth = bitwidth // 8
bitswapped = bytearray()
i = 0
while i < len(data_block):
data = int.from_bytes(data_block[i:i+bytewidth], byteorder='big', signed=False)
b = '{:0{width}b}'.format(data, width=bitwidth)
bitswapped.extend(int(b[::-1], 2).to_bytes(bytewidth, byteorder='big'))
i = i + bytewidth
return bytes(bitswapped)
def convert(ifile, ofile):
# Open the image and convert it to 1-bit mode (black & white)
im = Image.open(ifile).transpose(Image.Transpose.FLIP_LEFT_RIGHT)
# im = Image.open(ifile)
im = im.convert("1") # pixels will be either 0 (black) or 255 (white)
# Get pixel data in row-major order
pixels = list(im.getdata())
packed = []
current = 0
count = 0
# Process each pixel: assign bit value 1 for white (255) and 0 for black (0)
for p in pixels:
bit = 0 if p else 1
# Place the bit in the current 32-bit integer at the position given by count
current |= (bit << (31 - count))
count += 1
if count == 32:
packed.append(current)
current = 0
count = 0
# If there are remaining pixels that do not fill up a complete 32-bit word,
# append the last partially-filled integer.
if count > 0:
packed.append(current)
with open(ofile, "w") as output:
output.write("#![cfg_attr(rustfmt, rustfmt_skip)]\n")
output.write("pub const BITMAP: [u32; 512] = [\n")
for index in range(512 // 4):
output.write(" 0x{:08x}, 0x{:08x}, 0x{:08x}, 0x{:08x},\n"
.format(packed[index * 4 + 3], packed[index * 4 + 2], packed[index * 4 + 1], packed[index * 4 + 0]))
output.write("\n];\n")
def main():
parser = argparse.ArgumentParser(description="Convert BMP to rust header file")
parser.add_argument(
"-f", "--file", required=False, help="filename to process", type=str, default="libs/ux-api/src/bitmaps/test1.png"
)
parser.add_argument(
"-o", "--output-file", required=False, help="name of output Rust file", type=str, default="test1.rs"
)
args = parser.parse_args()
ifile = args.file
convert(ifile, args.output_file)
if __name__ == "__main__":
main()

View file

@ -0,0 +1,91 @@
use bao1x_hal::acram::OneWayCounter;
use utralib::*;
use ux_api::minigfx::FrameBuffer;
// build with `cargo xtask bao1x-baremetal-baosec --loader-feature factory-utils`
pub fn pddb_erase() {
crate::println!("entering pddb_erase");
let one_way = OneWayCounter::new();
while one_way.get_decoded::<bao1x_api::BootWaitCoding>().expect("couldn't fetch flag")
!= bao1x_api::BootWaitCoding::Enable
{
one_way.inc_coded::<bao1x_api::BootWaitCoding>().unwrap();
}
// setup all the board pins to a known state
let iox = Iox::new(utra::iox::HW_IOX_BASE as *mut u32);
bao1x_hal::board::setup_display_pins(&iox);
bao1x_hal::board::setup_memory_pins(&iox);
bao1x_hal::board::setup_oled_power_pin(&iox);
// this routine is used to initialize baosec products - sets the board type and
// erases the off-chip FLASH
use bao1x_api::baosec::PDDB_ORIGIN;
use bao1x_hal::{
board::SPINOR_BULK_ERASE_SIZE,
ifram::IframRange,
iox::Iox,
udma::{Spim, *},
};
let perclk = 100_000_000;
let udma_global = GlobalConfig::new();
// setup the I/O pins
let channel = bao1x_hal::board::setup_memory_pins(&iox);
udma_global.clock_on(bao1x_api::PeriphId::from(channel));
// safety: this is safe because clocks have been set up
let mut flash_spim = unsafe {
Spim::new_with_ifram(
channel,
// has to be half the clock frequency reaching the block, but
// run it as fast
// as we can run perclk
perclk / 4,
perclk / 2,
SpimClkPol::LeadingEdgeRise,
SpimClkPha::CaptureOnLeading,
SpimCs::Cs0,
0,
0,
None,
256 + 16, /* just enough space to send commands + programming
* page */
4096,
Some(6),
Some(SpimMode::Standard), // guess Standard
IframRange::from_raw_parts(
bao1x_hal::board::SPIM_FLASH_IFRAM_ADDR,
bao1x_hal::board::SPIM_FLASH_IFRAM_ADDR,
4096 * 2,
),
)
};
flash_spim.identify_flash_reset_qpi();
let flash_id = flash_spim.mem_read_id_flash();
crate::println!("flash ID (init): {:x}", flash_id);
if !bao1x_api::SPI_FLASH_IDS.contains(&(flash_id & 0xFF_FF_FF)) {
return;
}
let pddb_erase_len = SPINOR_BULK_ERASE_SIZE as usize * 2;
for addr in (PDDB_ORIGIN..PDDB_ORIGIN + pddb_erase_len).step_by(SPINOR_BULK_ERASE_SIZE as usize) {
crate::println!(" {:x}...", addr);
flash_spim.flash_erase_block(addr, SPINOR_BULK_ERASE_SIZE as usize);
}
crate::println!("...done!");
let mut iox = Iox::new(utra::iox::HW_IOX_BASE as *mut u32);
// redraw or show the boot logo - depending on how boot1 went, we may or may not have it already
let mut udma_global = GlobalConfig::new();
let mut sh1107 = bao1x_hal::sh1107::Oled128x128::new(
bao1x_hal::sh1107::MainThreadToken::new(),
perclk,
&mut iox,
&mut udma_global,
);
sh1107.init().ok();
sh1107.buffer_mut().fill(0xFFFF_FFFF);
sh1107.blit_screen(&crate::platform::bao1x::bitmaps::factory_mode::BITMAP);
sh1107.draw().ok();
crate::println!("leaving pddb_erase");
}