@@ -394,6 +394,7 @@ impl Flasher {
394
394
addr : text_addr,
395
395
data : Cow :: Borrowed ( & text) ,
396
396
} ,
397
+ None ,
397
398
)
398
399
. flashing ( ) ?;
399
400
@@ -407,6 +408,7 @@ impl Flasher {
407
408
addr : data_addr,
408
409
data : Cow :: Borrowed ( & data) ,
409
410
} ,
411
+ None ,
410
412
)
411
413
. flashing ( ) ?;
412
414
@@ -637,6 +639,9 @@ impl Flasher {
637
639
/// Note that this will not touch the flash on the device
638
640
pub fn load_elf_to_ram ( & mut self , elf_data : & [ u8 ] ) -> Result < ( ) , Error > {
639
641
let image = ElfFirmwareImage :: try_from ( elf_data) ?;
642
+ if image. rom_segments ( self . chip ) . next ( ) . is_some ( ) {
643
+ return Err ( Error :: ElfNotRamLoadable ) ;
644
+ }
640
645
641
646
let mut target = self . chip . ram_target (
642
647
Some ( image. entry ( ) ) ,
@@ -646,19 +651,21 @@ impl Flasher {
646
651
) ;
647
652
target. begin ( & mut self . connection ) . flashing ( ) ?;
648
653
649
- if image. rom_segments ( self . chip ) . next ( ) . is_some ( ) {
650
- return Err ( Error :: ElfNotRamLoadable ) ;
651
- }
652
-
653
654
for segment in image. ram_segments ( self . chip ) {
655
+ // Only display progress bars when the "cli" feature is enabled.
656
+ let progress_cb = if cfg ! ( feature = "cli" ) {
657
+ use crate :: cli:: { build_progress_bar_callback, progress_bar} ;
658
+
659
+ let progress = progress_bar ( format ! ( "segment 0x{:X}" , segment. addr) , None ) ;
660
+ let progress_cb = build_progress_bar_callback ( progress) ;
661
+
662
+ Some ( progress_cb)
663
+ } else {
664
+ None
665
+ } ;
666
+
654
667
target
655
- . write_segment (
656
- & mut self . connection ,
657
- RomSegment {
658
- addr : segment. addr ,
659
- data : Cow :: Borrowed ( segment. data ( ) ) ,
660
- } ,
661
- )
668
+ . write_segment ( & mut self . connection , segment. into ( ) , progress_cb)
662
669
. flashing ( ) ?;
663
670
}
664
671
@@ -694,12 +701,25 @@ impl Flasher {
694
701
flash_freq,
695
702
) ?;
696
703
704
+ // When the "cli" feature is enabled, display the image size information.
697
705
#[ cfg( feature = "cli" ) ]
698
706
crate :: cli:: display_image_size ( image. app_size ( ) , image. part_size ( ) ) ;
699
707
700
708
for segment in image. flash_segments ( ) {
709
+ // Only display progress bars when the "cli" feature is enabled.
710
+ let progress_cb = if cfg ! ( feature = "cli" ) {
711
+ use crate :: cli:: { build_progress_bar_callback, progress_bar} ;
712
+
713
+ let progress = progress_bar ( format ! ( "segment 0x{:X}" , segment. addr) , None ) ;
714
+ let progress_cb = build_progress_bar_callback ( progress) ;
715
+
716
+ Some ( progress_cb)
717
+ } else {
718
+ None
719
+ } ;
720
+
701
721
target
702
- . write_segment ( & mut self . connection , segment)
722
+ . write_segment ( & mut self . connection , segment, progress_cb )
703
723
. flashing ( ) ?;
704
724
}
705
725
@@ -709,15 +729,22 @@ impl Flasher {
709
729
}
710
730
711
731
/// Load an bin image to flash at a specific address
712
- pub fn write_bin_to_flash ( & mut self , addr : u32 , data : & [ u8 ] ) -> Result < ( ) , Error > {
713
- let mut target = self . chip . flash_target ( self . spi_params , self . use_stub ) ;
714
- target. begin ( & mut self . connection ) . flashing ( ) ?;
732
+ pub fn write_bin_to_flash (
733
+ & mut self ,
734
+ addr : u32 ,
735
+ data : & [ u8 ] ,
736
+ progress_cb : Option < Box < dyn Fn ( usize , usize ) > > ,
737
+ ) -> Result < ( ) , Error > {
715
738
let segment = RomSegment {
716
739
addr,
717
740
data : Cow :: from ( data) ,
718
741
} ;
719
- target. write_segment ( & mut self . connection , segment) ?;
742
+
743
+ let mut target = self . chip . flash_target ( self . spi_params , self . use_stub ) ;
744
+ target. begin ( & mut self . connection ) . flashing ( ) ?;
745
+ target. write_segment ( & mut self . connection , segment, progress_cb) ?;
720
746
target. finish ( & mut self . connection , true ) . flashing ( ) ?;
747
+
721
748
Ok ( ( ) )
722
749
}
723
750
0 commit comments