Skip to main content

esp_hal_ota/
structs.rs

1pub(crate) type Result<T> = core::result::Result<T, OtaError>;
2
3#[derive(Debug, PartialEq)]
4#[cfg_attr(feature = "defmt", derive(defmt::Format))]
5pub enum OtaError {
6    OtaPartitionTooSmall,
7    NotEnoughPartitions,
8    OtaNotStarted,
9    FlashRWError,
10    WrongCRC,
11    WrongOTAPArtitionOrder,
12    OtaVerifyError,
13    CannotFindCurrentBootPartition,
14}
15
16#[derive(Clone)]
17pub struct FlashProgress {
18    pub last_crc: u32,
19    pub flash_offset: u32,
20    pub flash_size: u32,
21    pub remaining: u32,
22
23    pub target_partition: usize,
24    pub target_crc: u32,
25}
26
27#[derive(Debug)]
28pub struct PartitionInfo {
29    pub ota_partitions: [(u32, u32); 16],
30    pub ota_partitions_count: usize,
31
32    pub otadata_offset: u32,
33    pub otadata_size: u32,
34}
35
36#[repr(u32)]
37#[derive(Debug, PartialEq)]
38#[cfg_attr(feature = "defmt", derive(defmt::Format))]
39pub enum OtaImgState {
40    EspOtaImgNew = 0x0,
41    EspOtaImgPendingVerify = 0x1,
42    EspOtaImgValid = 0x2,
43    EspOtaImgInvalid = 0x3,
44    EspOtaImgAborted = 0x4,
45    EspOtaImgUndefined = 0xFFFFFFFF,
46}
47
48#[repr(C)]
49#[derive(Debug)]
50pub struct EspOtaSelectEntry {
51    pub seq: u32,
52    pub seq_label: [u8; 20],
53    pub ota_state: OtaImgState,
54    pub crc: u32,
55}
56
57impl EspOtaSelectEntry {
58    /// Check if crc(of seq) is correct, if not - its setting seq to 0
59    pub fn check_crc(&mut self) {
60        if !crate::helpers::is_crc_seq_correct(self.seq, self.crc) {
61            self.seq = 0; // set seq to 0 if crc not correct!
62        }
63    }
64}