diff options
| author | Raul Alimbekov <[email protected]> | 2025-12-16 09:05:22 +0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-12-16 09:05:22 +0300 |
| commit | c9a04b4b732b7a3b696eb8223664c1a7942b1875 (patch) | |
| tree | 6dbe5c02e66eed8d8762f13f95afd24f8db2b38c /embassy-boot/src | |
| parent | cde24a3ef1117653ba5ed4184102b33f745782fb (diff) | |
| parent | 5ae6e060ec1c90561719aabdc29d5b6e7b8b0a82 (diff) | |
Merge branch 'main' into main
Diffstat (limited to 'embassy-boot/src')
| -rw-r--r-- | embassy-boot/src/boot_loader.rs | 18 | ||||
| -rw-r--r-- | embassy-boot/src/firmware_updater/asynch.rs | 4 | ||||
| -rw-r--r-- | embassy-boot/src/firmware_updater/blocking.rs | 6 | ||||
| -rw-r--r-- | embassy-boot/src/lib.rs | 19 | ||||
| -rw-r--r-- | embassy-boot/src/test_flash/blocking.rs | 2 |
5 files changed, 29 insertions, 20 deletions
diff --git a/embassy-boot/src/boot_loader.rs b/embassy-boot/src/boot_loader.rs index 5bffdc5ea..a3a307051 100644 --- a/embassy-boot/src/boot_loader.rs +++ b/embassy-boot/src/boot_loader.rs | |||
| @@ -1,11 +1,11 @@ | |||
| 1 | use core::cell::RefCell; | 1 | use core::cell::RefCell; |
| 2 | 2 | ||
| 3 | use embassy_embedded_hal::flash::partition::BlockingPartition; | 3 | use embassy_embedded_hal::flash::partition::BlockingPartition; |
| 4 | use embassy_sync::blocking_mutex::raw::NoopRawMutex; | ||
| 5 | use embassy_sync::blocking_mutex::Mutex; | 4 | use embassy_sync::blocking_mutex::Mutex; |
| 5 | use embassy_sync::blocking_mutex::raw::NoopRawMutex; | ||
| 6 | use embedded_storage::nor_flash::{NorFlash, NorFlashError, NorFlashErrorKind}; | 6 | use embedded_storage::nor_flash::{NorFlash, NorFlashError, NorFlashErrorKind}; |
| 7 | 7 | ||
| 8 | use crate::{State, DFU_DETACH_MAGIC, REVERT_MAGIC, STATE_ERASE_VALUE, SWAP_MAGIC}; | 8 | use crate::{DFU_DETACH_MAGIC, REVERT_MAGIC, STATE_ERASE_VALUE, SWAP_MAGIC, State}; |
| 9 | 9 | ||
| 10 | /// Errors returned by bootloader | 10 | /// Errors returned by bootloader |
| 11 | #[derive(PartialEq, Eq, Debug)] | 11 | #[derive(PartialEq, Eq, Debug)] |
| @@ -94,7 +94,7 @@ impl<'a, ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash> | |||
| 94 | dfu_flash: &'a Mutex<NoopRawMutex, RefCell<DFU>>, | 94 | dfu_flash: &'a Mutex<NoopRawMutex, RefCell<DFU>>, |
| 95 | state_flash: &'a Mutex<NoopRawMutex, RefCell<STATE>>, | 95 | state_flash: &'a Mutex<NoopRawMutex, RefCell<STATE>>, |
| 96 | ) -> Self { | 96 | ) -> Self { |
| 97 | extern "C" { | 97 | unsafe extern "C" { |
| 98 | static __bootloader_state_start: u32; | 98 | static __bootloader_state_start: u32; |
| 99 | static __bootloader_state_end: u32; | 99 | static __bootloader_state_end: u32; |
| 100 | static __bootloader_active_start: u32; | 100 | static __bootloader_active_start: u32; |
| @@ -135,10 +135,12 @@ pub struct BootLoader<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash> { | |||
| 135 | dfu: DFU, | 135 | dfu: DFU, |
| 136 | /// The state partition has the following format: | 136 | /// The state partition has the following format: |
| 137 | /// All ranges are in multiples of WRITE_SIZE bytes. | 137 | /// All ranges are in multiples of WRITE_SIZE bytes. |
| 138 | /// | Range | Description | | 138 | /// N = Active partition size divided by WRITE_SIZE. |
| 139 | /// | 0..1 | Magic indicating bootloader state. BOOT_MAGIC means boot, SWAP_MAGIC means swap. | | 139 | /// | Range | Description | |
| 140 | /// | 1..2 | Progress validity. ERASE_VALUE means valid, !ERASE_VALUE means invalid. | | 140 | /// | 0..1 | Magic indicating bootloader state. BOOT_MAGIC means boot, SWAP_MAGIC means swap. | |
| 141 | /// | 2..2 + N | Progress index used while swapping or reverting | 141 | /// | 1..2 | Progress validity. ERASE_VALUE means valid, !ERASE_VALUE means invalid. | |
| 142 | /// | 2..(2 + 2N) | Progress index used while swapping | | ||
| 143 | /// | (2 + 2N)..(2 + 4N) | Progress index used while reverting | ||
| 142 | state: STATE, | 144 | state: STATE, |
| 143 | } | 145 | } |
| 144 | 146 | ||
| @@ -429,7 +431,7 @@ fn assert_partitions<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash>( | |||
| 429 | assert_eq!(dfu.capacity() as u32 % page_size, 0); | 431 | assert_eq!(dfu.capacity() as u32 % page_size, 0); |
| 430 | // DFU partition has to be bigger than ACTIVE partition to handle swap algorithm | 432 | // DFU partition has to be bigger than ACTIVE partition to handle swap algorithm |
| 431 | assert!(dfu.capacity() as u32 - active.capacity() as u32 >= page_size); | 433 | assert!(dfu.capacity() as u32 - active.capacity() as u32 >= page_size); |
| 432 | assert!(2 + 2 * (active.capacity() as u32 / page_size) <= state.capacity() as u32 / STATE::WRITE_SIZE as u32); | 434 | assert!(2 + 4 * (active.capacity() as u32 / page_size) <= state.capacity() as u32 / STATE::WRITE_SIZE as u32); |
| 433 | } | 435 | } |
| 434 | 436 | ||
| 435 | #[cfg(test)] | 437 | #[cfg(test)] |
diff --git a/embassy-boot/src/firmware_updater/asynch.rs b/embassy-boot/src/firmware_updater/asynch.rs index 66e311e38..26d4d39bd 100644 --- a/embassy-boot/src/firmware_updater/asynch.rs +++ b/embassy-boot/src/firmware_updater/asynch.rs | |||
| @@ -6,7 +6,7 @@ use embassy_sync::blocking_mutex::raw::NoopRawMutex; | |||
| 6 | use embedded_storage_async::nor_flash::NorFlash; | 6 | use embedded_storage_async::nor_flash::NorFlash; |
| 7 | 7 | ||
| 8 | use super::FirmwareUpdaterConfig; | 8 | use super::FirmwareUpdaterConfig; |
| 9 | use crate::{FirmwareUpdaterError, State, BOOT_MAGIC, DFU_DETACH_MAGIC, STATE_ERASE_VALUE, SWAP_MAGIC}; | 9 | use crate::{BOOT_MAGIC, DFU_DETACH_MAGIC, FirmwareUpdaterError, STATE_ERASE_VALUE, SWAP_MAGIC, State}; |
| 10 | 10 | ||
| 11 | /// FirmwareUpdater is an application API for interacting with the BootLoader without the ability to | 11 | /// FirmwareUpdater is an application API for interacting with the BootLoader without the ability to |
| 12 | /// 'mess up' the internal bootloader state | 12 | /// 'mess up' the internal bootloader state |
| @@ -25,7 +25,7 @@ impl<'a, DFU: NorFlash, STATE: NorFlash> | |||
| 25 | dfu_flash: &'a embassy_sync::mutex::Mutex<NoopRawMutex, DFU>, | 25 | dfu_flash: &'a embassy_sync::mutex::Mutex<NoopRawMutex, DFU>, |
| 26 | state_flash: &'a embassy_sync::mutex::Mutex<NoopRawMutex, STATE>, | 26 | state_flash: &'a embassy_sync::mutex::Mutex<NoopRawMutex, STATE>, |
| 27 | ) -> Self { | 27 | ) -> Self { |
| 28 | extern "C" { | 28 | unsafe extern "C" { |
| 29 | static __bootloader_state_start: u32; | 29 | static __bootloader_state_start: u32; |
| 30 | static __bootloader_state_end: u32; | 30 | static __bootloader_state_end: u32; |
| 31 | static __bootloader_dfu_start: u32; | 31 | static __bootloader_dfu_start: u32; |
diff --git a/embassy-boot/src/firmware_updater/blocking.rs b/embassy-boot/src/firmware_updater/blocking.rs index 0fedac1ea..5554025fc 100644 --- a/embassy-boot/src/firmware_updater/blocking.rs +++ b/embassy-boot/src/firmware_updater/blocking.rs | |||
| @@ -6,7 +6,7 @@ use embassy_sync::blocking_mutex::raw::NoopRawMutex; | |||
| 6 | use embedded_storage::nor_flash::NorFlash; | 6 | use embedded_storage::nor_flash::NorFlash; |
| 7 | 7 | ||
| 8 | use super::FirmwareUpdaterConfig; | 8 | use super::FirmwareUpdaterConfig; |
| 9 | use crate::{FirmwareUpdaterError, State, BOOT_MAGIC, DFU_DETACH_MAGIC, STATE_ERASE_VALUE, SWAP_MAGIC}; | 9 | use crate::{BOOT_MAGIC, DFU_DETACH_MAGIC, FirmwareUpdaterError, STATE_ERASE_VALUE, SWAP_MAGIC, State}; |
| 10 | 10 | ||
| 11 | /// Blocking FirmwareUpdater is an application API for interacting with the BootLoader without the ability to | 11 | /// Blocking FirmwareUpdater is an application API for interacting with the BootLoader without the ability to |
| 12 | /// 'mess up' the internal bootloader state | 12 | /// 'mess up' the internal bootloader state |
| @@ -55,7 +55,7 @@ impl<'a, DFU: NorFlash, STATE: NorFlash> | |||
| 55 | dfu_flash: &'a embassy_sync::blocking_mutex::Mutex<NoopRawMutex, core::cell::RefCell<DFU>>, | 55 | dfu_flash: &'a embassy_sync::blocking_mutex::Mutex<NoopRawMutex, core::cell::RefCell<DFU>>, |
| 56 | state_flash: &'a embassy_sync::blocking_mutex::Mutex<NoopRawMutex, core::cell::RefCell<STATE>>, | 56 | state_flash: &'a embassy_sync::blocking_mutex::Mutex<NoopRawMutex, core::cell::RefCell<STATE>>, |
| 57 | ) -> Self { | 57 | ) -> Self { |
| 58 | extern "C" { | 58 | unsafe extern "C" { |
| 59 | static __bootloader_state_start: u32; | 59 | static __bootloader_state_start: u32; |
| 60 | static __bootloader_state_end: u32; | 60 | static __bootloader_state_end: u32; |
| 61 | static __bootloader_dfu_start: u32; | 61 | static __bootloader_dfu_start: u32; |
| @@ -399,8 +399,8 @@ mod tests { | |||
| 399 | use core::cell::RefCell; | 399 | use core::cell::RefCell; |
| 400 | 400 | ||
| 401 | use embassy_embedded_hal::flash::partition::BlockingPartition; | 401 | use embassy_embedded_hal::flash::partition::BlockingPartition; |
| 402 | use embassy_sync::blocking_mutex::raw::NoopRawMutex; | ||
| 403 | use embassy_sync::blocking_mutex::Mutex; | 402 | use embassy_sync::blocking_mutex::Mutex; |
| 403 | use embassy_sync::blocking_mutex::raw::NoopRawMutex; | ||
| 404 | use sha1::{Digest, Sha1}; | 404 | use sha1::{Digest, Sha1}; |
| 405 | 405 | ||
| 406 | use super::*; | 406 | use super::*; |
diff --git a/embassy-boot/src/lib.rs b/embassy-boot/src/lib.rs index e2c4cf771..3e61d6036 100644 --- a/embassy-boot/src/lib.rs +++ b/embassy-boot/src/lib.rs | |||
| @@ -1,7 +1,12 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![allow(async_fn_in_trait)] | 2 | #![allow(async_fn_in_trait)] |
| 3 | #![allow(unsafe_op_in_unsafe_fn)] | ||
| 3 | #![warn(missing_docs)] | 4 | #![warn(missing_docs)] |
| 4 | #![doc = include_str!("../README.md")] | 5 | #![doc = include_str!("../README.md")] |
| 6 | |||
| 7 | //! ## Feature flags | ||
| 8 | #![doc = document_features::document_features!(feature_label = r#"<span class="stab portability"><code>{feature}</code></span>"#)] | ||
| 9 | |||
| 5 | mod fmt; | 10 | mod fmt; |
| 6 | 11 | ||
| 7 | mod boot_loader; | 12 | mod boot_loader; |
| @@ -341,11 +346,13 @@ mod tests { | |||
| 341 | &mut aligned, | 346 | &mut aligned, |
| 342 | ); | 347 | ); |
| 343 | 348 | ||
| 344 | assert!(block_on(updater.verify_and_mark_updated( | 349 | assert!( |
| 345 | &public_key.to_bytes(), | 350 | block_on(updater.verify_and_mark_updated( |
| 346 | &signature.to_bytes(), | 351 | &public_key.to_bytes(), |
| 347 | firmware_len as u32, | 352 | &signature.to_bytes(), |
| 348 | )) | 353 | firmware_len as u32, |
| 349 | .is_ok()); | 354 | )) |
| 355 | .is_ok() | ||
| 356 | ); | ||
| 350 | } | 357 | } |
| 351 | } | 358 | } |
diff --git a/embassy-boot/src/test_flash/blocking.rs b/embassy-boot/src/test_flash/blocking.rs index 5ec476c65..7334346fd 100644 --- a/embassy-boot/src/test_flash/blocking.rs +++ b/embassy-boot/src/test_flash/blocking.rs | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | use core::cell::RefCell; | 1 | use core::cell::RefCell; |
| 2 | 2 | ||
| 3 | use embassy_embedded_hal::flash::partition::BlockingPartition; | 3 | use embassy_embedded_hal::flash::partition::BlockingPartition; |
| 4 | use embassy_sync::blocking_mutex::raw::NoopRawMutex; | ||
| 5 | use embassy_sync::blocking_mutex::Mutex; | 4 | use embassy_sync::blocking_mutex::Mutex; |
| 5 | use embassy_sync::blocking_mutex::raw::NoopRawMutex; | ||
| 6 | use embedded_storage::nor_flash::NorFlash; | 6 | use embedded_storage::nor_flash::NorFlash; |
| 7 | 7 | ||
| 8 | use crate::BootLoaderConfig; | 8 | use crate::BootLoaderConfig; |
