1- use std:: fs:: read;
1+ use std:: fs:: { read, read_to_string } ;
22
3- use espflash:: { Config , Error , Flasher } ;
3+ use espflash:: { Config , Error , Flasher , PartitionTable } ;
44use miette:: { IntoDiagnostic , Result , WrapErr } ;
55use pico_args:: Arguments ;
66use serial:: { BaudRate , FlowControl , SerialPort } ;
77
88#[ allow( clippy:: unnecessary_wraps) ]
99fn 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>" ) ;
1111 Ok ( ( ) )
1212}
1313
@@ -21,6 +21,12 @@ fn main() -> Result<()> {
2121
2222 let ram = args. contains ( "--ram" ) ;
2323 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 ( ) ?;
2430
2531 let mut serial: Option < String > = args. opt_free_from_str ( ) . into_diagnostic ( ) ?;
2632 let mut elf: Option < String > = args. opt_free_from_str ( ) . into_diagnostic ( ) ?;
@@ -67,7 +73,32 @@ fn main() -> Result<()> {
6773 if ram {
6874 flasher. load_elf_to_ram ( & input_bytes) ?;
6975 } 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) ?;
71102 }
72103
73104 Ok ( ( ) )
0 commit comments