Skip to content
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
7 changes: 7 additions & 0 deletions gateway-messages/src/sp_to_mgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,7 @@ pub enum UpdateError {
ImageMismatch,
SignatureNotValidated,
VersionNotSupported,
InvalidPreferredSlotId,
}

impl fmt::Display for UpdateError {
Expand Down Expand Up @@ -1353,6 +1354,12 @@ impl fmt::Display for UpdateError {
Self::InvalidComponent => {
write!(f, "invalid component for operation")
}
Self::InvalidPreferredSlotId => {
write!(
f,
"updating a bootloader preferred slot is not permitted"
)
}
}
}
}
Expand Down
84 changes: 84 additions & 0 deletions gateway-messages/tests/versioning/v19.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
//! tests can be removed as we will stop supporting $VERSION.

use super::assert_serialized;
use gateway_messages::ImageError;
use gateway_messages::SpStateV3;
use gateway_messages::UpdateError;
use gateway_messages::{HfError, MgsRequest, SpError, SpResponse};

#[test]
Expand Down Expand Up @@ -60,3 +63,84 @@ fn read_host_flash() {
assert_serialized(&[38, i as u8], &request);
}
}

#[test]
fn sp_response() {
let response = SpResponse::SpStateV3(SpStateV3 {
hubris_archive_id: [1, 2, 3, 4, 5, 6, 7, 8],
serial_number: [
9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
],
model: [
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72,
],
revision: 0xf0f1f2f3,
base_mac_address: [73, 74, 75, 76, 77, 78],
power_state: gateway_messages::PowerState::A0,
});

#[rustfmt::skip]
let expected = vec![
44, // SpStateV3
1, 2, 3, 4, 5, 6, 7, 8, // hubris_archive_id

9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
39, 40, // serial_number

41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
71, 72, // model

0xf3, 0xf2, 0xf1, 0xf0, // revision
73, 74, 75, 76, 77, 78, // base_mac_address
0, // power_state
];

assert_serialized(&expected, &response);
}

#[test]
fn host_request() {
let request = MgsRequest::VersionedRotBootInfo { version: 3 };

#[rustfmt::skip]
let expected = vec![
45, // VersionedRotBootInfo
3, // version
];

assert_serialized(&expected, &request);
}

#[test]
fn error_enums() {
let response: [ImageError; 13] = [
ImageError::Unchecked,
ImageError::FirstPageErased,
ImageError::PartiallyProgrammed,
ImageError::InvalidLength,
ImageError::HeaderNotProgrammed,
ImageError::BootloaderTooSmall,
ImageError::BadMagic,
ImageError::HeaderImageSize,
ImageError::UnalignedLength,
ImageError::UnsupportedType,
ImageError::ResetVectorNotThumb2,
ImageError::ResetVector,
ImageError::Signature,
];
let expected = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
assert_serialized(&expected, &response);

let response: [UpdateError; 4] = [
UpdateError::BlockOutOfOrder,
UpdateError::InvalidComponent,
UpdateError::InvalidSlotIdForOperation,
UpdateError::InvalidPreferredSlotId,
];
let expected = vec![27, 28, 29, 34];
assert_serialized(&expected, &response);
}
2 changes: 2 additions & 0 deletions gateway-sp-comms/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ pub enum UpdateError {
InvalidComponent,
#[error("an image was not found")]
ImageNotFound,
#[error("updating a bootloader preferred slot is not permitted")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should add this variant right now.

This UpdateError (unlike the one in gateway-messages) is used internally in gateway-sp-comms, so (1) we don't need an InvalidPreferredSlotId variant here in order to make progress on SP work, and (2) it's not obvious when gateway-sp-comms will produce this error.

Copy link
Contributor Author

@lzrd lzrd Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This supports a new semantic where attempts to update a RoT Hubris image that is a preferred boot image will fail with this error. See Hubris PR #2050

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that, and the variant in gateway_messages::sp_to_mgs::UpdateError is necessary for hubris#2050. I'm saying that adding a variant to gateway_sp_comms::Error doesn't need to happen in this PR, because we don't have clear semantics for how it would be used.

InvalidPreferredSlotId,
}

#[derive(Debug, thiserror::Error, SlogInlineError)]
Expand Down
Loading