@@ -142,6 +142,9 @@ pub struct FlashArgs {
142142 /// Logging format.
143143 #[ arg( long, short = 'L' , default_value = "serial" , requires = "monitor" ) ]
144144 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 ,
145148 /// Open a serial monitor after flashing
146149 #[ arg( short = 'M' , long) ]
147150 pub monitor : bool ,
@@ -193,6 +196,9 @@ pub struct SaveImageArgs {
193196 pub chip : Chip ,
194197 /// File name to save the generated image to
195198 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 ,
196202 /// Boolean flag to merge binaries into single binary
197203 #[ arg( long) ]
198204 pub merge : bool ,
@@ -285,6 +291,36 @@ pub fn completions(args: &CompletionsArgs, app: &mut clap::Command, bin_name: &s
285291 Ok ( ( ) )
286292}
287293
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+
288324/// Print information about a chip
289325pub fn print_board_info ( flasher : & mut Flasher ) -> Result < ( ) > {
290326 let info = flasher. device_info ( ) ?;
@@ -342,6 +378,7 @@ pub fn serial_monitor(args: MonitorArgs, config: &Config) -> Result<()> {
342378/// Convert the provided firmware image from ELF to binary
343379pub fn save_elf_as_image (
344380 chip : Chip ,
381+ min_rev_full : u16 ,
345382 elf_data : & [ u8 ] ,
346383 image_path : PathBuf ,
347384 image_format : Option < ImageFormatKind > ,
@@ -397,6 +434,7 @@ pub fn save_elf_as_image(
397434 target_app_partition,
398435 image_format,
399436 None ,
437+ min_rev_full,
400438 flash_mode,
401439 flash_size,
402440 flash_freq,
@@ -439,6 +477,7 @@ pub fn save_elf_as_image(
439477 None ,
440478 image_format,
441479 None ,
480+ min_rev_full,
442481 flash_mode,
443482 flash_size,
444483 flash_freq,
@@ -557,6 +596,7 @@ pub fn flash_elf_image(
557596 flash_size : Option < FlashSize > ,
558597 flash_freq : Option < FlashFrequency > ,
559598 partition_table_offset : Option < u32 > ,
599+ min_rev_full : u16 ,
560600) -> Result < ( ) > {
561601 // If the '--bootloader' option is provided, load the binary file at the
562602 // specified path.
@@ -581,6 +621,7 @@ pub fn flash_elf_image(
581621 flash_size,
582622 flash_freq,
583623 partition_table_offset,
624+ min_rev_full,
584625 Some ( & mut EspflashProgress :: default ( ) ) ,
585626 ) ?;
586627 info ! ( "Flashing has completed!" ) ;
0 commit comments