Skip to content

[reconfigurator-cli] RoT bootloader support #8620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions dev-tools/reconfigurator-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ fn process_command(
cmd_sled_update_install_dataset(sim, args)
}
Commands::SledUpdateSp(args) => cmd_sled_update_sp(sim, args),
Commands::SledUpdateRotBootloader(args) => {
cmd_sled_update_rot_bootlaoder(sim, args)
}
Commands::SiloList => cmd_silo_list(sim),
Commands::SiloAdd(args) => cmd_silo_add(sim, args),
Commands::SiloRemove(args) => cmd_silo_remove(sim, args),
Expand Down Expand Up @@ -284,6 +287,8 @@ enum Commands {
SledSet(SledSetArgs),
/// update the install dataset on a sled, simulating a mupdate
SledUpdateInstallDataset(SledUpdateInstallDatasetArgs),
/// simulate updating the sled's RoT Bootloader versions
SledUpdateRotBootloader(SledUpdateRotBootloaderArgs),
/// simulate updating the sled's SP versions
SledUpdateSp(SledUpdateSpArgs),

Expand Down Expand Up @@ -484,6 +489,21 @@ struct SledMupdateValidSource {
to_target_release: bool,
}

#[derive(Debug, Args)]
struct SledUpdateRotBootloaderArgs {
/// id of the sled
sled_id: SledOpt,

/// sets the version reported for the RoT bootloader stage0 (active) slot
#[clap(long, required_unless_present_any = &["stage0_next"])]
stage0: Option<ArtifactVersion>,

/// sets the version reported for the RoT bootloader stage0_next (inactive)
/// slot
#[clap(long, required_unless_present_any = &["stage0"])]
stage0_next: Option<ExpectedVersion>,
}

#[derive(Debug, Args)]
struct SledUpdateSpArgs {
/// id of the sled
Expand Down Expand Up @@ -1278,6 +1298,8 @@ fn cmd_sled_show(
let state = sim.current_state();
let description = state.system().description();
let sled_id = args.sled_id.to_sled_id(description)?;
let stage0_version = description.sled_stage0_version(sled_id)?;
let stage0_next_version = description.sled_stage0_next_version(sled_id)?;
let sp_active_version = description.sled_sp_active_version(sled_id)?;
let sp_inactive_version = description.sled_sp_inactive_version(sled_id)?;
let planning_input = description
Expand All @@ -1290,6 +1312,12 @@ fn cmd_sled_show(
swriteln!(s, "sled {} ({}, {})", sled_id, sled.policy, sled.state);
swriteln!(s, "serial {}", sled.baseboard_id.serial_number);
swriteln!(s, "subnet {}", sled_resources.subnet.net());
swriteln!(s, "RoT bootloader stage 0 version: {:?}", stage0_version);
swriteln!(
s,
"RoT bootloader stage 0 next version: {:?}",
stage0_next_version
);
swriteln!(s, "SP active version: {:?}", sp_active_version);
swriteln!(s, "SP inactive version: {:?}", sp_inactive_version);
swriteln!(s, "zpools ({}):", sled_resources.zpools.len());
Expand Down Expand Up @@ -1373,6 +1401,48 @@ fn cmd_sled_update_install_dataset(
)))
}

fn cmd_sled_update_rot_bootlaoder(
sim: &mut ReconfiguratorSim,
args: SledUpdateRotBootloaderArgs,
) -> anyhow::Result<Option<String>> {
let mut labels = Vec::new();
if let Some(stage0) = &args.stage0 {
labels.push(format!("stage0 -> {}", stage0));
}
if let Some(stage0_next) = &args.stage0_next {
labels.push(format!("stage0_next -> {}", stage0_next));
}

assert!(
!labels.is_empty(),
"clap configuration requires that at least one argument is specified"
);

let mut state = sim.current_state().to_mut();
let system = state.system_mut();
let sled_id = args.sled_id.to_sled_id(system.description())?;
system.description_mut().sled_update_rot_bootloader_versions(
sled_id,
args.stage0,
args.stage0_next,
)?;

sim.commit_and_bump(
format!(
"reconfigurator-cli sled-update-rot-bootloader: {}: {}",
sled_id,
labels.join(", "),
),
state,
);

Ok(Some(format!(
"set sled {} RoT bootloader versions: {}",
sled_id,
labels.join(", ")
)))
}

fn cmd_sled_update_sp(
sim: &mut ReconfiguratorSim,
args: SledUpdateSpArgs,
Expand Down
12 changes: 12 additions & 0 deletions dev-tools/reconfigurator-cli/tests/input/cmds.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ sled-show dde1c0e2-b10d-4621-b420-f179f7a7a00a
sled-update-sp dde1c0e2-b10d-4621-b420-f179f7a7a00a --active 4.0.0 --inactive 5.0.0
sled-show dde1c0e2-b10d-4621-b420-f179f7a7a00a

sled-update-rot-bootloader dde1c0e2-b10d-4621-b420-f179f7a7a00a
sled-update-rot-bootloader dde1c0e2-b10d-4621-b420-f179f7a7a00a --stage0 1.0.0
sled-show dde1c0e2-b10d-4621-b420-f179f7a7a00a
sled-update-rot-bootloader dde1c0e2-b10d-4621-b420-f179f7a7a00a --stage0-next 2.0.0
sled-show dde1c0e2-b10d-4621-b420-f179f7a7a00a
sled-update-rot-bootloader dde1c0e2-b10d-4621-b420-f179f7a7a00a --stage0 3.0.0
sled-show dde1c0e2-b10d-4621-b420-f179f7a7a00a
sled-update-rot-bootloader dde1c0e2-b10d-4621-b420-f179f7a7a00a --stage0 4.0.0 --stage0-next invalid
sled-show dde1c0e2-b10d-4621-b420-f179f7a7a00a
sled-update-rot-bootloader dde1c0e2-b10d-4621-b420-f179f7a7a00a --stage0 4.0.0 --stage0-next 5.0.0
sled-show dde1c0e2-b10d-4621-b420-f179f7a7a00a

inventory-generate
inventory-list

Expand Down
4 changes: 4 additions & 0 deletions dev-tools/reconfigurator-cli/tests/output/cmds-example-stdout
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ T ENA ID PARENT
sled 2eb69596-f081-4e2d-9425-9994926e0832 (in service, active)
serial serial1
subnet fd00:1122:3344:102::/64
RoT bootloader stage 0 version: Some("0.0.1")
RoT bootloader stage 0 next version: None
SP active version: Some("0.0.1")
SP inactive version: None
zpools (10):
Expand Down Expand Up @@ -425,6 +427,8 @@ T ENA ID PARENT
sled 89d02b1b-478c-401a-8e28-7a26f74fa41b (in service, active)
serial serial0
subnet fd00:1122:3344:101::/64
RoT bootloader stage 0 version: Some("0.0.1")
RoT bootloader stage 0 next version: None
SP active version: Some("0.0.1")
SP inactive version: None
zpools (4):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ INFO created directory to store extracted artifacts, path: <CREATED_DIRECTORY_TO
INFO added artifact, name: SimGimletSp, kind: gimlet_sp, version: 1.0.0, hash: 7e6667e646ad001b54c8365a3d309c03f89c59102723d38d01697ee8079fe670, length: 747
INFO added artifact, name: fake-gimlet-rot, kind: gimlet_rot_image_a, version: 1.0.0, hash: 04e4a7fdb84acca92c8fd3235e26d64ea61bef8a5f98202589fd346989c5720a, length: 735
INFO added artifact, name: fake-gimlet-rot, kind: gimlet_rot_image_b, version: 1.0.0, hash: 04e4a7fdb84acca92c8fd3235e26d64ea61bef8a5f98202589fd346989c5720a, length: 735
INFO added artifact, name: fake-gimlet-rot-bootloader, kind: gimlet_rot_bootloader, version: 1.0.0, hash: 005ea358f1cd316df42465b1e3a0334ea22cc0c0442cf9ddf9b42fbf49780236, length: 750
INFO added artifact, name: SimRotStage0, kind: gimlet_rot_bootloader, version: 1.0.0, hash: 005ea358f1cd316df42465b1e3a0334ea22cc0c0442cf9ddf9b42fbf49780236, length: 750
INFO added artifact, name: fake-host, kind: host_phase_1, version: 1.0.0, hash: 2053f8594971bbf0a7326c833e2ffc12b065b9d823b9c0b967d275fa595e4e89, length: 524288
INFO added artifact, name: fake-host, kind: host_phase_2, version: 1.0.0, hash: f3dd0c7a1bd4500ea0d8bcf67581f576d47752b2f1998a4cb0f0c3155c483008, length: 1048576
INFO added artifact, name: fake-trampoline, kind: trampoline_phase_1, version: 1.0.0, hash: 9b7575cad720f017e936fe5994fc4e21fe040acaaf83c2edd86132aa3d667c7b, length: 524288
Expand Down
7 changes: 7 additions & 0 deletions dev-tools/reconfigurator-cli/tests/output/cmds-stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ error: the following required arguments were not provided:
Usage: sled-update-sp --active <ACTIVE> --inactive <INACTIVE> <SLED_ID>

For more information, try '--help'.
error: the following required arguments were not provided:
--stage0 <STAGE0>
--stage0-next <STAGE0_NEXT>

Usage: sled-update-rot-bootloader --stage0 <STAGE0> --stage0-next <STAGE0_NEXT> <SLED_ID>

For more information, try '--help'.
Loading
Loading