1
- use std:: fs:: read;
1
+ use std:: fs:: { read, read_to_string } ;
2
2
3
- use espflash:: { Config , Error , Flasher } ;
3
+ use espflash:: { Config , Error , Flasher , PartitionTable } ;
4
4
use miette:: { IntoDiagnostic , Result , WrapErr } ;
5
5
use pico_args:: Arguments ;
6
6
use serial:: { BaudRate , FlowControl , SerialPort } ;
7
7
8
8
#[ allow( clippy:: unnecessary_wraps) ]
9
9
fn help ( ) -> Result < ( ) > {
10
- println ! ( "Usage: espflash [--board-info] [--ram] <serial> <elf image>" ) ;
10
+ println ! ( "Usage: espflash [--board-info] [--ram] [--partition-table partition.csv] [--bootloader boot.bin] <serial> <elf image>" ) ;
11
11
Ok ( ( ) )
12
12
}
13
13
@@ -21,6 +21,12 @@ fn main() -> Result<()> {
21
21
22
22
let ram = args. contains ( "--ram" ) ;
23
23
let board_info = args. contains ( "--board-info" ) ;
24
+ let bootloader_path = args
25
+ . opt_value_from_str :: < _ , String > ( "--bootloader" )
26
+ . into_diagnostic ( ) ?;
27
+ let partition_table_path = args
28
+ . opt_value_from_str :: < _ , String > ( "--partition-table" )
29
+ . into_diagnostic ( ) ?;
24
30
25
31
let mut serial: Option < String > = args. opt_free_from_str ( ) . into_diagnostic ( ) ?;
26
32
let mut elf: Option < String > = args. opt_free_from_str ( ) . into_diagnostic ( ) ?;
@@ -67,7 +73,32 @@ fn main() -> Result<()> {
67
73
if ram {
68
74
flasher. load_elf_to_ram ( & input_bytes) ?;
69
75
} else {
70
- flasher. load_elf_to_flash ( & input_bytes, None , None ) ?;
76
+ let bootloader = bootloader_path
77
+ . as_deref ( )
78
+ . map ( read)
79
+ . transpose ( )
80
+ . into_diagnostic ( )
81
+ . wrap_err_with ( || {
82
+ format ! (
83
+ "Failed to open bootloader image \" {}\" " ,
84
+ bootloader_path. unwrap( )
85
+ )
86
+ } ) ?;
87
+ let partition_table = partition_table_path
88
+ . as_deref ( )
89
+ . map ( |path| {
90
+ let table = read_to_string ( path) ?;
91
+ PartitionTable :: try_from_str ( & table) . map_err ( Error :: from)
92
+ } )
93
+ . transpose ( )
94
+ . into_diagnostic ( )
95
+ . wrap_err_with ( || {
96
+ format ! (
97
+ "Failed to load partition table \" {}\" " ,
98
+ partition_table_path. unwrap( )
99
+ )
100
+ } ) ?;
101
+ flasher. load_elf_to_flash ( & input_bytes, bootloader, partition_table) ?;
71
102
}
72
103
73
104
Ok ( ( ) )
0 commit comments