@@ -21,9 +21,10 @@ use crate::{
21
21
cli:: monitor:: monitor,
22
22
cli:: serial:: get_serial_port_info,
23
23
elf:: { ElfFirmwareImage , FlashFrequency , FlashMode } ,
24
- error:: Error ,
24
+ error:: { Error , NoOtadataError } ,
25
25
flasher:: FlashSize ,
26
- Chip , Flasher , ImageFormatId , InvalidPartitionTable , PartitionTable ,
26
+ partition_table, Chip , Flasher , ImageFormatId , InvalidPartitionTable , MissingPartitionTable ,
27
+ PartitionTable ,
27
28
} ;
28
29
29
30
pub mod config;
@@ -59,6 +60,10 @@ pub struct FlashOpts {
59
60
/// Open a serial monitor after flashing
60
61
#[ clap( long) ]
61
62
pub monitor : bool ,
63
+ /// Erase the OTADATA partition
64
+ /// This is useful when using multiple OTA partitions and still wanting to be able to reflash via espflash
65
+ #[ clap( long) ]
66
+ pub erase_otadata : bool ,
62
67
}
63
68
64
69
#[ derive( Debug , Clone , Parser ) ]
@@ -283,6 +288,7 @@ pub fn flash_elf_image(
283
288
flash_mode : Option < FlashMode > ,
284
289
flash_size : Option < FlashSize > ,
285
290
flash_freq : Option < FlashFrequency > ,
291
+ erase_otadata : bool ,
286
292
) -> Result < ( ) > {
287
293
// If the '--bootloader' option is provided, load the binary file at the
288
294
// specified path.
@@ -310,6 +316,26 @@ pub fn flash_elf_image(
310
316
None
311
317
} ;
312
318
319
+ if erase_otadata {
320
+ let partition_table = match & partition_table {
321
+ Some ( partition_table) => partition_table,
322
+ None => return Err ( ( MissingPartitionTable { } ) . into ( ) ) ,
323
+ } ;
324
+
325
+ let otadata = match partition_table. find_by_subtype (
326
+ partition_table:: Type :: CoreType ( partition_table:: CoreType :: Data ) ,
327
+ partition_table:: SubType :: Data ( partition_table:: DataType :: Ota ) ,
328
+ ) {
329
+ Some ( otadata) => otadata,
330
+ None => return Err ( ( NoOtadataError { } ) . into ( ) ) ,
331
+ } ;
332
+
333
+ let offset = otadata. offset ( ) ;
334
+ let size = otadata. size ( ) ;
335
+
336
+ flasher. erase_region ( offset, size) ?;
337
+ }
338
+
313
339
// Load the ELF data, optionally using the provider bootloader/partition
314
340
// table/image format, to the device's flash memory.
315
341
flasher. load_elf_to_flash_with_format (
0 commit comments