Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added
- `save-image` now checks if the ELF contains the app descriptor (#920)

### Changed

Expand Down
11 changes: 7 additions & 4 deletions cargo-espflash/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use espflash::{
*,
},
flasher::FlashSize,
image_format::{ImageFormat, ImageFormatKind, idf::check_idf_bootloader},
image_format::{ImageFormat, ImageFormatKind, idf::check_app_descriptor},
logging::initialize_logger,
target::{Chip, XtalFrequency},
update::check_for_update,
Expand Down Expand Up @@ -336,9 +336,8 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
// Read the ELF data from the build path and load it to the target.
let elf_data = fs::read(build_ctx.artifact_path.clone()).into_diagnostic()?;

// Check if the ELF contains the app descriptor, if required.
if args.flash_args.image.check_app_descriptor.unwrap_or(true) {
check_idf_bootloader(&elf_data)?;
if args.flash_args.image.check_app_descriptor && args.format == ImageFormatKind::EspIdf {
check_app_descriptor(&elf_data)?;
}

let mut monitor_args = args.flash_args.monitor_args;
Expand Down Expand Up @@ -617,6 +616,10 @@ fn save_image(args: SaveImageArgs, config: &Config) -> Result<()> {
let build_ctx = build(&args.build_args, &cargo_config, args.save_image_args.chip)?;
let elf_data = fs::read(&build_ctx.artifact_path).into_diagnostic()?;

if args.save_image_args.image.check_app_descriptor && args.format == ImageFormatKind::EspIdf {
check_app_descriptor(&elf_data)?;
}

// Since we have no `Flasher` instance and as such cannot print the board
// information, we will print whatever information we _do_ have.
println!("Chip type: {}", args.save_image_args.chip);
Expand Down
11 changes: 7 additions & 4 deletions espflash/src/bin/espflash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use espflash::{
*,
},
flasher::FlashSize,
image_format::{ImageFormat, ImageFormatKind, idf::check_idf_bootloader},
image_format::{ImageFormat, ImageFormatKind, idf::check_app_descriptor},
logging::initialize_logger,
target::{Chip, XtalFrequency},
update::check_for_update,
Expand Down Expand Up @@ -263,9 +263,8 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
// Read the ELF data from the build path and load it to the target.
let elf_data = fs::read(&args.image).into_diagnostic()?;

// Check if the ELF contains the app descriptor, if required.
if args.flash_args.image.check_app_descriptor.unwrap_or(true) {
check_idf_bootloader(&elf_data)?;
if args.flash_args.image.check_app_descriptor && args.format == ImageFormatKind::EspIdf {
check_app_descriptor(&elf_data)?;
}

print_board_info(&mut flasher)?;
Expand Down Expand Up @@ -344,6 +343,10 @@ fn save_image(args: SaveImageArgs, config: &Config) -> Result<()> {
.into_diagnostic()
.wrap_err_with(|| format!("Failed to open image {}", args.image.display()))?;

if args.save_image_args.image.check_app_descriptor && args.format == ImageFormatKind::EspIdf {
check_app_descriptor(&elf_data)?;
}

// Since we have no `Flasher` instance and as such cannot print the board
// information, we will print whatever information we _do_ have.
println!("Chip type: {}", args.save_image_args.chip);
Expand Down
2 changes: 1 addition & 1 deletion espflash/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ pub struct ImageArgs {
pub mmu_page_size: Option<u32>,
/// Flag to check the app descriptor in bootloader
#[arg(long, default_value = "true", value_parser = clap::value_parser!(bool))]
pub check_app_descriptor: Option<bool>,
pub check_app_descriptor: bool,
}

/// ESP-IDF image format arguments
Expand Down
2 changes: 1 addition & 1 deletion espflash/src/image_format/idf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ where
}

/// 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).
pub fn check_idf_bootloader(elf_data: &Vec<u8>) -> Result<()> {
pub fn check_app_descriptor(elf_data: &Vec<u8>) -> Result<()> {
let object = File::parse(elf_data.as_slice()).into_diagnostic()?;

let has_app_desc = object.symbols().any(|sym| sym.name() == Ok("esp_app_desc"));
Expand Down
Loading