Skip to content

Commit 0a983fa

Browse files
authored
Check app_desc _only_ for esp-hal projects (#892)
* App desc check only for esp-hal projects * clippy * comment why it is esp-hal specific * Check if the project is esp-idf based and if it has an app desc section present * clippy * reviews * fmt * update link
1 parent 29371c3 commit 0a983fa

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

espflash/src/error.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,9 @@ pub enum Error {
266266
)]
267267
PartitionTableDoesNotFit(FlashSize),
268268

269-
#[error(
270-
"The app descriptor is not present in the project. You need to add the https://github.com/esp-rs/esp-hal/tree/main/esp-bootloader-esp-idf to your project."
271-
)]
269+
#[error("{0}")]
272270
#[diagnostic(code(espflash::app_desc::app_descriptor_not_present))]
273-
AppDescriptorNotPresent,
271+
AppDescriptorNotPresent(String),
274272
}
275273

276274
#[cfg(feature = "serialport")]

espflash/src/image_format/idf.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -814,11 +814,25 @@ where
814814
/// Check if the provided ELF contains the app descriptor required by [the IDF bootloader](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-guides/bootloader.html).
815815
pub fn check_idf_bootloader(elf_data: &Vec<u8>) -> Result<()> {
816816
let object = File::parse(elf_data.as_slice()).into_diagnostic()?;
817-
let section = object.section_by_name(".rodata_desc").is_some();
818-
let symbol = object.symbols().any(|sym| sym.name() == Ok("esp_app_desc"));
819817

820-
if !section || !symbol {
821-
return Err(Error::AppDescriptorNotPresent).into_diagnostic();
818+
let has_app_desc = object.symbols().any(|sym| sym.name() == Ok("esp_app_desc"));
819+
let is_esp_hal = object.section_by_name(".espressif.metadata").is_some();
820+
821+
if !has_app_desc {
822+
if is_esp_hal {
823+
return Err(Error::AppDescriptorNotPresent(
824+
"The app descriptor is not present in the `esp-hal` based project.\n\
825+
You need to add the https://crates.io/crates/esp-bootloader-esp-idf \
826+
to your project."
827+
.to_string(),
828+
))
829+
.into_diagnostic();
830+
} else {
831+
return Err(Error::AppDescriptorNotPresent(
832+
"The app descriptor is not present in the `esp-idf` based project.".to_string(),
833+
))
834+
.into_diagnostic();
835+
}
822836
}
823837

824838
Ok(())

0 commit comments

Comments
 (0)