ota.rs
1 use alloc::boxed::Box; 2 use defmt::info; 3 use esp_bootloader_esp_idf::ota::OtaImageState; 4 use esp_bootloader_esp_idf::ota_updater::OtaUpdater; 5 use esp_bootloader_esp_idf::partitions::PARTITION_TABLE_MAX_LEN; 6 use esp_storage::FlashStorage; 7 8 pub fn validate_ota_slot(flash: &mut FlashStorage<'_>) { 9 let mut buffer = Box::new([0u8; PARTITION_TABLE_MAX_LEN]); 10 let Ok(mut ota) = OtaUpdater::new(flash, &mut buffer) else { 11 info!("OTA updater init failed (may not have OTA partitions)"); 12 return; 13 }; 14 15 match ota.current_ota_state() { 16 Ok(OtaImageState::New) | Ok(OtaImageState::PendingVerify) => { 17 if let Err(error) = ota.set_current_ota_state(OtaImageState::Valid) { 18 info!("failed to mark OTA slot valid: {:?}", error); 19 } else { 20 info!("marked current OTA slot as valid"); 21 } 22 } 23 Ok(state) => { 24 info!("OTA slot already in state {:?}, no action needed", state); 25 } 26 Err(error) => { 27 info!("failed to read OTA state: {:?}", error); 28 } 29 } 30 }