@@ -8,7 +8,7 @@ use crate::{
8
8
chip:: Chip ,
9
9
command:: { Command , CommandType } ,
10
10
connection:: Connection ,
11
- elf:: { FirmwareImage , RomSegment } ,
11
+ elf:: { FirmwareImageBuilder , FlashFrequency , FlashMode , RomSegment } ,
12
12
error:: { ConnectionError , FlashDetectError , ResultExt } ,
13
13
image_format:: ImageFormatId ,
14
14
Error , PartitionTable ,
@@ -376,15 +376,9 @@ impl Flasher {
376
376
self . chip
377
377
}
378
378
379
- /// The flash size of the board that the flasher is connected to
380
- pub fn flash_size ( & self ) -> FlashSize {
381
- self . flash_size
382
- }
383
-
384
379
/// Read and print any information we can about the connected board
385
380
pub fn board_info ( & mut self ) -> Result < ( ) , Error > {
386
381
let chip = self . chip ( ) ;
387
- let size = self . flash_size ( ) ;
388
382
389
383
let maybe_revision = chip. chip_revision ( self . connection ( ) ) ?;
390
384
let features = chip. chip_features ( self . connection ( ) ) ?;
@@ -397,7 +391,7 @@ impl Flasher {
397
391
None => println ! ( ) ,
398
392
}
399
393
println ! ( "Crystal frequency: {}MHz" , freq) ;
400
- println ! ( "Flash size: {}" , size ) ;
394
+ println ! ( "Flash size: {}" , self . flash_size ) ;
401
395
println ! ( "Features: {}" , features. join( ", " ) ) ;
402
396
println ! ( "MAC address: {}" , mac) ;
403
397
@@ -408,7 +402,7 @@ impl Flasher {
408
402
///
409
403
/// Note that this will not touch the flash on the device
410
404
pub fn load_elf_to_ram ( & mut self , elf_data : & [ u8 ] ) -> Result < ( ) , Error > {
411
- let image = FirmwareImage :: from_data ( elf_data) ?;
405
+ let image = FirmwareImageBuilder :: new ( elf_data) . build ( ) ?;
412
406
413
407
let mut target = self . chip . ram_target ( ) ;
414
408
target. begin ( & mut self . connection , & image) . flashing ( ) ?;
@@ -439,9 +433,20 @@ impl Flasher {
439
433
bootloader : Option < Vec < u8 > > ,
440
434
partition_table : Option < PartitionTable > ,
441
435
image_format : Option < ImageFormatId > ,
436
+ flash_mode : Option < FlashMode > ,
437
+ flash_size : Option < FlashSize > ,
438
+ flash_freq : Option < FlashFrequency > ,
442
439
) -> Result < ( ) , Error > {
443
- let mut image = FirmwareImage :: from_data ( elf_data) ?;
444
- image. flash_size = self . flash_size ( ) ;
440
+ let mut builder = FirmwareImageBuilder :: new ( elf_data)
441
+ . flash_mode ( flash_mode)
442
+ . flash_size ( flash_size)
443
+ . flash_freq ( flash_freq) ;
444
+
445
+ if builder. flash_size . is_none ( ) {
446
+ builder = builder. flash_size ( Some ( self . flash_size ) ) ;
447
+ }
448
+
449
+ let image = builder. build ( ) ?;
445
450
446
451
let mut target = self . chip . flash_target ( self . spi_params ) ;
447
452
target. begin ( & mut self . connection , & image) . flashing ( ) ?;
@@ -471,8 +476,19 @@ impl Flasher {
471
476
elf_data : & [ u8 ] ,
472
477
bootloader : Option < Vec < u8 > > ,
473
478
partition_table : Option < PartitionTable > ,
479
+ flash_mode : Option < FlashMode > ,
480
+ flash_size : Option < FlashSize > ,
481
+ flash_freq : Option < FlashFrequency > ,
474
482
) -> Result < ( ) , Error > {
475
- self . load_elf_to_flash_with_format ( elf_data, bootloader, partition_table, None )
483
+ self . load_elf_to_flash_with_format (
484
+ elf_data,
485
+ bootloader,
486
+ partition_table,
487
+ None ,
488
+ flash_mode,
489
+ flash_size,
490
+ flash_freq,
491
+ )
476
492
}
477
493
478
494
pub fn change_baud ( & mut self , speed : u32 ) -> Result < ( ) , Error > {
0 commit comments