summaryrefslogtreecommitdiff
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.rs35
1 files changed, 20 insertions, 15 deletions
diff --git a/embassy-boot/stm32/src/lib.rs b/embassy-boot/stm32/src/lib.rs
index 5a4f2d05..39f08051 100644
--- a/embassy-boot/stm32/src/lib.rs
+++ b/embassy-boot/stm32/src/lib.rs
@@ -1,19 +1,20 @@
#![no_std]
#![feature(generic_associated_types)]
#![feature(type_alias_impl_trait)]
-#![allow(incomplete_features)]
-#![feature(generic_const_exprs)]
-
+#![warn(missing_docs)]
+#![doc = include_str!("../../README.md")]
mod fmt;
-pub use embassy_boot::{FirmwareUpdater, FlashConfig, FlashProvider, Partition, SingleFlashProvider, State};
-use embedded_storage::nor_flash::NorFlash;
+pub use embassy_boot::{AlignedBuffer, BootFlash, FirmwareUpdater, FlashConfig, Partition, SingleFlashConfig, State};
-pub struct BootLoader<const PAGE_SIZE: usize> {
- boot: embassy_boot::BootLoader<PAGE_SIZE>,
+/// A bootloader for STM32 devices.
+pub struct BootLoader<const PAGE_SIZE: usize, const WRITE_SIZE: usize> {
+ boot: embassy_boot::BootLoader,
+ magic: AlignedBuffer<WRITE_SIZE>,
+ page: AlignedBuffer<PAGE_SIZE>,
}
-impl<const PAGE_SIZE: usize> BootLoader<PAGE_SIZE> {
+impl<const PAGE_SIZE: usize, const WRITE_SIZE: usize> BootLoader<PAGE_SIZE, WRITE_SIZE> {
/// Create a new bootloader instance using parameters from linker script
pub fn default() -> Self {
extern "C" {
@@ -55,21 +56,25 @@ impl<const PAGE_SIZE: usize> BootLoader<PAGE_SIZE> {
pub fn new(active: Partition, dfu: Partition, state: Partition) -> Self {
Self {
boot: embassy_boot::BootLoader::new(active, dfu, state),
+ magic: AlignedBuffer([0; WRITE_SIZE]),
+ page: AlignedBuffer([0; PAGE_SIZE]),
}
}
- /// Boots the application
- pub fn prepare<F: FlashProvider>(&mut self, flash: &mut F) -> usize
- where
- [(); <<F as FlashProvider>::STATE as FlashConfig>::FLASH::WRITE_SIZE]:,
- [(); <<F as FlashProvider>::ACTIVE as FlashConfig>::FLASH::ERASE_SIZE]:,
- {
- match self.boot.prepare_boot(flash) {
+ /// Inspect the bootloader state and perform actions required before booting, such as swapping
+ /// firmware.
+ pub fn prepare<F: FlashConfig>(&mut self, flash: &mut F) -> usize {
+ match self.boot.prepare_boot(flash, self.magic.as_mut(), self.page.as_mut()) {
Ok(_) => embassy_stm32::flash::FLASH_BASE + self.boot.boot_address(),
Err(_) => panic!("boot prepare error!"),
}
}
+ /// Boots the application.
+ ///
+ /// # Safety
+ ///
+ /// This modifies the stack pointer and reset vector and will run code placed in the active partition.
pub unsafe fn load(&mut self, start: usize) -> ! {
trace!("Loading app at 0x{:x}", start);
#[allow(unused_mut)]