diff options
| author | Ulf Lilleengen <[email protected]> | 2023-08-03 20:56:04 +0200 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2023-08-06 19:46:53 +0200 |
| commit | a34331ae5fbf76a61bb2f65dbb13af4d34fcb176 (patch) | |
| tree | eddfa2b200b206923a91b9aae1474156c04e40fa /examples/boot/application/nrf/src/bin/a.rs | |
| parent | a40daa923ba031b543ce402f8bd83c2ec41329d8 (diff) | |
Refactor firmware updater
* Allow manipulating state without accessing DFU partition.
* Provide aligned buffer when creating updater to reduce potential wrong parameters passed.
Diffstat (limited to 'examples/boot/application/nrf/src/bin/a.rs')
| -rw-r--r-- | examples/boot/application/nrf/src/bin/a.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/examples/boot/application/nrf/src/bin/a.rs b/examples/boot/application/nrf/src/bin/a.rs index 021d77f3b..8b510ed35 100644 --- a/examples/boot/application/nrf/src/bin/a.rs +++ b/examples/boot/application/nrf/src/bin/a.rs | |||
| @@ -52,20 +52,20 @@ async fn main(_spawner: Spawner) { | |||
| 52 | let nvmc = Mutex::new(BlockingAsync::new(nvmc)); | 52 | let nvmc = Mutex::new(BlockingAsync::new(nvmc)); |
| 53 | 53 | ||
| 54 | let config = FirmwareUpdaterConfig::from_linkerfile(&nvmc); | 54 | let config = FirmwareUpdaterConfig::from_linkerfile(&nvmc); |
| 55 | let mut updater = FirmwareUpdater::new(config); | 55 | let mut magic = [0; 4]; |
| 56 | let mut updater = FirmwareUpdater::new(config, &mut magic); | ||
| 56 | loop { | 57 | loop { |
| 57 | led.set_low(); | 58 | led.set_low(); |
| 58 | button.wait_for_any_edge().await; | 59 | button.wait_for_any_edge().await; |
| 59 | if button.is_low() { | 60 | if button.is_low() { |
| 60 | let mut offset = 0; | 61 | let mut offset = 0; |
| 61 | let mut magic = [0; 4]; | ||
| 62 | for chunk in APP_B.chunks(4096) { | 62 | for chunk in APP_B.chunks(4096) { |
| 63 | let mut buf: [u8; 4096] = [0; 4096]; | 63 | let mut buf: [u8; 4096] = [0; 4096]; |
| 64 | buf[..chunk.len()].copy_from_slice(chunk); | 64 | buf[..chunk.len()].copy_from_slice(chunk); |
| 65 | updater.write_firmware(&mut magic, offset, &buf).await.unwrap(); | 65 | updater.write_firmware(offset, &buf).await.unwrap(); |
| 66 | offset += chunk.len(); | 66 | offset += chunk.len(); |
| 67 | } | 67 | } |
| 68 | updater.mark_updated(&mut magic).await.unwrap(); | 68 | updater.mark_updated().await.unwrap(); |
| 69 | led.set_high(); | 69 | led.set_high(); |
| 70 | cortex_m::peripheral::SCB::sys_reset(); | 70 | cortex_m::peripheral::SCB::sys_reset(); |
| 71 | } | 71 | } |
