Skip to content

Commit

Permalink
Merge branch 'main' into feat/config
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioGasquez authored Feb 1, 2024
2 parents aed1b47 + 9721049 commit d4ccf51
Show file tree
Hide file tree
Showing 32 changed files with 534 additions and 152 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Changelog check

on:
pull_request:
# Run on labeled/unlabeled in addition to defaults to detect
# adding/removing skip-changelog labels.
types: [opened, reopened, labeled, unlabeled, synchronize]

jobs:
changelog:
runs-on: ubuntu-latest
steps:
- uses: dangoslen/changelog-enforcer@v3
with:
changeLogPath: CHANGELOG.md
skipLabels: "skip-changelog"
missingUpdateErrorMessage: "Please add a changelog entry in the CHANGELOG.md file."
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
arch: ${{ matrix.platform.arch }}
target: ${{ matrix.platform.target }}

- run: cargo check --lib --no-default-features ${{ matrix.platform.features }}
- run: cargo check -p espflash --lib --no-default-features ${{ matrix.platform.features }}

msrv:
name: Check MSRV (${{ matrix.platform.target }})
Expand Down
22 changes: 12 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Added reset strategies (#487)
- Read esp-println generated defmt messages (#466)
- Add --target-app-partition argument to flash command (#461)
- Add --confirm-port argument to flash command (#455)
- Add --chip argument for flash and write-bin commands (#514)
- Add --partition-table-offset argument for specifying the partition table offset (#516)
- Read `esp-println` generated `defmt` messages (#466)
- Add `--target-app-partition` argument to flash command (#461)
- Add `--confirm-port` argument to flash command (#455)
- Add `--chip argument` for flash and write-bin commands (#514)
- Add `--partition-table-offset` argument for specifying the partition table offset (#516)
- 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)
- Add `--min-chip-rev` argument to specify minimum chip revision (#525)
- Add `serialport` feature. (#535)
- Add support for 26 MHz bootloader for ESP32 and ESP32-C2 (#553)
- Add CI check to verify that CHANGELOG is updated (#560)

### Fixed

- Fixed printing panic backtraces when using `esp-println` and `defmt` (#496)
- Fixed defmt parsing when data is read in parts (#503)
- Fixed `defmt` parsing when data is read in parts (#503)
- Use partition table instead of hard-coded values for the location of partitions (#516)
- Fixed a missed `flush` call that may be causing communication errors (#521)
- Fix "SHA-256 comparison failed: [...] attempting to boot anyway..." (#567)

### 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)
- Created `FlashData`, `FlashDataBuilder` and `FlashSettings` structs to reduce number of input arguments in some functions (#512, #566)
- `espflash` will now exit with an error if `defmt` is selected but not usable (#524)

### Removed

Expand Down
1 change: 1 addition & 0 deletions cargo-espflash/LICENSE-APACHE
1 change: 1 addition & 0 deletions cargo-espflash/LICENSE-MIT
34 changes: 21 additions & 13 deletions cargo-espflash/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ use clap::{Args, CommandFactory, Parser, Subcommand};
use espflash::{
cli::{
self, board_info, checksum_md5, completions, config::Config, connect, erase_flash,
erase_partitions, erase_region, flash_elf_image, monitor::monitor, parse_partition_table,
partition_table, print_board_info, save_elf_as_image, serial_monitor, ChecksumMd5Args,
CompletionsArgs, ConnectArgs, EraseFlashArgs, EraseRegionArgs, EspflashProgress,
FlashConfigArgs, MonitorArgs, PartitionTableArgs,
erase_partitions, erase_region, flash_elf_image, monitor::monitor, partition_table,
print_board_info, save_elf_as_image, serial_monitor, ChecksumMd5Args, CompletionsArgs,
ConnectArgs, EraseFlashArgs, EraseRegionArgs, EspflashProgress, FlashConfigArgs,
MonitorArgs, PartitionTableArgs,
},
error::Error as EspflashError,
flasher::{FlashData, FlashSettings},
flasher::{parse_partition_table, FlashData, FlashSettings},
image_format::ImageFormatKind,
logging::initialize_logger,
targets::Chip,
targets::{Chip, XtalFrequency},
update::check_for_update,
};
use log::{debug, info, LevelFilter};
Expand Down Expand Up @@ -335,19 +335,21 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
)?;
}

flash_elf_image(&mut flasher, &elf_data, flash_data)?;
flash_elf_image(&mut flasher, &elf_data, flash_data, target_xtal_freq)?;
}

if args.flash_args.monitor {
let pid = flasher.get_usb_pid()?;

// The 26MHz ESP32-C2's need to be treated as a special case.
let default_baud =
if chip == Chip::Esp32c2 && args.connect_args.no_stub && target_xtal_freq == 26 {
74_880
} else {
115_200
};
let default_baud = if chip == Chip::Esp32c2
&& args.connect_args.no_stub
&& target_xtal_freq == XtalFrequency::_26Mhz
{
74_880
} else {
115_200
};

monitor(
flasher.into_interface(),
Expand Down Expand Up @@ -576,13 +578,19 @@ fn save_image(args: SaveImageArgs, config: &Config) -> Result<()> {
args.save_image_args.min_chip_rev,
)?;

let xtal_freq = args
.save_image_args
.xtal_freq
.unwrap_or(XtalFrequency::default(args.save_image_args.chip));

save_elf_as_image(
&elf_data,
args.save_image_args.chip,
args.save_image_args.file,
flash_data,
args.save_image_args.merge,
args.save_image_args.skip_padding,
xtal_freq,
)?;

Ok(())
Expand Down
1 change: 1 addition & 0 deletions espflash/LICENSE-APACHE
1 change: 1 addition & 0 deletions espflash/LICENSE-MIT
2 changes: 1 addition & 1 deletion espflash/resources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ The bootloaders have been built by hand from ESP-IDF, using the `release/v5.1` b
https://github.com/espressif/esp-idf/tree/release/v5.1

The ESP32s flasher stubs are taken from the **esp-rs/esp-flasher-stub** repository:
https://github.com/esp-rs/esp-flasher-stub/latests
https://github.com/esp-rs/esp-flasher-stub/releases/latest
The ESP8266 flasher stub is taken from the **espressif/esptool** repository:
https://github.com/espressif/esptool/tree/master/esptool/targets/stub_flasher
Binary file not shown.
Binary file not shown.
Binary file modified espflash/resources/bootloaders/esp32p4-bootloader.bin
Binary file not shown.
34 changes: 21 additions & 13 deletions espflash/src/bin/espflash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ use clap::{Args, CommandFactory, Parser, Subcommand};
use espflash::{
cli::{
self, board_info, checksum_md5, completions, config::Config, connect, erase_flash,
erase_partitions, erase_region, flash_elf_image, monitor::monitor, parse_partition_table,
parse_uint32, partition_table, print_board_info, save_elf_as_image, serial_monitor,
ChecksumMd5Args, CompletionsArgs, ConnectArgs, EraseFlashArgs, EraseRegionArgs,
EspflashProgress, FlashConfigArgs, MonitorArgs, PartitionTableArgs,
erase_partitions, erase_region, flash_elf_image, monitor::monitor, parse_uint32,
partition_table, print_board_info, save_elf_as_image, serial_monitor, ChecksumMd5Args,
CompletionsArgs, ConnectArgs, EraseFlashArgs, EraseRegionArgs, EspflashProgress,
FlashConfigArgs, MonitorArgs, PartitionTableArgs,
},
error::Error,
flasher::{FlashData, FlashSettings},
flasher::{parse_partition_table, FlashData, FlashSettings},
image_format::ImageFormatKind,
logging::initialize_logger,
targets::Chip,
targets::{Chip, XtalFrequency},
update::check_for_update,
};
use log::{debug, info, LevelFilter};
Expand Down Expand Up @@ -271,19 +271,21 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
)?;
}

flash_elf_image(&mut flasher, &elf_data, flash_data)?;
flash_elf_image(&mut flasher, &elf_data, flash_data, target_xtal_freq)?;
}

if args.flash_args.monitor {
let pid = flasher.get_usb_pid()?;

// The 26MHz ESP32-C2's need to be treated as a special case.
let default_baud =
if chip == Chip::Esp32c2 && args.connect_args.no_stub && target_xtal_freq == 26 {
74_880
} else {
115_200
};
let default_baud = if chip == Chip::Esp32c2
&& args.connect_args.no_stub
&& target_xtal_freq == XtalFrequency::_26Mhz
{
74_880
} else {
115_200
};

monitor(
flasher.into_interface(),
Expand Down Expand Up @@ -344,13 +346,19 @@ fn save_image(args: SaveImageArgs, config: &Config) -> Result<()> {
args.save_image_args.min_chip_rev,
)?;

let xtal_freq = args
.save_image_args
.xtal_freq
.unwrap_or(XtalFrequency::default(args.save_image_args.chip));

save_elf_as_image(
&elf_data,
args.save_image_args.chip,
args.save_image_args.file,
flash_data,
args.save_image_args.merge,
args.save_image_args.skip_padding,
xtal_freq,
)?;

Ok(())
Expand Down
47 changes: 23 additions & 24 deletions espflash/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@
//! [espflash]: https://crates.io/crates/espflash

use std::num::ParseIntError;
use std::{
collections::HashMap,
fs,
io::Write,
path::{Path, PathBuf},
};
use std::{collections::HashMap, fs, io::Write, path::PathBuf};

use clap::Args;
use clap_complete::Shell;
Expand All @@ -35,10 +30,13 @@ use self::{
use crate::{
elf::ElfFirmwareImage,
error::{Error, MissingPartition, MissingPartitionTable},
flasher::{FlashData, FlashFrequency, FlashMode, FlashSize, Flasher, ProgressCallbacks},
flasher::{
parse_partition_table, FlashData, FlashFrequency, FlashMode, FlashSize, Flasher,
ProgressCallbacks,
},
image_format::ImageFormatKind,
interface::Interface,
targets::Chip,
targets::{Chip, XtalFrequency},
};

pub mod config;
Expand Down Expand Up @@ -220,6 +218,9 @@ pub struct SaveImageArgs {
/// Don't pad the image to the flash size
#[arg(long, short = 'P', requires = "merge")]
pub skip_padding: bool,
/// Cristal frequency of the target
#[arg(long, short = 'x')]
pub xtal_freq: Option<XtalFrequency>,
}

/// Open the serial monitor without flashing
Expand Down Expand Up @@ -372,7 +373,7 @@ pub fn print_board_info(flasher: &mut Flasher) -> Result<()> {
} else {
println!();
}
println!("Crystal frequency: {}MHz", info.crystal_frequency);
println!("Crystal frequency: {}", info.crystal_frequency);
println!("Flash size: {}", info.flash_size);
println!("Features: {}", info.features.join(", "));
println!("MAC address: {}", info.mac_address);
Expand Down Expand Up @@ -400,7 +401,7 @@ pub fn serial_monitor(args: MonitorArgs, config: &Config) -> Result<()> {
// The 26MHz ESP32-C2's need to be treated as a special case.
let default_baud = if chip == Chip::Esp32c2
&& args.connect_args.no_stub
&& target.crystal_freq(flasher.connection())? == 26
&& target.crystal_freq(flasher.connection())? == XtalFrequency::_26Mhz
{
74_880
} else {
Expand All @@ -424,15 +425,16 @@ pub fn save_elf_as_image(
flash_data: FlashData,
merge: bool,
skip_padding: bool,
xtal_freq: XtalFrequency,
) -> Result<()> {
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.clone(), None)?;
let image =
chip.into_target()
.get_flash_image(&image, flash_data.clone(), None, xtal_freq)?;

display_image_size(image.app_size(), image.part_size());

Expand Down Expand Up @@ -466,7 +468,7 @@ pub fn save_elf_as_image(
} else {
let image = chip
.into_target()
.get_flash_image(&image, flash_data, None)?;
.get_flash_image(&image, flash_data, None, xtal_freq)?;

display_image_size(image.app_size(), image.part_size());

Expand Down Expand Up @@ -573,24 +575,21 @@ pub fn flash_elf_image(
flasher: &mut Flasher,
elf_data: &[u8],
flash_data: FlashData,
xtal_freq: XtalFrequency,
) -> 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(elf_data, flash_data, Some(&mut EspflashProgress::default()))?;
flasher.load_elf_to_flash(
elf_data,
flash_data,
Some(&mut EspflashProgress::default()),
xtal_freq,
)?;
info!("Flashing has completed!");

Ok(())
}

/// Parse a [PartitionTable] from the provided path
pub fn parse_partition_table(path: &Path) -> Result<PartitionTable> {
let data = fs::read(path)
.into_diagnostic()
.wrap_err("Failed to open partition table")?;

PartitionTable::try_from(data).into_diagnostic()
}

/// Erase one or more partitions by label or [DataType]
pub fn erase_partitions(
flasher: &mut Flasher,
Expand Down
Loading

0 comments on commit d4ccf51

Please sign in to comment.