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,7 +259,33 @@ mod imp {
}
pub fn write(key: &str, value: &[u8]) -> Result<(), Error> {
match 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)
@ -267,6 +293,7 @@ mod imp {
res => res
}
}
}
pub fn write_int(key: &str, value: u32) -> Result<(), Error> {
let mut buf = [0; 16];