diff options
| author | William Yager <[email protected]> | 2024-03-03 18:50:27 -0500 |
|---|---|---|
| committer | William Yager <[email protected]> | 2024-03-03 18:50:27 -0500 |
| commit | cde6e2b58be4910c73b3738bb3b0e264c8ac6049 (patch) | |
| tree | 4b59eba00c939b84f49701e88fb08d658e930a1e | |
| parent | 873934aae5dd320133c383891b7b334d34d6454d (diff) | |
ok
| -rw-r--r-- | embassy-boot-nrf/src/lib.rs | 17 | ||||
| -rw-r--r-- | embassy-boot-rp/src/lib.rs | 15 |
2 files changed, 23 insertions, 9 deletions
diff --git a/embassy-boot-nrf/src/lib.rs b/embassy-boot-nrf/src/lib.rs index 5b20a93c6..6996a92f8 100644 --- a/embassy-boot-nrf/src/lib.rs +++ b/embassy-boot-nrf/src/lib.rs | |||
| @@ -4,8 +4,8 @@ | |||
| 4 | mod fmt; | 4 | mod fmt; |
| 5 | 5 | ||
| 6 | pub use embassy_boot::{ | 6 | pub use embassy_boot::{ |
| 7 | AlignedBuffer, BlockingFirmwareState, BlockingFirmwareUpdater, BootLoaderConfig, FirmwareState, FirmwareUpdater, | 7 | AlignedBuffer, BlockingFirmwareState, BlockingFirmwareUpdater, BootError, BootLoaderConfig, FirmwareState, |
| 8 | FirmwareUpdaterConfig, | 8 | FirmwareUpdater, FirmwareUpdaterConfig, |
| 9 | }; | 9 | }; |
| 10 | use embassy_nrf::nvmc::PAGE_SIZE; | 10 | use embassy_nrf::nvmc::PAGE_SIZE; |
| 11 | use embassy_nrf::peripherals::WDT; | 11 | use embassy_nrf::peripherals::WDT; |
| @@ -16,14 +16,21 @@ use embedded_storage::nor_flash::{ErrorType, NorFlash, ReadNorFlash}; | |||
| 16 | pub struct BootLoader<const BUFFER_SIZE: usize = PAGE_SIZE>; | 16 | pub struct BootLoader<const BUFFER_SIZE: usize = PAGE_SIZE>; |
| 17 | 17 | ||
| 18 | impl<const BUFFER_SIZE: usize> BootLoader<BUFFER_SIZE> { | 18 | impl<const BUFFER_SIZE: usize> BootLoader<BUFFER_SIZE> { |
| 19 | /// Inspect the bootloader state and perform actions required before booting, such as swapping firmware. | 19 | /// Inspect the bootloader state and perform actions required before booting, such as swapping firmware |
| 20 | pub fn prepare<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash>( | 20 | pub fn prepare<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash>( |
| 21 | config: BootLoaderConfig<ACTIVE, DFU, STATE>, | 21 | config: BootLoaderConfig<ACTIVE, DFU, STATE>, |
| 22 | ) -> Self { | 22 | ) -> Self { |
| 23 | Self::try_prepare::<ACTIVE, DFU, STATE>(config).expect("Boot prepare error") | ||
| 24 | } | ||
| 25 | |||
| 26 | /// Inspect the bootloader state and perform actions required before booting, such as swapping firmware | ||
| 27 | pub fn try_prepare<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash>( | ||
| 28 | config: BootLoaderConfig<ACTIVE, DFU, STATE>, | ||
| 29 | ) -> Result<Self, BootError> { | ||
| 23 | let mut aligned_buf = AlignedBuffer([0; BUFFER_SIZE]); | 30 | let mut aligned_buf = AlignedBuffer([0; BUFFER_SIZE]); |
| 24 | let mut boot = embassy_boot::BootLoader::new(config); | 31 | let mut boot = embassy_boot::BootLoader::new(config); |
| 25 | boot.prepare_boot(&mut aligned_buf.0).expect("Boot prepare error"); | 32 | let state = boot.prepare_boot(aligned_buf.as_mut())?; |
| 26 | Self | 33 | Ok(Self) |
| 27 | } | 34 | } |
| 28 | 35 | ||
| 29 | /// Boots the application without softdevice mechanisms. | 36 | /// Boots the application without softdevice mechanisms. |
diff --git a/embassy-boot-rp/src/lib.rs b/embassy-boot-rp/src/lib.rs index 07a5b3f4d..d88e6dfc6 100644 --- a/embassy-boot-rp/src/lib.rs +++ b/embassy-boot-rp/src/lib.rs | |||
| @@ -4,8 +4,8 @@ | |||
| 4 | mod fmt; | 4 | mod fmt; |
| 5 | 5 | ||
| 6 | pub use embassy_boot::{ | 6 | pub use embassy_boot::{ |
| 7 | AlignedBuffer, BlockingFirmwareState, BlockingFirmwareUpdater, BootLoaderConfig, FirmwareState, FirmwareUpdater, | 7 | AlignedBuffer, BlockingFirmwareState, BlockingFirmwareUpdater, BootError, BootLoaderConfig, FirmwareState, |
| 8 | FirmwareUpdaterConfig, State, | 8 | FirmwareUpdater, FirmwareUpdaterConfig, State, |
| 9 | }; | 9 | }; |
| 10 | use embassy_rp::flash::{Blocking, Flash, ERASE_SIZE}; | 10 | use embassy_rp::flash::{Blocking, Flash, ERASE_SIZE}; |
| 11 | use embassy_rp::peripherals::{FLASH, WATCHDOG}; | 11 | use embassy_rp::peripherals::{FLASH, WATCHDOG}; |
| @@ -21,10 +21,17 @@ impl<const BUFFER_SIZE: usize> BootLoader<BUFFER_SIZE> { | |||
| 21 | pub fn prepare<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash>( | 21 | pub fn prepare<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash>( |
| 22 | config: BootLoaderConfig<ACTIVE, DFU, STATE>, | 22 | config: BootLoaderConfig<ACTIVE, DFU, STATE>, |
| 23 | ) -> Self { | 23 | ) -> Self { |
| 24 | Self::try_prepare::<ACTIVE, DFU, STATE>(config).expect("Boot prepare error") | ||
| 25 | } | ||
| 26 | |||
| 27 | /// Inspect the bootloader state and perform actions required before booting, such as swapping firmware | ||
| 28 | pub fn try_prepare<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash>( | ||
| 29 | config: BootLoaderConfig<ACTIVE, DFU, STATE>, | ||
| 30 | ) -> Result<Self, BootError> { | ||
| 24 | let mut aligned_buf = AlignedBuffer([0; BUFFER_SIZE]); | 31 | let mut aligned_buf = AlignedBuffer([0; BUFFER_SIZE]); |
| 25 | let mut boot = embassy_boot::BootLoader::new(config); | 32 | let mut boot = embassy_boot::BootLoader::new(config); |
| 26 | boot.prepare_boot(aligned_buf.as_mut()).expect("Boot prepare error"); | 33 | let state = boot.prepare_boot(aligned_buf.as_mut())?; |
| 27 | Self | 34 | Ok(Self { state }) |
| 28 | } | 35 | } |
| 29 | 36 | ||
| 30 | /// Boots the application. | 37 | /// Boots the application. |
