diff options
| author | Ulf Lilleengen <[email protected]> | 2024-09-19 09:15:08 +0200 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2024-09-19 09:16:19 +0200 |
| commit | ab0a227e4c02137bc3a621907d17ede0ace4cb1d (patch) | |
| tree | 93e7b4e82f113283fa1b136871d48416968d52f3 /embassy-boot/src/lib.rs | |
| parent | b1897c58fa617dbab02b39e7f5e399ed1c9d54b4 (diff) | |
Ensure bootloader state is parsed correctly
Diffstat (limited to 'embassy-boot/src/lib.rs')
| -rw-r--r-- | embassy-boot/src/lib.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/embassy-boot/src/lib.rs b/embassy-boot/src/lib.rs index 7d5cc58f9..e2c4cf771 100644 --- a/embassy-boot/src/lib.rs +++ b/embassy-boot/src/lib.rs | |||
| @@ -44,6 +44,24 @@ pub enum State { | |||
| 44 | DfuDetach, | 44 | DfuDetach, |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | impl<T> From<T> for State | ||
| 48 | where | ||
| 49 | T: AsRef<[u8]>, | ||
| 50 | { | ||
| 51 | fn from(magic: T) -> State { | ||
| 52 | let magic = magic.as_ref(); | ||
| 53 | if !magic.iter().any(|&b| b != SWAP_MAGIC) { | ||
| 54 | State::Swap | ||
| 55 | } else if !magic.iter().any(|&b| b != REVERT_MAGIC) { | ||
| 56 | State::Revert | ||
| 57 | } else if !magic.iter().any(|&b| b != DFU_DETACH_MAGIC) { | ||
| 58 | State::DfuDetach | ||
| 59 | } else { | ||
| 60 | State::Boot | ||
| 61 | } | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 47 | /// Buffer aligned to 32 byte boundary, largest known alignment requirement for embassy-boot. | 65 | /// Buffer aligned to 32 byte boundary, largest known alignment requirement for embassy-boot. |
| 48 | #[repr(align(32))] | 66 | #[repr(align(32))] |
| 49 | pub struct AlignedBuffer<const N: usize>(pub [u8; N]); | 67 | pub struct AlignedBuffer<const N: usize>(pub [u8; N]); |
