Refactor firmware updater

* Allow manipulating state without accessing DFU partition.
* Provide aligned buffer when creating updater to reduce potential wrong parameters passed.
This commit is contained in:
Ulf Lilleengen
2023-08-03 20:56:04 +02:00
parent a40daa923b
commit a34331ae5f
16 changed files with 307 additions and 255 deletions

View File

@ -31,17 +31,17 @@ async fn main(_spawner: Spawner) {
led.set_high();
let config = FirmwareUpdaterConfig::from_linkerfile(&flash);
let mut updater = FirmwareUpdater::new(config);
let mut magic = AlignedBuffer([0; WRITE_SIZE]);
let mut updater = FirmwareUpdater::new(config, &mut magic.0);
button.wait_for_falling_edge().await;
let mut offset = 0;
let mut magic = AlignedBuffer([0; WRITE_SIZE]);
for chunk in APP_B.chunks(2048) {
let mut buf: [u8; 2048] = [0; 2048];
buf[..chunk.len()].copy_from_slice(chunk);
updater.write_firmware(magic.as_mut(), offset, &buf).await.unwrap();
updater.write_firmware(offset, &buf).await.unwrap();
offset += chunk.len();
}
updater.mark_updated(magic.as_mut()).await.unwrap();
updater.mark_updated().await.unwrap();
led.set_low();
cortex_m::peripheral::SCB::sys_reset();
}