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