Skip to content

Commit e765bd8

Browse files
Normalize similar arguments (#759)
* feat: Normalize similar arguments * feat: Remove unnecesary value_names * feat: Remove some short version of arguments * docs: Update changelog * tests: Fix arguments * feat: Use elf for MonitorConfigArgs to avoid duplication * feat: Rename monitor_baud arg * fix: Allow using log-format with custom runner * feat: Add help for NoElf error * clippy: Remove too_many_args expection
1 parent bba9040 commit e765bd8

File tree

8 files changed

+53
-43
lines changed

8 files changed

+53
-43
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414

1515
### Changed
1616
- Split the baudrate for connecting and monitorinig in `flash` subcommand (#737)
17+
- Normalized arguments of the CLI commands (#759)
1718

1819
- `board-info` now prints `Security information`. (#758)
1920

cargo-espflash/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,10 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
351351
// The 26MHz ESP32-C2's need to be treated as a special case.
352352
if chip == Chip::Esp32c2
353353
&& target_xtal_freq == XtalFrequency::_26Mhz
354-
&& monitor_args.baud_rate == 115_200
354+
&& monitor_args.monitor_baud == 115_200
355355
{
356356
// 115_200 * 26 MHz / 40 MHz = 74_880
357-
monitor_args.baud_rate = 74_880;
357+
monitor_args.monitor_baud = 74_880;
358358
}
359359

360360
monitor_args.elf = Some(build_ctx.artifact_path);

espflash/src/bin/espflash.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ struct FlashArgs {
125125
#[derive(Debug, Args)]
126126
#[non_exhaustive]
127127
struct SaveImageArgs {
128-
/// ELF image to flash
128+
/// ELF image
129129
image: PathBuf,
130130
/// Flashing configuration
131131
#[clap(flatten)]
@@ -141,9 +141,9 @@ struct SaveImageArgs {
141141
struct WriteBinArgs {
142142
/// Address at which to write the binary file
143143
#[arg(value_parser = parse_u32)]
144-
pub addr: u32,
144+
pub address: u32,
145145
/// File containing the binary data to write
146-
pub bin_file: String,
146+
pub file: String,
147147
/// Connection configuration
148148
#[clap(flatten)]
149149
connect_args: ConnectArgs,
@@ -285,10 +285,10 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
285285
// The 26MHz ESP32-C2's need to be treated as a special case.
286286
if chip == Chip::Esp32c2
287287
&& target_xtal_freq == XtalFrequency::_26Mhz
288-
&& monitor_args.baud_rate == 115_200
288+
&& monitor_args.monitor_baud == 115_200
289289
{
290290
// 115_200 * 26 MHz / 40 MHz = 74_880
291-
monitor_args.baud_rate = 74_880;
291+
monitor_args.monitor_baud = 74_880;
292292
}
293293

294294
monitor_args.elf = Some(args.image);
@@ -340,12 +340,16 @@ fn write_bin(args: WriteBinArgs, config: &Config) -> Result<()> {
340340
let mut flasher = connect(&args.connect_args, config, false, false)?;
341341
print_board_info(&mut flasher)?;
342342

343-
let mut f = File::open(&args.bin_file).into_diagnostic()?;
343+
let mut f = File::open(&args.file).into_diagnostic()?;
344344
let size = f.metadata().into_diagnostic()?.len();
345345
let mut buffer = Vec::with_capacity(size.try_into().into_diagnostic()?);
346346
f.read_to_end(&mut buffer).into_diagnostic()?;
347347

348-
flasher.write_bin_to_flash(args.addr, &buffer, Some(&mut EspflashProgress::default()))?;
348+
flasher.write_bin_to_flash(
349+
args.address,
350+
&buffer,
351+
Some(&mut EspflashProgress::default()),
352+
)?;
349353

350354
Ok(())
351355
}

espflash/src/cli/mod.rs

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub struct ConnectArgs {
7171
#[arg(short = 'c', long)]
7272
pub chip: Option<Chip>,
7373
/// Require confirmation before auto-connecting to a recognized device.
74-
#[arg(short = 'C', long)]
74+
#[arg(long)]
7575
pub confirm_port: bool,
7676
/// List all available ports.
7777
#[arg(long)]
@@ -108,11 +108,15 @@ pub struct EraseRegionArgs {
108108
/// Connection configuration
109109
#[clap(flatten)]
110110
pub connect_args: ConnectArgs,
111-
/// Offset to start erasing from
112-
#[arg(value_name = "OFFSET", value_parser = parse_u32)]
113-
pub addr: u32,
111+
/// Start address
112+
///
113+
/// Must be multiple of 4096(0x1000)
114+
#[arg(value_parser = parse_u32)]
115+
pub address: u32,
114116
/// Size of the region to erase
115-
#[arg(value_name = "SIZE", value_parser = parse_u32)]
117+
///
118+
/// Must be multiple of 4096(0x1000)
119+
#[arg(value_parser = parse_u32)]
116120
pub size: u32,
117121
}
118122

@@ -183,9 +187,9 @@ pub struct PartitionTableArgs {
183187
#[derive(Debug, Args)]
184188
#[non_exhaustive]
185189
pub struct ReadFlashArgs {
186-
/// Offset to start reading from
187-
#[arg(value_name = "OFFSET", value_parser = parse_u32)]
188-
pub addr: u32,
190+
/// Address to start reading from
191+
#[arg(value_parser = parse_u32)]
192+
pub address: u32,
189193
/// Size of each individual packet of data
190194
///
191195
/// Defaults to 0x1000 (FLASH_SECTOR_SIZE)
@@ -195,10 +199,9 @@ pub struct ReadFlashArgs {
195199
#[clap(flatten)]
196200
connect_args: ConnectArgs,
197201
/// Size of the region to read
198-
#[arg(value_name = "SIZE", value_parser = parse_u32)]
202+
#[arg(value_parser = parse_u32)]
199203
pub size: u32,
200-
/// Name of binary dump
201-
#[arg(value_name = "FILE")]
204+
/// File name to save the read data to
202205
pub file: PathBuf,
203206
/// Maximum number of un-acked packets
204207
#[arg(long, default_value = "64", value_parser = parse_u32)]
@@ -219,7 +222,7 @@ pub struct SaveImageArgs {
219222
#[arg(long)]
220223
pub merge: bool,
221224
/// Don't pad the image to the flash size
222-
#[arg(long, short = 'P', requires = "merge")]
225+
#[arg(long, requires = "merge")]
223226
pub skip_padding: bool,
224227
/// Cristal frequency of the target
225228
#[arg(long, short = 'x')]
@@ -236,7 +239,7 @@ pub struct ImageArgs {
236239
#[arg(long, value_name = "FILE")]
237240
pub bootloader: Option<PathBuf>,
238241
/// Path to a CSV file containing partition table
239-
#[arg(long, short = 'T', value_name = "FILE")]
242+
#[arg(long, value_name = "FILE")]
240243
pub partition_table: Option<PathBuf>,
241244
/// Partition table offset
242245
#[arg(long, value_name = "OFFSET", value_parser = parse_u32)]
@@ -264,11 +267,11 @@ pub struct MonitorArgs {
264267
#[derive(Debug, Args)]
265268
#[non_exhaustive]
266269
pub struct MonitorConfigArgs {
267-
/// Baud rate at which to communicate with target device
270+
/// Baud rate at which to monitor the target device
268271
#[arg(short = 'r', long, env = "MONITOR_BAUD", default_value = "115_200", value_parser = parse_u32)]
269-
pub baud_rate: u32,
270-
/// File name of the ELF image to load the symbols from
271-
#[arg(short = 'e', long, value_name = "FILE")]
272+
pub monitor_baud: u32,
273+
/// ELF image to load the symbols from
274+
#[arg(long, value_name = "FILE")]
272275
pub elf: Option<PathBuf>,
273276
/// Avoids asking the user for interactions like resetting the device
274277
#[arg(long)]
@@ -277,7 +280,7 @@ pub struct MonitorConfigArgs {
277280
#[arg(long, requires = "non_interactive")]
278281
no_reset: bool,
279282
/// Logging format.
280-
#[arg(long, short = 'L', default_value = "serial", requires = "elf")]
283+
#[arg(long, short = 'L', default_value = "serial")]
281284
log_format: LogFormat,
282285
/// External log processors to use (comma separated executables)
283286
#[arg(long)]
@@ -288,11 +291,11 @@ pub struct MonitorConfigArgs {
288291
#[non_exhaustive]
289292
pub struct ChecksumMd5Args {
290293
/// Start address
291-
#[clap(long, value_parser=parse_u32)]
294+
#[clap(value_parser=parse_u32)]
292295
address: u32,
293-
/// Length
294-
#[clap(short, long, value_parser=parse_u32)]
295-
length: u32,
296+
/// Size of the region to check
297+
#[clap(value_parser=parse_u32)]
298+
size: u32,
296299
/// Connection configuration
297300
#[clap(flatten)]
298301
connect_args: ConnectArgs,
@@ -387,7 +390,7 @@ pub fn board_info(args: &ConnectArgs, config: &Config) -> Result<()> {
387390
pub fn checksum_md5(args: &ChecksumMd5Args, config: &Config) -> Result<()> {
388391
let mut flasher = connect(&args.connect_args, config, true, true)?;
389392

390-
let checksum = flasher.checksum_md5(args.address, args.length)?;
393+
let checksum = flasher.checksum_md5(args.address, args.size)?;
391394
println!("0x{:x}", checksum);
392395

393396
Ok(())
@@ -470,10 +473,10 @@ pub fn serial_monitor(args: MonitorArgs, config: &Config) -> Result<()> {
470473
// The 26MHz ESP32-C2's need to be treated as a special case.
471474
if chip == Chip::Esp32c2
472475
&& target.crystal_freq(flasher.connection())? == XtalFrequency::_26Mhz
473-
&& monitor_args.baud_rate == 115_200
476+
&& monitor_args.monitor_baud == 115_200
474477
{
475478
// 115_200 * 26 MHz / 40 MHz = 74_880
476-
monitor_args.baud_rate = 74_880;
479+
monitor_args.monitor_baud = 74_880;
477480
}
478481

479482
monitor(flasher.into_serial(), elf.as_deref(), pid, monitor_args)
@@ -629,10 +632,10 @@ pub fn erase_region(args: EraseRegionArgs, config: &Config) -> Result<()> {
629632

630633
info!(
631634
"Erasing region at 0x{:08x} ({} bytes)",
632-
args.addr, args.size
635+
args.address, args.size
633636
);
634637

635-
flasher.erase_region(args.addr, args.size)?;
638+
flasher.erase_region(args.address, args.size)?;
636639
flasher
637640
.connection()
638641
.reset_after(!args.connect_args.no_stub)?;
@@ -733,7 +736,7 @@ pub fn read_flash(args: ReadFlashArgs, config: &Config) -> Result<()> {
733736
let mut flasher = connect(&args.connect_args, config, false, false)?;
734737
print_board_info(&mut flasher)?;
735738
flasher.read_flash(
736-
args.addr,
739+
args.address,
737740
args.size,
738741
args.block_size,
739742
args.max_in_flight,

espflash/src/cli/monitor/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ impl Drop for RawModeGuard {
7171

7272
/// Open a serial monitor on the given serial port, using the given input
7373
/// parser.
74-
#[allow(clippy::too_many_arguments)]
7574
pub fn monitor(
7675
mut serial: Port,
7776
elf: Option<&[u8]>,
@@ -87,7 +86,7 @@ pub fn monitor(
8786
reset_after_flash(&mut serial, pid).into_diagnostic()?;
8887
}
8988

90-
let baud = monitor_args.baud_rate;
89+
let baud = monitor_args.monitor_baud;
9190
debug!("Opening serial monitor with baudrate: {}", baud);
9291

9392
// Explicitly set the baud rate when starting the serial monitor, to allow using

espflash/src/cli/monitor/parser/esp_defmt.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ use crate::cli::monitor::parser::InputParser;
1111
#[error("Could not set up defmt logger")]
1212
pub enum DefmtError {
1313
#[error("No elf data available")]
14-
#[diagnostic(code(espflash::monitor::defmt::no_elf))]
14+
#[diagnostic(
15+
code(espflash::monitor::defmt::no_elf),
16+
help("Please provide an ELF file with the `--elf` argument")
17+
)]
1518
NoElf,
1619

1720
#[error("No defmt data was found in the elf file")]

espflash/src/command.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,13 @@ impl Command<'_> {
312312
#[derive(Zeroable, Pod, Copy, Clone, Debug)]
313313
#[repr(C)]
314314
struct WriteRegParams {
315-
addr: u32,
315+
address: u32,
316316
value: u32,
317317
mask: u32,
318318
delay_us: u32,
319319
}
320320
let params = WriteRegParams {
321-
addr: address,
321+
address,
322322
value,
323323
mask: mask.unwrap_or(0xFFFFFFFF),
324324
delay_us: 0,

espflash/tests/scripts/checksum-md5.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ echo "$result"
55
if [[ ! $result =~ "Flash has been erased!" ]]; then
66
exit 1
77
fi
8-
result=$(espflash checksum-md5 --address 0x1000 --length 0x100 2>&1)
8+
result=$(espflash checksum-md5 0x1000 0x100 2>&1)
99
echo "$result"
1010
if [[ ! $result =~ "0x827f263ef9fb63d05499d14fcef32f60" ]]; then
1111
exit 1

0 commit comments

Comments
 (0)