aboutsummaryrefslogtreecommitdiff
path: root/embassy-boot/stm32/src/lib.rs
diff options
context:
space:
mode:
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();