Skip to content
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

Update stage0 #209

Merged
merged 1 commit into from
Apr 29, 2024
Merged
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion faux-mgs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "faux-mgs"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
license = "MPL-2.0"

Expand Down
72 changes: 67 additions & 5 deletions faux-mgs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use gateway_messages::ComponentAction;
use gateway_messages::IgnitionCommand;
use gateway_messages::LedComponentAction;
use gateway_messages::PowerState;
use gateway_messages::RotBootInfo;
use gateway_messages::SpComponent;
use gateway_messages::StartupOptions;
use gateway_messages::UpdateId;
Expand Down Expand Up @@ -178,6 +179,16 @@ enum Command {
},

/// Get or set the active slot of a component (e.g., `host-boot-flash`).
///
/// Except for component "stage0", setting the active slot can be
/// viewed as an atomic operation.
///
/// Setting "stage0" slot 1 as the active slot initiates a copy from
/// slot 1 to slot 0 if the contents of slot 1 still match those seen
/// at last RoT reset and the contents are properly signed.
///
/// Power failures during the copy can disable the RoT. Only one stage0
/// update should be in process in a rack at any time.
ComponentActiveSlot {
#[clap(value_parser = parse_sp_component)]
component: SpComponent,
Expand Down Expand Up @@ -373,6 +384,14 @@ enum Command {

/// Reads the lock status of any VPD in the system
VpdLockStatus,

/// Read the RoT's boot-time information.
RotBootInfo {
/// Return highest version of RotBootInfo less then or equal to our
/// highest known version.
#[clap(long, short, default_value_t = RotBootInfo::HIGHEST_KNOWN_VERSION)]
version: u8,
},
}

#[derive(Subcommand, Debug, Clone)]
Expand Down Expand Up @@ -827,9 +846,12 @@ async fn run_command(
));
lines.push(format!("hubris version: {:?}", state.version));
lines.push(format!("power state: {:?}", state.power_state));

// TODO: pretty print RoT state?
lines.push(format!("RoT state: {:?}", state.rot));
match state.rot {
Ok(rot) => {
lines.push(format!("rot: Ok({})", rot.display()))
}
Err(err) => lines.push(format!("rot: Err({})", err)),
}
Ok(Output::Lines(lines))
}
VersionedSpState::V2(state) => {
Expand Down Expand Up @@ -857,10 +879,50 @@ async fn run_command(
.join(":")
));
lines.push(format!("power state: {:?}", state.power_state));
// TODO: pretty print RoT state?
lines.push(format!("RoT state: {:?}", state.rot));
match state.rot {
Ok(rot) => lines.push(format!("rot: Ok({})", rot)),
Err(err) => lines.push(format!("rot: Err({})", err)),
}
Ok(Output::Lines(lines))
}
VersionedSpState::V3(state) => {
lines.push(format!(
"hubris archive: {}",
hex::encode(state.hubris_archive_id)
));

lines.push(format!(
"serial number: {}",
zero_padded_to_str(state.serial_number)
));
lines.push(format!(
"model: {}",
zero_padded_to_str(state.model)
));
lines.push(format!("revision: {}", state.revision));
lines.push(format!(
"base MAC address: {}",
state
.base_mac_address
.iter()
.map(|b| format!("{b:02x}"))
.collect::<Vec<_>>()
.join(":")
));
lines.push(format!("power state: {:?}", state.power_state));
Ok(Output::Lines(lines))
}
}
}
Command::RotBootInfo { version } => {
let rot_state = sp.rot_state(version).await?;
info!(log, "{rot_state:x?}");
if json {
Ok(Output::Json(serde_json::to_value(rot_state).unwrap()))
} else {
let mut lines = Vec::new();
lines.push(format!("{}", rot_state.display()));
Ok(Output::Lines(lines))
}
}
Command::Ignition { target } => {
Expand Down
4 changes: 2 additions & 2 deletions gateway-messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub const ROT_PAGE_SIZE: usize = 512;
/// for more detail and discussion.
pub mod version {
pub const MIN: u32 = 2;
pub const CURRENT: u32 = 12;
pub const CURRENT: u32 = 13;

/// MGS protocol version in which SP watchdog messages were added
pub const WATCHDOG_VERSION: u32 = 12;
Expand Down Expand Up @@ -129,7 +129,7 @@ pub enum BadRequestReason {
DeserializationError,
}

/// Image slot name for SwitchDefaultImage
/// Image slot name for SwitchDefaultImage on component ROT
#[derive(
Debug, Clone, Copy, PartialEq, Eq, SerializedSize, Serialize, Deserialize,
)]
Expand Down
5 changes: 5 additions & 0 deletions gateway-messages/src/mgs_to_sp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ pub enum MgsRequest {
ComponentWatchdogSupported {
component: SpComponent,
},

/// Read RoT boot state at the highest version not to exceed specified version.
jgallagher marked this conversation as resolved.
Show resolved Hide resolved
VersionedRotBootInfo {
version: u8,
},
}

#[derive(
Expand Down
21 changes: 21 additions & 0 deletions gateway-messages/src/sp_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::MgsError;
use crate::MgsRequest;
use crate::MgsResponse;
use crate::PowerState;
use crate::RotBootInfo;
use crate::RotRequest;
use crate::RotResponse;
use crate::RotSlotId;
Expand Down Expand Up @@ -412,6 +413,13 @@ pub trait SpHandler {
&mut self,
component: SpComponent,
) -> Result<(), SpError>;

fn versioned_rot_boot_info(
&mut self,
sender: SocketAddrV6,
port: SpPort,
version: u8,
) -> Result<RotBootInfo, SpError>;
}

/// Handle a single incoming message.
Expand Down Expand Up @@ -991,6 +999,10 @@ fn handle_mgs_request<H: SpHandler>(
MgsRequest::ComponentWatchdogSupported { component } => handler
.component_watchdog_supported(component)
.map(|()| SpResponse::ComponentWatchdogSupportedAck),
MgsRequest::VersionedRotBootInfo { version } => {
let r = handler.versioned_rot_boot_info(sender, port, version);
r.map(SpResponse::RotBootInfo)
}
};

let response = match result {
Expand Down Expand Up @@ -1416,6 +1428,15 @@ mod tests {
) -> Result<(), SpError> {
unimplemented!()
}

fn versioned_rot_boot_info(
&mut self,
_sender: SocketAddrV6,
_port: SpPort,
_version: u8,
) -> Result<RotBootInfo, SpError> {
unimplemented!()
}
}

#[cfg(feature = "std")]
Expand Down
Loading
Loading