@@ -142,6 +142,9 @@ pub struct FlashArgs {
142
142
/// Logging format.
143
143
#[ arg( long, short = 'L' , default_value = "serial" , requires = "monitor" ) ]
144
144
pub log_format : LogFormat ,
145
+ /// Minimum chip revision supported by image, in format: major.minor
146
+ #[ arg( long, default_value = "0.0" , value_parser = parse_chip_rev) ]
147
+ pub min_chip_rev : u16 ,
145
148
/// Open a serial monitor after flashing
146
149
#[ arg( short = 'M' , long) ]
147
150
pub monitor : bool ,
@@ -193,6 +196,9 @@ pub struct SaveImageArgs {
193
196
pub chip : Chip ,
194
197
/// File name to save the generated image to
195
198
pub file : PathBuf ,
199
+ /// Minimum chip revision supported by image, in format: major.minor
200
+ #[ arg( long, default_value = "0.0" , value_parser = parse_chip_rev) ]
201
+ pub min_chip_rev : u16 ,
196
202
/// Boolean flag to merge binaries into single binary
197
203
#[ arg( long) ]
198
204
pub merge : bool ,
@@ -285,6 +291,36 @@ pub fn completions(args: &CompletionsArgs, app: &mut clap::Command, bin_name: &s
285
291
Ok ( ( ) )
286
292
}
287
293
294
+ /// Parses chip revision from string to major * 100 + minor format
295
+ pub fn parse_chip_rev ( chip_rev : & str ) -> Result < u16 > {
296
+ let mut split = chip_rev. split ( '.' ) ;
297
+
298
+ let parse_or_error = |value : Option < & str > | {
299
+ value
300
+ . ok_or_else ( || Error :: ParseChipRevError {
301
+ chip_rev : chip_rev. to_string ( ) ,
302
+ } )
303
+ . and_then ( |v| {
304
+ v. parse :: < u16 > ( ) . map_err ( |_| Error :: ParseChipRevError {
305
+ chip_rev : chip_rev. to_string ( ) ,
306
+ } )
307
+ } )
308
+ . into_diagnostic ( )
309
+ } ;
310
+
311
+ let major = parse_or_error ( split. next ( ) ) ?;
312
+ let minor = parse_or_error ( split. next ( ) ) ?;
313
+
314
+ if split. next ( ) . is_some ( ) {
315
+ return Err ( Error :: ParseChipRevError {
316
+ chip_rev : chip_rev. to_string ( ) ,
317
+ } )
318
+ . into_diagnostic ( ) ;
319
+ }
320
+
321
+ Ok ( major * 100 + minor)
322
+ }
323
+
288
324
/// Print information about a chip
289
325
pub fn print_board_info ( flasher : & mut Flasher ) -> Result < ( ) > {
290
326
let info = flasher. device_info ( ) ?;
@@ -342,6 +378,7 @@ pub fn serial_monitor(args: MonitorArgs, config: &Config) -> Result<()> {
342
378
/// Convert the provided firmware image from ELF to binary
343
379
pub fn save_elf_as_image (
344
380
chip : Chip ,
381
+ min_rev_full : u16 ,
345
382
elf_data : & [ u8 ] ,
346
383
image_path : PathBuf ,
347
384
image_format : Option < ImageFormatKind > ,
@@ -397,6 +434,7 @@ pub fn save_elf_as_image(
397
434
target_app_partition,
398
435
image_format,
399
436
None ,
437
+ min_rev_full,
400
438
flash_mode,
401
439
flash_size,
402
440
flash_freq,
@@ -439,6 +477,7 @@ pub fn save_elf_as_image(
439
477
None ,
440
478
image_format,
441
479
None ,
480
+ min_rev_full,
442
481
flash_mode,
443
482
flash_size,
444
483
flash_freq,
@@ -557,6 +596,7 @@ pub fn flash_elf_image(
557
596
flash_size : Option < FlashSize > ,
558
597
flash_freq : Option < FlashFrequency > ,
559
598
partition_table_offset : Option < u32 > ,
599
+ min_rev_full : u16 ,
560
600
) -> Result < ( ) > {
561
601
// If the '--bootloader' option is provided, load the binary file at the
562
602
// specified path.
@@ -581,6 +621,7 @@ pub fn flash_elf_image(
581
621
flash_size,
582
622
flash_freq,
583
623
partition_table_offset,
624
+ min_rev_full,
584
625
Some ( & mut EspflashProgress :: default ( ) ) ,
585
626
) ?;
586
627
info ! ( "Flashing has completed!" ) ;
0 commit comments