From fa2bec53be1c31c24194e29d5942c5ae3465bae3 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Thu, 16 Nov 2023 13:27:38 +0100 Subject: [PATCH 1/6] refactor: Use structs to simplify some functions args --- cargo-espflash/src/main.rs | 62 +++++----- espflash/src/bin/espflash.rs | 60 +++++----- espflash/src/cli/mod.rs | 113 +++--------------- espflash/src/flasher/mod.rs | 123 ++++++++++++++++---- espflash/src/image_format/esp8266.rs | 14 +-- espflash/src/image_format/idf_bootloader.rs | 25 ++-- espflash/src/image_format/mod.rs | 1 - espflash/src/targets/esp32.rs | 14 +-- espflash/src/targets/esp32c2.rs | 14 +-- espflash/src/targets/esp32c3.rs | 14 +-- espflash/src/targets/esp32c6.rs | 14 +-- espflash/src/targets/esp32h2.rs | 14 +-- espflash/src/targets/esp32s2.rs | 14 +-- espflash/src/targets/esp32s3.rs | 14 +-- espflash/src/targets/esp8266.rs | 16 ++- espflash/src/targets/mod.rs | 8 +- 16 files changed, 247 insertions(+), 273 deletions(-) diff --git a/cargo-espflash/src/main.rs b/cargo-espflash/src/main.rs index 92bb826a..073bb925 100644 --- a/cargo-espflash/src/main.rs +++ b/cargo-espflash/src/main.rs @@ -15,6 +15,7 @@ use espflash::{ FlashConfigArgs, MonitorArgs, PartitionTableArgs, }, error::Error as EspflashError, + flasher::{FlashData, FlashSettings}, image_format::ImageFormatKind, logging::initialize_logger, targets::Chip, @@ -313,33 +314,32 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> { println!("Partition table: {}", path.display()); } - let partition_table = match partition_table { - Some(path) => Some(parse_partition_table(path)?), - None => None, - }; + let flash_settings = FlashSettings::new( + args.build_args.flash_config_args.flash_mode, + args.build_args.flash_config_args.flash_size, + args.build_args.flash_config_args.flash_freq, + ); + + let flash_data = FlashData::new( + &elf_data, + bootloader, + partition_table, + args.flash_args.partition_table_offset, + args.flash_args.format.or(metadata.format), + args.flash_args.target_app_partition, + flash_settings, + )?; if args.flash_args.erase_parts.is_some() || args.flash_args.erase_data_parts.is_some() { erase_partitions( &mut flasher, - partition_table.clone(), + flash_data.partition_table.clone(), args.flash_args.erase_parts, args.flash_args.erase_data_parts, )?; } - flash_elf_image( - &mut flasher, - &elf_data, - bootloader, - partition_table, - args.flash_args.target_app_partition, - args.flash_args.format.or(metadata.format), - args.build_args.flash_config_args.flash_mode, - args.build_args.flash_config_args.flash_size, - args.build_args.flash_config_args.flash_freq, - args.flash_args.partition_table_offset, - args.flash_args.min_chip_rev, - )?; + flash_elf_image(&mut flasher, flash_data)?; } if args.flash_args.monitor { @@ -564,20 +564,28 @@ fn save_image(args: SaveImageArgs) -> Result<()> { println!("Partition table: {}", path.display()); } - save_elf_as_image( - args.save_image_args.chip, - args.save_image_args.min_chip_rev, - &elf_data, - args.save_image_args.file, - args.format.or(metadata.format), + let flash_settings = FlashSettings::new( args.build_args.flash_config_args.flash_mode, args.build_args.flash_config_args.flash_size, args.build_args.flash_config_args.flash_freq, + ); + + let flash_data = FlashData::new( + &elf_data, + bootloader.as_deref(), + partition_table.as_deref(), args.save_image_args.partition_table_offset, - args.save_image_args.merge, - bootloader, - partition_table, + args.format.or(metadata.format), args.save_image_args.target_app_partition, + flash_settings, + )?; + + save_elf_as_image( + args.save_image_args.chip, + args.save_image_args.file, + flash_data, + args.save_image_args.merge, + args.save_image_args.skip_padding, args.save_image_args.skip_padding, )?; diff --git a/espflash/src/bin/espflash.rs b/espflash/src/bin/espflash.rs index fe4bb86a..c2c99882 100644 --- a/espflash/src/bin/espflash.rs +++ b/espflash/src/bin/espflash.rs @@ -14,6 +14,7 @@ use espflash::{ EspflashProgress, FlashConfigArgs, MonitorArgs, PartitionTableArgs, }, error::Error, + flasher::{FlashData, FlashSettings}, image_format::ImageFormatKind, logging::initialize_logger, targets::Chip, @@ -237,33 +238,31 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> { println!("Partition table: {}", path.display()); } - let partition_table = match partition_table { - Some(path) => Some(parse_partition_table(path)?), - None => None, - }; + let flash_settings = FlashSettings::new( + args.flash_config_args.flash_mode, + args.flash_config_args.flash_size, + args.flash_config_args.flash_freq, + ); + + let flash_data = FlashData::new( + &elf_data, + bootloader, + partition_table, + args.flash_args.format, + args.flash_args.target_app_partition, + flash_settings, + )?; if args.flash_args.erase_parts.is_some() || args.flash_args.erase_data_parts.is_some() { erase_partitions( &mut flasher, - partition_table.clone(), + flash_data.partition_table.clone(), args.flash_args.erase_parts, args.flash_args.erase_data_parts, )?; } - flash_elf_image( - &mut flasher, - &elf_data, - bootloader, - partition_table, - args.flash_args.target_app_partition, - args.flash_args.format, - args.flash_config_args.flash_mode, - args.flash_config_args.flash_size, - args.flash_config_args.flash_freq, - args.flash_args.partition_table_offset, - args.flash_args.min_chip_rev, - )?; + flash_elf_image(&mut flasher, flash_data)?; } if args.flash_args.monitor { @@ -309,20 +308,27 @@ fn save_image(args: SaveImageArgs) -> Result<()> { println!("Partition table: {}", path.display()); } - save_elf_as_image( - args.save_image_args.chip, - args.save_image_args.min_chip_rev, - &elf_data, - args.save_image_args.file, - args.format, + let flash_settings = FlashSettings::new( args.flash_config_args.flash_mode, args.flash_config_args.flash_size, args.flash_config_args.flash_freq, + ); + + let flash_data = FlashData::new( + &elf_data, + args.save_image_args.bootloader.as_deref(), + args.save_image_args.partition_table.as_deref(), args.save_image_args.partition_table_offset, - args.save_image_args.merge, - args.save_image_args.bootloader, - args.save_image_args.partition_table, + args.format, args.save_image_args.target_app_partition, + flash_settings, + )?; + + save_elf_as_image( + args.save_image_args.chip, + args.save_image_args.file, + flash_data, + args.save_image_args.merge, args.save_image_args.skip_padding, )?; diff --git a/espflash/src/cli/mod.rs b/espflash/src/cli/mod.rs index f48138c3..5d003faa 100644 --- a/espflash/src/cli/mod.rs +++ b/espflash/src/cli/mod.rs @@ -35,7 +35,7 @@ use self::{ use crate::{ elf::ElfFirmwareImage, error::{Error, MissingPartition, MissingPartitionTable}, - flasher::{FlashFrequency, FlashMode, FlashSize, Flasher, ProgressCallbacks}, + flasher::{FlashData, FlashFrequency, FlashMode, FlashSize, Flasher, ProgressCallbacks}, image_format::ImageFormatKind, interface::Interface, targets::Chip, @@ -419,67 +419,25 @@ pub fn serial_monitor(args: MonitorArgs, config: &Config) -> Result<()> { /// Convert the provided firmware image from ELF to binary pub fn save_elf_as_image( chip: Chip, - min_rev_full: u16, - elf_data: &[u8], image_path: PathBuf, - image_format: Option, - flash_mode: Option, - flash_size: Option, - flash_freq: Option, - partition_table_offset: Option, + flash_data: FlashData, merge: bool, - bootloader_path: Option, - partition_table_path: Option, - target_app_partition: Option, skip_padding: bool, ) -> Result<()> { - let image = ElfFirmwareImage::try_from(elf_data)?; + let image = ElfFirmwareImage::try_from(flash_data.elf_data)?; if merge { - // merge_bin is TRUE - // merge bootloader, partition table and app binaries - // basic functionality, only merge 3 binaries - - // If the '-B' option is provided, load the bootloader binary file at the - // specified path. - let bootloader = if let Some(bootloader_path) = bootloader_path { - let path = fs::canonicalize(bootloader_path).into_diagnostic()?; - let data = fs::read(path).into_diagnostic()?; - - Some(data) - } else { - None - }; - - // If the '-T' option is provided, load the partition table from - // the CSV or binary file at the specified path. - let partition_table = if let Some(partition_table_path) = partition_table_path { - let path = fs::canonicalize(partition_table_path).into_diagnostic()?; - let data = fs::read(path) - .into_diagnostic() - .wrap_err("Failed to open partition table")?; - - let table = PartitionTable::try_from(data).into_diagnostic()?; - - Some(table) - } else { - None - }; - // To get a chip revision, the connection is needed // For simplicity, the revision None is used let image = chip.into_target().get_flash_image( &image, - bootloader, - partition_table, - target_app_partition, - image_format, + flash_data.bootloader, + flash_data.partition_table, + flash_data.partition_table_offset, + flash_data.target_app_partition, + flash_data.image_format, None, - min_rev_full, - flash_mode, - flash_size, - flash_freq, - partition_table_offset, + flash_data.flash_settings, )?; display_image_size(image.app_size(), image.part_size()); @@ -505,7 +463,8 @@ pub fn save_elf_as_image( // Take flash_size as input parameter, if None, use default value of 4Mb let padding_bytes = vec![ 0xffu8; - flash_size.unwrap_or_default().size() as usize + flash_data.flash_settings.size.unwrap_or_default().size() + as usize - file.metadata().into_diagnostic()?.len() as usize ]; file.write_all(&padding_bytes).into_diagnostic()?; @@ -515,14 +474,11 @@ pub fn save_elf_as_image( &image, None, None, + flash_data.target_app_partition, + flash_data.partition_table_offset, + flash_data.image_format, None, - image_format, - None, - min_rev_full, - flash_mode, - flash_size, - flash_freq, - partition_table_offset, + flash_data.flash_settings, )?; display_image_size(image.app_size(), image.part_size()); @@ -626,45 +582,10 @@ pub fn erase_region(args: EraseRegionArgs, config: &Config) -> Result<()> { } /// Write an ELF image to a target device's flash -pub fn flash_elf_image( - flasher: &mut Flasher, - elf_data: &[u8], - bootloader: Option<&Path>, - partition_table: Option, - target_app_partition: Option, - image_format: Option, - flash_mode: Option, - flash_size: Option, - flash_freq: Option, - partition_table_offset: Option, - min_rev_full: u16, -) -> Result<()> { - // If the '--bootloader' option is provided, load the binary file at the - // specified path. - let bootloader = if let Some(path) = bootloader { - let path = fs::canonicalize(path).into_diagnostic()?; - let data = fs::read(path).into_diagnostic()?; - - Some(data) - } else { - None - }; - +pub fn flash_elf_image(flasher: &mut Flasher, flash_data: FlashData) -> Result<()> { // Load the ELF data, optionally using the provider bootloader/partition // table/image format, to the device's flash memory. - flasher.load_elf_to_flash_with_format( - elf_data, - bootloader, - partition_table, - target_app_partition, - image_format, - flash_mode, - flash_size, - flash_freq, - partition_table_offset, - min_rev_full, - Some(&mut EspflashProgress::default()), - )?; + flasher.load_elf_to_flash(flash_data, Some(&mut EspflashProgress::default()))?; info!("Flashing has completed!"); Ok(()) diff --git a/espflash/src/flasher/mod.rs b/espflash/src/flasher/mod.rs index c6d1e77a..2c00ee9d 100644 --- a/espflash/src/flasher/mod.rs +++ b/espflash/src/flasher/mod.rs @@ -4,17 +4,18 @@ //! application to a target device. It additionally provides some operations to //! read information from the target device. -use std::{borrow::Cow, str::FromStr, thread::sleep}; +use std::{borrow::Cow, fs, path::Path, str::FromStr, thread::sleep}; use bytemuck::{Pod, Zeroable, __core::time::Duration}; use esp_idf_part::PartitionTable; use log::{debug, info, warn}; -use serde::{Deserialize, Serialize}; +use miette::{IntoDiagnostic, Result}; use serialport::UsbPortInfo; use strum::{Display, EnumIter, EnumVariantNames}; use self::stubs::FlashStub; use crate::{ + cli::parse_partition_table, command::{Command, CommandType}, connection::Connection, elf::{ElfFirmwareImage, FirmwareImage, RomSegment}, @@ -254,6 +255,88 @@ impl FromStr for FlashSize { } } +/// Flash settings to use when flashing a device +#[derive(Copy, Clone, Debug)] +#[non_exhaustive] +pub struct FlashSettings { + pub mode: Option, + pub size: Option, + pub freq: Option, +} + +impl FlashSettings { + pub const fn default() -> Self { + FlashSettings { + mode: None, + size: None, + freq: None, + } + } + pub fn new( + mode: Option, + size: Option, + freq: Option, + ) -> Self { + FlashSettings { mode, size, freq } + } +} + +/// Flash data and configuration +#[derive(Debug, Clone)] +#[non_exhaustive] +pub struct FlashData<'a> { + pub elf_data: &'a [u8], + pub bootloader: Option>, + pub partition_table: Option, + pub partition_table_offset: Option, + pub image_format: Option, + pub target_app_partition: Option, + pub flash_settings: FlashSettings, + pub min_chip_rev: u16, +} + +impl<'a> FlashData<'a> { + pub fn new( + elf_data: &'a [u8], + bootloader: Option<&'a Path>, + partition_table: Option<&'a Path>, + partition_table_offset: Option, + image_format: Option, + target_app_partition: Option, + flash_settings: FlashSettings, + min_chip_rev: u16, + ) -> Result { + // If the '--bootloader' option is provided, load the binary file at the + // specified path. + let bootloader = if let Some(path) = bootloader { + let path = fs::canonicalize(path).into_diagnostic()?; + let data = fs::read(path).into_diagnostic()?; + + Some(data) + } else { + None + }; + + // If the '-T' option is provided, load the partition table from + // the CSV or binary file at the specified path. + let partition_table = match partition_table { + Some(path) => Some(parse_partition_table(path)?), + None => None, + }; + + Ok(FlashData { + elf_data, + bootloader, + partition_table, + partition_table_offset, + image_format, + target_app_partition, + flash_settings, + min_chip_rev, + }) + } +} + /// Parameters of the attached SPI flash chip (sizes, etc). #[derive(Copy, Clone, Debug)] #[repr(C)] @@ -808,21 +891,12 @@ impl Flasher { } /// Load an ELF image to flash and execute it - pub fn load_elf_to_flash_with_format( + pub fn load_elf_to_flash( &mut self, - elf_data: &[u8], - bootloader: Option>, - partition_table: Option, - target_app_partition: Option, - image_format: Option, - flash_mode: Option, - flash_size: Option, - flash_freq: Option, - partition_table_offset: Option, - min_rev_full: u16, + flash_data: FlashData, mut progress: Option<&mut dyn ProgressCallbacks>, ) -> Result<(), Error> { - let image = ElfFirmwareImage::try_from(elf_data)?; + let image = ElfFirmwareImage::try_from(flash_data.elf_data)?; let mut target = self.chip @@ -841,18 +915,21 @@ impl Flasher { None }; + let flash_settings = FlashSettings::new( + flash_data.flash_settings.mode, + flash_data.flash_settings.size.or(Some(self.flash_size)), + flash_data.flash_settings.freq, + ); + let image = self.chip.into_target().get_flash_image( &image, - bootloader, - partition_table, - target_app_partition, - image_format, + flash_data.bootloader, + flash_data.partition_table, + flash_data.target_app_partition, + flash_data.image_format, chip_revision, - min_rev_full, - flash_mode, - flash_size.or(Some(self.flash_size)), - flash_freq, - partition_table_offset, + flash_data.min_chip_rev, + flash_settings, )?; // When the `cli` feature is enabled, display the image size information. diff --git a/espflash/src/image_format/esp8266.rs b/espflash/src/image_format/esp8266.rs index 528d88d4..39d4f001 100644 --- a/espflash/src/image_format/esp8266.rs +++ b/espflash/src/image_format/esp8266.rs @@ -5,7 +5,7 @@ use bytemuck::bytes_of; use crate::{ elf::{CodeSegment, FirmwareImage, RomSegment}, error::Error, - flasher::{FlashFrequency, FlashMode, FlashSize}, + flasher::FlashSettings, image_format::{ update_checksum, ImageFormat, ImageHeader, SegmentHeader, ESP_CHECKSUM_MAGIC, ESP_MAGIC, }, @@ -22,9 +22,7 @@ pub struct Esp8266Format<'a> { impl<'a> Esp8266Format<'a> { pub fn new( image: &'a dyn FirmwareImage<'a>, - flash_mode: Option, - flash_size: Option, - flash_freq: Option, + flash_settings: FlashSettings, ) -> Result { // IROM goes into a separate plain binary let irom_data = merge_rom_segments(image.rom_segments(Chip::Esp8266)); @@ -37,7 +35,7 @@ impl<'a> Esp8266Format<'a> { ); // Common header - let flash_mode = flash_mode.unwrap_or_default() as u8; + let flash_mode = flash_settings.mode.unwrap_or_default() as u8; let segment_count = image.ram_segments(Chip::Esp8266).count() as u8; let mut header = ImageHeader { @@ -48,8 +46,8 @@ impl<'a> Esp8266Format<'a> { ..Default::default() }; header.write_flash_config( - flash_size.unwrap_or_default(), - flash_freq.unwrap_or_default(), + flash_settings.size.unwrap_or_default(), + flash_settings.freq.unwrap_or_default(), Chip::Esp8266, )?; @@ -178,7 +176,7 @@ mod tests { let expected_bin = fs::read("tests/resources/esp8266_hal_blinky.bin").unwrap(); let image = ElfFirmwareImage::try_from(input_bytes.as_slice()).unwrap(); - let flash_image = Esp8266Format::new(&image, None, None, None).unwrap(); + let flash_image = Esp8266Format::new(&image, FlashSettings::default()).unwrap(); let segments = flash_image.flash_segments().collect::>(); let buf = segments[0].data.as_ref(); diff --git a/espflash/src/image_format/idf_bootloader.rs b/espflash/src/image_format/idf_bootloader.rs index 9ff393ec..4d671844 100644 --- a/espflash/src/image_format/idf_bootloader.rs +++ b/espflash/src/image_format/idf_bootloader.rs @@ -7,7 +7,7 @@ use sha2::{Digest, Sha256}; use crate::{ elf::{CodeSegment, FirmwareImage, RomSegment}, error::Error, - flasher::{FlashFrequency, FlashMode, FlashSize}, + flasher::FlashSettings, image_format::{ update_checksum, ImageFormat, ImageHeader, SegmentHeader, ESP_CHECKSUM_MAGIC, ESP_MAGIC, WP_PIN_DISABLED, @@ -37,15 +37,14 @@ impl<'a> IdfBootloaderFormat<'a> { min_rev_full: u16, params: Esp32Params, partition_table: Option, + partition_table_offset: Option, target_app_partition: Option, bootloader: Option>, - flash_mode: Option, - flash_size: Option, - flash_freq: Option, - partition_table_offset: Option, + flash_settings: FlashSettings, ) -> Result { - let partition_table = partition_table - .unwrap_or_else(|| params.default_partition_table(flash_size.map(|v| v.size()))); + let partition_table = partition_table.unwrap_or_else(|| { + params.default_partition_table(flash_settings.size.map(|v| v.size())) + }); let mut bootloader = if let Some(bytes) = bootloader { Cow::Owned(bytes) } else { @@ -59,13 +58,13 @@ impl<'a> IdfBootloaderFormat<'a> { } // update the header if a user has specified any custom arguments - if let Some(mode) = flash_mode { + if let Some(mode) = flash_settings.mode { header.flash_mode = mode as u8; } header.write_flash_config( - flash_size.unwrap_or_default(), - flash_freq.unwrap_or(params.flash_freq), + flash_settings.size.unwrap_or_default(), + flash_settings.freq.unwrap_or(params.flash_freq), chip, )?; @@ -345,7 +344,7 @@ pub mod tests { use std::fs; use super::*; - use crate::elf::ElfFirmwareImage; + use crate::{elf::ElfFirmwareImage, image_format::FlashFrequency}; // Copied from: src/targets/esp32.rs const PARAMS: Esp32Params = Esp32Params::new( @@ -372,9 +371,7 @@ pub mod tests { None, None, None, - None, - None, - None, + FlashSettings::default(), ) .unwrap(); diff --git a/espflash/src/image_format/mod.rs b/espflash/src/image_format/mod.rs index ade8c666..7e011ab3 100644 --- a/espflash/src/image_format/mod.rs +++ b/espflash/src/image_format/mod.rs @@ -20,7 +20,6 @@ use crate::{ flasher::{FlashFrequency, FlashMode, FlashSize}, targets::Chip, }; - mod direct_boot; mod esp8266; mod idf_bootloader; diff --git a/espflash/src/targets/esp32.rs b/espflash/src/targets/esp32.rs index bbcee321..fdfba81d 100644 --- a/espflash/src/targets/esp32.rs +++ b/espflash/src/targets/esp32.rs @@ -6,7 +6,7 @@ use crate::{ connection::Connection, elf::FirmwareImage, error::{Error, UnsupportedImageFormatError}, - flasher::{FlashFrequency, FlashMode, FlashSize}, + flasher::{FlashFrequency, FlashSettings}, image_format::{IdfBootloaderFormat, ImageFormat, ImageFormatKind}, targets::{bytes_to_mac_addr, Chip, Esp32Params, ReadEFuse, SpiRegisters, Target}, }; @@ -155,14 +155,12 @@ impl Target for Esp32 { image: &'a dyn FirmwareImage<'a>, bootloader: Option>, partition_table: Option, + partition_table_offset: Option, target_app_partition: Option, image_format: Option, _chip_revision: Option<(u32, u32)>, min_rev_full: u16, - flash_mode: Option, - flash_size: Option, - flash_freq: Option, - partition_table_offset: Option, + flash_settings: FlashSettings, ) -> Result + 'a>, Error> { let image_format = image_format.unwrap_or(ImageFormatKind::EspBootloader); @@ -173,12 +171,10 @@ impl Target for Esp32 { min_rev_full, PARAMS, partition_table, + partition_table_offset, target_app_partition, bootloader, - flash_mode, - flash_size, - flash_freq, - partition_table_offset, + flash_settings, )?)), _ => Err(UnsupportedImageFormatError::new(image_format, Chip::Esp32, None).into()), } diff --git a/espflash/src/targets/esp32c2.rs b/espflash/src/targets/esp32c2.rs index da12bf62..916a0a9a 100644 --- a/espflash/src/targets/esp32c2.rs +++ b/espflash/src/targets/esp32c2.rs @@ -6,7 +6,7 @@ use crate::{ connection::Connection, elf::FirmwareImage, error::Error, - flasher::{FlashFrequency, FlashMode, FlashSize}, + flasher::{FlashFrequency, FlashSettings}, image_format::{DirectBootFormat, IdfBootloaderFormat, ImageFormat, ImageFormatKind}, targets::{bytes_to_mac_addr, Chip, Esp32Params, ReadEFuse, SpiRegisters, Target}, }; @@ -89,14 +89,12 @@ impl Target for Esp32c2 { image: &'a dyn FirmwareImage<'a>, bootloader: Option>, partition_table: Option, + partition_table_offset: Option, target_app_partition: Option, image_format: Option, _chip_revision: Option<(u32, u32)>, + flash_settings: FlashSettings, min_rev_full: u16, - flash_mode: Option, - flash_size: Option, - flash_freq: Option, - partition_table_offset: Option, ) -> Result + 'a>, Error> { let image_format = image_format.unwrap_or(ImageFormatKind::EspBootloader); @@ -107,12 +105,10 @@ impl Target for Esp32c2 { min_rev_full, PARAMS, partition_table, + partition_table_offset, target_app_partition, bootloader, - flash_mode, - flash_size, - flash_freq, - partition_table_offset, + flash_settings, )?)), ImageFormatKind::DirectBoot => Ok(Box::new(DirectBootFormat::new(image, 0)?)), } diff --git a/espflash/src/targets/esp32c3.rs b/espflash/src/targets/esp32c3.rs index 3ec97f04..de214338 100644 --- a/espflash/src/targets/esp32c3.rs +++ b/espflash/src/targets/esp32c3.rs @@ -6,7 +6,7 @@ use crate::{ connection::Connection, elf::FirmwareImage, error::{Error, UnsupportedImageFormatError}, - flasher::{FlashFrequency, FlashMode, FlashSize}, + flasher::{FlashFrequency, FlashSettings}, image_format::{DirectBootFormat, IdfBootloaderFormat, ImageFormat, ImageFormatKind}, targets::{Chip, Esp32Params, ReadEFuse, SpiRegisters, Target}, }; @@ -76,14 +76,12 @@ impl Target for Esp32c3 { image: &'a dyn FirmwareImage<'a>, bootloader: Option>, partition_table: Option, + partition_table_offset: Option, target_app_partition: Option, image_format: Option, chip_revision: Option<(u32, u32)>, min_rev_full: u16, - flash_mode: Option, - flash_size: Option, - flash_freq: Option, - partition_table_offset: Option, + flash_settings: FlashSettings, ) -> Result + 'a>, Error> { let image_format = image_format.unwrap_or(ImageFormatKind::EspBootloader); @@ -94,12 +92,10 @@ impl Target for Esp32c3 { min_rev_full, PARAMS, partition_table, + partition_table_offset, target_app_partition, bootloader, - flash_mode, - flash_size, - flash_freq, - partition_table_offset, + flash_settings, )?)), (ImageFormatKind::DirectBoot, None | Some((_, 3..))) => { Ok(Box::new(DirectBootFormat::new(image, 0)?)) diff --git a/espflash/src/targets/esp32c6.rs b/espflash/src/targets/esp32c6.rs index dd624bb0..1db11a97 100644 --- a/espflash/src/targets/esp32c6.rs +++ b/espflash/src/targets/esp32c6.rs @@ -6,7 +6,7 @@ use crate::{ connection::Connection, elf::FirmwareImage, error::Error, - flasher::{FlashFrequency, FlashMode, FlashSize}, + flasher::{FlashFrequency, FlashSettings}, image_format::{DirectBootFormat, IdfBootloaderFormat, ImageFormat, ImageFormatKind}, targets::{Chip, Esp32Params, ReadEFuse, SpiRegisters, Target}, }; @@ -73,14 +73,12 @@ impl Target for Esp32c6 { image: &'a dyn FirmwareImage<'a>, bootloader: Option>, partition_table: Option, + partition_table_offset: Option, target_app_partition: Option, image_format: Option, _chip_revision: Option<(u32, u32)>, min_rev_full: u16, - flash_mode: Option, - flash_size: Option, - flash_freq: Option, - partition_table_offset: Option, + flash_settings: FlashSettings, ) -> Result + 'a>, Error> { let image_format = image_format.unwrap_or(ImageFormatKind::EspBootloader); @@ -91,12 +89,10 @@ impl Target for Esp32c6 { min_rev_full, PARAMS, partition_table, + partition_table_offset, target_app_partition, bootloader, - flash_mode, - flash_size, - flash_freq, - partition_table_offset, + flash_settings, )?)), ImageFormatKind::DirectBoot => Ok(Box::new(DirectBootFormat::new(image, 0x0)?)), } diff --git a/espflash/src/targets/esp32h2.rs b/espflash/src/targets/esp32h2.rs index 81a7523b..1548ead3 100644 --- a/espflash/src/targets/esp32h2.rs +++ b/espflash/src/targets/esp32h2.rs @@ -8,7 +8,7 @@ use crate::{ connection::Connection, elf::FirmwareImage, error::Error, - flasher::{FlashFrequency, FlashMode, FlashSize}, + flasher::{FlashFrequency, FlashSettings}, image_format::{DirectBootFormat, IdfBootloaderFormat, ImageFormat, ImageFormatKind}, }; @@ -81,14 +81,12 @@ impl Target for Esp32h2 { image: &'a dyn FirmwareImage<'a>, bootloader: Option>, partition_table: Option, + partition_table_offset: Option, target_app_partition: Option, image_format: Option, _chip_revision: Option<(u32, u32)>, min_rev_full: u16, - flash_mode: Option, - flash_size: Option, - flash_freq: Option, - partition_table_offset: Option, + flash_settings: FlashSettings, ) -> Result + 'a>, Error> { let image_format = image_format.unwrap_or(ImageFormatKind::EspBootloader); @@ -99,12 +97,10 @@ impl Target for Esp32h2 { min_rev_full, PARAMS, partition_table, + partition_table_offset, target_app_partition, bootloader, - flash_mode, - flash_size, - flash_freq, - partition_table_offset, + flash_settings, )?)), ImageFormatKind::DirectBoot => Ok(Box::new(DirectBootFormat::new(image, 0x0)?)), } diff --git a/espflash/src/targets/esp32s2.rs b/espflash/src/targets/esp32s2.rs index 822bccc9..eb56f1ba 100644 --- a/espflash/src/targets/esp32s2.rs +++ b/espflash/src/targets/esp32s2.rs @@ -6,7 +6,7 @@ use crate::{ connection::Connection, elf::FirmwareImage, error::{Error, UnsupportedImageFormatError}, - flasher::{FlashFrequency, FlashMode, FlashSize, FLASH_WRITE_SIZE}, + flasher::{FlashFrequency, FlashSettings, FLASH_WRITE_SIZE}, image_format::{IdfBootloaderFormat, ImageFormat, ImageFormatKind}, targets::{Chip, Esp32Params, ReadEFuse, SpiRegisters, Target, MAX_RAM_BLOCK_SIZE}, }; @@ -141,14 +141,12 @@ impl Target for Esp32s2 { image: &'a dyn FirmwareImage<'a>, bootloader: Option>, partition_table: Option, + partition_table_offset: Option, target_app_partition: Option, image_format: Option, _chip_revision: Option<(u32, u32)>, min_rev_full: u16, - flash_mode: Option, - flash_size: Option, - flash_freq: Option, - partition_table_offset: Option, + flash_settings: FlashSettings, ) -> Result + 'a>, Error> { let image_format = image_format.unwrap_or(ImageFormatKind::EspBootloader); @@ -159,12 +157,10 @@ impl Target for Esp32s2 { min_rev_full, PARAMS, partition_table, + partition_table_offset, target_app_partition, bootloader, - flash_mode, - flash_size, - flash_freq, - partition_table_offset, + flash_settings, )?)), _ => Err(UnsupportedImageFormatError::new(image_format, Chip::Esp32s2, None).into()), } diff --git a/espflash/src/targets/esp32s3.rs b/espflash/src/targets/esp32s3.rs index 08d0b722..09fc4acd 100644 --- a/espflash/src/targets/esp32s3.rs +++ b/espflash/src/targets/esp32s3.rs @@ -6,7 +6,7 @@ use crate::{ connection::Connection, elf::FirmwareImage, error::Error, - flasher::{FlashFrequency, FlashMode, FlashSize}, + flasher::{FlashFrequency, FlashSettings}, image_format::{DirectBootFormat, IdfBootloaderFormat, ImageFormat, ImageFormatKind}, targets::{Chip, Esp32Params, ReadEFuse, SpiRegisters, Target}, }; @@ -95,14 +95,12 @@ impl Target for Esp32s3 { image: &'a dyn FirmwareImage<'a>, bootloader: Option>, partition_table: Option, + partition_table_offset: Option, target_app_partition: Option, image_format: Option, _chip_revision: Option<(u32, u32)>, min_rev_full: u16, - flash_mode: Option, - flash_size: Option, - flash_freq: Option, - partition_table_offset: Option, + flash_settings: FlashSettings, ) -> Result + 'a>, Error> { let image_format = image_format.unwrap_or(ImageFormatKind::EspBootloader); @@ -113,12 +111,10 @@ impl Target for Esp32s3 { min_rev_full, PARAMS, partition_table, + partition_table_offset, target_app_partition, bootloader, - flash_mode, - flash_size, - flash_freq, - partition_table_offset, + flash_settings, )?)), ImageFormatKind::DirectBoot => Ok(Box::new(DirectBootFormat::new(image, 0x400)?)), } diff --git a/espflash/src/targets/esp8266.rs b/espflash/src/targets/esp8266.rs index 1b03ddd0..b6d3d82c 100644 --- a/espflash/src/targets/esp8266.rs +++ b/espflash/src/targets/esp8266.rs @@ -6,7 +6,7 @@ use crate::{ connection::Connection, elf::FirmwareImage, error::{Error, UnsupportedImageFormatError}, - flasher::{FlashFrequency, FlashMode, FlashSize}, + flasher::FlashSettings, image_format::{Esp8266Format, ImageFormat, ImageFormatKind}, targets::{bytes_to_mac_addr, Chip, ReadEFuse, SpiRegisters, Target}, }; @@ -75,21 +75,19 @@ impl Target for Esp8266 { image: &'a dyn FirmwareImage<'a>, _bootloader: Option>, _partition_table: Option, + _partition_table_offset: Option, _target_app_partition: Option, image_format: Option, _chip_revision: Option<(u32, u32)>, - _min_rev_full: u16, - flash_mode: Option, - flash_size: Option, - flash_freq: Option, - _partition_table_offset: Option, + min_rev_full: u16, + flash_settings: FlashSettings, ) -> Result + 'a>, Error> { let image_format = image_format.unwrap_or(ImageFormatKind::EspBootloader); match image_format { - ImageFormatKind::EspBootloader => Ok(Box::new(Esp8266Format::new( - image, flash_mode, flash_size, flash_freq, - )?)), + ImageFormatKind::EspBootloader => { + Ok(Box::new(Esp8266Format::new(image, flash_settings)?)) + } _ => Err(UnsupportedImageFormatError::new(image_format, Chip::Esp8266, None).into()), } } diff --git a/espflash/src/targets/mod.rs b/espflash/src/targets/mod.rs index 17492fa7..4ca62009 100644 --- a/espflash/src/targets/mod.rs +++ b/espflash/src/targets/mod.rs @@ -27,7 +27,7 @@ use crate::{ connection::Connection, elf::FirmwareImage, error::Error, - flasher::{FlashFrequency, FlashMode, FlashSize, SpiAttachParams, FLASH_WRITE_SIZE}, + flasher::{FlashFrequency, FlashSettings, SpiAttachParams, FLASH_WRITE_SIZE}, image_format::{ImageFormat, ImageFormatKind}, }; @@ -299,14 +299,12 @@ pub trait Target: ReadEFuse { image: &'a dyn FirmwareImage<'a>, bootloader: Option>, partition_table: Option, + partition_table_offset: Option, target_app_partition: Option, image_format: Option, chip_revision: Option<(u32, u32)>, min_rev_full: u16, - flash_mode: Option, - flash_size: Option, - flash_freq: Option, - partition_table_offset: Option, + flash_settings: FlashSettings, ) -> Result + 'a>, Error>; /// What is the MAC address? From 5ca89f80ce71518bc7da98658217a41d79572bd3 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Thu, 16 Nov 2023 13:55:37 +0100 Subject: [PATCH 2/6] refactor: Refactor FlashData so it can be reused in other functions --- cargo-espflash/src/main.rs | 5 ++--- espflash/src/bin/espflash.rs | 5 ++--- espflash/src/cli/mod.rs | 37 +++++++++++++-------------------- espflash/src/flasher/mod.rs | 15 ++++++------- espflash/src/targets/esp32.rs | 28 ++++++++++++------------- espflash/src/targets/esp32c2.rs | 28 ++++++++++++------------- espflash/src/targets/esp32c3.rs | 30 +++++++++++++------------- espflash/src/targets/esp32c6.rs | 24 +++++++++------------ espflash/src/targets/esp32h2.rs | 24 +++++++++------------ espflash/src/targets/esp32s2.rs | 24 +++++++++------------ espflash/src/targets/esp32s3.rs | 24 +++++++++------------ espflash/src/targets/esp8266.rs | 21 ++++++++----------- espflash/src/targets/mod.rs | 12 +++++------ 13 files changed, 122 insertions(+), 155 deletions(-) diff --git a/cargo-espflash/src/main.rs b/cargo-espflash/src/main.rs index 073bb925..21641770 100644 --- a/cargo-espflash/src/main.rs +++ b/cargo-espflash/src/main.rs @@ -321,7 +321,6 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> { ); let flash_data = FlashData::new( - &elf_data, bootloader, partition_table, args.flash_args.partition_table_offset, @@ -339,7 +338,7 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> { )?; } - flash_elf_image(&mut flasher, flash_data)?; + flash_elf_image(&mut flasher, &elf_data, flash_data)?; } if args.flash_args.monitor { @@ -571,7 +570,6 @@ fn save_image(args: SaveImageArgs) -> Result<()> { ); let flash_data = FlashData::new( - &elf_data, bootloader.as_deref(), partition_table.as_deref(), args.save_image_args.partition_table_offset, @@ -581,6 +579,7 @@ fn save_image(args: SaveImageArgs) -> Result<()> { )?; save_elf_as_image( + &elf_data, args.save_image_args.chip, args.save_image_args.file, flash_data, diff --git a/espflash/src/bin/espflash.rs b/espflash/src/bin/espflash.rs index c2c99882..39612892 100644 --- a/espflash/src/bin/espflash.rs +++ b/espflash/src/bin/espflash.rs @@ -245,7 +245,6 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> { ); let flash_data = FlashData::new( - &elf_data, bootloader, partition_table, args.flash_args.format, @@ -262,7 +261,7 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> { )?; } - flash_elf_image(&mut flasher, flash_data)?; + flash_elf_image(&mut flasher, &elf_data, flash_data)?; } if args.flash_args.monitor { @@ -315,7 +314,6 @@ fn save_image(args: SaveImageArgs) -> Result<()> { ); let flash_data = FlashData::new( - &elf_data, args.save_image_args.bootloader.as_deref(), args.save_image_args.partition_table.as_deref(), args.save_image_args.partition_table_offset, @@ -325,6 +323,7 @@ fn save_image(args: SaveImageArgs) -> Result<()> { )?; save_elf_as_image( + &elf_data, args.save_image_args.chip, args.save_image_args.file, flash_data, diff --git a/espflash/src/cli/mod.rs b/espflash/src/cli/mod.rs index 5d003faa..7dd5ad9a 100644 --- a/espflash/src/cli/mod.rs +++ b/espflash/src/cli/mod.rs @@ -418,27 +418,21 @@ pub fn serial_monitor(args: MonitorArgs, config: &Config) -> Result<()> { /// Convert the provided firmware image from ELF to binary pub fn save_elf_as_image( + elf_data: &[u8], chip: Chip, image_path: PathBuf, flash_data: FlashData, merge: bool, skip_padding: bool, ) -> Result<()> { - let image = ElfFirmwareImage::try_from(flash_data.elf_data)?; + let image = ElfFirmwareImage::try_from(elf_data)?; if merge { // To get a chip revision, the connection is needed // For simplicity, the revision None is used - let image = chip.into_target().get_flash_image( - &image, - flash_data.bootloader, - flash_data.partition_table, - flash_data.partition_table_offset, - flash_data.target_app_partition, - flash_data.image_format, - None, - flash_data.flash_settings, - )?; + let image = chip + .into_target() + .get_flash_image(&image, flash_data.clone(), None)?; display_image_size(image.app_size(), image.part_size()); @@ -470,16 +464,9 @@ pub fn save_elf_as_image( file.write_all(&padding_bytes).into_diagnostic()?; } } else { - let image = chip.into_target().get_flash_image( - &image, - None, - None, - flash_data.target_app_partition, - flash_data.partition_table_offset, - flash_data.image_format, - None, - flash_data.flash_settings, - )?; + let image = chip + .into_target() + .get_flash_image(&image, flash_data, None)?; display_image_size(image.app_size(), image.part_size()); @@ -582,10 +569,14 @@ pub fn erase_region(args: EraseRegionArgs, config: &Config) -> Result<()> { } /// Write an ELF image to a target device's flash -pub fn flash_elf_image(flasher: &mut Flasher, flash_data: FlashData) -> Result<()> { +pub fn flash_elf_image( + flasher: &mut Flasher, + elf_data: &[u8], + flash_data: FlashData, +) -> Result<()> { // Load the ELF data, optionally using the provider bootloader/partition // table/image format, to the device's flash memory. - flasher.load_elf_to_flash(flash_data, Some(&mut EspflashProgress::default()))?; + flasher.load_elf_to_flash(elf_data, flash_data, Some(&mut EspflashProgress::default()))?; info!("Flashing has completed!"); Ok(()) diff --git a/espflash/src/flasher/mod.rs b/espflash/src/flasher/mod.rs index 2c00ee9d..92cc5220 100644 --- a/espflash/src/flasher/mod.rs +++ b/espflash/src/flasher/mod.rs @@ -284,8 +284,7 @@ impl FlashSettings { /// Flash data and configuration #[derive(Debug, Clone)] #[non_exhaustive] -pub struct FlashData<'a> { - pub elf_data: &'a [u8], +pub struct FlashData { pub bootloader: Option>, pub partition_table: Option, pub partition_table_offset: Option, @@ -295,12 +294,10 @@ pub struct FlashData<'a> { pub min_chip_rev: u16, } -impl<'a> FlashData<'a> { +impl FlashData { pub fn new( - elf_data: &'a [u8], - bootloader: Option<&'a Path>, - partition_table: Option<&'a Path>, - partition_table_offset: Option, + bootloader: Option<&Path>, + partition_table: Option<&Path>, image_format: Option, target_app_partition: Option, flash_settings: FlashSettings, @@ -325,7 +322,6 @@ impl<'a> FlashData<'a> { }; Ok(FlashData { - elf_data, bootloader, partition_table, partition_table_offset, @@ -893,10 +889,11 @@ impl Flasher { /// Load an ELF image to flash and execute it pub fn load_elf_to_flash( &mut self, + elf_data: &[u8], flash_data: FlashData, mut progress: Option<&mut dyn ProgressCallbacks>, ) -> Result<(), Error> { - let image = ElfFirmwareImage::try_from(flash_data.elf_data)?; + let image = ElfFirmwareImage::try_from(elf_data)?; let mut target = self.chip diff --git a/espflash/src/targets/esp32.rs b/espflash/src/targets/esp32.rs index fdfba81d..e4cbdf6a 100644 --- a/espflash/src/targets/esp32.rs +++ b/espflash/src/targets/esp32.rs @@ -1,12 +1,10 @@ use std::ops::Range; -use esp_idf_part::PartitionTable; - use crate::{ connection::Connection, elf::FirmwareImage, error::{Error, UnsupportedImageFormatError}, - flasher::{FlashFrequency, FlashSettings}, + flasher::{FlashData, FlashFrequency}, image_format::{IdfBootloaderFormat, ImageFormat, ImageFormatKind}, targets::{bytes_to_mac_addr, Chip, Esp32Params, ReadEFuse, SpiRegisters, Target}, }; @@ -153,16 +151,18 @@ impl Target for Esp32 { fn get_flash_image<'a>( &self, image: &'a dyn FirmwareImage<'a>, - bootloader: Option>, - partition_table: Option, - partition_table_offset: Option, - target_app_partition: Option, - image_format: Option, + flash_data: FlashData, + // bootloader: Option>, + // partition_table: Option, + // target_app_partition: Option, + // image_format: Option, _chip_revision: Option<(u32, u32)>, min_rev_full: u16, flash_settings: FlashSettings, ) -> Result + 'a>, Error> { - let image_format = image_format.unwrap_or(ImageFormatKind::EspBootloader); + let image_format = flash_data + .image_format + .unwrap_or(ImageFormatKind::EspBootloader); match image_format { ImageFormatKind::EspBootloader => Ok(Box::new(IdfBootloaderFormat::new( @@ -170,11 +170,11 @@ impl Target for Esp32 { Chip::Esp32, min_rev_full, PARAMS, - partition_table, - partition_table_offset, - target_app_partition, - bootloader, - flash_settings, + flash_data.partition_table, + flash_data.partition_table_offset, + flash_data.target_app_partition, + flash_data.bootloader, + flash_data.flash_settings, )?)), _ => Err(UnsupportedImageFormatError::new(image_format, Chip::Esp32, None).into()), } diff --git a/espflash/src/targets/esp32c2.rs b/espflash/src/targets/esp32c2.rs index 916a0a9a..05eebda5 100644 --- a/espflash/src/targets/esp32c2.rs +++ b/espflash/src/targets/esp32c2.rs @@ -1,12 +1,10 @@ use std::{collections::HashMap, ops::Range}; -use esp_idf_part::PartitionTable; - use crate::{ connection::Connection, elf::FirmwareImage, error::Error, - flasher::{FlashFrequency, FlashSettings}, + flasher::{FlashData, FlashFrequency}, image_format::{DirectBootFormat, IdfBootloaderFormat, ImageFormat, ImageFormatKind}, targets::{bytes_to_mac_addr, Chip, Esp32Params, ReadEFuse, SpiRegisters, Target}, }; @@ -87,16 +85,18 @@ impl Target for Esp32c2 { fn get_flash_image<'a>( &self, image: &'a dyn FirmwareImage<'a>, - bootloader: Option>, - partition_table: Option, - partition_table_offset: Option, - target_app_partition: Option, - image_format: Option, + flash_data: FlashData, + // bootloader: Option>, + // partition_table: Option, + // target_app_partition: Option, + // image_format: Option, _chip_revision: Option<(u32, u32)>, flash_settings: FlashSettings, min_rev_full: u16, ) -> Result + 'a>, Error> { - let image_format = image_format.unwrap_or(ImageFormatKind::EspBootloader); + let image_format = flash_data + .image_format + .unwrap_or(ImageFormatKind::EspBootloader); match image_format { ImageFormatKind::EspBootloader => Ok(Box::new(IdfBootloaderFormat::new( @@ -104,11 +104,11 @@ impl Target for Esp32c2 { Chip::Esp32c2, min_rev_full, PARAMS, - partition_table, - partition_table_offset, - target_app_partition, - bootloader, - flash_settings, + flash_data.partition_table, + flash_data.partition_table_offset, + flash_data.target_app_partition, + flash_data.bootloader, + flash_data.flash_settings, )?)), ImageFormatKind::DirectBoot => Ok(Box::new(DirectBootFormat::new(image, 0)?)), } diff --git a/espflash/src/targets/esp32c3.rs b/espflash/src/targets/esp32c3.rs index de214338..53a3d35b 100644 --- a/espflash/src/targets/esp32c3.rs +++ b/espflash/src/targets/esp32c3.rs @@ -1,12 +1,10 @@ use std::ops::Range; -use esp_idf_part::PartitionTable; - use crate::{ connection::Connection, elf::FirmwareImage, error::{Error, UnsupportedImageFormatError}, - flasher::{FlashFrequency, FlashSettings}, + flasher::{FlashData, FlashFrequency}, image_format::{DirectBootFormat, IdfBootloaderFormat, ImageFormat, ImageFormatKind}, targets::{Chip, Esp32Params, ReadEFuse, SpiRegisters, Target}, }; @@ -74,16 +72,18 @@ impl Target for Esp32c3 { fn get_flash_image<'a>( &self, image: &'a dyn FirmwareImage<'a>, - bootloader: Option>, - partition_table: Option, - partition_table_offset: Option, - target_app_partition: Option, - image_format: Option, + flash_data: FlashData, + // bootloader: Option>, + // partition_table: Option, + // target_app_partition: Option, + // image_format: Option, chip_revision: Option<(u32, u32)>, + // flash_settings: FlashSettings, min_rev_full: u16, - flash_settings: FlashSettings, ) -> Result + 'a>, Error> { - let image_format = image_format.unwrap_or(ImageFormatKind::EspBootloader); + let image_format = flash_data + .image_format + .unwrap_or(ImageFormatKind::EspBootloader); match (image_format, chip_revision) { (ImageFormatKind::EspBootloader, _) => Ok(Box::new(IdfBootloaderFormat::new( @@ -91,11 +91,11 @@ impl Target for Esp32c3 { Chip::Esp32c3, min_rev_full, PARAMS, - partition_table, - partition_table_offset, - target_app_partition, - bootloader, - flash_settings, + flash_data.partition_table, + flash_data.partition_table_offset, + flash_data.target_app_partition, + flash_data.bootloader, + flash_data.flash_settings, )?)), (ImageFormatKind::DirectBoot, None | Some((_, 3..))) => { Ok(Box::new(DirectBootFormat::new(image, 0)?)) diff --git a/espflash/src/targets/esp32c6.rs b/espflash/src/targets/esp32c6.rs index 1db11a97..8b7b85a5 100644 --- a/espflash/src/targets/esp32c6.rs +++ b/espflash/src/targets/esp32c6.rs @@ -1,12 +1,10 @@ use std::ops::Range; -use esp_idf_part::PartitionTable; - use crate::{ connection::Connection, elf::FirmwareImage, error::Error, - flasher::{FlashFrequency, FlashSettings}, + flasher::{FlashData, FlashFrequency}, image_format::{DirectBootFormat, IdfBootloaderFormat, ImageFormat, ImageFormatKind}, targets::{Chip, Esp32Params, ReadEFuse, SpiRegisters, Target}, }; @@ -71,16 +69,14 @@ impl Target for Esp32c6 { fn get_flash_image<'a>( &self, image: &'a dyn FirmwareImage<'a>, - bootloader: Option>, - partition_table: Option, - partition_table_offset: Option, - target_app_partition: Option, - image_format: Option, + flash_data: FlashData, _chip_revision: Option<(u32, u32)>, min_rev_full: u16, flash_settings: FlashSettings, ) -> Result + 'a>, Error> { - let image_format = image_format.unwrap_or(ImageFormatKind::EspBootloader); + let image_format = flash_data + .image_format + .unwrap_or(ImageFormatKind::EspBootloader); match image_format { ImageFormatKind::EspBootloader => Ok(Box::new(IdfBootloaderFormat::new( @@ -88,11 +84,11 @@ impl Target for Esp32c6 { Chip::Esp32c6, min_rev_full, PARAMS, - partition_table, - partition_table_offset, - target_app_partition, - bootloader, - flash_settings, + flash_data.partition_table, + flash_data.partition_table_offset, + flash_data.target_app_partition, + flash_data.bootloader, + flash_data.flash_settings, )?)), ImageFormatKind::DirectBoot => Ok(Box::new(DirectBootFormat::new(image, 0x0)?)), } diff --git a/espflash/src/targets/esp32h2.rs b/espflash/src/targets/esp32h2.rs index 1548ead3..ee44107c 100644 --- a/espflash/src/targets/esp32h2.rs +++ b/espflash/src/targets/esp32h2.rs @@ -1,14 +1,12 @@ use std::collections::HashMap; use std::ops::Range; -use esp_idf_part::PartitionTable; - use super::{Chip, Esp32Params, ReadEFuse, SpiRegisters, Target}; use crate::{ connection::Connection, elf::FirmwareImage, error::Error, - flasher::{FlashFrequency, FlashSettings}, + flasher::{FlashData, FlashFrequency}, image_format::{DirectBootFormat, IdfBootloaderFormat, ImageFormat, ImageFormatKind}, }; @@ -79,16 +77,14 @@ impl Target for Esp32h2 { fn get_flash_image<'a>( &self, image: &'a dyn FirmwareImage<'a>, - bootloader: Option>, - partition_table: Option, - partition_table_offset: Option, - target_app_partition: Option, - image_format: Option, + flash_data: FlashData, _chip_revision: Option<(u32, u32)>, min_rev_full: u16, flash_settings: FlashSettings, ) -> Result + 'a>, Error> { - let image_format = image_format.unwrap_or(ImageFormatKind::EspBootloader); + let image_format = flash_data + .image_format + .unwrap_or(ImageFormatKind::EspBootloader); match image_format { ImageFormatKind::EspBootloader => Ok(Box::new(IdfBootloaderFormat::new( @@ -96,11 +92,11 @@ impl Target for Esp32h2 { Chip::Esp32h2, min_rev_full, PARAMS, - partition_table, - partition_table_offset, - target_app_partition, - bootloader, - flash_settings, + flash_data.partition_table, + flash_data.partition_table_offset, + flash_data.target_app_partition, + flash_data.bootloader, + flash_data.flash_settings, )?)), ImageFormatKind::DirectBoot => Ok(Box::new(DirectBootFormat::new(image, 0x0)?)), } diff --git a/espflash/src/targets/esp32s2.rs b/espflash/src/targets/esp32s2.rs index eb56f1ba..3c49fe91 100644 --- a/espflash/src/targets/esp32s2.rs +++ b/espflash/src/targets/esp32s2.rs @@ -1,12 +1,10 @@ use std::ops::Range; -use esp_idf_part::PartitionTable; - use crate::{ connection::Connection, elf::FirmwareImage, error::{Error, UnsupportedImageFormatError}, - flasher::{FlashFrequency, FlashSettings, FLASH_WRITE_SIZE}, + flasher::{FlashData, FlashFrequency, FLASH_WRITE_SIZE}, image_format::{IdfBootloaderFormat, ImageFormat, ImageFormatKind}, targets::{Chip, Esp32Params, ReadEFuse, SpiRegisters, Target, MAX_RAM_BLOCK_SIZE}, }; @@ -139,16 +137,14 @@ impl Target for Esp32s2 { fn get_flash_image<'a>( &self, image: &'a dyn FirmwareImage<'a>, - bootloader: Option>, - partition_table: Option, - partition_table_offset: Option, - target_app_partition: Option, - image_format: Option, + flash_data: FlashData, _chip_revision: Option<(u32, u32)>, min_rev_full: u16, flash_settings: FlashSettings, ) -> Result + 'a>, Error> { - let image_format = image_format.unwrap_or(ImageFormatKind::EspBootloader); + let image_format = flash_data + .image_format + .unwrap_or(ImageFormatKind::EspBootloader); match image_format { ImageFormatKind::EspBootloader => Ok(Box::new(IdfBootloaderFormat::new( @@ -156,11 +152,11 @@ impl Target for Esp32s2 { Chip::Esp32s2, min_rev_full, PARAMS, - partition_table, - partition_table_offset, - target_app_partition, - bootloader, - flash_settings, + flash_data.partition_table, + flash_data.partition_table_offset, + flash_data.target_app_partition, + flash_data.bootloader, + flash_data.flash_settings, )?)), _ => Err(UnsupportedImageFormatError::new(image_format, Chip::Esp32s2, None).into()), } diff --git a/espflash/src/targets/esp32s3.rs b/espflash/src/targets/esp32s3.rs index 09fc4acd..d564ee42 100644 --- a/espflash/src/targets/esp32s3.rs +++ b/espflash/src/targets/esp32s3.rs @@ -1,12 +1,10 @@ use std::ops::Range; -use esp_idf_part::PartitionTable; - use crate::{ connection::Connection, elf::FirmwareImage, error::Error, - flasher::{FlashFrequency, FlashSettings}, + flasher::{FlashData, FlashFrequency}, image_format::{DirectBootFormat, IdfBootloaderFormat, ImageFormat, ImageFormatKind}, targets::{Chip, Esp32Params, ReadEFuse, SpiRegisters, Target}, }; @@ -93,16 +91,14 @@ impl Target for Esp32s3 { fn get_flash_image<'a>( &self, image: &'a dyn FirmwareImage<'a>, - bootloader: Option>, - partition_table: Option, - partition_table_offset: Option, - target_app_partition: Option, - image_format: Option, + flash_data: FlashData, _chip_revision: Option<(u32, u32)>, min_rev_full: u16, flash_settings: FlashSettings, ) -> Result + 'a>, Error> { - let image_format = image_format.unwrap_or(ImageFormatKind::EspBootloader); + let image_format = flash_data + .image_format + .unwrap_or(ImageFormatKind::EspBootloader); match image_format { ImageFormatKind::EspBootloader => Ok(Box::new(IdfBootloaderFormat::new( @@ -110,11 +106,11 @@ impl Target for Esp32s3 { Chip::Esp32s3, min_rev_full, PARAMS, - partition_table, - partition_table_offset, - target_app_partition, - bootloader, - flash_settings, + flash_data.partition_table, + flash_data.partition_table_offset, + flash_data.target_app_partition, + flash_data.bootloader, + flash_data.flash_settings, )?)), ImageFormatKind::DirectBoot => Ok(Box::new(DirectBootFormat::new(image, 0x400)?)), } diff --git a/espflash/src/targets/esp8266.rs b/espflash/src/targets/esp8266.rs index b6d3d82c..42d79945 100644 --- a/espflash/src/targets/esp8266.rs +++ b/espflash/src/targets/esp8266.rs @@ -1,12 +1,10 @@ use std::ops::Range; -use esp_idf_part::PartitionTable; - use crate::{ connection::Connection, elf::FirmwareImage, error::{Error, UnsupportedImageFormatError}, - flasher::FlashSettings, + flasher::FlashData, image_format::{Esp8266Format, ImageFormat, ImageFormatKind}, targets::{bytes_to_mac_addr, Chip, ReadEFuse, SpiRegisters, Target}, }; @@ -73,21 +71,20 @@ impl Target for Esp8266 { fn get_flash_image<'a>( &self, image: &'a dyn FirmwareImage<'a>, - _bootloader: Option>, - _partition_table: Option, - _partition_table_offset: Option, - _target_app_partition: Option, - image_format: Option, + flash_data: FlashData, _chip_revision: Option<(u32, u32)>, min_rev_full: u16, flash_settings: FlashSettings, ) -> Result + 'a>, Error> { - let image_format = image_format.unwrap_or(ImageFormatKind::EspBootloader); + let image_format = flash_data + .image_format + .unwrap_or(ImageFormatKind::EspBootloader); match image_format { - ImageFormatKind::EspBootloader => { - Ok(Box::new(Esp8266Format::new(image, flash_settings)?)) - } + ImageFormatKind::EspBootloader => Ok(Box::new(Esp8266Format::new( + image, + flash_data.flash_settings, + )?)), _ => Err(UnsupportedImageFormatError::new(image_format, Chip::Esp8266, None).into()), } } diff --git a/espflash/src/targets/mod.rs b/espflash/src/targets/mod.rs index 4ca62009..496a63a6 100644 --- a/espflash/src/targets/mod.rs +++ b/espflash/src/targets/mod.rs @@ -27,7 +27,7 @@ use crate::{ connection::Connection, elf::FirmwareImage, error::Error, - flasher::{FlashFrequency, FlashSettings, SpiAttachParams, FLASH_WRITE_SIZE}, + flasher::{FlashData, FlashFrequency, SpiAttachParams, FLASH_WRITE_SIZE}, image_format::{ImageFormat, ImageFormatKind}, }; @@ -297,11 +297,11 @@ pub trait Target: ReadEFuse { fn get_flash_image<'a>( &self, image: &'a dyn FirmwareImage<'a>, - bootloader: Option>, - partition_table: Option, - partition_table_offset: Option, - target_app_partition: Option, - image_format: Option, + // bootloader: Option>, + // partition_table: Option, + // target_app_partition: Option, + // image_format: Option, + flash_data: FlashData, chip_revision: Option<(u32, u32)>, min_rev_full: u16, flash_settings: FlashSettings, From f08c7842e3aa473ca5865865cd8408fbcdde1ddc Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Fri, 17 Nov 2023 12:21:13 +0100 Subject: [PATCH 3/6] style: Remove unnecesary comments --- espflash/src/targets/esp32.rs | 4 ---- espflash/src/targets/esp32c2.rs | 4 ---- espflash/src/targets/esp32c3.rs | 4 ---- espflash/src/targets/mod.rs | 4 ---- 4 files changed, 16 deletions(-) diff --git a/espflash/src/targets/esp32.rs b/espflash/src/targets/esp32.rs index e4cbdf6a..c7e749e6 100644 --- a/espflash/src/targets/esp32.rs +++ b/espflash/src/targets/esp32.rs @@ -152,10 +152,6 @@ impl Target for Esp32 { &self, image: &'a dyn FirmwareImage<'a>, flash_data: FlashData, - // bootloader: Option>, - // partition_table: Option, - // target_app_partition: Option, - // image_format: Option, _chip_revision: Option<(u32, u32)>, min_rev_full: u16, flash_settings: FlashSettings, diff --git a/espflash/src/targets/esp32c2.rs b/espflash/src/targets/esp32c2.rs index 05eebda5..9684422e 100644 --- a/espflash/src/targets/esp32c2.rs +++ b/espflash/src/targets/esp32c2.rs @@ -86,10 +86,6 @@ impl Target for Esp32c2 { &self, image: &'a dyn FirmwareImage<'a>, flash_data: FlashData, - // bootloader: Option>, - // partition_table: Option, - // target_app_partition: Option, - // image_format: Option, _chip_revision: Option<(u32, u32)>, flash_settings: FlashSettings, min_rev_full: u16, diff --git a/espflash/src/targets/esp32c3.rs b/espflash/src/targets/esp32c3.rs index 53a3d35b..57d218ac 100644 --- a/espflash/src/targets/esp32c3.rs +++ b/espflash/src/targets/esp32c3.rs @@ -73,10 +73,6 @@ impl Target for Esp32c3 { &self, image: &'a dyn FirmwareImage<'a>, flash_data: FlashData, - // bootloader: Option>, - // partition_table: Option, - // target_app_partition: Option, - // image_format: Option, chip_revision: Option<(u32, u32)>, // flash_settings: FlashSettings, min_rev_full: u16, diff --git a/espflash/src/targets/mod.rs b/espflash/src/targets/mod.rs index 496a63a6..5f35025e 100644 --- a/espflash/src/targets/mod.rs +++ b/espflash/src/targets/mod.rs @@ -297,10 +297,6 @@ pub trait Target: ReadEFuse { fn get_flash_image<'a>( &self, image: &'a dyn FirmwareImage<'a>, - // bootloader: Option>, - // partition_table: Option, - // target_app_partition: Option, - // image_format: Option, flash_data: FlashData, chip_revision: Option<(u32, u32)>, min_rev_full: u16, From 51241739c5ece85a6a3e8614d7a1a03d2527962a Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Mon, 20 Nov 2023 16:06:08 +0100 Subject: [PATCH 4/6] docs: Udpate changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d639781..c844f7eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed a missed `flush` call that may be causing communication errors (#521) ### Changed +- Created `FlashData` and `FlashSettings` structs to reduce number of input arguments in some functions (#512) - espflash will now exit with an error if `defmt` is selected but not usable (#524) From fb82cc3089d267a22da370b2585ba1df820af58f Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Wed, 22 Nov 2023 12:09:46 +0100 Subject: [PATCH 5/6] fix: Fix rebase errors --- cargo-espflash/src/main.rs | 1 - espflash/src/bin/espflash.rs | 1 + espflash/src/flasher/mod.rs | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cargo-espflash/src/main.rs b/cargo-espflash/src/main.rs index 21641770..d702b619 100644 --- a/cargo-espflash/src/main.rs +++ b/cargo-espflash/src/main.rs @@ -585,7 +585,6 @@ fn save_image(args: SaveImageArgs) -> Result<()> { flash_data, args.save_image_args.merge, args.save_image_args.skip_padding, - args.save_image_args.skip_padding, )?; Ok(()) diff --git a/espflash/src/bin/espflash.rs b/espflash/src/bin/espflash.rs index 39612892..42c0b557 100644 --- a/espflash/src/bin/espflash.rs +++ b/espflash/src/bin/espflash.rs @@ -247,6 +247,7 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> { let flash_data = FlashData::new( bootloader, partition_table, + args.flash_args.partition_table_offset, args.flash_args.format, args.flash_args.target_app_partition, flash_settings, diff --git a/espflash/src/flasher/mod.rs b/espflash/src/flasher/mod.rs index 92cc5220..b82f4cfb 100644 --- a/espflash/src/flasher/mod.rs +++ b/espflash/src/flasher/mod.rs @@ -298,6 +298,7 @@ impl FlashData { pub fn new( bootloader: Option<&Path>, partition_table: Option<&Path>, + partition_table_offset: Option, image_format: Option, target_app_partition: Option, flash_settings: FlashSettings, From f21dfc7faa95932219de60224fe6d56065aae337 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Fri, 22 Dec 2023 10:18:54 +0100 Subject: [PATCH 6/6] fix: Rebase errors --- CHANGELOG.md | 1 + cargo-espflash/src/main.rs | 2 ++ espflash/src/bin/espflash.rs | 2 ++ espflash/src/flasher/mod.rs | 50 ++++---------------------------- espflash/src/image_format/mod.rs | 1 + espflash/src/targets/esp32.rs | 4 +-- espflash/src/targets/esp32c2.rs | 4 +-- espflash/src/targets/esp32c3.rs | 4 +-- espflash/src/targets/esp32c6.rs | 4 +-- espflash/src/targets/esp32h2.rs | 4 +-- espflash/src/targets/esp32s2.rs | 4 +-- espflash/src/targets/esp32s3.rs | 4 +-- espflash/src/targets/esp8266.rs | 2 -- espflash/src/targets/mod.rs | 2 -- 14 files changed, 18 insertions(+), 70 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c844f7eb..e725567d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `Serialize` and `Deserialize` to `FlashFrequency`, `FlashMode` and `FlashSize`. (#528) - Add `checksum-md5` command (#536) - Add verify and skipping of unchanged flash regions - add `--no-verify` and `--no-skip` (#538) +- Add --min-chip-rev argument to specify minimum chip revision (#252) ### Fixed diff --git a/cargo-espflash/src/main.rs b/cargo-espflash/src/main.rs index d702b619..517bb372 100644 --- a/cargo-espflash/src/main.rs +++ b/cargo-espflash/src/main.rs @@ -327,6 +327,7 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> { args.flash_args.format.or(metadata.format), args.flash_args.target_app_partition, flash_settings, + args.flash_args.min_chip_rev, )?; if args.flash_args.erase_parts.is_some() || args.flash_args.erase_data_parts.is_some() { @@ -576,6 +577,7 @@ fn save_image(args: SaveImageArgs) -> Result<()> { args.format.or(metadata.format), args.save_image_args.target_app_partition, flash_settings, + args.save_image_args.min_chip_rev, )?; save_elf_as_image( diff --git a/espflash/src/bin/espflash.rs b/espflash/src/bin/espflash.rs index 42c0b557..4df6c83f 100644 --- a/espflash/src/bin/espflash.rs +++ b/espflash/src/bin/espflash.rs @@ -251,6 +251,7 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> { args.flash_args.format, args.flash_args.target_app_partition, flash_settings, + args.flash_args.min_chip_rev, )?; if args.flash_args.erase_parts.is_some() || args.flash_args.erase_data_parts.is_some() { @@ -321,6 +322,7 @@ fn save_image(args: SaveImageArgs) -> Result<()> { args.format, args.save_image_args.target_app_partition, flash_settings, + args.save_image_args.min_chip_rev, )?; save_elf_as_image( diff --git a/espflash/src/flasher/mod.rs b/espflash/src/flasher/mod.rs index b82f4cfb..157a5b9a 100644 --- a/espflash/src/flasher/mod.rs +++ b/espflash/src/flasher/mod.rs @@ -10,6 +10,7 @@ use bytemuck::{Pod, Zeroable, __core::time::Duration}; use esp_idf_part::PartitionTable; use log::{debug, info, warn}; use miette::{IntoDiagnostic, Result}; +use serde::{Deserialize, Serialize}; use serialport::UsbPortInfo; use strum::{Display, EnumIter, EnumVariantNames}; @@ -913,22 +914,10 @@ impl Flasher { None }; - let flash_settings = FlashSettings::new( - flash_data.flash_settings.mode, - flash_data.flash_settings.size.or(Some(self.flash_size)), - flash_data.flash_settings.freq, - ); - - let image = self.chip.into_target().get_flash_image( - &image, - flash_data.bootloader, - flash_data.partition_table, - flash_data.target_app_partition, - flash_data.image_format, - chip_revision, - flash_data.min_chip_rev, - flash_settings, - )?; + let image = self + .chip + .into_target() + .get_flash_image(&image, flash_data, chip_revision)?; // When the `cli` feature is enabled, display the image size information. #[cfg(feature = "cli")] @@ -990,35 +979,6 @@ impl Flasher { }) } - /// Load an ELF image to flash and execute it - pub fn load_elf_to_flash( - &mut self, - elf_data: &[u8], - bootloader: Option>, - partition_table: Option, - target_app_partition: Option, - flash_mode: Option, - flash_size: Option, - flash_freq: Option, - partition_table_offset: Option, - min_rev_full: u16, - progress: Option<&mut dyn ProgressCallbacks>, - ) -> Result<(), Error> { - self.load_elf_to_flash_with_format( - elf_data, - bootloader, - partition_table, - target_app_partition, - None, - flash_mode, - flash_size, - flash_freq, - partition_table_offset, - min_rev_full, - progress, - ) - } - pub fn change_baud(&mut self, speed: u32) -> Result<(), Error> { debug!("Change baud to: {}", speed); diff --git a/espflash/src/image_format/mod.rs b/espflash/src/image_format/mod.rs index 7e011ab3..ade8c666 100644 --- a/espflash/src/image_format/mod.rs +++ b/espflash/src/image_format/mod.rs @@ -20,6 +20,7 @@ use crate::{ flasher::{FlashFrequency, FlashMode, FlashSize}, targets::Chip, }; + mod direct_boot; mod esp8266; mod idf_bootloader; diff --git a/espflash/src/targets/esp32.rs b/espflash/src/targets/esp32.rs index c7e749e6..03e9135d 100644 --- a/espflash/src/targets/esp32.rs +++ b/espflash/src/targets/esp32.rs @@ -153,8 +153,6 @@ impl Target for Esp32 { image: &'a dyn FirmwareImage<'a>, flash_data: FlashData, _chip_revision: Option<(u32, u32)>, - min_rev_full: u16, - flash_settings: FlashSettings, ) -> Result + 'a>, Error> { let image_format = flash_data .image_format @@ -164,7 +162,7 @@ impl Target for Esp32 { ImageFormatKind::EspBootloader => Ok(Box::new(IdfBootloaderFormat::new( image, Chip::Esp32, - min_rev_full, + flash_data.min_chip_rev, PARAMS, flash_data.partition_table, flash_data.partition_table_offset, diff --git a/espflash/src/targets/esp32c2.rs b/espflash/src/targets/esp32c2.rs index 9684422e..848ec164 100644 --- a/espflash/src/targets/esp32c2.rs +++ b/espflash/src/targets/esp32c2.rs @@ -87,8 +87,6 @@ impl Target for Esp32c2 { image: &'a dyn FirmwareImage<'a>, flash_data: FlashData, _chip_revision: Option<(u32, u32)>, - flash_settings: FlashSettings, - min_rev_full: u16, ) -> Result + 'a>, Error> { let image_format = flash_data .image_format @@ -98,7 +96,7 @@ impl Target for Esp32c2 { ImageFormatKind::EspBootloader => Ok(Box::new(IdfBootloaderFormat::new( image, Chip::Esp32c2, - min_rev_full, + flash_data.min_chip_rev, PARAMS, flash_data.partition_table, flash_data.partition_table_offset, diff --git a/espflash/src/targets/esp32c3.rs b/espflash/src/targets/esp32c3.rs index 57d218ac..2f2cd195 100644 --- a/espflash/src/targets/esp32c3.rs +++ b/espflash/src/targets/esp32c3.rs @@ -74,8 +74,6 @@ impl Target for Esp32c3 { image: &'a dyn FirmwareImage<'a>, flash_data: FlashData, chip_revision: Option<(u32, u32)>, - // flash_settings: FlashSettings, - min_rev_full: u16, ) -> Result + 'a>, Error> { let image_format = flash_data .image_format @@ -85,7 +83,7 @@ impl Target for Esp32c3 { (ImageFormatKind::EspBootloader, _) => Ok(Box::new(IdfBootloaderFormat::new( image, Chip::Esp32c3, - min_rev_full, + flash_data.min_chip_rev, PARAMS, flash_data.partition_table, flash_data.partition_table_offset, diff --git a/espflash/src/targets/esp32c6.rs b/espflash/src/targets/esp32c6.rs index 8b7b85a5..035605cc 100644 --- a/espflash/src/targets/esp32c6.rs +++ b/espflash/src/targets/esp32c6.rs @@ -71,8 +71,6 @@ impl Target for Esp32c6 { image: &'a dyn FirmwareImage<'a>, flash_data: FlashData, _chip_revision: Option<(u32, u32)>, - min_rev_full: u16, - flash_settings: FlashSettings, ) -> Result + 'a>, Error> { let image_format = flash_data .image_format @@ -82,7 +80,7 @@ impl Target for Esp32c6 { ImageFormatKind::EspBootloader => Ok(Box::new(IdfBootloaderFormat::new( image, Chip::Esp32c6, - min_rev_full, + flash_data.min_chip_rev, PARAMS, flash_data.partition_table, flash_data.partition_table_offset, diff --git a/espflash/src/targets/esp32h2.rs b/espflash/src/targets/esp32h2.rs index ee44107c..943e6ba9 100644 --- a/espflash/src/targets/esp32h2.rs +++ b/espflash/src/targets/esp32h2.rs @@ -79,8 +79,6 @@ impl Target for Esp32h2 { image: &'a dyn FirmwareImage<'a>, flash_data: FlashData, _chip_revision: Option<(u32, u32)>, - min_rev_full: u16, - flash_settings: FlashSettings, ) -> Result + 'a>, Error> { let image_format = flash_data .image_format @@ -90,7 +88,7 @@ impl Target for Esp32h2 { ImageFormatKind::EspBootloader => Ok(Box::new(IdfBootloaderFormat::new( image, Chip::Esp32h2, - min_rev_full, + flash_data.min_chip_rev, PARAMS, flash_data.partition_table, flash_data.partition_table_offset, diff --git a/espflash/src/targets/esp32s2.rs b/espflash/src/targets/esp32s2.rs index 3c49fe91..cabb2e56 100644 --- a/espflash/src/targets/esp32s2.rs +++ b/espflash/src/targets/esp32s2.rs @@ -139,8 +139,6 @@ impl Target for Esp32s2 { image: &'a dyn FirmwareImage<'a>, flash_data: FlashData, _chip_revision: Option<(u32, u32)>, - min_rev_full: u16, - flash_settings: FlashSettings, ) -> Result + 'a>, Error> { let image_format = flash_data .image_format @@ -150,7 +148,7 @@ impl Target for Esp32s2 { ImageFormatKind::EspBootloader => Ok(Box::new(IdfBootloaderFormat::new( image, Chip::Esp32s2, - min_rev_full, + flash_data.min_chip_rev, PARAMS, flash_data.partition_table, flash_data.partition_table_offset, diff --git a/espflash/src/targets/esp32s3.rs b/espflash/src/targets/esp32s3.rs index d564ee42..f4df473a 100644 --- a/espflash/src/targets/esp32s3.rs +++ b/espflash/src/targets/esp32s3.rs @@ -93,8 +93,6 @@ impl Target for Esp32s3 { image: &'a dyn FirmwareImage<'a>, flash_data: FlashData, _chip_revision: Option<(u32, u32)>, - min_rev_full: u16, - flash_settings: FlashSettings, ) -> Result + 'a>, Error> { let image_format = flash_data .image_format @@ -104,7 +102,7 @@ impl Target for Esp32s3 { ImageFormatKind::EspBootloader => Ok(Box::new(IdfBootloaderFormat::new( image, Chip::Esp32s3, - min_rev_full, + flash_data.min_chip_rev, PARAMS, flash_data.partition_table, flash_data.partition_table_offset, diff --git a/espflash/src/targets/esp8266.rs b/espflash/src/targets/esp8266.rs index 42d79945..53f73564 100644 --- a/espflash/src/targets/esp8266.rs +++ b/espflash/src/targets/esp8266.rs @@ -73,8 +73,6 @@ impl Target for Esp8266 { image: &'a dyn FirmwareImage<'a>, flash_data: FlashData, _chip_revision: Option<(u32, u32)>, - min_rev_full: u16, - flash_settings: FlashSettings, ) -> Result + 'a>, Error> { let image_format = flash_data .image_format diff --git a/espflash/src/targets/mod.rs b/espflash/src/targets/mod.rs index 5f35025e..5ae72f51 100644 --- a/espflash/src/targets/mod.rs +++ b/espflash/src/targets/mod.rs @@ -299,8 +299,6 @@ pub trait Target: ReadEFuse { image: &'a dyn FirmwareImage<'a>, flash_data: FlashData, chip_revision: Option<(u32, u32)>, - min_rev_full: u16, - flash_settings: FlashSettings, ) -> Result + 'a>, Error>; /// What is the MAC address?