@@ -8,7 +8,7 @@ use std::{
8
8
use cargo_metadata:: Message ;
9
9
use clap:: { App , Arg , ArgMatches , SubCommand } ;
10
10
use error:: Error ;
11
- use espflash:: { Chip , Config , FirmwareImage , Flasher , PartitionTable } ;
11
+ use espflash:: { Chip , Config , FirmwareImage , Flasher , ImageFormatId , PartitionTable } ;
12
12
use miette:: { IntoDiagnostic , Result , WrapErr } ;
13
13
use monitor:: monitor;
14
14
use package_metadata:: CargoEspFlashMeta ;
@@ -17,6 +17,7 @@ use serial::{BaudRate, FlowControl, SerialPort};
17
17
use crate :: cargo_config:: CargoConfig ;
18
18
use crate :: error:: NoTargetError ;
19
19
use crate :: { cargo_config:: parse_cargo_config, error:: UnsupportedTargetError } ;
20
+ use std:: str:: FromStr ;
20
21
21
22
mod cargo_config;
22
23
mod error;
@@ -42,6 +43,11 @@ fn main() -> Result<()> {
42
43
. takes_value ( true )
43
44
. value_name ( "FEATURES" )
44
45
. help ( "Comma delimited list of build features" ) ,
46
+ Arg :: with_name ( "format" )
47
+ . long ( "format" )
48
+ . takes_value ( true )
49
+ . value_name ( "image format" )
50
+ . help ( "Image format to flash" ) ,
45
51
] ;
46
52
let connect_args = [ Arg :: with_name ( "serial" )
47
53
. takes_value ( true )
@@ -228,12 +234,18 @@ fn flash(
228
234
None
229
235
} ;
230
236
237
+ let image_format = matches
238
+ . value_of ( "format" )
239
+ . map ( ImageFormatId :: from_str)
240
+ . transpose ( ) ?
241
+ . or ( metadata. format ) ;
242
+
231
243
// Read the ELF data from the build path and load it to the target.
232
244
let elf_data = fs:: read ( path) . into_diagnostic ( ) ?;
233
245
if matches. is_present ( "ram" ) {
234
246
flasher. load_elf_to_ram ( & elf_data) ?;
235
247
} else {
236
- flasher. load_elf_to_flash ( & elf_data, bootloader, partition_table) ?;
248
+ flasher. load_elf_to_flash ( & elf_data, bootloader, partition_table, image_format ) ?;
237
249
}
238
250
println ! ( "\n Flashing has completed!" ) ;
239
251
@@ -266,13 +278,6 @@ fn build(
266
278
cargo_config : & CargoConfig ,
267
279
chip : Option < Chip > ,
268
280
) -> Result < PathBuf > {
269
- // The 'build-std' unstable cargo feature is required to enable
270
- // cross-compilation. If it has not been set then we cannot build the
271
- // application.
272
- if !cargo_config. has_build_std ( ) {
273
- return Err ( Error :: NoBuildStd . into ( ) ) ;
274
- } ;
275
-
276
281
let target = cargo_config
277
282
. target ( )
278
283
. ok_or_else ( || NoTargetError :: new ( chip) ) ?;
@@ -281,6 +286,13 @@ fn build(
281
286
return Err ( Error :: UnsupportedTarget ( UnsupportedTargetError :: new ( target, chip) ) . into ( ) ) ;
282
287
}
283
288
}
289
+ // The 'build-std' unstable cargo feature is required to enable
290
+ // cross-compilation for xtensa targets.
291
+ // If it has not been set then we cannot build the
292
+ // application.
293
+ if !cargo_config. has_build_std ( ) && target. starts_with ( "xtensa-" ) {
294
+ return Err ( Error :: NoBuildStd . into ( ) ) ;
295
+ } ;
284
296
285
297
// Build the list of arguments to pass to 'cargo build'.
286
298
let mut args = vec ! [ ] ;
@@ -356,7 +368,7 @@ fn build(
356
368
fn save_image (
357
369
matches : & ArgMatches ,
358
370
_config : Config ,
359
- _metadata : CargoEspFlashMeta ,
371
+ metadata : CargoEspFlashMeta ,
360
372
cargo_config : CargoConfig ,
361
373
) -> Result < ( ) > {
362
374
let target = cargo_config
@@ -370,7 +382,13 @@ fn save_image(
370
382
371
383
let image = FirmwareImage :: from_data ( & elf_data) ?;
372
384
373
- let flash_image = chip. get_flash_image ( & image, None , None , None ) ?;
385
+ let image_format = matches
386
+ . value_of ( "format" )
387
+ . map ( ImageFormatId :: from_str)
388
+ . transpose ( ) ?
389
+ . or ( metadata. format ) ;
390
+
391
+ let flash_image = chip. get_flash_image ( & image, None , None , image_format, None ) ?;
374
392
let parts: Vec < _ > = flash_image. ota_segments ( ) . collect ( ) ;
375
393
376
394
let out_path = matches. value_of ( "file" ) . unwrap ( ) ;
0 commit comments