mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-25 16:23:10 +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`.
|
/// `mark_booted`.
|
||||||
pub async fn get_state(&mut self) -> Result<State, FirmwareUpdaterError> {
|
pub async fn get_state(&mut self) -> Result<State, FirmwareUpdaterError> {
|
||||||
self.state.read(0, &mut self.aligned).await?;
|
self.state.read(0, &mut self.aligned).await?;
|
||||||
|
Ok(State::from(&self.aligned))
|
||||||
if !self.aligned.iter().any(|&b| b != SWAP_MAGIC) {
|
|
||||||
Ok(State::Swap)
|
|
||||||
} else {
|
|
||||||
Ok(State::Boot)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mark to trigger firmware swap on next boot.
|
/// Mark to trigger firmware swap on next boot.
|
||||||
|
@ -339,14 +339,7 @@ impl<'d, STATE: NorFlash> BlockingFirmwareState<'d, STATE> {
|
|||||||
/// `mark_booted`.
|
/// `mark_booted`.
|
||||||
pub fn get_state(&mut self) -> Result<State, FirmwareUpdaterError> {
|
pub fn get_state(&mut self) -> Result<State, FirmwareUpdaterError> {
|
||||||
self.state.read(0, &mut self.aligned)?;
|
self.state.read(0, &mut self.aligned)?;
|
||||||
|
Ok(State::from(&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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mark to trigger firmware swap on next boot.
|
/// Mark to trigger firmware swap on next boot.
|
||||||
|
@ -44,6 +44,24 @@ pub enum State {
|
|||||||
DfuDetach,
|
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.
|
/// Buffer aligned to 32 byte boundary, largest known alignment requirement for embassy-boot.
|
||||||
#[repr(align(32))]
|
#[repr(align(32))]
|
||||||
pub struct AlignedBuffer<const N: usize>(pub [u8; N]);
|
pub struct AlignedBuffer<const N: usize>(pub [u8; N]);
|
||||||
|
Loading…
Reference in New Issue
Block a user