@@ -11,22 +11,41 @@ use tokio_serial::SerialStream;
1111
1212use crate :: bootloader_serial:: { issue_command, Command , Response } ;
1313use crate :: errors:: { TockError , TockloaderError } ;
14+ use crate :: IOCommands ;
1415
1516/// This structure contains all relevant information about a tock application.
1617///
1718/// All data is stored either within [TbfHeader]s, or [TbfFooter]s.
1819///
1920/// See also <https://book.tockos.org/doc/tock_binary_format>
20- #[ derive( Debug ) ]
21+ #[ derive( Debug , Clone ) ]
2122pub struct AppAttributes {
23+ pub address : u64 ,
24+ pub size : u32 ,
25+ pub index : u8 ,
2226 pub tbf_header : TbfHeader ,
2327 pub tbf_footers : Vec < TbfFooter > ,
28+ pub installed : bool ,
29+ pub is_padding : bool ,
30+ }
31+
32+ impl std:: fmt:: Display for AppAttributes {
33+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
34+ write ! (
35+ f,
36+ "{}. {} - start: {:#x}, size: {}" ,
37+ self . index,
38+ self . tbf_header. get_package_name( ) . unwrap_or( "" ) ,
39+ self . address,
40+ self . size
41+ )
42+ }
2443}
2544
2645/// This structure represents a footer of a Tock application. Currently, footers
2746/// only contain credentials, which are used to verify the integrity of the
2847/// application.
29- #[ derive( Debug ) ]
48+ #[ derive( Debug , Clone ) ]
3049pub struct TbfFooter {
3150 pub credentials : TbfFooterV2Credentials ,
3251 pub size : u32 ,
@@ -41,10 +60,22 @@ impl TbfFooter {
4160// TODO(george-cosma): Could take advantages of the trait rework
4261
4362impl AppAttributes {
44- pub ( crate ) fn new ( header_data : TbfHeader , footers_data : Vec < TbfFooter > ) -> AppAttributes {
63+ pub ( crate ) fn new (
64+ address : u64 ,
65+ size : u32 ,
66+ index : u8 ,
67+ header_data : TbfHeader ,
68+ footers_data : Vec < TbfFooter > ,
69+ installed : bool ,
70+ ) -> AppAttributes {
4571 AppAttributes {
72+ address,
73+ size,
74+ index,
4675 tbf_header : header_data,
4776 tbf_footers : footers_data,
77+ installed,
78+ is_padding : false ,
4879 }
4980 }
5081
@@ -117,6 +148,11 @@ impl AppAttributes {
117148 // crash the process.
118149 let binary_end_offset = header. get_binary_end ( ) ;
119150
151+ if !header. is_app ( ) {
152+ appaddr += total_size as u64 ;
153+ continue ;
154+ }
155+
120156 let mut footers: Vec < TbfFooter > = vec ! [ ] ;
121157 let total_footers_size = total_size - binary_end_offset;
122158 let mut footer_offset = binary_end_offset;
@@ -129,9 +165,9 @@ impl AppAttributes {
129165 // binary_end_offset`) , even if we overread.
130166 let mut appfooter =
131167 vec ! [ 0u8 ; ( total_footers_size - ( footer_offset - binary_end_offset) ) as usize ] ;
132-
168+ // log::info!("footer init {:?}", appfooter);
133169 board_core. read ( appaddr + footer_offset as u64 , & mut appfooter) ?;
134-
170+ // log::info!("footer read {:?}", appfooter);
135171 let footer_info =
136172 parse_tbf_footer ( & appfooter) . map_err ( TockError :: InvalidAppTbfHeader ) ?;
137173
@@ -142,9 +178,10 @@ impl AppAttributes {
142178 footer_offset += footer_info. 1 + 4 ;
143179 }
144180
145- let details: AppAttributes = AppAttributes :: new ( header, footers) ;
181+ let details: AppAttributes =
182+ AppAttributes :: new ( appaddr, total_size, apps_counter, header, footers, true ) ;
146183
147- apps_details. insert ( apps_counter, details) ;
184+ apps_details. insert ( apps_counter. into ( ) , details) ;
148185 apps_counter += 1 ;
149186 appaddr += total_size as u64 ;
150187 }
@@ -232,8 +269,14 @@ impl AppAttributes {
232269 log:: debug!( "App #{apps_counter}: Header data: {header_data:?}" ) ;
233270 let header = parse_tbf_header ( & header_data, tbf_version)
234271 . map_err ( TockError :: InvalidAppTbfHeader ) ?;
272+
235273 let binary_end_offset = header. get_binary_end ( ) ;
236274
275+ if !header. is_app ( ) {
276+ appaddr += total_size as u64 ;
277+ continue ;
278+ }
279+
237280 let mut footers: Vec < TbfFooter > = vec ! [ ] ;
238281 let total_footers_size = total_size - binary_end_offset;
239282 let mut footer_offset = binary_end_offset;
@@ -273,12 +316,17 @@ impl AppAttributes {
273316 footer_offset += footer_info. 1 + 4 ;
274317 }
275318
276- let details: AppAttributes = AppAttributes :: new ( header, footers) ;
319+ let details: AppAttributes =
320+ AppAttributes :: new ( appaddr, total_size, apps_counter, header, footers, true ) ;
277321
278- apps_details. insert ( apps_counter, details) ;
322+ apps_details. insert ( apps_counter. into ( ) , details) ;
279323 apps_counter += 1 ;
280324 appaddr += total_size as u64 ;
281325 }
282326 Ok ( apps_details)
283327 }
328+
329+ pub async fn read ( & mut self , conn : & mut dyn IOCommands ) -> Result < Vec < u8 > , TockloaderError > {
330+ conn. read ( self . address , self . size as usize ) . await
331+ }
284332}
0 commit comments