diff options
| author | Rasmus Melchior Jacobsen <[email protected]> | 2023-05-30 13:57:19 +0200 |
|---|---|---|
| committer | Rasmus Melchior Jacobsen <[email protected]> | 2023-05-30 13:57:19 +0200 |
| commit | 887ecef3690b55234e640ae16d33a2d79a822bf0 (patch) | |
| tree | 403aaf475b5f17cb3a5c27803c566a099efa3ffc /embassy-boot | |
| parent | 24dee870a862d16fa2dc9be13d3f10dc3941b54b (diff) | |
Align stm32
Diffstat (limited to 'embassy-boot')
| -rw-r--r-- | embassy-boot/stm32/src/lib.rs | 70 |
1 files changed, 17 insertions, 53 deletions
diff --git a/embassy-boot/stm32/src/lib.rs b/embassy-boot/stm32/src/lib.rs index ccf136c74..b47b2db43 100644 --- a/embassy-boot/stm32/src/lib.rs +++ b/embassy-boot/stm32/src/lib.rs | |||
| @@ -3,30 +3,34 @@ | |||
| 3 | #![doc = include_str!("../README.md")] | 3 | #![doc = include_str!("../README.md")] |
| 4 | mod fmt; | 4 | mod fmt; |
| 5 | 5 | ||
| 6 | pub use embassy_boot::{AlignedBuffer, BootFlash, FirmwareUpdater, FlashConfig, Partition, SingleFlashConfig, State}; | 6 | #[cfg(feature = "nightly")] |
| 7 | pub use embassy_boot::FirmwareUpdater; | ||
| 8 | pub use embassy_boot::{AlignedBuffer, BlockingFirmwareUpdater, BootLoaderConfig, FirmwareUpdaterConfig, State}; | ||
| 9 | use embedded_storage::nor_flash::NorFlash; | ||
| 7 | 10 | ||
| 8 | /// A bootloader for STM32 devices. | 11 | /// A bootloader for STM32 devices. |
| 9 | pub struct BootLoader<const BUFFER_SIZE: usize> { | 12 | pub struct BootLoader<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash, const BUFFER_SIZE: usize> { |
| 10 | boot: embassy_boot::BootLoader, | 13 | boot: embassy_boot::BootLoader<ACTIVE, DFU, STATE>, |
| 11 | aligned_buf: AlignedBuffer<BUFFER_SIZE>, | 14 | aligned_buf: AlignedBuffer<BUFFER_SIZE>, |
| 12 | } | 15 | } |
| 13 | 16 | ||
| 14 | impl<const BUFFER_SIZE: usize> BootLoader<BUFFER_SIZE> { | 17 | impl<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash, const BUFFER_SIZE: usize> |
| 18 | BootLoader<ACTIVE, DFU, STATE, BUFFER_SIZE> | ||
| 19 | { | ||
| 15 | /// Create a new bootloader instance using the supplied partitions for active, dfu and state. | 20 | /// Create a new bootloader instance using the supplied partitions for active, dfu and state. |
| 16 | pub fn new(active: Partition, dfu: Partition, state: Partition) -> Self { | 21 | pub fn new(config: BootLoaderConfig<ACTIVE, DFU, STATE>) -> Self { |
| 17 | Self { | 22 | Self { |
| 18 | boot: embassy_boot::BootLoader::new(active, dfu, state), | 23 | boot: embassy_boot::BootLoader::new(config), |
| 19 | aligned_buf: AlignedBuffer([0; BUFFER_SIZE]), | 24 | aligned_buf: AlignedBuffer([0; BUFFER_SIZE]), |
| 20 | } | 25 | } |
| 21 | } | 26 | } |
| 22 | 27 | ||
| 23 | /// Inspect the bootloader state and perform actions required before booting, such as swapping | 28 | /// Inspect the bootloader state and perform actions required before booting, such as swapping |
| 24 | /// firmware. | 29 | /// firmware. |
| 25 | pub fn prepare<F: FlashConfig>(&mut self, flash: &mut F) -> usize { | 30 | pub fn prepare(&mut self) { |
| 26 | match self.boot.prepare_boot(flash, self.aligned_buf.as_mut()) { | 31 | self.boot |
| 27 | Ok(_) => embassy_stm32::flash::FLASH_BASE + self.boot.boot_address(), | 32 | .prepare_boot(self.aligned_buf.as_mut()) |
| 28 | Err(_) => panic!("boot prepare error!"), | 33 | .expect("Boot prepare error"); |
| 29 | } | ||
| 30 | } | 34 | } |
| 31 | 35 | ||
| 32 | /// Boots the application. | 36 | /// Boots the application. |
| @@ -34,54 +38,14 @@ impl<const BUFFER_SIZE: usize> BootLoader<BUFFER_SIZE> { | |||
| 34 | /// # Safety | 38 | /// # Safety |
| 35 | /// | 39 | /// |
| 36 | /// This modifies the stack pointer and reset vector and will run code placed in the active partition. | 40 | /// This modifies the stack pointer and reset vector and will run code placed in the active partition. |
| 37 | pub unsafe fn load(&mut self, start: usize) -> ! { | 41 | pub unsafe fn load(&mut self, start: u32) -> ! { |
| 38 | trace!("Loading app at 0x{:x}", start); | 42 | trace!("Loading app at 0x{:x}", start); |
| 39 | #[allow(unused_mut)] | 43 | #[allow(unused_mut)] |
| 40 | let mut p = cortex_m::Peripherals::steal(); | 44 | let mut p = cortex_m::Peripherals::steal(); |
| 41 | #[cfg(not(armv6m))] | 45 | #[cfg(not(armv6m))] |
| 42 | p.SCB.invalidate_icache(); | 46 | p.SCB.invalidate_icache(); |
| 43 | p.SCB.vtor.write(start as u32); | 47 | p.SCB.vtor.write(start); |
| 44 | 48 | ||
| 45 | cortex_m::asm::bootload(start as *const u32) | 49 | cortex_m::asm::bootload(start as *const u32) |
| 46 | } | 50 | } |
| 47 | } | 51 | } |
| 48 | |||
| 49 | #[cfg(target_os = "none")] | ||
| 50 | impl<const BUFFER_SIZE: usize> Default for BootLoader<BUFFER_SIZE> { | ||
| 51 | /// Create a new bootloader instance using parameters from linker script | ||
| 52 | fn default() -> Self { | ||
| 53 | extern "C" { | ||
| 54 | static __bootloader_state_start: u32; | ||
| 55 | static __bootloader_state_end: u32; | ||
| 56 | static __bootloader_active_start: u32; | ||
| 57 | static __bootloader_active_end: u32; | ||
| 58 | static __bootloader_dfu_start: u32; | ||
| 59 | static __bootloader_dfu_end: u32; | ||
| 60 | } | ||
| 61 | |||
| 62 | let active = unsafe { | ||
| 63 | Partition::new( | ||
| 64 | &__bootloader_active_start as *const u32 as u32, | ||
| 65 | &__bootloader_active_end as *const u32 as u32, | ||
| 66 | ) | ||
| 67 | }; | ||
| 68 | let dfu = unsafe { | ||
| 69 | Partition::new( | ||
| 70 | &__bootloader_dfu_start as *const u32 as u32, | ||
| 71 | &__bootloader_dfu_end as *const u32 as u32, | ||
| 72 | ) | ||
| 73 | }; | ||
| 74 | let state = unsafe { | ||
| 75 | Partition::new( | ||
| 76 | &__bootloader_state_start as *const u32 as u32, | ||
| 77 | &__bootloader_state_end as *const u32 as u32, | ||
| 78 | ) | ||
| 79 | }; | ||
| 80 | |||
| 81 | trace!("ACTIVE: 0x{:x} - 0x{:x}", active.from, active.to); | ||
| 82 | trace!("DFU: 0x{:x} - 0x{:x}", dfu.from, dfu.to); | ||
| 83 | trace!("STATE: 0x{:x} - 0x{:x}", state.from, state.to); | ||
| 84 | |||
| 85 | Self::new(active, dfu, state) | ||
| 86 | } | ||
| 87 | } | ||
