config: impl flashing over mgmt

This commit is contained in:
occheung 2024-08-26 17:37:32 +08:00
parent 378d962edb
commit 86f692fe7b

View File

@ -259,12 +259,39 @@ mod imp {
}
pub fn write(key: &str, value: &[u8]) -> Result<(), Error> {
match append(key, value) {
Err(Error::SpaceExhausted) => {
compact()?;
append(key, value)
fn flash_binary(origin: usize, payload: &[u8]) {
let mut offset = 0;
while offset < payload.len() {
unsafe {
spiflash::erase_sector(origin + offset);
}
offset += spiflash::SECTOR_SIZE;
}
unsafe {
spiflash::write(origin, payload);
}
}
match key {
"gateware" => {
flash_binary(0, value);
Ok(())
}
"bootloader" => {
flash_binary(::mem::ROM_BASE, value);
Ok(())
}
"firmware" => {
flash_binary(::mem::FLASH_BOOT_ADDRESS, value);
Ok(())
}
_ => match append(key, value) {
Err(Error::SpaceExhausted) => {
compact()?;
append(key, value)
}
res => res
}
res => res
}
}