33// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44
55use crate :: Responsiveness ;
6- use crate :: SIM_ROT_BOARD ;
76use crate :: SimulatedSp ;
87use crate :: config:: GimletConfig ;
98use crate :: config:: SpComponentConfig ;
109use crate :: helpers:: rot_slot_id_from_u16;
1110use crate :: helpers:: rot_slot_id_to_u16;
11+ use crate :: helpers:: rot_state_v2;
1212use crate :: sensors:: Sensors ;
1313use crate :: serial_number_padded;
1414use crate :: server;
1515use crate :: server:: SimSpHandler ;
1616use crate :: server:: UdpServer ;
17+ use crate :: update:: BaseboardKind ;
1718use crate :: update:: SimSpUpdate ;
1819use anyhow:: { Context , Result , anyhow, bail} ;
1920use async_trait:: async_trait;
@@ -63,19 +64,6 @@ use tokio::sync::watch;
6364use tokio:: task:: { self , JoinHandle } ;
6465
6566pub const SIM_GIMLET_BOARD : & str = "SimGimletSp" ;
66- const SP_GITC0 : & [ u8 ] = b"ffffffff" ;
67- const SP_GITC1 : & [ u8 ] = b"fefefefe" ;
68- const SP_BORD : & [ u8 ] = SIM_GIMLET_BOARD . as_bytes ( ) ;
69- const SP_NAME : & [ u8 ] = b"SimGimlet" ;
70- const SP_VERS0 : & [ u8 ] = b"0.0.2" ;
71- const SP_VERS1 : & [ u8 ] = b"0.0.1" ;
72-
73- const ROT_GITC0 : & [ u8 ] = b"eeeeeeee" ;
74- const ROT_GITC1 : & [ u8 ] = b"edededed" ;
75- const ROT_BORD : & [ u8 ] = SIM_ROT_BOARD . as_bytes ( ) ;
76- const ROT_NAME : & [ u8 ] = b"SimGimletRot" ;
77- const ROT_VERS0 : & [ u8 ] = b"0.0.4" ;
78- const ROT_VERS1 : & [ u8 ] = b"0.0.3" ;
7967
8068// Type alias for the remote end of an MGS serial console connection.
8169type AttachedMgsSerialConsole =
@@ -656,7 +644,6 @@ struct Handler {
656644 // this, our caller will pass us a function to call if they should ignore
657645 // whatever result we return and fail to respond at all.
658646 should_fail_to_respond_signal : Option < Box < dyn FnOnce ( ) + Send > > ,
659- no_stage0_caboose : bool ,
660647 old_rot_state : bool ,
661648 sp_dumps : HashMap < [ u8 ; 16 ] , u32 > ,
662649}
@@ -699,12 +686,14 @@ impl Handler {
699686 rot_active_slot : RotSlotId :: A ,
700687 power_state : PowerState :: A2 ,
701688 startup_options : StartupOptions :: empty ( ) ,
702- update_state : SimSpUpdate :: default ( ) ,
689+ update_state : SimSpUpdate :: new (
690+ BaseboardKind :: Gimlet ,
691+ no_stage0_caboose,
692+ ) ,
703693 reset_pending : None ,
704694 last_request_handled : None ,
705695 should_fail_to_respond_signal : None ,
706696 old_rot_state,
707- no_stage0_caboose,
708697 sp_dumps,
709698 }
710699 }
@@ -723,14 +712,7 @@ impl Handler {
723712 revision : 0 ,
724713 base_mac_address : [ 0 ; 6 ] ,
725714 power_state : self . power_state ,
726- rot : Ok ( gateway_messages:: RotStateV2 {
727- active : RotSlotId :: A ,
728- persistent_boot_preference : RotSlotId :: A ,
729- pending_persistent_boot_preference : None ,
730- transient_boot_preference : None ,
731- slot_a_sha3_256_digest : Some ( [ 0x55 ; 32 ] ) ,
732- slot_b_sha3_256_digest : Some ( [ 0x66 ; 32 ] ) ,
733- } ) ,
715+ rot : Ok ( rot_state_v2 ( self . update_state . rot_state ( ) ) ) ,
734716 }
735717 }
736718}
@@ -1338,44 +1320,8 @@ impl SpHandler for Handler {
13381320 slot : u16 ,
13391321 key : [ u8 ; 4 ] ,
13401322 buf : & mut [ u8 ] ,
1341- ) -> std:: result:: Result < usize , SpError > {
1342- use crate :: SIM_ROT_STAGE0_BOARD ;
1343-
1344- const STAGE0_GITC0 : & [ u8 ] = b"ddddddddd" ;
1345- const STAGE0_GITC1 : & [ u8 ] = b"dadadadad" ;
1346- const STAGE0_BORD : & [ u8 ] = SIM_ROT_STAGE0_BOARD . as_bytes ( ) ;
1347- const STAGE0_NAME : & [ u8 ] = b"SimGimletRot" ;
1348- const STAGE0_VERS0 : & [ u8 ] = b"0.0.200" ;
1349- const STAGE0_VERS1 : & [ u8 ] = b"0.0.200" ;
1350-
1351- let val = match ( component, & key, slot, self . no_stage0_caboose ) {
1352- ( SpComponent :: SP_ITSELF , b"GITC" , 0 , _) => SP_GITC0 ,
1353- ( SpComponent :: SP_ITSELF , b"GITC" , 1 , _) => SP_GITC1 ,
1354- ( SpComponent :: SP_ITSELF , b"BORD" , _, _) => SP_BORD ,
1355- ( SpComponent :: SP_ITSELF , b"NAME" , _, _) => SP_NAME ,
1356- ( SpComponent :: SP_ITSELF , b"VERS" , 0 , _) => SP_VERS0 ,
1357- ( SpComponent :: SP_ITSELF , b"VERS" , 1 , _) => SP_VERS1 ,
1358- ( SpComponent :: ROT , b"GITC" , 0 , _) => ROT_GITC0 ,
1359- ( SpComponent :: ROT , b"GITC" , 1 , _) => ROT_GITC1 ,
1360- ( SpComponent :: ROT , b"BORD" , _, _) => ROT_BORD ,
1361- ( SpComponent :: ROT , b"NAME" , _, _) => ROT_NAME ,
1362- ( SpComponent :: ROT , b"VERS" , 0 , _) => ROT_VERS0 ,
1363- ( SpComponent :: ROT , b"VERS" , 1 , _) => ROT_VERS1 ,
1364- // gimlet staging/devel hash
1365- ( SpComponent :: ROT , b"SIGN" , _, _) => & "11594bb5548a757e918e6fe056e2ad9e084297c9555417a025d8788eacf55daf" . as_bytes ( ) ,
1366- ( SpComponent :: STAGE0 , b"GITC" , 0 , false ) => STAGE0_GITC0 ,
1367- ( SpComponent :: STAGE0 , b"GITC" , 1 , false ) => STAGE0_GITC1 ,
1368- ( SpComponent :: STAGE0 , b"BORD" , _, false ) => STAGE0_BORD ,
1369- ( SpComponent :: STAGE0 , b"NAME" , _, false ) => STAGE0_NAME ,
1370- ( SpComponent :: STAGE0 , b"VERS" , 0 , false ) => STAGE0_VERS0 ,
1371- ( SpComponent :: STAGE0 , b"VERS" , 1 , false ) => STAGE0_VERS1 ,
1372- // gimlet staging/devel hash
1373- ( SpComponent :: STAGE0 , b"SIGN" , _, false ) => & "11594bb5548a757e918e6fe056e2ad9e084297c9555417a025d8788eacf55daf" . as_bytes ( ) ,
1374- _ => return Err ( SpError :: NoSuchCabooseKey ( key) ) ,
1375- } ;
1376-
1377- buf[ ..val. len ( ) ] . copy_from_slice ( val) ;
1378- Ok ( val. len ( ) )
1323+ ) -> Result < usize , SpError > {
1324+ self . update_state . get_component_caboose_value ( component, slot, key, buf)
13791325 }
13801326
13811327 fn read_sensor (
@@ -1468,45 +1414,14 @@ impl SpHandler for Handler {
14681414 if self . old_rot_state {
14691415 Err ( SpError :: RequestUnsupportedForSp )
14701416 } else {
1471- const SLOT_A_DIGEST : [ u8 ; 32 ] = [ 0xaa ; 32 ] ;
1472- const SLOT_B_DIGEST : [ u8 ; 32 ] = [ 0xbb ; 32 ] ;
1473- const STAGE0_DIGEST : [ u8 ; 32 ] = [ 0xcc ; 32 ] ;
1474- const STAGE0NEXT_DIGEST : [ u8 ; 32 ] = [ 0xdd ; 32 ] ;
1475-
14761417 match version {
14771418 0 => Err ( SpError :: Update (
14781419 gateway_messages:: UpdateError :: VersionNotSupported ,
14791420 ) ) ,
1480- 1 => Ok ( RotBootInfo :: V2 ( gateway_messages:: RotStateV2 {
1481- active : RotSlotId :: A ,
1482- persistent_boot_preference : RotSlotId :: A ,
1483- pending_persistent_boot_preference : None ,
1484- transient_boot_preference : None ,
1485- slot_a_sha3_256_digest : Some ( SLOT_A_DIGEST ) ,
1486- slot_b_sha3_256_digest : Some ( SLOT_B_DIGEST ) ,
1487- } ) ) ,
1488- _ => Ok ( RotBootInfo :: V3 ( gateway_messages:: RotStateV3 {
1489- active : RotSlotId :: A ,
1490- persistent_boot_preference : RotSlotId :: A ,
1491- pending_persistent_boot_preference : None ,
1492- transient_boot_preference : None ,
1493- slot_a_fwid : gateway_messages:: Fwid :: Sha3_256 (
1494- SLOT_A_DIGEST ,
1495- ) ,
1496- slot_b_fwid : gateway_messages:: Fwid :: Sha3_256 (
1497- SLOT_B_DIGEST ,
1498- ) ,
1499- stage0_fwid : gateway_messages:: Fwid :: Sha3_256 (
1500- STAGE0_DIGEST ,
1501- ) ,
1502- stage0next_fwid : gateway_messages:: Fwid :: Sha3_256 (
1503- STAGE0NEXT_DIGEST ,
1504- ) ,
1505- slot_a_status : Ok ( ( ) ) ,
1506- slot_b_status : Ok ( ( ) ) ,
1507- stage0_status : Ok ( ( ) ) ,
1508- stage0next_status : Ok ( ( ) ) ,
1509- } ) ) ,
1421+ 1 => Ok ( RotBootInfo :: V2 ( rot_state_v2 (
1422+ self . update_state . rot_state ( ) ,
1423+ ) ) ) ,
1424+ _ => Ok ( RotBootInfo :: V3 ( self . update_state . rot_state ( ) ) ) ,
15101425 }
15111426 }
15121427 }
0 commit comments