diff --git a/Cargo.lock b/Cargo.lock index 8fce190..48b4843 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -619,7 +619,6 @@ dependencies = [ "flate2", "indicatif", "log", - "maplit", "miette", "parse_int", "rppal", @@ -630,7 +629,6 @@ dependencies = [ "sha2", "slip-codec", "strum", - "strum_macros", "thiserror", "toml", "update-informer", @@ -913,12 +911,6 @@ dependencies = [ "libc", ] -[[package]] -name = "maplit" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" - [[package]] name = "maybe-uninit" version = "2.0.0" diff --git a/cargo-espflash/src/error.rs b/cargo-espflash/src/error.rs index c42611f..208640d 100644 --- a/cargo-espflash/src/error.rs +++ b/cargo-espflash/src/error.rs @@ -3,7 +3,7 @@ use std::{ iter::once, }; -use espflash::Chip; +use espflash::targets::Chip; use miette::{Diagnostic, LabeledSpan, SourceCode, SourceOffset}; use thiserror::Error; @@ -141,7 +141,7 @@ impl UnsupportedTargetError { impl UnsupportedTargetError { fn supported_targets(&self) -> String { - self.chip.supported_targets().join(", ") + self.chip.into_target().supported_build_targets().join(", ") } } @@ -164,7 +164,11 @@ impl Diagnostic for NoTargetError { fn help<'a>(&'a self) -> Option> { Some(Box::new(match &self.chip { - Some(chip) => format!("Specify the target in `.cargo/config.toml`, the {} support the following targets: {}", chip, chip.supported_targets().join(", ")), + Some(chip) => format!( + "Specify the target in `.cargo/config.toml`, the {} support the following targets: {}", + chip, + chip.into_target().supported_build_targets().join(", ") + ), None => "Specify the target in `.cargo/config.toml`".into(), } )) diff --git a/cargo-espflash/src/main.rs b/cargo-espflash/src/main.rs index 52e32cb..97e4d6b 100644 --- a/cargo-espflash/src/main.rs +++ b/cargo-espflash/src/main.rs @@ -9,14 +9,14 @@ use cargo_metadata::Message; use clap::{Args, Parser, Subcommand}; use espflash::{ cli::{ - board_info, connect, flash_elf_image, monitor::monitor, partition_table, save_elf_as_image, - serial_monitor, ConnectArgs, FlashArgs as BaseFlashArgs, FlashConfigArgs, - PartitionTableArgs, SaveImageArgs as BaseSaveImageArgs, + board_info, config::Config, connect, flash_elf_image, monitor::monitor, partition_table, + save_elf_as_image, serial_monitor, ConnectArgs, FlashArgs as BaseFlashArgs, + FlashConfigArgs, PartitionTableArgs, SaveImageArgs as BaseSaveImageArgs, }, - image_format::ImageFormatType, + image_format::{ImageFormatId, ImageFormatType}, logging::initialize_logger, + targets::Chip, update::check_for_update, - Chip, Config, ImageFormatId, }; use log::{debug, LevelFilter}; use miette::{IntoDiagnostic, Result, WrapErr}; @@ -244,7 +244,7 @@ fn build( .or_else(|| cargo_config.target()) .ok_or_else(|| NoTargetError::new(Some(chip)))?; - if !chip.supports_target(target) { + if !chip.into_target().supports_build_target(target) { return Err(Error::UnsupportedTarget(UnsupportedTargetError::new(target, chip)).into()); } diff --git a/cargo-espflash/src/package_metadata.rs b/cargo-espflash/src/package_metadata.rs index ecb0594..577897b 100644 --- a/cargo-espflash/src/package_metadata.rs +++ b/cargo-espflash/src/package_metadata.rs @@ -5,7 +5,7 @@ use std::{ }; use cargo_toml::Manifest; -use espflash::ImageFormatId; +use espflash::image_format::ImageFormatId; use miette::{IntoDiagnostic, Result, WrapErr}; use serde::Deserialize; diff --git a/espflash/Cargo.toml b/espflash/Cargo.toml index dc3ef76..dd18f42 100644 --- a/espflash/Cargo.toml +++ b/espflash/Cargo.toml @@ -48,7 +48,6 @@ env_logger = "0.9.0" flate2 = "1.0.24" indicatif = "0.17.1" log = "0.4.17" -maplit = "1.0.2" miette = { version = "5.3.0", features = ["fancy"] } parse_int = "0.6.0" rppal = { version = "0.13", optional = true } @@ -58,8 +57,7 @@ serde_json = "1.0.85" serialport = "4.2.0" sha2 = "0.10.6" slip-codec = "0.3.3" -strum = "0.24.1" -strum_macros = "0.24.3" +strum = { version = "0.24.1", features = ["derive"] } thiserror = "1.0.35" toml = "0.5.9" update-informer = { version = "0.5.0", optional = true } diff --git a/espflash/src/bin/espflash.rs b/espflash/src/bin/espflash.rs index 9d2a47a..2fff739 100644 --- a/espflash/src/bin/espflash.rs +++ b/espflash/src/bin/espflash.rs @@ -9,14 +9,13 @@ use std::{ use clap::{Args, Parser, Subcommand}; use espflash::{ cli::{ - board_info, connect, flash_elf_image, monitor::monitor, partition_table, save_elf_as_image, - serial_monitor, ConnectArgs, FlashArgs as BaseFlashArgs, FlashConfigArgs, - PartitionTableArgs, SaveImageArgs as BaseSaveImageArgs, + board_info, config::Config, connect, flash_elf_image, monitor::monitor, partition_table, + save_elf_as_image, serial_monitor, ConnectArgs, FlashArgs as BaseFlashArgs, + FlashConfigArgs, PartitionTableArgs, SaveImageArgs as BaseSaveImageArgs, }, image_format::{ImageFormatId, ImageFormatType}, logging::initialize_logger, update::check_for_update, - Config, }; use log::{debug, LevelFilter}; use miette::{IntoDiagnostic, Result, WrapErr}; diff --git a/espflash/src/cli/mod.rs b/espflash/src/cli/mod.rs index 6032d56..b2e7e5b 100644 --- a/espflash/src/cli/mod.rs +++ b/espflash/src/cli/mod.rs @@ -18,11 +18,11 @@ use strum::VariantNames; use self::{config::Config, monitor::monitor, serial::get_serial_port_info}; use crate::{ elf::ElfFirmwareImage, - error::NoOtadataError, - flasher::{FlashFrequency, FlashMode, FlashSize}, - image_format::ImageFormatType, + error::{MissingPartitionTable, NoOtadataError}, + flasher::{FlashFrequency, FlashMode, FlashSize, Flasher}, + image_format::{ImageFormatId, ImageFormatType}, interface::Interface, - Chip, Flasher, ImageFormatId, MissingPartitionTable, + targets::Chip, }; pub mod config; @@ -237,7 +237,7 @@ pub fn save_elf_as_image( // To get a chip revision, the connection is needed // For simplicity, the revision None is used - let image = chip.get_flash_image( + let image = chip.into_target().get_flash_image( &image, bootloader, partition_table, @@ -275,7 +275,7 @@ pub fn save_elf_as_image( file.write_all(&padding_bytes).into_diagnostic()?; } } else { - let flash_image = chip.get_flash_image( + let flash_image = chip.into_target().get_flash_image( &image, None, None, diff --git a/espflash/src/command.rs b/espflash/src/command.rs index 4468503..a28b8de 100644 --- a/espflash/src/command.rs +++ b/espflash/src/command.rs @@ -1,9 +1,9 @@ -use crate::flasher::{checksum, SpiAttachParams, CHECKSUM_INIT}; +use std::{io::Write, mem::size_of, time::Duration}; + use bytemuck::{bytes_of, Pod, Zeroable}; -use std::io::Write; -use std::mem::size_of; -use std::time::Duration; -use strum_macros::Display; +use strum::Display; + +use crate::flasher::{checksum, SpiAttachParams, CHECKSUM_INIT}; const DEFAULT_TIMEOUT: Duration = Duration::from_secs(3); const ERASE_REGION_TIMEOUT_PER_MB: Duration = Duration::from_secs(30); diff --git a/espflash/src/elf.rs b/espflash/src/elf.rs index 7dd200c..dfe3917 100644 --- a/espflash/src/elf.rs +++ b/espflash/src/elf.rs @@ -13,8 +13,8 @@ use xmas_elf::{ }; use crate::{ - chip::Chip, error::{ElfError, Error}, + targets::Chip, }; pub const ESP_CHECKSUM_MAGIC: u8 = 0xef; @@ -27,14 +27,14 @@ pub trait FirmwareImage<'a> { fn rom_segments(&'a self, chip: Chip) -> Box> + 'a> { Box::new( self.segments() - .filter(move |segment| chip.addr_is_flash(segment.addr)), + .filter(move |segment| chip.into_target().addr_is_flash(segment.addr)), ) } fn ram_segments(&'a self, chip: Chip) -> Box> + 'a> { Box::new( self.segments() - .filter(move |segment| !chip.addr_is_flash(segment.addr)), + .filter(move |segment| !chip.into_target().addr_is_flash(segment.addr)), ) } } diff --git a/espflash/src/error.rs b/espflash/src/error.rs index 8f8f791..00c7b6e 100644 --- a/espflash/src/error.rs +++ b/espflash/src/error.rs @@ -13,7 +13,7 @@ use crate::{ flasher::{FlashFrequency, FlashMode, FlashSize}, image_format::ImageFormatId, interface::SerialConfigError, - Chip, + targets::Chip, }; #[derive(Error, Debug, Diagnostic)] @@ -450,6 +450,7 @@ impl UnsupportedImageFormatError { fn supported_formats(&self) -> String { self.chip + .into_target() .supported_image_formats() .iter() .map(|format| format.into()) diff --git a/espflash/src/flasher/mod.rs b/espflash/src/flasher/mod.rs index 653d072..44dbd60 100644 --- a/espflash/src/flasher/mod.rs +++ b/espflash/src/flasher/mod.rs @@ -4,18 +4,17 @@ use bytemuck::{Pod, Zeroable, __core::time::Duration}; use esp_idf_part::PartitionTable; use log::debug; use serialport::UsbPortInfo; -use strum_macros::{Display, EnumVariantNames}; +use strum::{Display, EnumVariantNames}; use self::stubs::FlashStub; use crate::{ - chip::Chip, command::{Command, CommandType}, connection::Connection, elf::{ElfFirmwareImage, FirmwareImage, RomSegment}, - error::{ConnectionError, FlashDetectError, ResultExt}, + error::{ConnectionError, Error, FlashDetectError, ResultExt}, image_format::ImageFormatId, interface::Interface, - Error, + targets::Chip, }; mod stubs; @@ -338,7 +337,9 @@ impl Flasher { let mut ram_target = self.chip.ram_target( Some(stub.entry()), - self.chip.max_ram_block_size(&mut self.connection)?, + self.chip + .into_target() + .max_ram_block_size(&mut self.connection)?, ); ram_target.begin(&mut self.connection).flashing()?; @@ -478,7 +479,7 @@ impl Flasher { assert!(read_bits < 32); assert!(data.len() < 64); - let spi_registers = self.chip.spi_registers(); + let spi_registers = self.chip.into_target().spi_registers(); let old_spi_usr = self.connection.read_reg(spi_registers.usr())?; let old_spi_usr2 = self.connection.read_reg(spi_registers.usr2())?; @@ -571,10 +572,11 @@ impl Flasher { pub fn board_info(&mut self) -> Result<(), Error> { let chip = self.chip(); - let maybe_revision = chip.chip_revision(self.connection())?; - let features = chip.chip_features(self.connection())?; - let freq = chip.crystal_freq(self.connection())?; - let mac = chip.mac_address(self.connection())?; + let target = chip.into_target(); + let maybe_revision = target.chip_revision(self.connection())?; + let features = target.chip_features(self.connection())?; + let freq = target.crystal_freq(self.connection())?; + let mac = target.mac_address(self.connection())?; print!("Chip type: {}", chip); match maybe_revision { @@ -597,7 +599,9 @@ impl Flasher { let mut target = self.chip.ram_target( Some(image.entry()), - self.chip.max_ram_block_size(&mut self.connection)?, + self.chip + .into_target() + .max_ram_block_size(&mut self.connection)?, ); target.begin(&mut self.connection).flashing()?; @@ -636,12 +640,14 @@ impl Flasher { let mut target = self.chip.flash_target(self.spi_params, self.use_stub); target.begin(&mut self.connection).flashing()?; - let flash_image = self.chip.get_flash_image( + let flash_image = self.chip.into_target().get_flash_image( &image, bootloader, partition_table, image_format, - self.chip.chip_revision(&mut self.connection)?, + self.chip + .into_target() + .chip_revision(&mut self.connection)?, flash_mode, flash_size.or(Some(self.flash_size)), flash_freq, diff --git a/espflash/src/flasher/stubs.rs b/espflash/src/flasher/stubs.rs index 93c618d..6699ce7 100644 --- a/espflash/src/flasher/stubs.rs +++ b/espflash/src/flasher/stubs.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use crate::Chip; +use crate::targets::Chip; /// Flash stub object (deserialized from json as used by `esptool.py`) #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] @@ -66,7 +66,7 @@ mod tests { use strum::IntoEnumIterator; use super::FlashStub; - use crate::Chip; + use crate::targets::Chip; #[test] fn check_stub_encodings() { diff --git a/espflash/src/image_format/esp32bootloader.rs b/espflash/src/image_format/esp32bootloader.rs index 34a6b5f..8518bef 100644 --- a/espflash/src/image_format/esp32bootloader.rs +++ b/espflash/src/image_format/esp32bootloader.rs @@ -6,7 +6,6 @@ use sha2::{Digest, Sha256}; use super::encode_flash_frequency; use crate::{ - chip::Esp32Params, elf::{ merge_adjacent_segments, update_checksum, CodeSegment, FirmwareImage, RomSegment, ESP_CHECKSUM_MAGIC, @@ -14,7 +13,7 @@ use crate::{ error::{Error, FlashDetectError}, flasher::{FlashFrequency, FlashMode, FlashSize}, image_format::{EspCommonHeader, ImageFormat, SegmentHeader, ESP_MAGIC, WP_PIN_DISABLED}, - Chip, + targets::{Chip, Esp32Params}, }; /// Image format for esp32 family chips using a 2nd stage bootloader diff --git a/espflash/src/image_format/esp8266.rs b/espflash/src/image_format/esp8266.rs index 4c76595..52e9178 100644 --- a/espflash/src/image_format/esp8266.rs +++ b/espflash/src/image_format/esp8266.rs @@ -6,9 +6,9 @@ use super::encode_flash_frequency; use crate::{ elf::{update_checksum, CodeSegment, FirmwareImage, RomSegment, ESP_CHECKSUM_MAGIC}, error::{Error, FlashDetectError}, - flasher::FlashSize, + flasher::{FlashFrequency, FlashMode, FlashSize}, image_format::{EspCommonHeader, ImageFormat, SegmentHeader, ESP_MAGIC}, - Chip, FlashFrequency, FlashMode, + targets::Chip, }; /// Image format for flashing to esp8266 chips diff --git a/espflash/src/image_format/mod.rs b/espflash/src/image_format/mod.rs index 432c600..c4674f0 100644 --- a/espflash/src/image_format/mod.rs +++ b/espflash/src/image_format/mod.rs @@ -2,10 +2,10 @@ use std::str::FromStr; use bytemuck::{Pod, Zeroable}; use serde::Deserialize; -use strum_macros::{Display, EnumVariantNames, IntoStaticStr}; +use strum::{Display, EnumVariantNames, IntoStaticStr}; pub use self::{esp32bootloader::*, esp32directboot::*, esp8266::*}; -use crate::{chip::Chip, elf::RomSegment, error::Error, flasher::FlashFrequency}; +use crate::{elf::RomSegment, error::Error, flasher::FlashFrequency, targets::Chip}; mod esp32bootloader; mod esp32directboot; @@ -92,7 +92,7 @@ impl FromStr for ImageFormatId { } pub(crate) fn encode_flash_frequency(chip: Chip, frequency: FlashFrequency) -> Result { - let encodings = chip.flash_frequency_encodings(); + let encodings = chip.into_target().flash_frequency_encodings(); if let Some(&f) = encodings.get(&frequency) { Ok(f) } else { diff --git a/espflash/src/interface.rs b/espflash/src/interface.rs index 2468eea..a7b0792 100644 --- a/espflash/src/interface.rs +++ b/espflash/src/interface.rs @@ -1,11 +1,14 @@ use std::io::Read; -use crate::{cli::ConnectArgs, Config, Error}; use miette::{Context, Result}; -use serialport::{FlowControl, SerialPort, SerialPortInfo}; - #[cfg(feature = "raspberry")] use rppal::gpio::{Gpio, OutputPin}; +use serialport::{FlowControl, SerialPort, SerialPortInfo}; + +use crate::{ + cli::{config::Config, ConnectArgs}, + error::Error, +}; #[derive(thiserror::Error, Debug)] pub enum SerialConfigError { @@ -18,7 +21,8 @@ pub enum SerialConfigError { GpioUnavailable(u8), } -/// Wrapper around SerialPort where platform-specific modifications can be implemented. +/// Wrapper around SerialPort where platform-specific modifications can be +/// implemented. pub struct Interface { pub serial_port: Box, #[cfg(feature = "raspberry")] @@ -132,8 +136,8 @@ impl Interface { } } -// Note(dbuga): this impl is necessary because using `dyn SerialPort` as `dyn Read` -// requires trait_upcasting which isn't stable yet. +// Note(dbuga): this impl is necessary because using `dyn SerialPort` as `dyn +// Read` requires trait_upcasting which isn't stable yet. impl Read for Interface { fn read(&mut self, buf: &mut [u8]) -> std::io::Result { self.serial_port.read(buf) diff --git a/espflash/src/lib.rs b/espflash/src/lib.rs index ef3e505..906db4d 100644 --- a/espflash/src/lib.rs +++ b/espflash/src/lib.rs @@ -1,23 +1,13 @@ #[cfg(feature = "cli")] -pub use self::cli::config::Config; -pub use self::{ - chip::Chip, - error::{Error, MissingPartitionTable}, - flasher::{FlashFrequency, FlashMode, FlashSize, Flasher}, - image_format::ImageFormatId, -}; - -pub mod chip; -#[cfg(feature = "cli")] pub mod cli; pub mod command; pub mod connection; pub mod elf; pub mod error; -pub mod flash_target; pub mod flasher; pub mod image_format; pub mod interface; +pub mod targets; pub mod logging { use env_logger::Env; diff --git a/espflash/src/targets/esp32.rs b/espflash/src/targets/esp32.rs index d06e0ca..5472e07 100644 --- a/espflash/src/targets/esp32.rs +++ b/espflash/src/targets/esp32.rs @@ -2,14 +2,12 @@ use std::ops::Range; use esp_idf_part::PartitionTable; -use super::{ - bytes_to_mac_addr, Chip, Esp32Params, Esp32Target, FlashTarget, ReadEFuse, SpiRegisters, Target, -}; +use super::{bytes_to_mac_addr, Chip, Esp32Params, ReadEFuse, SpiRegisters, Target}; use crate::{ connection::Connection, elf::FirmwareImage, error::{Error, UnsupportedImageFormatError}, - flasher::{FlashFrequency, FlashMode, FlashSize, SpiAttachParams}, + flasher::{FlashFrequency, FlashMode, FlashSize}, image_format::{Esp32BootloaderFormat, ImageFormat, ImageFormatId}, }; @@ -147,10 +145,6 @@ impl Target for Esp32 { Ok(norm_xtal) } - fn flash_target(&self, spi_params: SpiAttachParams, use_stub: bool) -> Box { - Box::new(Esp32Target::new(Chip::Esp32, spi_params, use_stub)) - } - fn get_flash_image<'a>( &self, image: &'a dyn FirmwareImage<'a>, @@ -202,7 +196,7 @@ impl Target for Esp32 { } } - fn supported_targets(&self) -> &[&str] { + fn supported_build_targets(&self) -> &[&str] { &["xtensa-esp32-none-elf", "xtensa-esp32-espidf"] } } diff --git a/espflash/src/targets/esp32c2.rs b/espflash/src/targets/esp32c2.rs index 7412535..21d4be7 100644 --- a/espflash/src/targets/esp32c2.rs +++ b/espflash/src/targets/esp32c2.rs @@ -2,12 +2,12 @@ use std::{collections::HashMap, ops::Range}; use esp_idf_part::PartitionTable; -use super::{Chip, Esp32Params, Esp32Target, FlashTarget, ReadEFuse, SpiRegisters, Target}; +use super::{Chip, Esp32Params, ReadEFuse, SpiRegisters, Target}; use crate::{ connection::Connection, elf::FirmwareImage, error::Error, - flasher::{FlashFrequency, FlashMode, FlashSize, SpiAttachParams}, + flasher::{FlashFrequency, FlashMode, FlashSize}, image_format::{Esp32BootloaderFormat, Esp32DirectBootFormat, ImageFormat, ImageFormatId}, }; @@ -81,10 +81,6 @@ impl Target for Esp32c2 { HashMap::from(encodings) } - fn flash_target(&self, spi_params: SpiAttachParams, use_stub: bool) -> Box { - Box::new(Esp32Target::new(Chip::Esp32c2, spi_params, use_stub)) - } - fn get_flash_image<'a>( &self, image: &'a dyn FirmwareImage<'a>, @@ -129,7 +125,7 @@ impl Target for Esp32c2 { &[ImageFormatId::Bootloader, ImageFormatId::DirectBoot] } - fn supported_targets(&self) -> &[&str] { + fn supported_build_targets(&self) -> &[&str] { &[ "riscv32imac-unknown-none-elf", "riscv32imc-esp-espidf", diff --git a/espflash/src/targets/esp32c3.rs b/espflash/src/targets/esp32c3.rs index 622a8d9..4f0785e 100644 --- a/espflash/src/targets/esp32c3.rs +++ b/espflash/src/targets/esp32c3.rs @@ -2,12 +2,12 @@ use std::ops::Range; use esp_idf_part::PartitionTable; -use super::{Chip, Esp32Params, Esp32Target, FlashTarget, ReadEFuse, SpiRegisters, Target}; +use super::{Chip, Esp32Params, ReadEFuse, SpiRegisters, Target}; use crate::{ connection::Connection, elf::FirmwareImage, error::{Error, UnsupportedImageFormatError}, - flasher::{FlashFrequency, FlashMode, FlashSize, SpiAttachParams}, + flasher::{FlashFrequency, FlashMode, FlashSize}, image_format::{Esp32BootloaderFormat, Esp32DirectBootFormat, ImageFormat, ImageFormatId}, }; @@ -68,10 +68,6 @@ impl Target for Esp32c3 { Ok(40) } - fn flash_target(&self, spi_params: SpiAttachParams, use_stub: bool) -> Box { - Box::new(Esp32Target::new(Chip::Esp32c3, spi_params, use_stub)) - } - fn get_flash_image<'a>( &self, image: &'a dyn FirmwareImage<'a>, @@ -121,7 +117,7 @@ impl Target for Esp32c3 { &[ImageFormatId::Bootloader, ImageFormatId::DirectBoot] } - fn supported_targets(&self) -> &[&str] { + fn supported_build_targets(&self) -> &[&str] { &[ "riscv32imac-unknown-none-elf", "riscv32imc-esp-espidf", diff --git a/espflash/src/targets/esp32s2.rs b/espflash/src/targets/esp32s2.rs index 4ecad80..ecd8949 100644 --- a/espflash/src/targets/esp32s2.rs +++ b/espflash/src/targets/esp32s2.rs @@ -2,15 +2,12 @@ use std::ops::Range; use esp_idf_part::PartitionTable; -use super::{ - Chip, Esp32Params, Esp32Target, FlashTarget, ReadEFuse, SpiRegisters, Target, - MAX_RAM_BLOCK_SIZE, -}; +use super::{Chip, Esp32Params, ReadEFuse, SpiRegisters, Target, MAX_RAM_BLOCK_SIZE}; use crate::{ connection::Connection, elf::FirmwareImage, error::{Error, UnsupportedImageFormatError}, - flasher::{FlashFrequency, FlashMode, FlashSize, SpiAttachParams, FLASH_WRITE_SIZE}, + flasher::{FlashFrequency, FlashMode, FlashSize, FLASH_WRITE_SIZE}, image_format::{Esp32BootloaderFormat, ImageFormat, ImageFormatId}, }; @@ -113,10 +110,6 @@ impl Target for Esp32s2 { Ok(40) } - fn flash_target(&self, spi_params: SpiAttachParams, use_stub: bool) -> Box { - Box::new(Esp32Target::new(Chip::Esp32s2, spi_params, use_stub)) - } - fn flash_write_size(&self, connection: &mut Connection) -> Result { Ok(if self.connection_is_usb_otg(connection)? { MAX_USB_BLOCK_SIZE @@ -173,7 +166,7 @@ impl Target for Esp32s2 { } } - fn supported_targets(&self) -> &[&str] { + fn supported_build_targets(&self) -> &[&str] { &["xtensa-esp32s2-none-elf", "xtensa-esp32s2-espidf"] } } diff --git a/espflash/src/targets/esp32s3.rs b/espflash/src/targets/esp32s3.rs index 2daf5ce..e9ba795 100644 --- a/espflash/src/targets/esp32s3.rs +++ b/espflash/src/targets/esp32s3.rs @@ -2,14 +2,12 @@ use std::ops::Range; use esp_idf_part::PartitionTable; -use super::{ - bytes_to_mac_addr, Chip, Esp32Params, Esp32Target, FlashTarget, ReadEFuse, SpiRegisters, Target, -}; +use super::{bytes_to_mac_addr, Chip, Esp32Params, ReadEFuse, SpiRegisters, Target}; use crate::{ connection::Connection, elf::FirmwareImage, error::Error, - flasher::{FlashFrequency, FlashMode, FlashSize, SpiAttachParams}, + flasher::{FlashFrequency, FlashMode, FlashSize}, image_format::{Esp32BootloaderFormat, Esp32DirectBootFormat, ImageFormat, ImageFormatId}, }; @@ -56,10 +54,6 @@ impl Target for Esp32s3 { Ok(40) } - fn flash_target(&self, spi_params: SpiAttachParams, use_stub: bool) -> Box { - Box::new(Esp32Target::new(Chip::Esp32s3, spi_params, use_stub)) - } - fn get_flash_image<'a>( &self, image: &'a dyn FirmwareImage<'a>, @@ -115,7 +109,7 @@ impl Target for Esp32s3 { &[ImageFormatId::Bootloader, ImageFormatId::DirectBoot] } - fn supported_targets(&self) -> &[&str] { + fn supported_build_targets(&self) -> &[&str] { &["xtensa-esp32s3-none-elf", "xtensa-esp32s3-espidf"] } } diff --git a/espflash/src/targets/esp8266.rs b/espflash/src/targets/esp8266.rs index a4af6c4..2e76590 100644 --- a/espflash/src/targets/esp8266.rs +++ b/espflash/src/targets/esp8266.rs @@ -2,12 +2,12 @@ use std::ops::Range; use esp_idf_part::PartitionTable; -use super::{bytes_to_mac_addr, Chip, Esp8266Target, FlashTarget, ReadEFuse, SpiRegisters, Target}; +use super::{bytes_to_mac_addr, Chip, ReadEFuse, SpiRegisters, Target}; use crate::{ connection::Connection, elf::FirmwareImage, error::{Error, UnsupportedImageFormatError}, - flasher::{FlashFrequency, FlashMode, FlashSize, SpiAttachParams}, + flasher::{FlashFrequency, FlashMode, FlashSize}, image_format::{Esp8266Format, ImageFormat, ImageFormatId}, }; @@ -53,10 +53,6 @@ impl Target for Esp8266 { Ok(norm_xtal) } - fn flash_target(&self, _spi_params: SpiAttachParams, _use_stub: bool) -> Box { - Box::new(Esp8266Target::new()) - } - fn get_flash_image<'a>( &self, image: &'a dyn FirmwareImage<'a>, @@ -116,7 +112,7 @@ impl Target for Esp8266 { } } - fn supported_targets(&self) -> &[&str] { + fn supported_build_targets(&self) -> &[&str] { &["xtensa-esp8266-none-elf"] } } diff --git a/espflash/src/targets/mod.rs b/espflash/src/targets/mod.rs index 8ec4b42..5ffbf23 100644 --- a/espflash/src/targets/mod.rs +++ b/espflash/src/targets/mod.rs @@ -103,6 +103,14 @@ impl Chip { _ => Box::new(Esp32Target::new(*self, spi_params, use_stub)), } } + + pub fn ram_target( + &self, + entry: Option, + max_ram_block_size: usize, + ) -> Box { + Box::new(RamTarget::new(entry, max_ram_block_size)) + } } #[derive(Debug, Clone, Copy)] @@ -250,12 +258,6 @@ pub trait Target: ReadEFuse { HashMap::from(encodings) } - fn ram_target(&self, entry: Option, max_ram_block_size: usize) -> Box { - Box::new(RamTarget::new(entry, max_ram_block_size)) - } - - fn flash_target(&self, spi_params: SpiAttachParams, use_stub: bool) -> Box; - fn flash_write_size(&self, _connection: &mut Connection) -> Result { Ok(FLASH_WRITE_SIZE) } @@ -293,10 +295,10 @@ pub trait Target: ReadEFuse { &[ImageFormatId::Bootloader] } - fn supported_targets(&self) -> &[&str]; + fn supported_build_targets(&self) -> &[&str]; - fn supports_target(&self, target: &str) -> bool { - self.supported_targets().contains(&target) + fn supports_build_target(&self, target: &str) -> bool { + self.supported_build_targets().contains(&target) } }