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 /embassy-boot-nrf/src/lib.rs | |
| parent | 873934aae5dd320133c383891b7b334d34d6454d (diff) | |
ok
Diffstat (limited to 'embassy-boot-nrf/src/lib.rs')
| -rw-r--r-- | embassy-boot-nrf/src/lib.rs | 17 |
1 files changed, 12 insertions, 5 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. |
