forked from M-Labs/artiq
1
0
Fork 0

config: impl flashing over mgmt

This commit is contained in:
occheung 2024-08-26 17:37:32 +08:00
parent 378d962edb
commit 86f692fe7b
1 changed files with 32 additions and 5 deletions

View File

@ -259,12 +259,39 @@ mod imp {
} }
pub fn write(key: &str, value: &[u8]) -> Result<(), Error> { pub fn write(key: &str, value: &[u8]) -> Result<(), Error> {
match append(key, value) { fn flash_binary(origin: usize, payload: &[u8]) {
Err(Error::SpaceExhausted) => { let mut offset = 0;
compact()?; while offset < payload.len() {
append(key, value) 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
} }
} }