diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1738bf6d..19b5be90 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ on: env: CARGO_TERM_COLOR: always - MSRV: "1.82" + MSRV: "1.85" # Cancel any currently running workflows from the same PR, branch, or # tag when a new workflow is triggered. diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ffd12b3..c00d8395 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `--non-interactive` may now react to key events (user input, Ctrl-C, Ctrl-R) if possible (#819) - Removed `get_` prefix from any functions which previously had it (#824) - Take elf data as bytes rather than `ElfFile` struct when creating an image format (#825) +- Updated to Rust 2024 edition (#843) ### Fixed diff --git a/cargo-espflash/Cargo.toml b/cargo-espflash/Cargo.toml index 23243473..74517c7c 100644 --- a/cargo-espflash/Cargo.toml +++ b/cargo-espflash/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "cargo-espflash" version = "4.0.0-dev" -edition = "2021" -rust-version = "1.82" +edition = "2024" +rust-version = "1.85" description = "Cargo subcommand for interacting with Espressif devices" repository = "https://github.com/esp-rs/espflash" license = "MIT OR Apache-2.0" diff --git a/cargo-espflash/README.md b/cargo-espflash/README.md index 9f23c578..55689198 100644 --- a/cargo-espflash/README.md +++ b/cargo-espflash/README.md @@ -2,7 +2,7 @@ # cargo-espflash [![Crates.io](https://img.shields.io/crates/v/cargo-espflash?labelColor=1C2C2E&color=C96329&logo=Rust&style=flat-square)](https://crates.io/crates/cargo-espflash) -![MSRV](https://img.shields.io/badge/MSRV-1.82-blue?labelColor=1C2C2E&logo=Rust&style=flat-square) +![MSRV](https://img.shields.io/badge/MSRV-1.85-blue?labelColor=1C2C2E&logo=Rust&style=flat-square) ![Crates.io](https://img.shields.io/crates/l/cargo-espflash?labelColor=1C2C2E&style=flat-square) Cross-compiler and Cargo extension for flashing Espressif devices. @@ -25,7 +25,7 @@ Supports the **ESP32**, **ESP32-C2/C3/C6**, **ESP32-H2**, **ESP32-P4**, and **ES ## Installation -If you are installing `cargo-espflash` from source (ie. using `cargo install`) then you must have `rustc>=1.82.0` installed on your system. +If you are installing `cargo-espflash` from source (ie. using `cargo install`) then you must have `rustc>=1.85.0` installed on your system. To install: diff --git a/cargo-espflash/src/cargo_config.rs b/cargo-espflash/src/cargo_config.rs index f1627922..1d4869b3 100644 --- a/cargo-espflash/src/cargo_config.rs +++ b/cargo-espflash/src/cargo_config.rs @@ -89,9 +89,5 @@ fn config_path(path: &Path) -> Option { } let toml = path.join(".cargo/config.toml"); - if toml.exists() { - Some(toml) - } else { - None - } + if toml.exists() { Some(toml) } else { None } } diff --git a/cargo-espflash/src/error.rs b/cargo-espflash/src/error.rs index 2bcb645d..b58468fc 100644 --- a/cargo-espflash/src/error.rs +++ b/cargo-espflash/src/error.rs @@ -27,8 +27,10 @@ pub enum Error { #[error("No executable artifact found")] #[diagnostic( code(cargo_espflash::no_artifact), - help("If you're trying to run an example you need to specify it using the `--example` argument.\n\ - If you're in a Cargo workspace, specify the binary package with `--package`.") + help( + "If you're trying to run an example you need to specify it using the `--example` argument.\n\ + If you're in a Cargo workspace, specify the binary package with `--package`." + ) )] NoArtifact, @@ -46,8 +48,10 @@ pub enum Error { #[error("No package could be located in the current workspace")] #[diagnostic( code(cargo_espflash::no_package), - help("Ensure that you are executing from a valid package, and that the specified package name \ - exists in the current workspace.") + help( + "Ensure that you are executing from a valid package, and that the specified package name \ + exists in the current workspace." + ) )] NoPackage, @@ -145,7 +149,6 @@ impl Diagnostic for NoTargetError { 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 c0116a73..6dc814d4 100644 --- a/cargo-espflash/src/main.rs +++ b/cargo-espflash/src/main.rs @@ -1,12 +1,13 @@ use std::{ fs, path::PathBuf, - process::{exit, Command, ExitStatus, Stdio}, + process::{Command, ExitStatus, Stdio, exit}, }; use cargo_metadata::{Message, MetadataCommand}; use clap::{Args, CommandFactory, Parser, Subcommand}; use espflash::{ + Error as EspflashError, cli::{ self, config::Config, @@ -17,9 +18,8 @@ use espflash::{ logging::initialize_logger, targets::{Chip, XtalFrequency}, update::check_for_update, - Error as EspflashError, }; -use log::{debug, info, LevelFilter}; +use log::{LevelFilter, debug, info}; use miette::{IntoDiagnostic, Result, WrapErr}; use crate::{ diff --git a/espflash/Cargo.toml b/espflash/Cargo.toml index bba64204..bb64f718 100644 --- a/espflash/Cargo.toml +++ b/espflash/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "espflash" version = "4.0.0-dev" -edition = "2021" -rust-version = "1.82" +edition = "2024" +rust-version = "1.85" description = "A command-line tool for interacting with Espressif devices" repository = "https://github.com/esp-rs/espflash" license = "MIT OR Apache-2.0" diff --git a/espflash/README.md b/espflash/README.md index f7403784..cf70305e 100644 --- a/espflash/README.md +++ b/espflash/README.md @@ -3,7 +3,7 @@ [![Crates.io](https://img.shields.io/crates/v/espflash?labelColor=1C2C2E&color=C96329&logo=Rust&style=flat-square)](https://crates.io/crates/espflash) [![docs.rs](https://img.shields.io/docsrs/espflash?labelColor=1C2C2E&color=C96329&logo=rust&style=flat-square)](https://docs.rs/espflash) -![MSRV](https://img.shields.io/badge/MSRV-1.82-blue?labelColor=1C2C2E&logo=Rust&style=flat-square) +![MSRV](https://img.shields.io/badge/MSRV-1.85-blue?labelColor=1C2C2E&logo=Rust&style=flat-square) ![Crates.io](https://img.shields.io/crates/l/espflash?labelColor=1C2C2E&style=flat-square) A library and command-line tool for flashing Espressif devices. @@ -27,7 +27,7 @@ Supports the **ESP32**, **ESP32-C2/C3/C6**, **ESP32-H2**, **ESP32-P4**, and **ES ## Installation -If you are installing `espflash` from source (ie. using `cargo install`) then you must have `rustc>=1.82.0` installed on your system. +If you are installing `espflash` from source (ie. using `cargo install`) then you must have `rustc>=1.85.0` installed on your system. To install: diff --git a/espflash/src/bin/espflash.rs b/espflash/src/bin/espflash.rs index 57e3990b..2653c506 100644 --- a/espflash/src/bin/espflash.rs +++ b/espflash/src/bin/espflash.rs @@ -2,6 +2,7 @@ use std::{fs, path::PathBuf}; use clap::{Args, CommandFactory, Parser, Subcommand}; use espflash::{ + Error, cli::{ self, config::Config, @@ -12,9 +13,8 @@ use espflash::{ logging::initialize_logger, targets::{Chip, XtalFrequency}, update::check_for_update, - Error, }; -use log::{debug, info, LevelFilter}; +use log::{LevelFilter, debug, info}; use miette::{IntoDiagnostic, Result, WrapErr}; #[derive(Debug, Parser)] diff --git a/espflash/src/cli/config.rs b/espflash/src/cli/config.rs index fbf99c40..d7a1fcd5 100644 --- a/espflash/src/cli/config.rs +++ b/espflash/src/cli/config.rs @@ -19,7 +19,7 @@ use miette::{IntoDiagnostic, Result, WrapErr}; use serde::{Deserialize, Serialize}; use serialport::UsbPortInfo; -use crate::{flasher::FlashSettings, Error}; +use crate::{Error, flasher::FlashSettings}; /// A configured, known serial connection #[derive(Debug, Deserialize, Serialize, Default, Clone)] diff --git a/espflash/src/cli/mod.rs b/espflash/src/cli/mod.rs index c42737b9..d284d5f3 100644 --- a/espflash/src/cli/mod.rs +++ b/espflash/src/cli/mod.rs @@ -20,21 +20,22 @@ use std::{ use clap::{Args, ValueEnum}; use clap_complete::Shell; -use comfy_table::{modifiers, presets::UTF8_FULL, Attribute, Cell, Color, Table}; +use comfy_table::{Attribute, Cell, Color, Table, modifiers, presets::UTF8_FULL}; use esp_idf_part::{DataType, Partition, PartitionTable}; -use indicatif::{style::ProgressStyle, HumanBytes, HumanCount, ProgressBar}; +use indicatif::{HumanBytes, HumanCount, ProgressBar, style::ProgressStyle}; use log::{debug, info, warn}; use miette::{IntoDiagnostic, Result, WrapErr}; use serialport::{FlowControl, SerialPortInfo, SerialPortType, UsbPortInfo}; use self::{ config::Config, - monitor::{check_monitor_args, monitor, LogFormat}, + monitor::{LogFormat, check_monitor_args, monitor}, }; use crate::{ connection::reset::{ResetAfterOperation, ResetBeforeOperation}, error::{Error, MissingPartition, MissingPartitionTable}, flasher::{ + FLASH_SECTOR_SIZE, FlashData, FlashFrequency, FlashMode, @@ -42,7 +43,6 @@ use crate::{ FlashSize, Flasher, ProgressCallbacks, - FLASH_SECTOR_SIZE, }, image_format::Metadata, targets::{Chip, XtalFrequency}, diff --git a/espflash/src/cli/monitor/external_processors.rs b/espflash/src/cli/monitor/external_processors.rs index 379af1ba..d7c9e8a1 100644 --- a/espflash/src/cli/monitor/external_processors.rs +++ b/espflash/src/cli/monitor/external_processors.rs @@ -21,7 +21,7 @@ //! //! Example processor which turns some letters into uppercase //! ```rust,no_run -//! use std::io::{stdin, stdout, Read, Write}; +//! use std::io::{Read, Write, stdin, stdout}; //! //! fn main() { //! let args: Vec = std::env::args().collect(); diff --git a/espflash/src/cli/monitor/mod.rs b/espflash/src/cli/monitor/mod.rs index 05470351..b1dda368 100644 --- a/espflash/src/cli/monitor/mod.rs +++ b/espflash/src/cli/monitor/mod.rs @@ -11,12 +11,12 @@ //! in our monitor the output is displayed immediately upon reading. use std::{ - io::{stdout, ErrorKind, Read, Write}, + io::{ErrorKind, Read, Write, stdout}, time::Duration, }; use crossterm::{ - event::{poll, read, Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers}, + event::{Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers, poll, read}, terminal::{disable_raw_mode, enable_raw_mode}, }; use external_processors::ExternalProcessors; @@ -28,10 +28,10 @@ use strum::{Display, EnumIter, EnumString, VariantNames}; use crate::{ cli::{ - monitor::parser::{InputParser, ResolvingPrinter}, MonitorConfigArgs, + monitor::parser::{InputParser, ResolvingPrinter}, }, - connection::{reset::reset_after_flash, Port}, + connection::{Port, reset::reset_after_flash}, image_format::Metadata, }; @@ -271,20 +271,26 @@ pub fn check_monitor_args(monitor: &bool, monitor_args: &MonitorConfigArgs) -> R || monitor_args.no_reset || monitor_args.monitor_baud != 115_200) { - warn!("Monitor options were provided, but `--monitor/-M` flag isn't set. These options will be ignored."); + warn!( + "Monitor options were provided, but `--monitor/-M` flag isn't set. These options will be ignored." + ); } // Check if log-format is used with serial but output-format is specified if let Some(LogFormat::Serial) = monitor_args.log_format { if monitor_args.output_format.is_some() { - warn!("Output format specified but log format is serial. The output format option will be ignored."); + warn!( + "Output format specified but log format is serial. The output format option will be ignored." + ); } } // Check if log-format is defmt but no ELF file is provided if let Some(LogFormat::Defmt) = monitor_args.log_format { if monitor_args.elf.is_none() { - warn!("Log format `defmt` requires an ELF file. Please provide one with the `--elf` option."); + warn!( + "Log format `defmt` requires an ELF file. Please provide one with the `--elf` option." + ); } } diff --git a/espflash/src/cli/monitor/parser/esp_defmt.rs b/espflash/src/cli/monitor/parser/esp_defmt.rs index e3440262..f0bcd6f6 100644 --- a/espflash/src/cli/monitor/parser/esp_defmt.rs +++ b/espflash/src/cli/monitor/parser/esp_defmt.rs @@ -1,13 +1,13 @@ use std::io::Write; -use crossterm::{style::Print, QueueableCommand}; +use crossterm::{QueueableCommand, style::Print}; use defmt_decoder::{ - log::format::{Formatter, FormatterConfig, FormatterFormat}, Frame, Table, + log::format::{Formatter, FormatterConfig, FormatterFormat}, }; use log::warn; -use miette::{bail, ensure, Context, Diagnostic, Result}; +use miette::{Context, Diagnostic, Result, bail, ensure}; use thiserror::Error; use crate::cli::monitor::parser::InputParser; @@ -144,7 +144,9 @@ impl DefmtData { .map_err(|_e| DefmtError::LocationDataParseFailed)?; let locs = if !table.is_empty() && locs.is_empty() { - warn!("Insufficient DWARF info; compile your program with `debug = 2` to enable location info."); + warn!( + "Insufficient DWARF info; compile your program with `debug = 2` to enable location info." + ); None } else if table.indices().all(|idx| locs.contains_key(&(idx as u64))) { Some(locs) diff --git a/espflash/src/cli/monitor/parser/mod.rs b/espflash/src/cli/monitor/parser/mod.rs index 5b59fe19..a2167f1d 100644 --- a/espflash/src/cli/monitor/parser/mod.rs +++ b/espflash/src/cli/monitor/parser/mod.rs @@ -1,8 +1,8 @@ use std::{borrow::Cow, io::Write, sync::LazyLock}; use crossterm::{ - style::{Color, Print, PrintStyledContent, Stylize}, QueueableCommand, + style::{Color, Print, PrintStyledContent, Stylize}, }; use regex::Regex; diff --git a/espflash/src/cli/monitor/symbols.rs b/espflash/src/cli/monitor/symbols.rs index 4b2b191f..53383f80 100644 --- a/espflash/src/cli/monitor/symbols.rs +++ b/espflash/src/cli/monitor/symbols.rs @@ -1,11 +1,11 @@ use std::error::Error; use addr2line::{ - gimli::{self, Dwarf, EndianSlice, LittleEndian, SectionId}, Context, LookupResult, + gimli::{self, Dwarf, EndianSlice, LittleEndian, SectionId}, }; -use object::{read::File, Object, ObjectSection, ObjectSegment, ObjectSymbol}; +use object::{Object, ObjectSection, ObjectSegment, ObjectSymbol, read::File}; // Wrapper around addr2line that allows to look up function names and // locations from a given address. diff --git a/espflash/src/cli/serial.rs b/espflash/src/cli/serial.rs index d2c8ed10..2c62b880 100644 --- a/espflash/src/cli/serial.rs +++ b/espflash/src/cli/serial.rs @@ -2,14 +2,14 @@ use std::fs; use crossterm::style::Stylize; -use dialoguer::{theme::ColorfulTheme, Confirm, Select}; +use dialoguer::{Confirm, Select, theme::ColorfulTheme}; use log::{error, info}; use miette::{IntoDiagnostic, Result}; -use serialport::{available_ports, SerialPortInfo, SerialPortType}; +use serialport::{SerialPortInfo, SerialPortType, available_ports}; use crate::{ - cli::{config::UsbDevice, Config, ConnectArgs}, Error, + cli::{Config, ConnectArgs, config::UsbDevice}, }; /// Return the information of a serial port taking into account the different diff --git a/espflash/src/connection/command.rs b/espflash/src/connection/command.rs index f53323fa..da8a1c31 100644 --- a/espflash/src/connection/command.rs +++ b/espflash/src/connection/command.rs @@ -2,7 +2,7 @@ use std::{io::Write, mem::size_of, time::Duration}; -use bytemuck::{bytes_of, Pod, Zeroable}; +use bytemuck::{Pod, Zeroable, bytes_of}; use strum::Display; use crate::flasher::{SpiAttachParams, SpiSetParams}; diff --git a/espflash/src/connection/mod.rs b/espflash/src/connection/mod.rs index dff50dbf..b5d5e06e 100644 --- a/espflash/src/connection/mod.rs +++ b/espflash/src/connection/mod.rs @@ -22,15 +22,15 @@ use self::{ command::{Command, CommandType}, encoder::SlipEncoder, reset::{ - construct_reset_strategy_sequence, - hard_reset, - reset_after_flash, - soft_reset, ClassicReset, ResetAfterOperation, ResetBeforeOperation, ResetStrategy, UsbJtagSerialReset, + construct_reset_strategy_sequence, + hard_reset, + reset_after_flash, + soft_reset, }, }; use crate::{ @@ -267,7 +267,7 @@ impl Connection { return Err(Error::RomError(RomError::new( CommandType::Sync, RomErrorKind::InvalidMessage, - ))) + ))); } } } @@ -345,7 +345,7 @@ impl Connection { return Err(Error::UnsupportedFeature { chip, feature: "watchdog reset".into(), - }) + }); } } diff --git a/espflash/src/connection/reset.rs b/espflash/src/connection/reset.rs index 85279743..36812cab 100644 --- a/espflash/src/connection/reset.rs +++ b/espflash/src/connection/reset.rs @@ -12,12 +12,12 @@ use serialport::SerialPort; use strum::{Display, EnumIter, EnumString, VariantNames}; use super::{ - command::{Command, CommandType}, Connection, Port, USB_SERIAL_JTAG_PID, + command::{Command, CommandType}, }; -use crate::{flasher::FLASH_WRITE_SIZE, Error}; +use crate::{Error, flasher::FLASH_WRITE_SIZE}; /// Default time to wait before releasing the boot pin after a reset const DEFAULT_RESET_DELAY: u64 = 50; // ms diff --git a/espflash/src/error.rs b/espflash/src/error.rs index 35ee9e81..9b217ffb 100644 --- a/espflash/src/error.rs +++ b/espflash/src/error.rs @@ -43,11 +43,15 @@ pub enum Error { #[error("Chip provided with `-c/--chip` ({0}) does not match the detected chip ({1})")] #[diagnostic( code(espflash::chip_mismatch), - help("Ensure that the correct chip is selected, or remove the `-c/--chip` option to autodetect the chip") + help( + "Ensure that the correct chip is selected, or remove the `-c/--chip` option to autodetect the chip" + ) )] ChipMismatch(String, String), - #[error("Chip not argument provided, this is required when using the `--before no-reset-no-sync` option")] + #[error( + "Chip not argument provided, this is required when using the `--before no-reset-no-sync` option" + )] #[diagnostic( code(espflash::chip_not_provided), help("Ensure that you provide the `-c/--chip` option with the proper chip") @@ -62,10 +66,14 @@ pub enum Error { #[diagnostic(code(espflash::read_flash::digest_mismatch))] DigestMismatch(Vec, Vec), - #[error("Supplied ELF image can not be run from RAM, as it includes segments mapped to ROM addresses")] + #[error( + "Supplied ELF image can not be run from RAM, as it includes segments mapped to ROM addresses" + )] #[diagnostic( code(espflash::not_ram_loadable), - help("Either build the binary to be all in RAM, or remove the `--ram` option to load the image to flash") + help( + "Either build the binary to be all in RAM, or remove the `--ram` option to load the image to flash" + ) )] ElfNotRamLoadable, @@ -75,7 +83,9 @@ pub enum Error { #[diagnostic( code(espflash::image_too_big), help("Reduce the size of the binary or increase the size of the app partition."), - url("https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html#built-in-partition-tables") + url( + "https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html#built-in-partition-tables" + ) )] ElfTooBig(u32, u32), @@ -116,7 +126,9 @@ pub enum Error { #[error("No serial ports could be detected")] #[diagnostic( code(espflash::no_serial), - help("Make sure you have connected a device to the host system. If the device is connected but not listed, try using the `--list-all-ports` flag.") + help( + "Make sure you have connected a device to the host system. If the device is connected but not listed, try using the `--list-all-ports` flag." + ) )] NoSerial, @@ -164,7 +176,9 @@ pub enum Error { found_minor: u16, }, - #[error("Failed to parse chip revision: {chip_rev}. Chip revision must be in the format `major.minor`")] + #[error( + "Failed to parse chip revision: {chip_rev}. Chip revision must be in the format `major.minor`" + )] #[diagnostic(code(espflash::cli::parse_chip_rev_error))] ParseChipRevError { chip_rev: String }, @@ -286,7 +300,9 @@ pub enum ConnectionError { #[error("Failed to connect to the device")] #[diagnostic( code(espflash::connection_failed), - help("Ensure that the device is connected and the reset and boot pins are not being held down") + help( + "Ensure that the device is connected and the reset and boot pins are not being held down" + ) )] ConnectionFailed, @@ -300,7 +316,9 @@ pub enum ConnectionError { #[error("Received packet has invalid SLIP framing")] #[diagnostic( code(espflash::slip_framing), - help("Try hard-resetting the device and try again, if the error persists your ROM may be corrupted") + help( + "Try hard-resetting the device and try again, if the error persists your ROM may be corrupted" + ) )] FramingError, @@ -317,11 +335,15 @@ pub enum ConnectionError { #[error("Received packet to large for buffer")] #[diagnostic( code(espflash::oversized_packet), - help("Try hard-resetting the device and try again, if the error persists your ROM may be corrupted") + help( + "Try hard-resetting the device and try again, if the error persists your ROM may be corrupted" + ) )] OverSizedPacket, - #[error("Failed to read the available bytes on the serial port. Available bytes: {0}, Read bytes: {1}")] + #[error( + "Failed to read the available bytes on the serial port. Available bytes: {0}, Read bytes: {1}" + )] #[diagnostic(code(espflash::read_missmatch))] ReadMissmatch(u32, u32), diff --git a/espflash/src/flasher/mod.rs b/espflash/src/flasher/mod.rs index b46f4904..8b17b98e 100644 --- a/espflash/src/flasher/mod.rs +++ b/espflash/src/flasher/mod.rs @@ -14,7 +14,7 @@ use log::{debug, info, warn}; #[cfg(feature = "serialport")] use md5::{Digest, Md5}; #[cfg(feature = "serialport")] -use object::{read::elf::ElfFile32 as ElfFile, Endianness}; +use object::{Endianness, read::elf::ElfFile32 as ElfFile}; use serde::{Deserialize, Serialize}; #[cfg(feature = "serialport")] use serialport::UsbPortInfo; @@ -24,26 +24,26 @@ use strum::{Display, EnumIter, IntoEnumIterator, VariantNames}; pub(crate) use self::stubs::{FLASH_SECTOR_SIZE, FLASH_WRITE_SIZE}; #[cfg(feature = "serialport")] pub use crate::targets::flash_target::ProgressCallbacks; +use crate::{ + Error, + targets::{Chip, XtalFrequency}, +}; #[cfg(feature = "serialport")] use crate::{ connection::{ - command::{Command, CommandType}, - reset::{ResetAfterOperation, ResetBeforeOperation}, Connection, Port, + command::{Command, CommandType}, + reset::{ResetAfterOperation, ResetBeforeOperation}, }, error::{ConnectionError, ResultExt as _}, flasher::stubs::{ - FlashStub, CHIP_DETECT_MAGIC_REG_ADDR, DEFAULT_TIMEOUT, EXPECTED_STUB_HANDSHAKE, + FlashStub, }, - image_format::{ram_segments, rom_segments, Segment}, -}; -use crate::{ - targets::{Chip, XtalFrequency}, - Error, + image_format::{Segment, ram_segments, rom_segments}, }; #[cfg(feature = "serialport")] @@ -175,7 +175,7 @@ impl fmt::Display for SecurityInfo { ] .iter() .enumerate() - .filter(|(_, &key)| self.security_flag_status(key)) + .filter(|(_, key)| self.security_flag_status(key)) .map(|(i, _)| format!("Secure Boot Key{} is Revoked", i)) .collect(); @@ -864,8 +864,7 @@ impl Flasher { Err(_) => { warn!( "Could not detect flash size (FlashID=0x{:02X}, SizeID=0x{:02X}), defaulting to 4MB", - flash_id, - size_id + flash_id, size_id ); FlashSize::default() } diff --git a/espflash/src/flasher/stubs.rs b/espflash/src/flasher/stubs.rs index 602d5ce8..b88c1bac 100644 --- a/espflash/src/flasher/stubs.rs +++ b/espflash/src/flasher/stubs.rs @@ -1,6 +1,6 @@ use std::time::Duration; -use base64::{engine::general_purpose, Engine as _}; +use base64::{Engine as _, engine::general_purpose}; use serde::{Deserialize, Serialize}; use crate::targets::Chip; diff --git a/espflash/src/image_format/esp_idf.rs b/espflash/src/image_format/esp_idf.rs index 2892494e..a9652a9d 100644 --- a/espflash/src/image_format/esp_idf.rs +++ b/espflash/src/image_format/esp_idf.rs @@ -2,18 +2,18 @@ use std::{borrow::Cow, ffi::c_char, io::Write, iter::once, mem::size_of}; -use bytemuck::{bytes_of, from_bytes, pod_read_unaligned, Pod, Zeroable}; +use bytemuck::{Pod, Zeroable, bytes_of, from_bytes, pod_read_unaligned}; use esp_idf_part::{AppType, DataType, Partition, PartitionTable, SubType, Type}; use log::warn; -use object::{read::elf::ElfFile32 as ElfFile, Endianness, Object, ObjectSection}; +use object::{Endianness, Object, ObjectSection, read::elf::ElfFile32 as ElfFile}; use sha2::{Digest, Sha256}; -use super::{ram_segments, rom_segments, Segment}; +use super::{Segment, ram_segments, rom_segments}; use crate::{ + Error, error::AppDescriptorError, flasher::{FlashData, FlashFrequency, FlashMode, FlashSize}, targets::{Chip, Esp32Params}, - Error, }; const ESP_CHECKSUM_MAGIC: u8 = 0xEF; diff --git a/espflash/src/image_format/mod.rs b/espflash/src/image_format/mod.rs index 54fd9c7e..9a23f1da 100644 --- a/espflash/src/image_format/mod.rs +++ b/espflash/src/image_format/mod.rs @@ -9,11 +9,11 @@ use std::{ }; use object::{ - elf::SHT_PROGBITS, - read::elf::{ElfFile32 as ElfFile, SectionHeader}, Endianness, Object as _, ObjectSection as _, + elf::SHT_PROGBITS, + read::elf::{ElfFile32 as ElfFile, SectionHeader}, }; pub use self::{esp_idf::IdfBootloaderFormat, metadata::Metadata}; diff --git a/espflash/src/lib.rs b/espflash/src/lib.rs index fa54af1e..86309180 100644 --- a/espflash/src/lib.rs +++ b/espflash/src/lib.rs @@ -64,7 +64,7 @@ pub mod update { use std::time::Duration; use log::info; - use update_informer::{registry::Crates, Check}; + use update_informer::{Check, registry::Crates}; pub fn check_for_update(name: &str, version: &str) { // By setting the interval to 0 seconds we invalidate the cache with each diff --git a/espflash/src/targets/esp32.rs b/espflash/src/targets/esp32.rs index bd2ba62d..6c370132 100644 --- a/espflash/src/targets/esp32.rs +++ b/espflash/src/targets/esp32.rs @@ -1,13 +1,13 @@ use std::ops::Range; -#[cfg(feature = "serialport")] -use crate::{connection::Connection, targets::bytes_to_mac_addr}; use crate::{ + Error, flasher::{FlashData, FlashFrequency}, image_format::IdfBootloaderFormat, targets::{Chip, Esp32Params, ReadEFuse, SpiRegisters, Target, XtalFrequency}, - Error, }; +#[cfg(feature = "serialport")] +use crate::{connection::Connection, targets::bytes_to_mac_addr}; pub(crate) const CHIP_ID: u16 = 0; @@ -171,7 +171,7 @@ impl Target for Esp32 { return Err(Error::UnsupportedFeature { chip: Chip::Esp32, feature: "the selected crystal frequency".into(), - }) + }); } }; diff --git a/espflash/src/targets/esp32c2.rs b/espflash/src/targets/esp32c2.rs index c14207a9..213ec902 100644 --- a/espflash/src/targets/esp32c2.rs +++ b/espflash/src/targets/esp32c2.rs @@ -2,14 +2,14 @@ use std::{collections::HashMap, ops::Range}; use log::debug; -#[cfg(feature = "serialport")] -use crate::{connection::Connection, targets::bytes_to_mac_addr}; use crate::{ + Error, flasher::{FlashData, FlashFrequency}, image_format::IdfBootloaderFormat, targets::{Chip, Esp32Params, ReadEFuse, SpiRegisters, Target, XtalFrequency}, - Error, }; +#[cfg(feature = "serialport")] +use crate::{connection::Connection, targets::bytes_to_mac_addr}; pub(crate) const CHIP_ID: u16 = 12; @@ -109,7 +109,7 @@ impl Target for Esp32c2 { return Err(Error::UnsupportedFeature { chip: Chip::Esp32c2, feature: "the selected crystal frequency".into(), - }) + }); } }; diff --git a/espflash/src/targets/esp32c3.rs b/espflash/src/targets/esp32c3.rs index 2d8abc3b..ef388e28 100644 --- a/espflash/src/targets/esp32c3.rs +++ b/espflash/src/targets/esp32c3.rs @@ -3,10 +3,10 @@ use std::ops::Range; #[cfg(feature = "serialport")] use crate::connection::Connection; use crate::{ + Error, flasher::{FlashData, FlashFrequency}, image_format::IdfBootloaderFormat, targets::{Chip, Esp32Params, ReadEFuse, SpiRegisters, Target, XtalFrequency}, - Error, }; pub(crate) const CHIP_ID: u16 = 5; diff --git a/espflash/src/targets/esp32c6.rs b/espflash/src/targets/esp32c6.rs index cd46b19c..a5eeb56b 100644 --- a/espflash/src/targets/esp32c6.rs +++ b/espflash/src/targets/esp32c6.rs @@ -3,10 +3,10 @@ use std::ops::Range; #[cfg(feature = "serialport")] use crate::connection::Connection; use crate::{ + Error, flasher::{FlashData, FlashFrequency}, image_format::IdfBootloaderFormat, targets::{Chip, Esp32Params, ReadEFuse, SpiRegisters, Target, XtalFrequency}, - Error, }; pub(crate) const CHIP_ID: u16 = 13; diff --git a/espflash/src/targets/esp32h2.rs b/espflash/src/targets/esp32h2.rs index 8e3b0fb2..4a778bb2 100644 --- a/espflash/src/targets/esp32h2.rs +++ b/espflash/src/targets/esp32h2.rs @@ -3,10 +3,10 @@ use std::{collections::HashMap, ops::Range}; #[cfg(feature = "serialport")] use crate::connection::Connection; use crate::{ + Error, flasher::{FlashData, FlashFrequency}, image_format::IdfBootloaderFormat, targets::{Chip, Esp32Params, ReadEFuse, SpiRegisters, Target, XtalFrequency}, - Error, }; pub(crate) const CHIP_ID: u16 = 16; diff --git a/espflash/src/targets/esp32p4.rs b/espflash/src/targets/esp32p4.rs index eb0e32a2..ca8519b6 100644 --- a/espflash/src/targets/esp32p4.rs +++ b/espflash/src/targets/esp32p4.rs @@ -3,10 +3,10 @@ use std::ops::Range; #[cfg(feature = "serialport")] use crate::connection::Connection; use crate::{ + Error, flasher::{FlashData, FlashFrequency}, image_format::IdfBootloaderFormat, targets::{Chip, Esp32Params, ReadEFuse, SpiRegisters, Target, XtalFrequency}, - Error, }; pub(crate) const CHIP_ID: u16 = 18; diff --git a/espflash/src/targets/esp32s2.rs b/espflash/src/targets/esp32s2.rs index 2424acaf..5da235fc 100644 --- a/espflash/src/targets/esp32s2.rs +++ b/espflash/src/targets/esp32s2.rs @@ -2,14 +2,14 @@ use std::ops::Range; #[cfg(feature = "serialport")] use super::flash_target::MAX_RAM_BLOCK_SIZE; -#[cfg(feature = "serialport")] -use crate::{connection::Connection, flasher::FLASH_WRITE_SIZE}; use crate::{ + Error, flasher::{FlashData, FlashFrequency}, image_format::IdfBootloaderFormat, targets::{Chip, Esp32Params, ReadEFuse, SpiRegisters, Target, XtalFrequency}, - Error, }; +#[cfg(feature = "serialport")] +use crate::{connection::Connection, flasher::FLASH_WRITE_SIZE}; pub(crate) const CHIP_ID: u16 = 2; diff --git a/espflash/src/targets/esp32s3.rs b/espflash/src/targets/esp32s3.rs index e617f547..97bdd5e9 100644 --- a/espflash/src/targets/esp32s3.rs +++ b/espflash/src/targets/esp32s3.rs @@ -3,10 +3,10 @@ use std::ops::Range; #[cfg(feature = "serialport")] use crate::connection::Connection; use crate::{ + Error, flasher::{FlashData, FlashFrequency}, image_format::IdfBootloaderFormat, targets::{Chip, Esp32Params, ReadEFuse, SpiRegisters, Target, XtalFrequency}, - Error, }; pub(crate) const CHIP_ID: u16 = 9; diff --git a/espflash/src/targets/flash_target/esp32.rs b/espflash/src/targets/flash_target/esp32.rs index 9a24e054..f5e27666 100644 --- a/espflash/src/targets/flash_target/esp32.rs +++ b/espflash/src/targets/flash_target/esp32.rs @@ -1,27 +1,27 @@ use std::io::Write; use flate2::{ - write::{ZlibDecoder, ZlibEncoder}, Compression, + write::{ZlibDecoder, ZlibEncoder}, }; use log::info; use md5::{Digest, Md5}; +use crate::{ + Error, + flasher::{FLASH_SECTOR_SIZE, SpiAttachParams}, + image_format::Segment, + targets::Chip, +}; #[cfg(feature = "serialport")] use crate::{ connection::{ - command::{Command, CommandType}, Connection, + command::{Command, CommandType}, }, flasher::ProgressCallbacks, targets::FlashTarget, }; -use crate::{ - flasher::{SpiAttachParams, FLASH_SECTOR_SIZE}, - image_format::Segment, - targets::Chip, - Error, -}; /// Applications running from an ESP32's (or variant's) flash #[derive(Debug)] diff --git a/espflash/src/targets/flash_target/mod.rs b/espflash/src/targets/flash_target/mod.rs index 6d036c2d..4c27e87e 100644 --- a/espflash/src/targets/flash_target/mod.rs +++ b/espflash/src/targets/flash_target/mod.rs @@ -1,6 +1,6 @@ pub(crate) use self::ram::MAX_RAM_BLOCK_SIZE; pub use self::{esp32::Esp32Target, ram::RamTarget}; -use crate::{connection::Connection, image_format::Segment, Error}; +use crate::{Error, connection::Connection, image_format::Segment}; mod esp32; mod ram; diff --git a/espflash/src/targets/flash_target/ram.rs b/espflash/src/targets/flash_target/ram.rs index ffee6441..19d2ee3c 100644 --- a/espflash/src/targets/flash_target/ram.rs +++ b/espflash/src/targets/flash_target/ram.rs @@ -1,13 +1,13 @@ +use crate::{Error, image_format::Segment}; #[cfg(feature = "serialport")] use crate::{ connection::{ - command::{Command, CommandType}, Connection, + command::{Command, CommandType}, }, flasher::ProgressCallbacks, targets::FlashTarget, }; -use crate::{image_format::Segment, Error}; pub const MAX_RAM_BLOCK_SIZE: usize = 0x1800; diff --git a/espflash/src/targets/mod.rs b/espflash/src/targets/mod.rs index ccd35c63..a9eb6315 100644 --- a/espflash/src/targets/mod.rs +++ b/espflash/src/targets/mod.rs @@ -11,13 +11,8 @@ use strum::{Display, EnumIter, EnumString, VariantNames}; #[cfg(feature = "serialport")] pub use self::flash_target::{Esp32Target, RamTarget}; -#[cfg(feature = "serialport")] -use crate::{ - connection::Connection, - flasher::{SpiAttachParams, FLASH_WRITE_SIZE}, - targets::flash_target::{FlashTarget, MAX_RAM_BLOCK_SIZE}, -}; use crate::{ + Error, flasher::{FlashData, FlashFrequency}, image_format::IdfBootloaderFormat, targets::{ @@ -30,7 +25,12 @@ use crate::{ esp32s2::Esp32s2, esp32s3::Esp32s3, }, - Error, +}; +#[cfg(feature = "serialport")] +use crate::{ + connection::Connection, + flasher::{FLASH_WRITE_SIZE, SpiAttachParams}, + targets::flash_target::{FlashTarget, MAX_RAM_BLOCK_SIZE}, }; mod esp32;