aboutsummaryrefslogtreecommitdiff
path: root/embassy-boot/rp/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/rp/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/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();