embassy_boot/firmware_updater/
mod.rs

1mod asynch;
2mod blocking;
3
4pub use asynch::{FirmwareState, FirmwareUpdater};
5pub use blocking::{BlockingFirmwareState, BlockingFirmwareUpdater};
6use 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.
13pub 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)]
22pub 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")]
32impl 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
42impl<E> From<E> for FirmwareUpdaterError
43where
44    E: NorFlashError,
45{
46    fn from(error: E) -> Self {
47        FirmwareUpdaterError::Flash(error.kind())
48    }
49}