mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-25 00:02:28 +00:00
Ensure bootloader state is parsed correctly
This commit is contained in:
parent
b1897c58fa
commit
ab0a227e4c
@ -304,12 +304,7 @@ impl<'d, STATE: NorFlash> FirmwareState<'d, STATE> {
|
||||
/// `mark_booted`.
|
||||
pub async fn get_state(&mut self) -> Result<State, FirmwareUpdaterError> {
|
||||
self.state.read(0, &mut self.aligned).await?;
|
||||
|
||||
if !self.aligned.iter().any(|&b| b != SWAP_MAGIC) {
|
||||
Ok(State::Swap)
|
||||
} else {
|
||||
Ok(State::Boot)
|
||||
}
|
||||
Ok(State::from(&self.aligned))
|
||||
}
|
||||
|
||||
/// Mark to trigger firmware swap on next boot.
|
||||
|
@ -339,14 +339,7 @@ impl<'d, STATE: NorFlash> BlockingFirmwareState<'d, STATE> {
|
||||
/// `mark_booted`.
|
||||
pub fn get_state(&mut self) -> Result<State, FirmwareUpdaterError> {
|
||||
self.state.read(0, &mut self.aligned)?;
|
||||
|
||||
if !self.aligned.iter().any(|&b| b != SWAP_MAGIC) {
|
||||
Ok(State::Swap)
|
||||
} else if !self.aligned.iter().any(|&b| b != DFU_DETACH_MAGIC) {
|
||||
Ok(State::DfuDetach)
|
||||
} else {
|
||||
Ok(State::Boot)
|
||||
}
|
||||
Ok(State::from(&self.aligned))
|
||||
}
|
||||
|
||||
/// Mark to trigger firmware swap on next boot.
|
||||
|
@ -44,6 +44,24 @@ pub enum State {
|
||||
DfuDetach,
|
||||
}
|
||||
|
||||
impl<T> From<T> for State
|
||||
where
|
||||
T: AsRef<[u8]>,
|
||||
{
|
||||
fn from(magic: T) -> State {
|
||||
let magic = magic.as_ref();
|
||||
if !magic.iter().any(|&b| b != SWAP_MAGIC) {
|
||||
State::Swap
|
||||
} else if !magic.iter().any(|&b| b != REVERT_MAGIC) {
|
||||
State::Revert
|
||||
} else if !magic.iter().any(|&b| b != DFU_DETACH_MAGIC) {
|
||||
State::DfuDetach
|
||||
} else {
|
||||
State::Boot
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Buffer aligned to 32 byte boundary, largest known alignment requirement for embassy-boot.
|
||||
#[repr(align(32))]
|
||||
pub struct AlignedBuffer<const N: usize>(pub [u8; N]);
|
||||
|
Loading…
Reference in New Issue
Block a user