diff options
32 files changed, 320 insertions, 71 deletions
| @@ -194,7 +194,8 @@ cargo batch \ | |||
| 194 | --- build --release --manifest-path examples/boot/bootloader/nrf/Cargo.toml --target thumbv8m.main-none-eabihf --features embassy-nrf/nrf9160-ns \ | 194 | --- build --release --manifest-path examples/boot/bootloader/nrf/Cargo.toml --target thumbv8m.main-none-eabihf --features embassy-nrf/nrf9160-ns \ |
| 195 | --- build --release --manifest-path examples/boot/bootloader/rp/Cargo.toml --target thumbv6m-none-eabi \ | 195 | --- build --release --manifest-path examples/boot/bootloader/rp/Cargo.toml --target thumbv6m-none-eabi \ |
| 196 | --- build --release --manifest-path examples/boot/bootloader/stm32/Cargo.toml --target thumbv7em-none-eabi --features embassy-stm32/stm32wl55jc-cm4 \ | 196 | --- build --release --manifest-path examples/boot/bootloader/stm32/Cargo.toml --target thumbv7em-none-eabi --features embassy-stm32/stm32wl55jc-cm4 \ |
| 197 | --- build --release --manifest-path examples/boot/bootloader/stm32wb-dfu/Cargo.toml --target thumbv7em-none-eabihf \ | 197 | --- build --release --manifest-path examples/boot/bootloader/stm32wb-dfu/Cargo.toml --target thumbv7em-none-eabihf --features embassy-stm32/stm32wb55rg \ |
| 198 | --- build --release --manifest-path examples/boot/bootloader/stm32-dual-bank/Cargo.toml --target thumbv7em-none-eabihf --features embassy-stm32/stm32h747xi-cm7 \ | ||
| 198 | --- build --release --manifest-path examples/wasm/Cargo.toml --target wasm32-unknown-unknown --out-dir out/examples/wasm \ | 199 | --- build --release --manifest-path examples/wasm/Cargo.toml --target wasm32-unknown-unknown --out-dir out/examples/wasm \ |
| 199 | --- build --release --manifest-path tests/stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32f103c8 --out-dir out/tests/stm32f103c8 \ | 200 | --- build --release --manifest-path tests/stm32/Cargo.toml --target thumbv7m-none-eabi --features stm32f103c8 --out-dir out/tests/stm32f103c8 \ |
| 200 | --- build --release --manifest-path tests/stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi --out-dir out/tests/stm32f429zi \ | 201 | --- build --release --manifest-path tests/stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f429zi --out-dir out/tests/stm32f429zi \ |
diff --git a/embassy-boot/src/boot_loader.rs b/embassy-boot/src/boot_loader.rs index e568001bc..ca1a1b10c 100644 --- a/embassy-boot/src/boot_loader.rs +++ b/embassy-boot/src/boot_loader.rs | |||
| @@ -49,16 +49,51 @@ pub struct BootLoaderConfig<ACTIVE, DFU, STATE> { | |||
| 49 | pub state: STATE, | 49 | pub state: STATE, |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | impl<'a, FLASH: NorFlash> | 52 | impl<'a, ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash> |
| 53 | BootLoaderConfig< | 53 | BootLoaderConfig< |
| 54 | BlockingPartition<'a, NoopRawMutex, FLASH>, | 54 | BlockingPartition<'a, NoopRawMutex, ACTIVE>, |
| 55 | BlockingPartition<'a, NoopRawMutex, FLASH>, | 55 | BlockingPartition<'a, NoopRawMutex, DFU>, |
| 56 | BlockingPartition<'a, NoopRawMutex, FLASH>, | 56 | BlockingPartition<'a, NoopRawMutex, STATE>, |
| 57 | > | 57 | > |
| 58 | { | 58 | { |
| 59 | /// Create a bootloader config from the flash and address symbols defined in the linkerfile | 59 | /// Constructs a `BootLoaderConfig` instance from flash memory and address symbols defined in the linker file. |
| 60 | /// | ||
| 61 | /// This method initializes `BlockingPartition` instances for the active, DFU (Device Firmware Update), | ||
| 62 | /// and state partitions, leveraging start and end addresses specified by the linker. These partitions | ||
| 63 | /// are critical for managing firmware updates, application state, and boot operations within the bootloader. | ||
| 64 | /// | ||
| 65 | /// # Parameters | ||
| 66 | /// - `active_flash`: A reference to a mutex-protected `RefCell` for the active partition's flash interface. | ||
| 67 | /// - `dfu_flash`: A reference to a mutex-protected `RefCell` for the DFU partition's flash interface. | ||
| 68 | /// - `state_flash`: A reference to a mutex-protected `RefCell` for the state partition's flash interface. | ||
| 69 | /// | ||
| 70 | /// # Safety | ||
| 71 | /// The method contains `unsafe` blocks for dereferencing raw pointers that represent the start and end addresses | ||
| 72 | /// of the bootloader's partitions in flash memory. It is crucial that these addresses are accurately defined | ||
| 73 | /// in the memory.x file to prevent undefined behavior. | ||
| 74 | /// | ||
| 75 | /// The caller must ensure that the memory regions defined by these symbols are valid and that the flash memory | ||
| 76 | /// interfaces provided are compatible with these regions. | ||
| 77 | /// | ||
| 78 | /// # Returns | ||
| 79 | /// A `BootLoaderConfig` instance with `BlockingPartition` instances for the active, DFU, and state partitions. | ||
| 80 | /// | ||
| 81 | /// # Example | ||
| 82 | /// ```ignore | ||
| 83 | /// // Assume `active_flash`, `dfu_flash`, and `state_flash` all share the same flash memory interface. | ||
| 84 | /// let layout = Flash::new_blocking(p.FLASH).into_blocking_regions(); | ||
| 85 | /// let flash = Mutex::new(RefCell::new(layout.bank1_region)); | ||
| 86 | /// | ||
| 87 | /// let config = BootLoaderConfig::from_linkerfile_blocking(&flash, &flash, &flash); | ||
| 88 | /// // `config` can now be used to create a `BootLoader` instance for managing boot operations. | ||
| 89 | /// ``` | ||
| 90 | /// Working examples can be found in the bootloader examples folder. | ||
| 60 | // #[cfg(target_os = "none")] | 91 | // #[cfg(target_os = "none")] |
| 61 | pub fn from_linkerfile_blocking(flash: &'a Mutex<NoopRawMutex, RefCell<FLASH>>) -> Self { | 92 | pub fn from_linkerfile_blocking( |
| 93 | active_flash: &'a Mutex<NoopRawMutex, RefCell<ACTIVE>>, | ||
| 94 | dfu_flash: &'a Mutex<NoopRawMutex, RefCell<DFU>>, | ||
| 95 | state_flash: &'a Mutex<NoopRawMutex, RefCell<STATE>>, | ||
| 96 | ) -> Self { | ||
| 62 | extern "C" { | 97 | extern "C" { |
| 63 | static __bootloader_state_start: u32; | 98 | static __bootloader_state_start: u32; |
| 64 | static __bootloader_state_end: u32; | 99 | static __bootloader_state_end: u32; |
| @@ -73,21 +108,21 @@ impl<'a, FLASH: NorFlash> | |||
| 73 | let end = &__bootloader_active_end as *const u32 as u32; | 108 | let end = &__bootloader_active_end as *const u32 as u32; |
| 74 | trace!("ACTIVE: 0x{:x} - 0x{:x}", start, end); | 109 | trace!("ACTIVE: 0x{:x} - 0x{:x}", start, end); |
| 75 | 110 | ||
| 76 | BlockingPartition::new(flash, start, end - start) | 111 | BlockingPartition::new(active_flash, start, end - start) |
| 77 | }; | 112 | }; |
| 78 | let dfu = unsafe { | 113 | let dfu = unsafe { |
| 79 | let start = &__bootloader_dfu_start as *const u32 as u32; | 114 | let start = &__bootloader_dfu_start as *const u32 as u32; |
| 80 | let end = &__bootloader_dfu_end as *const u32 as u32; | 115 | let end = &__bootloader_dfu_end as *const u32 as u32; |
| 81 | trace!("DFU: 0x{:x} - 0x{:x}", start, end); | 116 | trace!("DFU: 0x{:x} - 0x{:x}", start, end); |
| 82 | 117 | ||
| 83 | BlockingPartition::new(flash, start, end - start) | 118 | BlockingPartition::new(dfu_flash, start, end - start) |
| 84 | }; | 119 | }; |
| 85 | let state = unsafe { | 120 | let state = unsafe { |
| 86 | let start = &__bootloader_state_start as *const u32 as u32; | 121 | let start = &__bootloader_state_start as *const u32 as u32; |
| 87 | let end = &__bootloader_state_end as *const u32 as u32; | 122 | let end = &__bootloader_state_end as *const u32 as u32; |
| 88 | trace!("STATE: 0x{:x} - 0x{:x}", start, end); | 123 | trace!("STATE: 0x{:x} - 0x{:x}", start, end); |
| 89 | 124 | ||
| 90 | BlockingPartition::new(flash, start, end - start) | 125 | BlockingPartition::new(state_flash, start, end - start) |
| 91 | }; | 126 | }; |
| 92 | 127 | ||
| 93 | Self { active, dfu, state } | 128 | Self { active, dfu, state } |
diff --git a/embassy-boot/src/firmware_updater/asynch.rs b/embassy-boot/src/firmware_updater/asynch.rs index 2e43e1cc1..668f16f16 100644 --- a/embassy-boot/src/firmware_updater/asynch.rs +++ b/embassy-boot/src/firmware_updater/asynch.rs | |||
| @@ -16,11 +16,14 @@ pub struct FirmwareUpdater<'d, DFU: NorFlash, STATE: NorFlash> { | |||
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | #[cfg(target_os = "none")] | 18 | #[cfg(target_os = "none")] |
| 19 | impl<'a, FLASH: NorFlash> | 19 | impl<'a, DFU: NorFlash, STATE: NorFlash> |
| 20 | FirmwareUpdaterConfig<Partition<'a, NoopRawMutex, FLASH>, Partition<'a, NoopRawMutex, FLASH>> | 20 | FirmwareUpdaterConfig<Partition<'a, NoopRawMutex, DFU>, Partition<'a, NoopRawMutex, STATE>> |
| 21 | { | 21 | { |
| 22 | /// Create a firmware updater config from the flash and address symbols defined in the linkerfile | 22 | /// Create a firmware updater config from the flash and address symbols defined in the linkerfile |
| 23 | pub fn from_linkerfile(flash: &'a embassy_sync::mutex::Mutex<NoopRawMutex, FLASH>) -> Self { | 23 | pub fn from_linkerfile( |
| 24 | dfu_flash: &'a embassy_sync::mutex::Mutex<NoopRawMutex, DFU>, | ||
| 25 | state_flash: &'a embassy_sync::mutex::Mutex<NoopRawMutex, STATE>, | ||
| 26 | ) -> Self { | ||
| 24 | extern "C" { | 27 | extern "C" { |
| 25 | static __bootloader_state_start: u32; | 28 | static __bootloader_state_start: u32; |
| 26 | static __bootloader_state_end: u32; | 29 | static __bootloader_state_end: u32; |
| @@ -33,14 +36,14 @@ impl<'a, FLASH: NorFlash> | |||
| 33 | let end = &__bootloader_dfu_end as *const u32 as u32; | 36 | let end = &__bootloader_dfu_end as *const u32 as u32; |
| 34 | trace!("DFU: 0x{:x} - 0x{:x}", start, end); | 37 | trace!("DFU: 0x{:x} - 0x{:x}", start, end); |
| 35 | 38 | ||
| 36 | Partition::new(flash, start, end - start) | 39 | Partition::new(dfu_flash, start, end - start) |
| 37 | }; | 40 | }; |
| 38 | let state = unsafe { | 41 | let state = unsafe { |
| 39 | let start = &__bootloader_state_start as *const u32 as u32; | 42 | let start = &__bootloader_state_start as *const u32 as u32; |
| 40 | let end = &__bootloader_state_end as *const u32 as u32; | 43 | let end = &__bootloader_state_end as *const u32 as u32; |
| 41 | trace!("STATE: 0x{:x} - 0x{:x}", start, end); | 44 | trace!("STATE: 0x{:x} - 0x{:x}", start, end); |
| 42 | 45 | ||
| 43 | Partition::new(flash, start, end - start) | 46 | Partition::new(state_flash, start, end - start) |
| 44 | }; | 47 | }; |
| 45 | 48 | ||
| 46 | Self { dfu, state } | 49 | Self { dfu, state } |
diff --git a/embassy-boot/src/firmware_updater/blocking.rs b/embassy-boot/src/firmware_updater/blocking.rs index f1368540d..4044871f0 100644 --- a/embassy-boot/src/firmware_updater/blocking.rs +++ b/embassy-boot/src/firmware_updater/blocking.rs | |||
| @@ -16,12 +16,43 @@ pub struct BlockingFirmwareUpdater<'d, DFU: NorFlash, STATE: NorFlash> { | |||
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | #[cfg(target_os = "none")] | 18 | #[cfg(target_os = "none")] |
| 19 | impl<'a, FLASH: NorFlash> | 19 | impl<'a, DFU: NorFlash, STATE: NorFlash> |
| 20 | FirmwareUpdaterConfig<BlockingPartition<'a, NoopRawMutex, FLASH>, BlockingPartition<'a, NoopRawMutex, FLASH>> | 20 | FirmwareUpdaterConfig<BlockingPartition<'a, NoopRawMutex, DFU>, BlockingPartition<'a, NoopRawMutex, STATE>> |
| 21 | { | 21 | { |
| 22 | /// Create a firmware updater config from the flash and address symbols defined in the linkerfile | 22 | /// Constructs a `FirmwareUpdaterConfig` instance from flash memory and address symbols defined in the linker file. |
| 23 | /// | ||
| 24 | /// This method initializes `BlockingPartition` instances for the DFU (Device Firmware Update), and state | ||
| 25 | /// partitions, leveraging start and end addresses specified by the linker. These partitions are critical | ||
| 26 | /// for managing firmware updates, application state, and boot operations within the bootloader. | ||
| 27 | /// | ||
| 28 | /// # Parameters | ||
| 29 | /// - `dfu_flash`: A reference to a mutex-protected `RefCell` for the DFU partition's flash interface. | ||
| 30 | /// - `state_flash`: A reference to a mutex-protected `RefCell` for the state partition's flash interface. | ||
| 31 | /// | ||
| 32 | /// # Safety | ||
| 33 | /// The method contains `unsafe` blocks for dereferencing raw pointers that represent the start and end addresses | ||
| 34 | /// of the bootloader's partitions in flash memory. It is crucial that these addresses are accurately defined | ||
| 35 | /// in the memory.x file to prevent undefined behavior. | ||
| 36 | /// | ||
| 37 | /// The caller must ensure that the memory regions defined by these symbols are valid and that the flash memory | ||
| 38 | /// interfaces provided are compatible with these regions. | ||
| 39 | /// | ||
| 40 | /// # Returns | ||
| 41 | /// A `FirmwareUpdaterConfig` instance with `BlockingPartition` instances for the DFU, and state partitions. | ||
| 42 | /// | ||
| 43 | /// # Example | ||
| 44 | /// ```ignore | ||
| 45 | /// // Assume `dfu_flash`, and `state_flash` share the same flash memory interface. | ||
| 46 | /// let layout = Flash::new_blocking(p.FLASH).into_blocking_regions(); | ||
| 47 | /// let flash = Mutex::new(RefCell::new(layout.bank1_region)); | ||
| 48 | /// | ||
| 49 | /// let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash, &flash); | ||
| 50 | /// // `config` can now be used to create a `FirmwareUpdater` instance for managing boot operations. | ||
| 51 | /// ``` | ||
| 52 | /// Working examples can be found in the bootloader examples folder. | ||
| 23 | pub fn from_linkerfile_blocking( | 53 | pub fn from_linkerfile_blocking( |
| 24 | flash: &'a embassy_sync::blocking_mutex::Mutex<NoopRawMutex, core::cell::RefCell<FLASH>>, | 54 | dfu_flash: &'a embassy_sync::blocking_mutex::Mutex<NoopRawMutex, core::cell::RefCell<DFU>>, |
| 55 | state_flash: &'a embassy_sync::blocking_mutex::Mutex<NoopRawMutex, core::cell::RefCell<STATE>>, | ||
| 25 | ) -> Self { | 56 | ) -> Self { |
| 26 | extern "C" { | 57 | extern "C" { |
| 27 | static __bootloader_state_start: u32; | 58 | static __bootloader_state_start: u32; |
| @@ -35,14 +66,14 @@ impl<'a, FLASH: NorFlash> | |||
| 35 | let end = &__bootloader_dfu_end as *const u32 as u32; | 66 | let end = &__bootloader_dfu_end as *const u32 as u32; |
| 36 | trace!("DFU: 0x{:x} - 0x{:x}", start, end); | 67 | trace!("DFU: 0x{:x} - 0x{:x}", start, end); |
| 37 | 68 | ||
| 38 | BlockingPartition::new(flash, start, end - start) | 69 | BlockingPartition::new(dfu_flash, start, end - start) |
| 39 | }; | 70 | }; |
| 40 | let state = unsafe { | 71 | let state = unsafe { |
| 41 | let start = &__bootloader_state_start as *const u32 as u32; | 72 | let start = &__bootloader_state_start as *const u32 as u32; |
| 42 | let end = &__bootloader_state_end as *const u32 as u32; | 73 | let end = &__bootloader_state_end as *const u32 as u32; |
| 43 | trace!("STATE: 0x{:x} - 0x{:x}", start, end); | 74 | trace!("STATE: 0x{:x} - 0x{:x}", start, end); |
| 44 | 75 | ||
| 45 | BlockingPartition::new(flash, start, end - start) | 76 | BlockingPartition::new(state_flash, start, end - start) |
| 46 | }; | 77 | }; |
| 47 | 78 | ||
| 48 | Self { dfu, state } | 79 | Self { dfu, state } |
diff --git a/embassy-boot/src/firmware_updater/mod.rs b/embassy-boot/src/firmware_updater/mod.rs index 4814786bf..4c4f4f10b 100644 --- a/embassy-boot/src/firmware_updater/mod.rs +++ b/embassy-boot/src/firmware_updater/mod.rs | |||
| @@ -8,7 +8,7 @@ use embedded_storage::nor_flash::{NorFlashError, NorFlashErrorKind}; | |||
| 8 | /// Firmware updater flash configuration holding the two flashes used by the updater | 8 | /// Firmware updater flash configuration holding the two flashes used by the updater |
| 9 | /// | 9 | /// |
| 10 | /// If only a single flash is actually used, then that flash should be partitioned into two partitions before use. | 10 | /// If only a single flash is actually used, then that flash should be partitioned into two partitions before use. |
| 11 | /// The easiest way to do this is to use [`FirmwareUpdaterConfig::from_linkerfile`] or [`FirmwareUpdaterConfig::from_linkerfile_blocking`] which will partition | 11 | /// The easiest way to do this is to use [`FirmwareUpdaterConfig::from_linkerfile_blocking`] or [`FirmwareUpdaterConfig::from_linkerfile_blocking`] which will partition |
| 12 | /// the provided flash according to symbols defined in the linkerfile. | 12 | /// the provided flash according to symbols defined in the linkerfile. |
| 13 | pub struct FirmwareUpdaterConfig<DFU, STATE> { | 13 | pub struct FirmwareUpdaterConfig<DFU, STATE> { |
| 14 | /// The dfu flash partition | 14 | /// The dfu flash partition |
diff --git a/examples/boot/application/nrf/src/bin/a.rs b/examples/boot/application/nrf/src/bin/a.rs index f3abfddbc..851a3d721 100644 --- a/examples/boot/application/nrf/src/bin/a.rs +++ b/examples/boot/application/nrf/src/bin/a.rs | |||
| @@ -50,7 +50,7 @@ async fn main(_spawner: Spawner) { | |||
| 50 | let nvmc = Nvmc::new(p.NVMC); | 50 | let nvmc = Nvmc::new(p.NVMC); |
| 51 | let nvmc = Mutex::new(BlockingAsync::new(nvmc)); | 51 | let nvmc = Mutex::new(BlockingAsync::new(nvmc)); |
| 52 | 52 | ||
| 53 | let config = FirmwareUpdaterConfig::from_linkerfile(&nvmc); | 53 | let config = FirmwareUpdaterConfig::from_linkerfile(&nvmc, &nvmc); |
| 54 | let mut magic = [0; 4]; | 54 | let mut magic = [0; 4]; |
| 55 | let mut updater = FirmwareUpdater::new(config, &mut magic); | 55 | let mut updater = FirmwareUpdater::new(config, &mut magic); |
| 56 | loop { | 56 | loop { |
diff --git a/examples/boot/application/rp/src/bin/a.rs b/examples/boot/application/rp/src/bin/a.rs index 3f0bf90e2..ede0c07da 100644 --- a/examples/boot/application/rp/src/bin/a.rs +++ b/examples/boot/application/rp/src/bin/a.rs | |||
| @@ -36,7 +36,7 @@ async fn main(_s: Spawner) { | |||
| 36 | let flash = Flash::<_, _, FLASH_SIZE>::new_blocking(p.FLASH); | 36 | let flash = Flash::<_, _, FLASH_SIZE>::new_blocking(p.FLASH); |
| 37 | let flash = Mutex::new(RefCell::new(flash)); | 37 | let flash = Mutex::new(RefCell::new(flash)); |
| 38 | 38 | ||
| 39 | let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash); | 39 | let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash, &flash); |
| 40 | let mut aligned = AlignedBuffer([0; 1]); | 40 | let mut aligned = AlignedBuffer([0; 1]); |
| 41 | let mut updater = BlockingFirmwareUpdater::new(config, &mut aligned.0); | 41 | let mut updater = BlockingFirmwareUpdater::new(config, &mut aligned.0); |
| 42 | 42 | ||
diff --git a/examples/boot/application/stm32f3/memory.x b/examples/boot/application/stm32f3/memory.x index f51875766..02ebe3ecf 100644 --- a/examples/boot/application/stm32f3/memory.x +++ b/examples/boot/application/stm32f3/memory.x | |||
| @@ -3,8 +3,8 @@ MEMORY | |||
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ |
| 4 | BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K | 4 | BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K |
| 5 | BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K | 5 | BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K |
| 6 | FLASH : ORIGIN = 0x08008000, LENGTH = 32K | 6 | FLASH : ORIGIN = 0x08008000, LENGTH = 64K |
| 7 | DFU : ORIGIN = 0x08010000, LENGTH = 36K | 7 | DFU : ORIGIN = 0x08018000, LENGTH = 66K |
| 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K | 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K |
| 9 | } | 9 | } |
| 10 | 10 | ||
diff --git a/examples/boot/application/stm32f3/src/bin/a.rs b/examples/boot/application/stm32f3/src/bin/a.rs index 3f9ebe5c8..8858ae3da 100644 --- a/examples/boot/application/stm32f3/src/bin/a.rs +++ b/examples/boot/application/stm32f3/src/bin/a.rs | |||
| @@ -28,7 +28,7 @@ async fn main(_spawner: Spawner) { | |||
| 28 | let mut led = Output::new(p.PA5, Level::Low, Speed::Low); | 28 | let mut led = Output::new(p.PA5, Level::Low, Speed::Low); |
| 29 | led.set_high(); | 29 | led.set_high(); |
| 30 | 30 | ||
| 31 | let config = FirmwareUpdaterConfig::from_linkerfile(&flash); | 31 | let config = FirmwareUpdaterConfig::from_linkerfile(&flash, &flash); |
| 32 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | 32 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); |
| 33 | let mut updater = FirmwareUpdater::new(config, &mut magic.0); | 33 | let mut updater = FirmwareUpdater::new(config, &mut magic.0); |
| 34 | button.wait_for_falling_edge().await; | 34 | button.wait_for_falling_edge().await; |
diff --git a/examples/boot/application/stm32f7/src/bin/a.rs b/examples/boot/application/stm32f7/src/bin/a.rs index c57c29263..d3df11fe4 100644 --- a/examples/boot/application/stm32f7/src/bin/a.rs +++ b/examples/boot/application/stm32f7/src/bin/a.rs | |||
| @@ -30,7 +30,7 @@ async fn main(_spawner: Spawner) { | |||
| 30 | let mut led = Output::new(p.PB7, Level::Low, Speed::Low); | 30 | let mut led = Output::new(p.PB7, Level::Low, Speed::Low); |
| 31 | led.set_high(); | 31 | led.set_high(); |
| 32 | 32 | ||
| 33 | let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash); | 33 | let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash, &flash); |
| 34 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | 34 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); |
| 35 | let mut updater = BlockingFirmwareUpdater::new(config, &mut magic.0); | 35 | let mut updater = BlockingFirmwareUpdater::new(config, &mut magic.0); |
| 36 | let writer = updater.prepare_update().unwrap(); | 36 | let writer = updater.prepare_update().unwrap(); |
diff --git a/examples/boot/application/stm32h7/src/bin/a.rs b/examples/boot/application/stm32h7/src/bin/a.rs index a00d17408..f61ac1f71 100644 --- a/examples/boot/application/stm32h7/src/bin/a.rs +++ b/examples/boot/application/stm32h7/src/bin/a.rs | |||
| @@ -30,7 +30,7 @@ async fn main(_spawner: Spawner) { | |||
| 30 | let mut led = Output::new(p.PB14, Level::Low, Speed::Low); | 30 | let mut led = Output::new(p.PB14, Level::Low, Speed::Low); |
| 31 | led.set_high(); | 31 | led.set_high(); |
| 32 | 32 | ||
| 33 | let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash); | 33 | let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash, &flash); |
| 34 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | 34 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); |
| 35 | let mut updater = BlockingFirmwareUpdater::new(config, &mut magic.0); | 35 | let mut updater = BlockingFirmwareUpdater::new(config, &mut magic.0); |
| 36 | let writer = updater.prepare_update().unwrap(); | 36 | let writer = updater.prepare_update().unwrap(); |
diff --git a/examples/boot/application/stm32l0/memory.x b/examples/boot/application/stm32l0/memory.x index a99330145..8866506a8 100644 --- a/examples/boot/application/stm32l0/memory.x +++ b/examples/boot/application/stm32l0/memory.x | |||
| @@ -3,8 +3,8 @@ MEMORY | |||
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ |
| 4 | BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K | 4 | BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K |
| 5 | BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K | 5 | BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K |
| 6 | FLASH : ORIGIN = 0x08008000, LENGTH = 32K | 6 | FLASH : ORIGIN = 0x08008000, LENGTH = 64K |
| 7 | DFU : ORIGIN = 0x08010000, LENGTH = 36K | 7 | DFU : ORIGIN = 0x08018000, LENGTH = 66K |
| 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 16K | 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 16K |
| 9 | } | 9 | } |
| 10 | 10 | ||
diff --git a/examples/boot/application/stm32l0/src/bin/a.rs b/examples/boot/application/stm32l0/src/bin/a.rs index dbec49d44..f066c1139 100644 --- a/examples/boot/application/stm32l0/src/bin/a.rs +++ b/examples/boot/application/stm32l0/src/bin/a.rs | |||
| @@ -30,7 +30,7 @@ async fn main(_spawner: Spawner) { | |||
| 30 | 30 | ||
| 31 | led.set_high(); | 31 | led.set_high(); |
| 32 | 32 | ||
| 33 | let config = FirmwareUpdaterConfig::from_linkerfile(&flash); | 33 | let config = FirmwareUpdaterConfig::from_linkerfile(&flash, &flash); |
| 34 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | 34 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); |
| 35 | let mut updater = FirmwareUpdater::new(config, &mut magic.0); | 35 | let mut updater = FirmwareUpdater::new(config, &mut magic.0); |
| 36 | button.wait_for_falling_edge().await; | 36 | button.wait_for_falling_edge().await; |
diff --git a/examples/boot/application/stm32l1/memory.x b/examples/boot/application/stm32l1/memory.x index a99330145..caa525278 100644 --- a/examples/boot/application/stm32l1/memory.x +++ b/examples/boot/application/stm32l1/memory.x | |||
| @@ -3,8 +3,8 @@ MEMORY | |||
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ |
| 4 | BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K | 4 | BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K |
| 5 | BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K | 5 | BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K |
| 6 | FLASH : ORIGIN = 0x08008000, LENGTH = 32K | 6 | FLASH : ORIGIN = 0x08008000, LENGTH = 46K |
| 7 | DFU : ORIGIN = 0x08010000, LENGTH = 36K | 7 | DFU : ORIGIN = 0x08013800, LENGTH = 54K |
| 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 16K | 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 16K |
| 9 | } | 9 | } |
| 10 | 10 | ||
diff --git a/examples/boot/application/stm32l1/src/bin/a.rs b/examples/boot/application/stm32l1/src/bin/a.rs index dbec49d44..f066c1139 100644 --- a/examples/boot/application/stm32l1/src/bin/a.rs +++ b/examples/boot/application/stm32l1/src/bin/a.rs | |||
| @@ -30,7 +30,7 @@ async fn main(_spawner: Spawner) { | |||
| 30 | 30 | ||
| 31 | led.set_high(); | 31 | led.set_high(); |
| 32 | 32 | ||
| 33 | let config = FirmwareUpdaterConfig::from_linkerfile(&flash); | 33 | let config = FirmwareUpdaterConfig::from_linkerfile(&flash, &flash); |
| 34 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | 34 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); |
| 35 | let mut updater = FirmwareUpdater::new(config, &mut magic.0); | 35 | let mut updater = FirmwareUpdater::new(config, &mut magic.0); |
| 36 | button.wait_for_falling_edge().await; | 36 | button.wait_for_falling_edge().await; |
diff --git a/examples/boot/application/stm32l4/memory.x b/examples/boot/application/stm32l4/memory.x index f51875766..e1d4e7fa8 100644 --- a/examples/boot/application/stm32l4/memory.x +++ b/examples/boot/application/stm32l4/memory.x | |||
| @@ -3,8 +3,8 @@ MEMORY | |||
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ |
| 4 | BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K | 4 | BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K |
| 5 | BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K | 5 | BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K |
| 6 | FLASH : ORIGIN = 0x08008000, LENGTH = 32K | 6 | FLASH : ORIGIN = 0x08008000, LENGTH = 64K |
| 7 | DFU : ORIGIN = 0x08010000, LENGTH = 36K | 7 | DFU : ORIGIN = 0x08018000, LENGTH = 68K |
| 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K | 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K |
| 9 | } | 9 | } |
| 10 | 10 | ||
diff --git a/examples/boot/application/stm32l4/src/bin/a.rs b/examples/boot/application/stm32l4/src/bin/a.rs index e946c3cdf..a0079ee33 100644 --- a/examples/boot/application/stm32l4/src/bin/a.rs +++ b/examples/boot/application/stm32l4/src/bin/a.rs | |||
| @@ -28,7 +28,7 @@ async fn main(_spawner: Spawner) { | |||
| 28 | let mut led = Output::new(p.PB14, Level::Low, Speed::Low); | 28 | let mut led = Output::new(p.PB14, Level::Low, Speed::Low); |
| 29 | led.set_high(); | 29 | led.set_high(); |
| 30 | 30 | ||
| 31 | let config = FirmwareUpdaterConfig::from_linkerfile(&flash); | 31 | let config = FirmwareUpdaterConfig::from_linkerfile(&flash, &flash); |
| 32 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | 32 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); |
| 33 | let mut updater = FirmwareUpdater::new(config, &mut magic.0); | 33 | let mut updater = FirmwareUpdater::new(config, &mut magic.0); |
| 34 | button.wait_for_falling_edge().await; | 34 | button.wait_for_falling_edge().await; |
diff --git a/examples/boot/application/stm32wb-dfu/README.md b/examples/boot/application/stm32wb-dfu/README.md index c8dce0387..7f656cde6 100644 --- a/examples/boot/application/stm32wb-dfu/README.md +++ b/examples/boot/application/stm32wb-dfu/README.md | |||
| @@ -1,29 +1,9 @@ | |||
| 1 | # Examples using bootloader | 1 | # Examples using bootloader |
| 2 | 2 | ||
| 3 | Example for STM32WL demonstrating the bootloader. The example consists of application binaries, 'a' | 3 | Example for STM32WB demonstrating the USB DFU application. |
| 4 | which allows you to press a button to start the DFU process, and 'b' which is the updated | ||
| 5 | application. | ||
| 6 | |||
| 7 | |||
| 8 | ## Prerequisites | ||
| 9 | |||
| 10 | * `cargo-binutils` | ||
| 11 | * `cargo-flash` | ||
| 12 | * `embassy-boot-stm32` | ||
| 13 | 4 | ||
| 14 | ## Usage | 5 | ## Usage |
| 15 | 6 | ||
| 16 | ``` | 7 | ``` |
| 17 | # Flash bootloader | 8 | cargo flash --release --chip STM32WB55RGVx |
| 18 | cargo flash --manifest-path ../../bootloader/stm32/Cargo.toml --release --features embassy-stm32/stm32wl55jc-cm4 --chip STM32WLE5JCIx | ||
| 19 | # Build 'b' | ||
| 20 | cargo build --release --bin b | ||
| 21 | # Generate binary for 'b' | ||
| 22 | cargo objcopy --release --bin b -- -O binary b.bin | ||
| 23 | ``` | ||
| 24 | |||
| 25 | # Flash `a` (which includes b.bin) | ||
| 26 | |||
| 27 | ``` | ||
| 28 | cargo flash --release --bin a --chip STM32WLE5JCIx | ||
| 29 | ``` | 9 | ``` |
diff --git a/examples/boot/application/stm32wb-dfu/src/main.rs b/examples/boot/application/stm32wb-dfu/src/main.rs index b2ccb9e1a..37c3d7d90 100644 --- a/examples/boot/application/stm32wb-dfu/src/main.rs +++ b/examples/boot/application/stm32wb-dfu/src/main.rs | |||
| @@ -30,7 +30,7 @@ async fn main(_spawner: Spawner) { | |||
| 30 | let flash = Flash::new_blocking(p.FLASH); | 30 | let flash = Flash::new_blocking(p.FLASH); |
| 31 | let flash = Mutex::new(RefCell::new(flash)); | 31 | let flash = Mutex::new(RefCell::new(flash)); |
| 32 | 32 | ||
| 33 | let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash); | 33 | let config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash, &flash); |
| 34 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | 34 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); |
| 35 | let mut firmware_state = BlockingFirmwareState::from_config(config, &mut magic.0); | 35 | let mut firmware_state = BlockingFirmwareState::from_config(config, &mut magic.0); |
| 36 | firmware_state.mark_booted().expect("Failed to mark booted"); | 36 | firmware_state.mark_booted().expect("Failed to mark booted"); |
diff --git a/examples/boot/application/stm32wl/memory.x b/examples/boot/application/stm32wl/memory.x index f51875766..e1d4e7fa8 100644 --- a/examples/boot/application/stm32wl/memory.x +++ b/examples/boot/application/stm32wl/memory.x | |||
| @@ -3,8 +3,8 @@ MEMORY | |||
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ |
| 4 | BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K | 4 | BOOTLOADER : ORIGIN = 0x08000000, LENGTH = 24K |
| 5 | BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K | 5 | BOOTLOADER_STATE : ORIGIN = 0x08006000, LENGTH = 4K |
| 6 | FLASH : ORIGIN = 0x08008000, LENGTH = 32K | 6 | FLASH : ORIGIN = 0x08008000, LENGTH = 64K |
| 7 | DFU : ORIGIN = 0x08010000, LENGTH = 36K | 7 | DFU : ORIGIN = 0x08018000, LENGTH = 68K |
| 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K | 8 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K |
| 9 | } | 9 | } |
| 10 | 10 | ||
diff --git a/examples/boot/application/stm32wl/src/bin/a.rs b/examples/boot/application/stm32wl/src/bin/a.rs index b582d8b25..2fb16bdc4 100644 --- a/examples/boot/application/stm32wl/src/bin/a.rs +++ b/examples/boot/application/stm32wl/src/bin/a.rs | |||
| @@ -28,7 +28,7 @@ async fn main(_spawner: Spawner) { | |||
| 28 | let mut led = Output::new(p.PB9, Level::Low, Speed::Low); | 28 | let mut led = Output::new(p.PB9, Level::Low, Speed::Low); |
| 29 | led.set_high(); | 29 | led.set_high(); |
| 30 | 30 | ||
| 31 | let config = FirmwareUpdaterConfig::from_linkerfile(&flash); | 31 | let config = FirmwareUpdaterConfig::from_linkerfile(&flash, &flash); |
| 32 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); | 32 | let mut magic = AlignedBuffer([0; WRITE_SIZE]); |
| 33 | let mut updater = FirmwareUpdater::new(config, &mut magic.0); | 33 | let mut updater = FirmwareUpdater::new(config, &mut magic.0); |
| 34 | button.wait_for_falling_edge().await; | 34 | button.wait_for_falling_edge().await; |
diff --git a/examples/boot/bootloader/nrf/src/main.rs b/examples/boot/bootloader/nrf/src/main.rs index 74e2e293f..67c700437 100644 --- a/examples/boot/bootloader/nrf/src/main.rs +++ b/examples/boot/bootloader/nrf/src/main.rs | |||
| @@ -31,7 +31,7 @@ fn main() -> ! { | |||
| 31 | let flash = WatchdogFlash::start(Nvmc::new(p.NVMC), p.WDT, wdt_config); | 31 | let flash = WatchdogFlash::start(Nvmc::new(p.NVMC), p.WDT, wdt_config); |
| 32 | let flash = Mutex::new(RefCell::new(flash)); | 32 | let flash = Mutex::new(RefCell::new(flash)); |
| 33 | 33 | ||
| 34 | let config = BootLoaderConfig::from_linkerfile_blocking(&flash); | 34 | let config = BootLoaderConfig::from_linkerfile_blocking(&flash, &flash, &flash); |
| 35 | let active_offset = config.active.offset(); | 35 | let active_offset = config.active.offset(); |
| 36 | let bl: BootLoader = BootLoader::prepare(config); | 36 | let bl: BootLoader = BootLoader::prepare(config); |
| 37 | 37 | ||
diff --git a/examples/boot/bootloader/rp/src/main.rs b/examples/boot/bootloader/rp/src/main.rs index c0e75d1ea..25b1657b8 100644 --- a/examples/boot/bootloader/rp/src/main.rs +++ b/examples/boot/bootloader/rp/src/main.rs | |||
| @@ -27,7 +27,7 @@ fn main() -> ! { | |||
| 27 | let flash = WatchdogFlash::<FLASH_SIZE>::start(p.FLASH, p.WATCHDOG, Duration::from_secs(8)); | 27 | let flash = WatchdogFlash::<FLASH_SIZE>::start(p.FLASH, p.WATCHDOG, Duration::from_secs(8)); |
| 28 | let flash = Mutex::new(RefCell::new(flash)); | 28 | let flash = Mutex::new(RefCell::new(flash)); |
| 29 | 29 | ||
| 30 | let config = BootLoaderConfig::from_linkerfile_blocking(&flash); | 30 | let config = BootLoaderConfig::from_linkerfile_blocking(&flash, &flash, &flash); |
| 31 | let active_offset = config.active.offset(); | 31 | let active_offset = config.active.offset(); |
| 32 | let bl: BootLoader = BootLoader::prepare(config); | 32 | let bl: BootLoader = BootLoader::prepare(config); |
| 33 | 33 | ||
diff --git a/examples/boot/bootloader/stm32-dual-bank/Cargo.toml b/examples/boot/bootloader/stm32-dual-bank/Cargo.toml new file mode 100644 index 000000000..313187adc --- /dev/null +++ b/examples/boot/bootloader/stm32-dual-bank/Cargo.toml | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | [package] | ||
| 2 | edition = "2021" | ||
| 3 | name = "stm32-bootloader-dual-bank-flash-example" | ||
| 4 | version = "0.1.0" | ||
| 5 | description = "Example bootloader for dual-bank flash STM32 chips" | ||
| 6 | license = "MIT OR Apache-2.0" | ||
| 7 | |||
| 8 | [dependencies] | ||
| 9 | defmt = { version = "0.3", optional = true } | ||
| 10 | defmt-rtt = { version = "0.4", optional = true } | ||
| 11 | |||
| 12 | embassy-stm32 = { path = "../../../../embassy-stm32", features = [] } | ||
| 13 | embassy-boot-stm32 = { path = "../../../../embassy-boot-stm32" } | ||
| 14 | cortex-m = { version = "0.7.6", features = [ | ||
| 15 | "inline-asm", | ||
| 16 | "critical-section-single-core", | ||
| 17 | ] } | ||
| 18 | embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } | ||
| 19 | cortex-m-rt = { version = "0.7" } | ||
| 20 | embedded-storage = "0.3.1" | ||
| 21 | embedded-storage-async = "0.4.0" | ||
| 22 | cfg-if = "1.0.0" | ||
| 23 | |||
| 24 | [features] | ||
| 25 | defmt = ["dep:defmt", "embassy-boot-stm32/defmt", "embassy-stm32/defmt"] | ||
| 26 | debug = ["defmt-rtt", "defmt"] | ||
| 27 | |||
| 28 | [profile.dev] | ||
| 29 | debug = 2 | ||
| 30 | debug-assertions = true | ||
| 31 | incremental = false | ||
| 32 | opt-level = 'z' | ||
| 33 | overflow-checks = true | ||
| 34 | |||
| 35 | [profile.release] | ||
| 36 | codegen-units = 1 | ||
| 37 | debug = 2 | ||
| 38 | debug-assertions = false | ||
| 39 | incremental = false | ||
| 40 | lto = 'fat' | ||
| 41 | opt-level = 'z' | ||
| 42 | overflow-checks = false | ||
| 43 | |||
| 44 | # do not optimize proc-macro crates = faster builds from scratch | ||
| 45 | [profile.dev.build-override] | ||
| 46 | codegen-units = 8 | ||
| 47 | debug = false | ||
| 48 | debug-assertions = false | ||
| 49 | opt-level = 0 | ||
| 50 | overflow-checks = false | ||
| 51 | |||
| 52 | [profile.release.build-override] | ||
| 53 | codegen-units = 8 | ||
| 54 | debug = false | ||
| 55 | debug-assertions = false | ||
| 56 | opt-level = 0 | ||
| 57 | overflow-checks = false | ||
diff --git a/examples/boot/bootloader/stm32-dual-bank/README.md b/examples/boot/bootloader/stm32-dual-bank/README.md new file mode 100644 index 000000000..3de3171cd --- /dev/null +++ b/examples/boot/bootloader/stm32-dual-bank/README.md | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | # STM32 dual-bank flash Bootloader | ||
| 2 | |||
| 3 | ## Overview | ||
| 4 | |||
| 5 | This bootloader leverages `embassy-boot` to interact with the flash. | ||
| 6 | This example targets STM32 devices with dual-bank flash memory, with a primary focus on the STM32H747XI series. | ||
| 7 | Users must modify the `memory.x` configuration file to match with the memory layout of their specific STM32 device. | ||
| 8 | |||
| 9 | Additionally, this example can be extended to utilize external flash memory, such as QSPI, for storing partitions. | ||
| 10 | |||
| 11 | ## Memory Configuration | ||
| 12 | |||
| 13 | In this example's `memory.x` file, various symbols are defined to assist in effective memory management within the bootloader environment. | ||
| 14 | For dual-bank STM32 devices, it's crucial to assign these symbols correctly to their respective memory banks. | ||
| 15 | |||
| 16 | ### Symbol Definitions | ||
| 17 | |||
| 18 | The bootloader's state and active symbols are anchored to the flash origin of **bank 1**: | ||
| 19 | |||
| 20 | - `__bootloader_state_start` and `__bootloader_state_end` | ||
| 21 | - `__bootloader_active_start` and `__bootloader_active_end` | ||
| 22 | |||
| 23 | In contrast, the Device Firmware Upgrade (DFU) symbols are aligned with the DFU flash origin in **bank 2**: | ||
| 24 | |||
| 25 | - `__bootloader_dfu_start` and `__bootloader_dfu_end` | ||
| 26 | |||
| 27 | ```rust | ||
| 28 | __bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(**FLASH**); | ||
| 29 | __bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(**FLASH**); | ||
| 30 | |||
| 31 | __bootloader_active_start = ORIGIN(ACTIVE) - ORIGIN(**FLASH**); | ||
| 32 | __bootloader_active_end = ORIGIN(ACTIVE) + LENGTH(ACTIVE) - ORIGIN(**FLASH**); | ||
| 33 | |||
| 34 | __bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(**DFU**); | ||
| 35 | __bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(**DFU**); | ||
| 36 | ``` | ||
| 37 | |||
| 38 | ## Flashing the Bootloader | ||
| 39 | |||
| 40 | To flash the bootloader onto your STM32H747XI device, use the following command: | ||
| 41 | |||
| 42 | ```bash | ||
| 43 | cargo flash --features embassy-stm32/stm32h747xi-cm7 --release --chip STM32H747XIHx | ||
| 44 | ``` | ||
diff --git a/examples/boot/bootloader/stm32-dual-bank/build.rs b/examples/boot/bootloader/stm32-dual-bank/build.rs new file mode 100644 index 000000000..fd605991f --- /dev/null +++ b/examples/boot/bootloader/stm32-dual-bank/build.rs | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | use std::env; | ||
| 2 | use std::fs::File; | ||
| 3 | use std::io::Write; | ||
| 4 | use std::path::PathBuf; | ||
| 5 | |||
| 6 | fn main() { | ||
| 7 | // Put `memory.x` in our output directory and ensure it's | ||
| 8 | // on the linker search path. | ||
| 9 | let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); | ||
| 10 | File::create(out.join("memory.x")) | ||
| 11 | .unwrap() | ||
| 12 | .write_all(include_bytes!("memory.x")) | ||
| 13 | .unwrap(); | ||
| 14 | println!("cargo:rustc-link-search={}", out.display()); | ||
| 15 | |||
| 16 | // By default, Cargo will re-run a build script whenever | ||
| 17 | // any file in the project changes. By specifying `memory.x` | ||
| 18 | // here, we ensure the build script is only re-run when | ||
| 19 | // `memory.x` is changed. | ||
| 20 | println!("cargo:rerun-if-changed=memory.x"); | ||
| 21 | |||
| 22 | println!("cargo:rustc-link-arg-bins=--nmagic"); | ||
| 23 | println!("cargo:rustc-link-arg-bins=-Tlink.x"); | ||
| 24 | if env::var("CARGO_FEATURE_DEFMT").is_ok() { | ||
| 25 | println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); | ||
| 26 | } | ||
| 27 | } | ||
diff --git a/examples/boot/bootloader/stm32-dual-bank/memory.x b/examples/boot/bootloader/stm32-dual-bank/memory.x new file mode 100644 index 000000000..665da7139 --- /dev/null +++ b/examples/boot/bootloader/stm32-dual-bank/memory.x | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | ||
| 4 | FLASH : ORIGIN = 0x08000000, LENGTH = 128K | ||
| 5 | BOOTLOADER_STATE : ORIGIN = 0x08020000, LENGTH = 128K | ||
| 6 | ACTIVE : ORIGIN = 0x08040000, LENGTH = 512K | ||
| 7 | DFU : ORIGIN = 0x08100000, LENGTH = 640K | ||
| 8 | RAM (rwx) : ORIGIN = 0x24000000, LENGTH = 512K | ||
| 9 | } | ||
| 10 | |||
| 11 | __bootloader_state_start = ORIGIN(BOOTLOADER_STATE) - ORIGIN(FLASH); | ||
| 12 | __bootloader_state_end = ORIGIN(BOOTLOADER_STATE) + LENGTH(BOOTLOADER_STATE) - ORIGIN(FLASH); | ||
| 13 | |||
| 14 | __bootloader_active_start = ORIGIN(ACTIVE) - ORIGIN(FLASH); | ||
| 15 | __bootloader_active_end = ORIGIN(ACTIVE) + LENGTH(ACTIVE) - ORIGIN(FLASH); | ||
| 16 | |||
| 17 | __bootloader_dfu_start = ORIGIN(DFU) - ORIGIN(DFU); | ||
| 18 | __bootloader_dfu_end = ORIGIN(DFU) + LENGTH(DFU) - ORIGIN(DFU); | ||
diff --git a/examples/boot/bootloader/stm32-dual-bank/src/main.rs b/examples/boot/bootloader/stm32-dual-bank/src/main.rs new file mode 100644 index 000000000..4d2e82d26 --- /dev/null +++ b/examples/boot/bootloader/stm32-dual-bank/src/main.rs | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use core::cell::RefCell; | ||
| 5 | |||
| 6 | use cortex_m_rt::{entry, exception}; | ||
| 7 | #[cfg(feature = "defmt")] | ||
| 8 | use defmt_rtt as _; | ||
| 9 | use embassy_boot_stm32::*; | ||
| 10 | use embassy_stm32::flash::{Flash, BANK1_REGION}; | ||
| 11 | use embassy_sync::blocking_mutex::Mutex; | ||
| 12 | |||
| 13 | #[entry] | ||
| 14 | fn main() -> ! { | ||
| 15 | let p = embassy_stm32::init(Default::default()); | ||
| 16 | |||
| 17 | // Uncomment this if you are debugging the bootloader with debugger/RTT attached, | ||
| 18 | // as it prevents a hard fault when accessing flash 'too early' after boot. | ||
| 19 | /* | ||
| 20 | for i in 0..10000000 { | ||
| 21 | cortex_m::asm::nop(); | ||
| 22 | } | ||
| 23 | */ | ||
| 24 | |||
| 25 | let layout = Flash::new_blocking(p.FLASH).into_blocking_regions(); | ||
| 26 | let flash_bank1 = Mutex::new(RefCell::new(layout.bank1_region)); | ||
| 27 | let flash_bank2 = Mutex::new(RefCell::new(layout.bank2_region)); | ||
| 28 | |||
| 29 | let config = BootLoaderConfig::from_linkerfile_blocking(&flash_bank1, &flash_bank2, &flash_bank1); | ||
| 30 | let active_offset = config.active.offset(); | ||
| 31 | let bl = BootLoader::prepare::<_, _, _, 2048>(config); | ||
| 32 | |||
| 33 | unsafe { bl.load(BANK1_REGION.base + active_offset) } | ||
| 34 | } | ||
| 35 | |||
| 36 | #[no_mangle] | ||
| 37 | #[cfg_attr(target_os = "none", link_section = ".HardFault.user")] | ||
| 38 | unsafe extern "C" fn HardFault() { | ||
| 39 | cortex_m::peripheral::SCB::sys_reset(); | ||
| 40 | } | ||
| 41 | |||
| 42 | #[exception] | ||
| 43 | unsafe fn DefaultHandler(_: i16) -> ! { | ||
| 44 | const SCB_ICSR: *const u32 = 0xE000_ED04 as *const u32; | ||
| 45 | let irqn = core::ptr::read_volatile(SCB_ICSR) as u8 as i16 - 16; | ||
| 46 | |||
| 47 | panic!("DefaultHandler #{:?}", irqn); | ||
| 48 | } | ||
| 49 | |||
| 50 | #[panic_handler] | ||
| 51 | fn panic(_info: &core::panic::PanicInfo) -> ! { | ||
| 52 | cortex_m::asm::udf(); | ||
| 53 | } | ||
diff --git a/examples/boot/bootloader/stm32/src/main.rs b/examples/boot/bootloader/stm32/src/main.rs index 5fd9ea588..99a7a6a6b 100644 --- a/examples/boot/bootloader/stm32/src/main.rs +++ b/examples/boot/bootloader/stm32/src/main.rs | |||
| @@ -25,7 +25,7 @@ fn main() -> ! { | |||
| 25 | let layout = Flash::new_blocking(p.FLASH).into_blocking_regions(); | 25 | let layout = Flash::new_blocking(p.FLASH).into_blocking_regions(); |
| 26 | let flash = Mutex::new(RefCell::new(layout.bank1_region)); | 26 | let flash = Mutex::new(RefCell::new(layout.bank1_region)); |
| 27 | 27 | ||
| 28 | let config = BootLoaderConfig::from_linkerfile_blocking(&flash); | 28 | let config = BootLoaderConfig::from_linkerfile_blocking(&flash, &flash, &flash); |
| 29 | let active_offset = config.active.offset(); | 29 | let active_offset = config.active.offset(); |
| 30 | let bl = BootLoader::prepare::<_, _, _, 2048>(config); | 30 | let bl = BootLoader::prepare::<_, _, _, 2048>(config); |
| 31 | 31 | ||
diff --git a/examples/boot/bootloader/stm32wb-dfu/Cargo.toml b/examples/boot/bootloader/stm32wb-dfu/Cargo.toml index 96635afa2..854f94d85 100644 --- a/examples/boot/bootloader/stm32wb-dfu/Cargo.toml +++ b/examples/boot/bootloader/stm32wb-dfu/Cargo.toml | |||
| @@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0" | |||
| 9 | defmt = { version = "0.3", optional = true } | 9 | defmt = { version = "0.3", optional = true } |
| 10 | defmt-rtt = { version = "0.4", optional = true } | 10 | defmt-rtt = { version = "0.4", optional = true } |
| 11 | 11 | ||
| 12 | embassy-stm32 = { path = "../../../../embassy-stm32", features = ["stm32wb55rg"] } | 12 | embassy-stm32 = { path = "../../../../embassy-stm32", features = [] } |
| 13 | embassy-boot-stm32 = { path = "../../../../embassy-boot-stm32" } | 13 | embassy-boot-stm32 = { path = "../../../../embassy-boot-stm32" } |
| 14 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } | 14 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } |
| 15 | embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } | 15 | embassy-sync = { version = "0.5.0", path = "../../../../embassy-sync" } |
diff --git a/examples/boot/bootloader/stm32wb-dfu/README.md b/examples/boot/bootloader/stm32wb-dfu/README.md index a82b730b9..d5c6ea57c 100644 --- a/examples/boot/bootloader/stm32wb-dfu/README.md +++ b/examples/boot/bootloader/stm32wb-dfu/README.md | |||
| @@ -7,5 +7,5 @@ The bootloader uses `embassy-boot` to interact with the flash. | |||
| 7 | Flash the bootloader | 7 | Flash the bootloader |
| 8 | 8 | ||
| 9 | ``` | 9 | ``` |
| 10 | cargo flash --features embassy-stm32/stm32wl55jc-cm4 --release --chip STM32WLE5JCIx | 10 | cargo flash --features embassy-stm32/stm32wb55rg --release --chip STM32WB55RGVx |
| 11 | ``` | 11 | ``` |
diff --git a/examples/boot/bootloader/stm32wb-dfu/src/main.rs b/examples/boot/bootloader/stm32wb-dfu/src/main.rs index a7ab813b6..d989fbfdf 100644 --- a/examples/boot/bootloader/stm32wb-dfu/src/main.rs +++ b/examples/boot/bootloader/stm32wb-dfu/src/main.rs | |||
| @@ -35,7 +35,7 @@ fn main() -> ! { | |||
| 35 | let layout = Flash::new_blocking(p.FLASH).into_blocking_regions(); | 35 | let layout = Flash::new_blocking(p.FLASH).into_blocking_regions(); |
| 36 | let flash = Mutex::new(RefCell::new(layout.bank1_region)); | 36 | let flash = Mutex::new(RefCell::new(layout.bank1_region)); |
| 37 | 37 | ||
| 38 | let config = BootLoaderConfig::from_linkerfile_blocking(&flash); | 38 | let config = BootLoaderConfig::from_linkerfile_blocking(&flash, &flash, &flash); |
| 39 | let active_offset = config.active.offset(); | 39 | let active_offset = config.active.offset(); |
| 40 | let bl = BootLoader::prepare::<_, _, _, 2048>(config); | 40 | let bl = BootLoader::prepare::<_, _, _, 2048>(config); |
| 41 | if bl.state == State::DfuDetach { | 41 | if bl.state == State::DfuDetach { |
| @@ -45,7 +45,7 @@ fn main() -> ! { | |||
| 45 | config.product = Some("USB-DFU Bootloader example"); | 45 | config.product = Some("USB-DFU Bootloader example"); |
| 46 | config.serial_number = Some("1235678"); | 46 | config.serial_number = Some("1235678"); |
| 47 | 47 | ||
| 48 | let fw_config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash); | 48 | let fw_config = FirmwareUpdaterConfig::from_linkerfile_blocking(&flash, &flash); |
| 49 | let mut buffer = AlignedBuffer([0; WRITE_SIZE]); | 49 | let mut buffer = AlignedBuffer([0; WRITE_SIZE]); |
| 50 | let updater = BlockingFirmwareUpdater::new(fw_config, &mut buffer.0[..]); | 50 | let updater = BlockingFirmwareUpdater::new(fw_config, &mut buffer.0[..]); |
| 51 | 51 | ||
