@@ -42,13 +42,13 @@ const MAX_HUBRIS_VERSION: u32 = 11;
4242
4343#[ derive( Debug , Serialize ) ]
4444pub struct HubrisManifest {
45- pub version : Option < String > ,
45+ pub version : String ,
4646 pub gitrev : Option < String > ,
4747 pub features : Vec < String > ,
48- pub board : Option < String > ,
48+ pub board : String ,
4949 pub image : Option < String > ,
50- pub name : Option < String > ,
51- pub target : Option < String > ,
50+ pub name : String ,
51+ pub target : String ,
5252 pub task_features : HashMap < String , Vec < String > > ,
5353 pub task_irqs : HashMap < String , Vec < ( u32 , u32 ) > > ,
5454 pub task_notifications : HashMap < String , Vec < String > > ,
@@ -73,9 +73,9 @@ impl HubrisManifest {
7373 config : & HubrisConfig ,
7474 rev : HubrisManifestRev ,
7575 ) -> Result < Self > {
76- let board = Some ( config. board . clone ( ) ) ;
77- let name = Some ( config. name . clone ( ) ) ;
78- let target = Some ( config. target . clone ( ) ) ;
76+ let board = config. board . clone ( ) ;
77+ let name = config. name . clone ( ) ;
78+ let target = config. target . clone ( ) ;
7979 let features = match config. kernel . features {
8080 Some ( ref features) => features. clone ( ) ,
8181 None => vec ! [ ] ,
@@ -537,9 +537,8 @@ impl<'a> IntoIterator for &'a HubrisI2cBusList {
537537}
538538
539539/// Portions of the [`HubrisManifest`] that are loaded from archive files
540- #[ derive( Default ) ]
541540pub struct HubrisManifestRev {
542- pub version : Option < String > ,
541+ pub version : String ,
543542 pub gitrev : Option < String > ,
544543 pub image : Option < String > ,
545544}
@@ -1156,7 +1155,7 @@ pub struct HubrisArchive {
11561155 pub manifest : HubrisManifest ,
11571156
11581157 // image ID
1159- pub imageid : Option < ( u32 , Vec < u8 > ) > ,
1158+ imageid : ( u32 , Vec < u8 > ) ,
11601159
11611160 // loaded regions
11621161 loaded : BTreeMap < u32 , HubrisRegion > ,
@@ -1353,19 +1352,23 @@ impl HubrisArchive {
13531352 }
13541353
13551354 // First, we'll load aspects of configuration.
1356- let mut manifest_rev = HubrisManifestRev :: default ( ) ;
1357- if let Ok ( git_rev) = hubris . extract_file ( "git-rev" ) {
1358- manifest_rev . gitrev =
1359- Some ( std :: str :: from_utf8 ( & git_rev ) ? . to_string ( ) ) ;
1360- }
1355+ let gitrev = if let Ok ( git_rev ) = hubris . extract_file ( "git-rev" ) {
1356+ Some ( std :: str :: from_utf8 ( & git_rev) ? . to_string ( ) )
1357+ } else {
1358+ None
1359+ } ;
13611360
1362- if let Ok ( image_name) = hubris. extract_file ( "image-name" ) {
1363- manifest_rev. image =
1364- Some ( std:: str:: from_utf8 ( & image_name) ?. to_string ( ) ) ;
1365- }
1361+ let image = if let Ok ( image_name) = hubris. extract_file ( "image-name" ) {
1362+ Some ( std:: str:: from_utf8 ( & image_name) ?. to_string ( ) )
1363+ } else {
1364+ None
1365+ } ;
13661366
1367- manifest_rev. version =
1368- Some ( format ! ( "hubris build archive v{}" , archive_version) ) ;
1367+ let manifest_rev = HubrisManifestRev {
1368+ version : format ! ( "hubris build archive v{archive_version}" ) ,
1369+ gitrev,
1370+ image,
1371+ } ;
13691372
13701373 // Load the main manifest config file
13711374 let app = hubris. extract_file ( "app.toml" ) ?;
@@ -1424,7 +1427,7 @@ impl HubrisArchive {
14241427 // forward slash: regardless of platform, paths within a ZIP archive
14251428 // use the forward slash as a separator.
14261429 //
1427- let mut loader = HubrisObjectLoader :: new ( 0 ) ? ;
1430+ let mut loader = HubrisObjectLoader :: new ( 0 ) ;
14281431 loader. load_object (
14291432 "kernel" ,
14301433 HubrisTask :: Kernel ,
@@ -1481,7 +1484,7 @@ impl HubrisArchive {
14811484 . into_par_iter ( )
14821485 . map ( |( id, name, buf) | {
14831486 let id: u32 = id. try_into ( ) . unwrap ( ) ;
1484- let mut loader = HubrisObjectLoader :: new ( id + 1 ) ? ;
1487+ let mut loader = HubrisObjectLoader :: new ( id + 1 ) ;
14851488 loader. load_object ( & name, HubrisTask :: Task ( id) , & buf) ?;
14861489 Ok ( loader)
14871490 } )
@@ -1533,9 +1536,12 @@ impl HubrisArchive {
15331536 loader. structs_byname . insert ( name. clone ( ) , * goff) ;
15341537 }
15351538
1539+ let Some ( imageid) = loader. imageid else {
1540+ bail ! ( "missing image id" ) ;
1541+ } ;
15361542 Ok ( Self {
15371543 hubris_archive : hubris,
1538- imageid : loader . imageid ,
1544+ imageid,
15391545 manifest,
15401546 loaded : loader. loaded ,
15411547 task_dump,
@@ -1609,11 +1615,6 @@ impl HubrisArchive {
16091615 flash. chip
16101616 }
16111617
1612- /// Destroys the `HubrisArchive`, returning the raw archive data
1613- pub fn take_raw_archive ( self ) -> Vec < u8 > {
1614- self . hubris_archive . zip
1615- }
1616-
16171618 /// Helper function to load a dump into a [`RawHubrisArchive`]
16181619 ///
16191620 /// Returns a tuple of `(raw archive, dump task)`; the second field is
@@ -1683,10 +1684,6 @@ impl HubrisArchive {
16831684 Ok ( ( archive, task_dump) )
16841685 }
16851686
1686- pub fn loaded ( & self ) -> bool {
1687- !self . modules . is_empty ( )
1688- }
1689-
16901687 ///
16911688 /// Takes a list of potentially similar types and deduplicates the list.
16921689 ///
@@ -2094,42 +2091,30 @@ impl HubrisArchive {
20942091 return Ok ( ( ) ) ;
20952092 }
20962093
2097- //
20982094 // To validate that what we're running on the target matches what
20992095 // we have in the archive, we are going to check the image ID, an
2100- // identifer created for this purpose. If we don't have an image ID,
2101- // we check the legacy mechanism of the .hubris_app_table; if we
2102- // don't have either of these, we don't have a way of validating the
2103- // archive and we fail.
2104- //
2105- if let Some ( imageid) = & self . imageid {
2106- let addr = imageid. 0 ;
2107- let nbytes = imageid. 1 . len ( ) ;
2108- assert ! ( nbytes > 0 ) ;
2109-
2110- let mut id = vec ! [ 0 ; nbytes] ;
2111- core. read_8 ( addr, & mut id[ 0 ..nbytes] ) . with_context ( || {
2112- format ! (
2113- "failed to read image ID at 0x{:x}; board mismatch?" ,
2114- addr
2115- )
2116- } ) ?;
2096+ // identifer created for this purpose.
2097+ let addr = self . imageid . 0 ;
2098+ let nbytes = self . imageid . 1 . len ( ) ;
2099+ assert ! ( nbytes > 0 ) ;
2100+
2101+ let mut id = vec ! [ 0 ; nbytes] ;
2102+ core. read_8 ( addr, & mut id[ 0 ..nbytes] ) . with_context ( || {
2103+ format ! ( "failed to read image ID at 0x{:x}; board mismatch?" , addr)
2104+ } ) ?;
21172105
2118- let deltas = id
2119- . iter ( )
2120- . zip ( imageid. 1 . iter ( ) )
2121- . filter ( |& ( lhs, rhs) | lhs != rhs)
2122- . count ( ) ;
2106+ let deltas = id
2107+ . iter ( )
2108+ . zip ( self . imageid . 1 . iter ( ) )
2109+ . filter ( |& ( lhs, rhs) | lhs != rhs)
2110+ . count ( ) ;
21232111
2124- if deltas > 0 || id. len ( ) != imageid. 1 . len ( ) {
2125- bail ! (
2112+ if deltas > 0 || id. len ( ) != self . imageid . 1 . len ( ) {
2113+ bail ! (
21262114 "image ID in archive ({:x?}) does not equal \
21272115 ID at 0x{:x} ({:x?})",
2128- imageid. 1 , imageid. 0 , id,
2116+ self . imageid. 1 , self . imageid. 0 , id,
21292117 ) ;
2130- }
2131- } else {
2132- bail ! ( "could not find HUBRIS_IMAGE_ID" ) ;
21332118 }
21342119
21352120 if criteria == HubrisValidate :: ArchiveMatch {
@@ -2333,12 +2318,12 @@ impl HubrisArchive {
23332318 Ok ( ( ) )
23342319 }
23352320
2336- pub fn image_id_addr ( & self ) -> Option < u32 > {
2337- self . imageid . as_ref ( ) . map ( |i| i . 0 )
2321+ pub fn image_id_addr ( & self ) -> u32 {
2322+ self . imageid . 0
23382323 }
23392324
2340- pub fn image_id ( & self ) -> Option < & [ u8 ] > {
2341- self . imageid . as_ref ( ) . map ( |i| i . 1 . as_slice ( ) )
2325+ pub fn image_id ( & self ) -> & [ u8 ] {
2326+ & self . imageid . 1
23422327 }
23432328
23442329 pub fn member_offset (
@@ -2751,12 +2736,12 @@ impl HubrisArchive {
27512736 // always 8-byte aligned; if we have our 17 floating point registers
27522737 // here, we also have an unstored pad.)
27532738 //
2754- let ( nregs_fp, align) =
2755- if self . manifest . target . as_ref ( ) . unwrap ( ) == "thumbv6m-none-eabi" {
2756- ( 0 , 0 )
2757- } else {
2758- ( 17 , 1 )
2759- } ;
2739+ let ( nregs_fp, align) = if self . manifest . target == "thumbv6m-none-eabi"
2740+ {
2741+ ( 0 , 0 )
2742+ } else {
2743+ ( 17 , 1 )
2744+ } ;
27602745
27612746 let nregs_frame: usize = NREGS_CORE + nregs_fp + align;
27622747
@@ -3729,8 +3714,8 @@ struct HubrisObjectLoader {
37293714}
37303715
37313716impl HubrisObjectLoader {
3732- fn new ( object_id : u32 ) -> Result < Self > {
3733- Ok ( Self {
3717+ fn new ( object_id : u32 ) -> Self {
3718+ Self {
37343719 object_id,
37353720 imageid : None ,
37363721 arrays : HashMap :: new ( ) ,
@@ -3759,7 +3744,7 @@ impl HubrisObjectLoader {
37593744 structs_byname : MultiMap :: new ( ) ,
37603745 subprograms : HashMap :: new ( ) ,
37613746 syscall_pushes : HashMap :: new ( ) ,
3762- } )
3747+ }
37633748 }
37643749
37653750 fn merge ( & mut self , loader : HubrisObjectLoader ) -> Result < ( ) > {
0 commit comments