11use async_trait:: async_trait;
22use probe_rs:: flashing:: DownloadOptions ;
3- use probe_rs:: { MemoryInterface } ;
4- use tbf_parser:: parse:: { parse_tbf_header_lengths} ;
3+ use probe_rs:: MemoryInterface ;
4+ use tbf_parser:: parse:: parse_tbf_header_lengths;
55
66use crate :: board_settings:: BoardSettings ;
77use crate :: connection:: { Connection , ProbeRSConnection } ;
@@ -10,10 +10,7 @@ use crate::CommandEraseApps;
1010
1111#[ async_trait]
1212impl CommandEraseApps for ProbeRSConnection {
13- async fn erase_apps (
14- & mut self ,
15- settings : & BoardSettings ,
16- ) -> Result < ( ) , TockloaderError > {
13+ async fn erase_apps ( & mut self , settings : & BoardSettings ) -> Result < ( ) , TockloaderError > {
1714 if !self . is_open ( ) {
1815 return Err ( InternalError :: ConnectionNotOpen . into ( ) ) ;
1916 }
@@ -29,22 +26,17 @@ impl CommandEraseApps for ProbeRSConnection {
2926
3027 board_core. read ( appaddr, & mut appdata) ?;
3128
32- let app_size: u32 ;
33-
3429 // The first 8 bytes of the application data contain the TBF header
3530 // lengths and version.
3631 //
3732 // Note on expect: `read` always fills up the entire buffer, which
3833 // was previously declared as 8 bytes.
39- log:: info!( "app data? {:?}" , appdata) ;
40- match parse_tbf_header_lengths (
34+ let app_size: u32 = match parse_tbf_header_lengths (
4135 & appdata
4236 . try_into ( )
4337 . expect ( "Buffer length must be at least 8 bytes long." ) ,
4438 ) {
45- Ok ( data) => {
46- app_size = data. 2 ;
47- }
39+ Ok ( data) => data. 2 ,
4840 _ => break ,
4941 } ;
5042
@@ -55,18 +47,15 @@ impl CommandEraseApps for ProbeRSConnection {
5547 let mut loader = session. target ( ) . flash_loader ( ) ;
5648
5749 let address = settings. start_address ;
58- // (adi): fill the memory with total_size values of 0xFF
50+ // (adi): fill the memory with total_size values of 0x0
5951 let buffer = [ 0x0 ] . repeat ( total_size as usize ) ;
60- loader. add_data (
61- ( address as u32 ) . into ( ) ,
62- & buffer
63- ) ?;
64-
52+ loader. add_data ( ( address as u32 ) . into ( ) , & buffer) ?;
53+
6554 let mut options = DownloadOptions :: default ( ) ;
6655 options. keep_unwritten_bytes = true ;
67-
56+
6857 // Finally, the data can be programmed
6958 loader. commit ( session, options) ?;
7059 Ok ( ( ) )
7160 }
72- }
61+ }
0 commit comments