diff options
Diffstat (limited to 'embassy-boot/src/boot_loader.rs')
| -rw-r--r-- | embassy-boot/src/boot_loader.rs | 18 |
1 files changed, 10 insertions, 8 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)] |
