Skip to content

Commit bbac857

Browse files
authored
sim-sp: move version and caboose-related info to update module (#8055)
1 parent 4a0e9c1 commit bbac857

File tree

9 files changed

+297
-212
lines changed

9 files changed

+297
-212
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nexus/inventory/tests/output/collector_basic.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ cabooses:
1010
board "SimGimletSp" name "SimGimlet" version "0.0.1" git_commit "fefefefe"
1111
board "SimGimletSp" name "SimGimlet" version "0.0.2" git_commit "ffffffff"
1212
board "SimRot" name "SimGimletRot" version "0.0.3" git_commit "edededed"
13-
board "SimRot" name "SimSidecar" version "0.0.3" git_commit "edededed"
13+
board "SimRot" name "SimSidecarRot" version "0.0.3" git_commit "edededed"
1414
board "SimRot" name "SimGimletRot" version "0.0.4" git_commit "eeeeeeee"
15-
board "SimRot" name "SimSidecar" version "0.0.4" git_commit "eeeeeeee"
16-
board "SimRotStage0" name "SimSidecar" version "0.0.200" git_commit "dadadada"
15+
board "SimRot" name "SimSidecarRot" version "0.0.4" git_commit "eeeeeeee"
1716
board "SimRotStage0" name "SimGimletRot" version "0.0.200" git_commit "dadadadad"
18-
board "SimRotStage0" name "SimSidecar" version "0.0.200" git_commit "dddddddd"
17+
board "SimRotStage0" name "SimSidecarRot" version "0.0.200" git_commit "dadadadad"
1918
board "SimRotStage0" name "SimGimletRot" version "0.0.200" git_commit "ddddddddd"
19+
board "SimRotStage0" name "SimSidecarRot" version "0.0.200" git_commit "ddddddddd"
2020
board "SimSidecarSp" name "SimSidecar" version "0.0.1" git_commit "fefefefe"
2121
board "SimSidecarSp" name "SimSidecar" version "0.0.2" git_commit "ffffffff"
2222

nexus/inventory/tests/output/collector_errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ cabooses:
88
board "SimGimletSp" name "SimGimlet" version "0.0.1" git_commit "fefefefe"
99
board "SimGimletSp" name "SimGimlet" version "0.0.2" git_commit "ffffffff"
1010
board "SimRot" name "SimGimletRot" version "0.0.3" git_commit "edededed"
11-
board "SimRot" name "SimSidecar" version "0.0.3" git_commit "edededed"
11+
board "SimRot" name "SimSidecarRot" version "0.0.3" git_commit "edededed"
1212
board "SimRot" name "SimGimletRot" version "0.0.4" git_commit "eeeeeeee"
13-
board "SimRot" name "SimSidecar" version "0.0.4" git_commit "eeeeeeee"
14-
board "SimRotStage0" name "SimSidecar" version "0.0.200" git_commit "dadadada"
13+
board "SimRot" name "SimSidecarRot" version "0.0.4" git_commit "eeeeeeee"
1514
board "SimRotStage0" name "SimGimletRot" version "0.0.200" git_commit "dadadadad"
16-
board "SimRotStage0" name "SimSidecar" version "0.0.200" git_commit "dddddddd"
15+
board "SimRotStage0" name "SimSidecarRot" version "0.0.200" git_commit "dadadadad"
1716
board "SimRotStage0" name "SimGimletRot" version "0.0.200" git_commit "ddddddddd"
17+
board "SimRotStage0" name "SimSidecarRot" version "0.0.200" git_commit "ddddddddd"
1818
board "SimSidecarSp" name "SimSidecar" version "0.0.1" git_commit "fefefefe"
1919
board "SimSidecarSp" name "SimSidecar" version "0.0.2" git_commit "ffffffff"
2020

nexus/inventory/tests/output/collector_sled_agent_errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ cabooses:
99
board "SimGimletSp" name "SimGimlet" version "0.0.1" git_commit "fefefefe"
1010
board "SimGimletSp" name "SimGimlet" version "0.0.2" git_commit "ffffffff"
1111
board "SimRot" name "SimGimletRot" version "0.0.3" git_commit "edededed"
12-
board "SimRot" name "SimSidecar" version "0.0.3" git_commit "edededed"
12+
board "SimRot" name "SimSidecarRot" version "0.0.3" git_commit "edededed"
1313
board "SimRot" name "SimGimletRot" version "0.0.4" git_commit "eeeeeeee"
14-
board "SimRot" name "SimSidecar" version "0.0.4" git_commit "eeeeeeee"
15-
board "SimRotStage0" name "SimSidecar" version "0.0.200" git_commit "dadadada"
14+
board "SimRot" name "SimSidecarRot" version "0.0.4" git_commit "eeeeeeee"
1615
board "SimRotStage0" name "SimGimletRot" version "0.0.200" git_commit "dadadadad"
17-
board "SimRotStage0" name "SimSidecar" version "0.0.200" git_commit "dddddddd"
16+
board "SimRotStage0" name "SimSidecarRot" version "0.0.200" git_commit "dadadadad"
1817
board "SimRotStage0" name "SimGimletRot" version "0.0.200" git_commit "ddddddddd"
18+
board "SimRotStage0" name "SimSidecarRot" version "0.0.200" git_commit "ddddddddd"
1919
board "SimSidecarSp" name "SimSidecar" version "0.0.1" git_commit "fefefefe"
2020
board "SimSidecarSp" name "SimSidecar" version "0.0.2" git_commit "ffffffff"
2121

sp-sim/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ futures.workspace = true
1616
gateway-messages.workspace = true
1717
gateway-types.workspace = true
1818
hex = { workspace = true, features = [ "serde" ] }
19+
hubtools.workspace = true
1920
omicron-common.workspace = true
2021
serde.workspace = true
2122
slog.workspace = true

sp-sim/src/gimlet.rs

Lines changed: 13 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

55
use crate::Responsiveness;
6-
use crate::SIM_ROT_BOARD;
76
use crate::SimulatedSp;
87
use crate::config::GimletConfig;
98
use crate::config::SpComponentConfig;
109
use crate::helpers::rot_slot_id_from_u16;
1110
use crate::helpers::rot_slot_id_to_u16;
11+
use crate::helpers::rot_state_v2;
1212
use crate::sensors::Sensors;
1313
use crate::serial_number_padded;
1414
use crate::server;
1515
use crate::server::SimSpHandler;
1616
use crate::server::UdpServer;
17+
use crate::update::BaseboardKind;
1718
use crate::update::SimSpUpdate;
1819
use anyhow::{Context, Result, anyhow, bail};
1920
use async_trait::async_trait;
@@ -63,19 +64,6 @@ use tokio::sync::watch;
6364
use tokio::task::{self, JoinHandle};
6465

6566
pub 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.
8169
type 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
}

sp-sim/src/helpers.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

5-
use gateway_messages::{RotSlotId, SpError};
5+
use gateway_messages::{Fwid, RotSlotId, RotStateV2, RotStateV3, SpError};
66

77
pub(crate) fn rot_slot_id_to_u16(slot_id: RotSlotId) -> u16 {
88
match slot_id {
@@ -18,3 +18,17 @@ pub(crate) fn rot_slot_id_from_u16(slot_id: u16) -> Result<RotSlotId, SpError> {
1818
_ => Err(SpError::InvalidSlotForComponent),
1919
}
2020
}
21+
22+
pub(crate) fn rot_state_v2(v3: RotStateV3) -> RotStateV2 {
23+
let Fwid::Sha3_256(slot_a_sha3_256_digest) = v3.slot_a_fwid;
24+
let Fwid::Sha3_256(slot_b_sha3_256_digest) = v3.slot_b_fwid;
25+
RotStateV2 {
26+
active: v3.active,
27+
persistent_boot_preference: v3.persistent_boot_preference,
28+
pending_persistent_boot_preference: v3
29+
.pending_persistent_boot_preference,
30+
transient_boot_preference: v3.transient_boot_preference,
31+
slot_a_sha3_256_digest: Some(slot_a_sha3_256_digest),
32+
slot_b_sha3_256_digest: Some(slot_b_sha3_256_digest),
33+
}
34+
}

0 commit comments

Comments
 (0)