aboutsummaryrefslogtreecommitdiff
path: root/embassy-boot/stm32/src/lib.rs
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/stm32/src/lib.rs
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/stm32/src/lib.rs')
-rw-r--r--embassy-boot/stm32/src/lib.rs33
1 files changed, 10 insertions, 23 deletions
diff --git a/embassy-boot/stm32/src/lib.rs b/embassy-boot/stm32/src/lib.rs
index 25f029423..c6350c495 100644
--- a/embassy-boot/stm32/src/lib.rs
+++ b/embassy-boot/stm32/src/lib.rs
@@ -11,28 +11,17 @@ pub use embassy_boot::{FirmwareState, FirmwareUpdater};
11use embedded_storage::nor_flash::NorFlash; 11use embedded_storage::nor_flash::NorFlash;
12 12
13/// A bootloader for STM32 devices. 13/// A bootloader for STM32 devices.
14pub struct BootLoader<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash, const BUFFER_SIZE: usize> { 14pub struct BootLoader;
15 boot: embassy_boot::BootLoader<ACTIVE, DFU, STATE>,
16 aligned_buf: AlignedBuffer<BUFFER_SIZE>,
17}
18
19impl<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash, const BUFFER_SIZE: usize>
20 BootLoader<ACTIVE, DFU, STATE, BUFFER_SIZE>
21{
22 /// Create a new bootloader instance using the supplied partitions for active, dfu and state.
23 pub fn new(config: BootLoaderConfig<ACTIVE, DFU, STATE>) -> Self {
24 Self {
25 boot: embassy_boot::BootLoader::new(config),
26 aligned_buf: AlignedBuffer([0; BUFFER_SIZE]),
27 }
28 }
29 15
30 /// Inspect the bootloader state and perform actions required before booting, such as swapping 16impl BootLoader {
31 /// firmware. 17 /// Inspect the bootloader state and perform actions required before booting, such as swapping firmware
32 pub fn prepare(&mut self) { 18 pub fn prepare<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash, const BUFFER_SIZE: usize>(
33 self.boot 19 config: BootLoaderConfig<ACTIVE, DFU, STATE>,
34 .prepare_boot(self.aligned_buf.as_mut()) 20 ) -> Self {
35 .expect("Boot prepare error"); 21 let mut aligned_buf = AlignedBuffer([0; BUFFER_SIZE]);
22 let mut boot = embassy_boot::BootLoader::new(config);
23 boot.prepare_boot(aligned_buf.as_mut()).expect("Boot prepare error");
24 Self
36 } 25 }
37 26
38 /// Boots the application. 27 /// Boots the application.
@@ -41,8 +30,6 @@ impl<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash, const BUFFER_SIZE: usize>
41 /// 30 ///
42 /// This modifies the stack pointer and reset vector and will run code placed in the active partition. 31 /// This modifies the stack pointer and reset vector and will run code placed in the active partition.
43 pub unsafe fn load(self, start: u32) -> ! { 32 pub unsafe fn load(self, start: u32) -> ! {
44 core::mem::drop(self.boot);
45
46 trace!("Loading app at 0x{:x}", start); 33 trace!("Loading app at 0x{:x}", start);
47 #[allow(unused_mut)] 34 #[allow(unused_mut)]
48 let mut p = cortex_m::Peripherals::steal(); 35 let mut p = cortex_m::Peripherals::steal();