@@ -24,7 +24,7 @@ use comfy_table::{modifiers, presets::UTF8_FULL, Attribute, Cell, Color, Table};
2424use esp_idf_part:: { DataType , Partition , PartitionTable } ;
2525use indicatif:: { style:: ProgressStyle , HumanCount , ProgressBar } ;
2626use log:: { debug, info, warn} ;
27- use miette:: { IntoDiagnostic , Result , WrapErr } ;
27+ use miette:: { miette , IntoDiagnostic , Result , WrapErr } ;
2828use serialport:: { FlowControl , SerialPortType , UsbPortInfo } ;
2929
3030use self :: {
@@ -513,13 +513,25 @@ pub fn save_elf_as_image(
513513
514514 display_image_size ( image. app_size ( ) , image. part_size ( ) ) ;
515515
516- let parts = image. ota_segments ( ) . collect :: < Vec < _ > > ( ) ;
516+ let parts = image. flash_segments ( ) . collect :: < Vec < _ > > ( ) ;
517517 match parts. as_slice ( ) {
518518 [ single] => fs:: write ( & image_path, & single. data ) . into_diagnostic ( ) ?,
519519 parts => {
520520 for part in parts {
521- let part_path = format ! ( "{:#x}_{}" , part. addr, image_path. display( ) ) ;
522- fs:: write ( part_path, & part. data ) . into_diagnostic ( ) ?
521+ let image_path_name = image_path
522+ . file_name ( )
523+ . ok_or ( miette ! ( "image file doesn't have a name: {:?}" , image_path) ) ?;
524+ let mut prefixed_image_path_name =
525+ std:: ffi:: OsString :: from ( format ! ( "{:#09x}_" , part. addr) ) ;
526+ prefixed_image_path_name. push ( image_path_name) ;
527+ let mut prefixed_image_path = image_path. clone ( ) ;
528+ prefixed_image_path. set_file_name ( prefixed_image_path_name) ;
529+ fs:: write ( & prefixed_image_path, & part. data )
530+ . into_diagnostic ( )
531+ . context ( format ! (
532+ "could not write partition data to {:?}" ,
533+ & prefixed_image_path
534+ ) ) ?
523535 }
524536 }
525537 }
0 commit comments