aboutsummaryrefslogtreecommitdiff
path: root/embassy-boot/nrf/src
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2023-08-11 19:47:24 +0200
committerUlf Lilleengen <[email protected]>2023-08-11 20:58:31 +0200
commit55ff397c0cde8a04c41cfc228645c3fd33383cd1 (patch)
treeb73e5fee9027422cb121b892e6d467fd0f73cfe7 /embassy-boot/nrf/src
parentc1da2c0219667085124c47d8059ffbf077adaf9d (diff)
boot: release flash after prepare and refactor api
This refactoring of the chip specific bootloader creates the internal boot instance and aligned buffer in the prepare stage, so that they are automatically dropped after. This unlocks a use case where peripherals owning the flash need to be Drop'ed before load() happens.
Diffstat (limited to 'embassy-boot/nrf/src')
-rw-r--r--embassy-boot/nrf/src/lib.rs37
1 files changed, 12 insertions, 25 deletions
diff --git a/embassy-boot/nrf/src/lib.rs b/embassy-boot/nrf/src/lib.rs
index df94819fc..b9d86eb17 100644
--- a/embassy-boot/nrf/src/lib.rs
+++ b/embassy-boot/nrf/src/lib.rs
@@ -14,28 +14,17 @@ use embassy_nrf::wdt;
14use embedded_storage::nor_flash::{ErrorType, NorFlash, ReadNorFlash}; 14use embedded_storage::nor_flash::{ErrorType, NorFlash, ReadNorFlash};
15 15
16/// A bootloader for nRF devices. 16/// A bootloader for nRF devices.
17pub struct BootLoader<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash, const BUFFER_SIZE: usize = PAGE_SIZE> { 17pub struct BootLoader<const BUFFER_SIZE: usize = PAGE_SIZE>;
18 boot: embassy_boot::BootLoader<ACTIVE, DFU, STATE>, 18
19 aligned_buf: AlignedBuffer<BUFFER_SIZE>, 19impl<const BUFFER_SIZE: usize> BootLoader<BUFFER_SIZE> {
20} 20 /// Inspect the bootloader state and perform actions required before booting, such as swapping firmware.
21 21 pub fn prepare<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash>(
22impl<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash, const BUFFER_SIZE: usize> 22 config: BootLoaderConfig<ACTIVE, DFU, STATE>,
23 BootLoader<ACTIVE, DFU, STATE, BUFFER_SIZE> 23 ) -> Self {
24{ 24 let mut aligned_buf = AlignedBuffer([0; BUFFER_SIZE]);
25 /// Create a new bootloader instance using the supplied partitions for active, dfu and state. 25 let mut boot = embassy_boot::BootLoader::new(config);
26 pub fn new(config: BootLoaderConfig<ACTIVE, DFU, STATE>) -> Self { 26 boot.prepare_boot(&mut aligned_buf.0).expect("Boot prepare error");
27 Self { 27 Self
28 boot: embassy_boot::BootLoader::new(config),
29 aligned_buf: AlignedBuffer([0; BUFFER_SIZE]),
30 }
31 }
32
33 /// Inspect the bootloader state and perform actions required before booting, such as swapping
34 /// firmware.
35 pub fn prepare(&mut self) {
36 self.boot
37 .prepare_boot(&mut self.aligned_buf.0)
38 .expect("Boot prepare error");
39 } 28 }
40 29
41 /// Boots the application without softdevice mechanisms. 30 /// Boots the application without softdevice mechanisms.
@@ -45,8 +34,6 @@ impl<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash, const BUFFER_SIZE: usize>
45 /// This modifies the stack pointer and reset vector and will run code placed in the active partition. 34 /// This modifies the stack pointer and reset vector and will run code placed in the active partition.
46 #[cfg(not(feature = "softdevice"))] 35 #[cfg(not(feature = "softdevice"))]
47 pub unsafe fn load(self, start: u32) -> ! { 36 pub unsafe fn load(self, start: u32) -> ! {
48 core::mem::drop(self.boot);
49
50 let mut p = cortex_m::Peripherals::steal(); 37 let mut p = cortex_m::Peripherals::steal();
51 p.SCB.invalidate_icache(); 38 p.SCB.invalidate_icache();
52 p.SCB.vtor.write(start); 39 p.SCB.vtor.write(start);
@@ -59,7 +46,7 @@ impl<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash, const BUFFER_SIZE: usize>
59 /// 46 ///
60 /// This modifies the stack pointer and reset vector and will run code placed in the active partition. 47 /// This modifies the stack pointer and reset vector and will run code placed in the active partition.
61 #[cfg(feature = "softdevice")] 48 #[cfg(feature = "softdevice")]
62 pub unsafe fn load(&mut self, _app: u32) -> ! { 49 pub unsafe fn load(self, _app: u32) -> ! {
63 use nrf_softdevice_mbr as mbr; 50 use nrf_softdevice_mbr as mbr;
64 const NRF_SUCCESS: u32 = 0; 51 const NRF_SUCCESS: u32 = 0;
65 52