@@ -11,10 +11,14 @@ use clap::Parser;
11
11
use config:: Config ;
12
12
use miette:: { IntoDiagnostic , Result , WrapErr } ;
13
13
use serialport:: { FlowControl , SerialPortType } ;
14
+ use strum:: VariantNames ;
14
15
15
16
use crate :: {
16
- cli:: serial:: get_serial_port_info, error:: Error , Chip , FirmwareImage , Flasher , ImageFormatId ,
17
- PartitionTable ,
17
+ cli:: serial:: get_serial_port_info,
18
+ elf:: { FirmwareImageBuilder , FlashFrequency , FlashMode } ,
19
+ error:: Error ,
20
+ flasher:: FlashSize ,
21
+ Chip , Flasher , ImageFormatId , PartitionTable ,
18
22
} ;
19
23
20
24
pub mod config;
@@ -48,6 +52,19 @@ pub struct FlashOpts {
48
52
pub monitor : bool ,
49
53
}
50
54
55
+ #[ derive( Parser ) ]
56
+ pub struct FlashConfigOpts {
57
+ /// Flash mode to use
58
+ #[ clap( short = 'm' , long, possible_values = FlashMode :: VARIANTS , value_name = "MODE" ) ]
59
+ pub flash_mode : Option < FlashMode > ,
60
+ /// Flash size of the target
61
+ #[ clap( short = 's' , long, possible_values = FlashSize :: VARIANTS , value_name = "SIZE" ) ]
62
+ pub flash_size : Option < FlashSize > ,
63
+ /// Flash frequency
64
+ #[ clap( short = 'f' , long, possible_values = FlashFrequency :: VARIANTS , value_name = "FREQUENCY" ) ]
65
+ pub flash_freq : Option < FlashFrequency > ,
66
+ }
67
+
51
68
pub fn connect ( opts : & ConnectOpts , config : & Config ) -> Result < Flasher > {
52
69
let port_info = get_serial_port_info ( opts, config) ?;
53
70
@@ -82,8 +99,15 @@ pub fn save_elf_as_image(
82
99
elf_data : & [ u8 ] ,
83
100
path : PathBuf ,
84
101
image_format : Option < ImageFormatId > ,
102
+ flash_mode : Option < FlashMode > ,
103
+ flash_size : Option < FlashSize > ,
104
+ flash_freq : Option < FlashFrequency > ,
85
105
) -> Result < ( ) > {
86
- let image = FirmwareImage :: from_data ( elf_data) ?;
106
+ let image = FirmwareImageBuilder :: new ( elf_data)
107
+ . flash_mode ( flash_mode)
108
+ . flash_size ( flash_size)
109
+ . flash_freq ( flash_freq)
110
+ . build ( ) ?;
87
111
88
112
let flash_image = chip. get_flash_image ( & image, None , None , image_format, None ) ?;
89
113
let parts: Vec < _ > = flash_image. ota_segments ( ) . collect ( ) ;
@@ -107,6 +131,9 @@ pub fn flash_elf_image(
107
131
bootloader : Option < & Path > ,
108
132
partition_table : Option < & Path > ,
109
133
image_format : Option < ImageFormatId > ,
134
+ flash_mode : Option < FlashMode > ,
135
+ flash_size : Option < FlashSize > ,
136
+ flash_freq : Option < FlashFrequency > ,
110
137
) -> Result < ( ) > {
111
138
// If the '--bootloader' option is provided, load the binary file at the
112
139
// specified path.
@@ -137,7 +164,15 @@ pub fn flash_elf_image(
137
164
138
165
// Load the ELF data, optionally using the provider bootloader/partition
139
166
// table/image format, to the device's flash memory.
140
- flasher. load_elf_to_flash_with_format ( elf_data, bootloader, partition_table, image_format) ?;
167
+ flasher. load_elf_to_flash_with_format (
168
+ elf_data,
169
+ bootloader,
170
+ partition_table,
171
+ image_format,
172
+ flash_mode,
173
+ flash_size,
174
+ flash_freq,
175
+ ) ?;
141
176
println ! ( "\n Flashing has completed!" ) ;
142
177
143
178
Ok ( ( ) )
0 commit comments