mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-22 14:53:03 +00:00
Merge pull request #2657 from wyager/bootloader-softfail
Add support for handling bootloader setup failure in `embassy-boot`
This commit is contained in:
commit
49807c0e7f
@ -4,8 +4,8 @@
|
|||||||
mod fmt;
|
mod fmt;
|
||||||
|
|
||||||
pub use embassy_boot::{
|
pub use embassy_boot::{
|
||||||
AlignedBuffer, BlockingFirmwareState, BlockingFirmwareUpdater, BootLoaderConfig, FirmwareState, FirmwareUpdater,
|
AlignedBuffer, BlockingFirmwareState, BlockingFirmwareUpdater, BootError, BootLoaderConfig, FirmwareState,
|
||||||
FirmwareUpdaterConfig,
|
FirmwareUpdater, FirmwareUpdaterConfig,
|
||||||
};
|
};
|
||||||
use embassy_nrf::nvmc::PAGE_SIZE;
|
use embassy_nrf::nvmc::PAGE_SIZE;
|
||||||
use embassy_nrf::peripherals::WDT;
|
use embassy_nrf::peripherals::WDT;
|
||||||
@ -16,14 +16,21 @@ use embedded_storage::nor_flash::{ErrorType, NorFlash, ReadNorFlash};
|
|||||||
pub struct BootLoader<const BUFFER_SIZE: usize = PAGE_SIZE>;
|
pub struct BootLoader<const BUFFER_SIZE: usize = PAGE_SIZE>;
|
||||||
|
|
||||||
impl<const BUFFER_SIZE: usize> BootLoader<BUFFER_SIZE> {
|
impl<const BUFFER_SIZE: usize> BootLoader<BUFFER_SIZE> {
|
||||||
/// Inspect the bootloader state and perform actions required before booting, such as swapping firmware.
|
/// Inspect the bootloader state and perform actions required before booting, such as swapping firmware
|
||||||
pub fn prepare<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash>(
|
pub fn prepare<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash>(
|
||||||
config: BootLoaderConfig<ACTIVE, DFU, STATE>,
|
config: BootLoaderConfig<ACTIVE, DFU, STATE>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
Self::try_prepare::<ACTIVE, DFU, STATE>(config).expect("Boot prepare error")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Inspect the bootloader state and perform actions required before booting, such as swapping firmware
|
||||||
|
pub fn try_prepare<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash>(
|
||||||
|
config: BootLoaderConfig<ACTIVE, DFU, STATE>,
|
||||||
|
) -> Result<Self, BootError> {
|
||||||
let mut aligned_buf = AlignedBuffer([0; BUFFER_SIZE]);
|
let mut aligned_buf = AlignedBuffer([0; BUFFER_SIZE]);
|
||||||
let mut boot = embassy_boot::BootLoader::new(config);
|
let mut boot = embassy_boot::BootLoader::new(config);
|
||||||
boot.prepare_boot(&mut aligned_buf.0).expect("Boot prepare error");
|
let _state = boot.prepare_boot(aligned_buf.as_mut())?;
|
||||||
Self
|
Ok(Self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Boots the application without softdevice mechanisms.
|
/// Boots the application without softdevice mechanisms.
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
mod fmt;
|
mod fmt;
|
||||||
|
|
||||||
pub use embassy_boot::{
|
pub use embassy_boot::{
|
||||||
AlignedBuffer, BlockingFirmwareState, BlockingFirmwareUpdater, BootLoaderConfig, FirmwareState, FirmwareUpdater,
|
AlignedBuffer, BlockingFirmwareState, BlockingFirmwareUpdater, BootError, BootLoaderConfig, FirmwareState,
|
||||||
FirmwareUpdaterConfig, State,
|
FirmwareUpdater, FirmwareUpdaterConfig, State,
|
||||||
};
|
};
|
||||||
use embassy_rp::flash::{Blocking, Flash, ERASE_SIZE};
|
use embassy_rp::flash::{Blocking, Flash, ERASE_SIZE};
|
||||||
use embassy_rp::peripherals::{FLASH, WATCHDOG};
|
use embassy_rp::peripherals::{FLASH, WATCHDOG};
|
||||||
@ -21,10 +21,17 @@ impl<const BUFFER_SIZE: usize> BootLoader<BUFFER_SIZE> {
|
|||||||
pub fn prepare<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash>(
|
pub fn prepare<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash>(
|
||||||
config: BootLoaderConfig<ACTIVE, DFU, STATE>,
|
config: BootLoaderConfig<ACTIVE, DFU, STATE>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
Self::try_prepare::<ACTIVE, DFU, STATE>(config).expect("Boot prepare error")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Inspect the bootloader state and perform actions required before booting, such as swapping firmware
|
||||||
|
pub fn try_prepare<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash>(
|
||||||
|
config: BootLoaderConfig<ACTIVE, DFU, STATE>,
|
||||||
|
) -> Result<Self, BootError> {
|
||||||
let mut aligned_buf = AlignedBuffer([0; BUFFER_SIZE]);
|
let mut aligned_buf = AlignedBuffer([0; BUFFER_SIZE]);
|
||||||
let mut boot = embassy_boot::BootLoader::new(config);
|
let mut boot = embassy_boot::BootLoader::new(config);
|
||||||
boot.prepare_boot(aligned_buf.as_mut()).expect("Boot prepare error");
|
let _state = boot.prepare_boot(aligned_buf.as_mut())?;
|
||||||
Self
|
Ok(Self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Boots the application.
|
/// Boots the application.
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
mod fmt;
|
mod fmt;
|
||||||
|
|
||||||
pub use embassy_boot::{
|
pub use embassy_boot::{
|
||||||
AlignedBuffer, BlockingFirmwareState, BlockingFirmwareUpdater, BootLoaderConfig, FirmwareState, FirmwareUpdater,
|
AlignedBuffer, BlockingFirmwareState, BlockingFirmwareUpdater, BootError, BootLoaderConfig, FirmwareState,
|
||||||
FirmwareUpdaterConfig, State,
|
FirmwareUpdater, FirmwareUpdaterConfig, State,
|
||||||
};
|
};
|
||||||
use embedded_storage::nor_flash::NorFlash;
|
use embedded_storage::nor_flash::NorFlash;
|
||||||
|
|
||||||
@ -20,10 +20,17 @@ impl BootLoader {
|
|||||||
pub fn prepare<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash, const BUFFER_SIZE: usize>(
|
pub fn prepare<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash, const BUFFER_SIZE: usize>(
|
||||||
config: BootLoaderConfig<ACTIVE, DFU, STATE>,
|
config: BootLoaderConfig<ACTIVE, DFU, STATE>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
Self::try_prepare::<ACTIVE, DFU, STATE, BUFFER_SIZE>(config).expect("Boot prepare error")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Inspect the bootloader state and perform actions required before booting, such as swapping firmware
|
||||||
|
pub fn try_prepare<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash, const BUFFER_SIZE: usize>(
|
||||||
|
config: BootLoaderConfig<ACTIVE, DFU, STATE>,
|
||||||
|
) -> Result<Self, BootError> {
|
||||||
let mut aligned_buf = AlignedBuffer([0; BUFFER_SIZE]);
|
let mut aligned_buf = AlignedBuffer([0; BUFFER_SIZE]);
|
||||||
let mut boot = embassy_boot::BootLoader::new(config);
|
let mut boot = embassy_boot::BootLoader::new(config);
|
||||||
let state = boot.prepare_boot(aligned_buf.as_mut()).expect("Boot prepare error");
|
let state = boot.prepare_boot(aligned_buf.as_mut())?;
|
||||||
Self { state }
|
Ok(Self { state })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Boots the application.
|
/// Boots the application.
|
||||||
|
Loading…
Reference in New Issue
Block a user