diff options
Diffstat (limited to 'embassy-boot/src/firmware_updater/mod.rs')
| -rw-r--r-- | embassy-boot/src/firmware_updater/mod.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/embassy-boot/src/firmware_updater/mod.rs b/embassy-boot/src/firmware_updater/mod.rs new file mode 100644 index 000000000..4814786bf --- /dev/null +++ b/embassy-boot/src/firmware_updater/mod.rs | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | mod asynch; | ||
| 2 | mod blocking; | ||
| 3 | |||
| 4 | pub use asynch::{FirmwareState, FirmwareUpdater}; | ||
| 5 | pub use blocking::{BlockingFirmwareState, BlockingFirmwareUpdater}; | ||
| 6 | use embedded_storage::nor_flash::{NorFlashError, NorFlashErrorKind}; | ||
| 7 | |||
| 8 | /// Firmware updater flash configuration holding the two flashes used by the updater | ||
| 9 | /// | ||
| 10 | /// If only a single flash is actually used, then that flash should be partitioned into two partitions before use. | ||
| 11 | /// The easiest way to do this is to use [`FirmwareUpdaterConfig::from_linkerfile`] or [`FirmwareUpdaterConfig::from_linkerfile_blocking`] which will partition | ||
| 12 | /// the provided flash according to symbols defined in the linkerfile. | ||
| 13 | pub struct FirmwareUpdaterConfig<DFU, STATE> { | ||
| 14 | /// The dfu flash partition | ||
| 15 | pub dfu: DFU, | ||
| 16 | /// The state flash partition | ||
| 17 | pub state: STATE, | ||
| 18 | } | ||
| 19 | |||
| 20 | /// Errors returned by FirmwareUpdater | ||
| 21 | #[derive(Debug)] | ||
| 22 | pub enum FirmwareUpdaterError { | ||
| 23 | /// Error from flash. | ||
| 24 | Flash(NorFlashErrorKind), | ||
| 25 | /// Signature errors. | ||
| 26 | Signature(signature::Error), | ||
| 27 | /// Bad state. | ||
| 28 | BadState, | ||
| 29 | } | ||
| 30 | |||
| 31 | #[cfg(feature = "defmt")] | ||
| 32 | impl defmt::Format for FirmwareUpdaterError { | ||
| 33 | fn format(&self, fmt: defmt::Formatter) { | ||
| 34 | match self { | ||
| 35 | FirmwareUpdaterError::Flash(_) => defmt::write!(fmt, "FirmwareUpdaterError::Flash(_)"), | ||
| 36 | FirmwareUpdaterError::Signature(_) => defmt::write!(fmt, "FirmwareUpdaterError::Signature(_)"), | ||
| 37 | FirmwareUpdaterError::BadState => defmt::write!(fmt, "FirmwareUpdaterError::BadState"), | ||
| 38 | } | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | impl<E> From<E> for FirmwareUpdaterError | ||
| 43 | where | ||
| 44 | E: NorFlashError, | ||
| 45 | { | ||
| 46 | fn from(error: E) -> Self { | ||
| 47 | FirmwareUpdaterError::Flash(error.kind()) | ||
| 48 | } | ||
| 49 | } | ||
