Skip to content

Commit ea32256

Browse files
committed
Add InvalidPreferredSlotId error for use in rot prep_image_update
1 parent 2514035 commit ea32256

File tree

4 files changed

+118
-0
lines changed

4 files changed

+118
-0
lines changed

gateway-messages/src/sp_to_mgs.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,7 @@ pub enum UpdateError {
12831283
ImageMismatch,
12841284
SignatureNotValidated,
12851285
VersionNotSupported,
1286+
InvalidPreferredSlotId,
12861287
}
12871288

12881289
impl fmt::Display for UpdateError {
@@ -1342,6 +1343,12 @@ impl fmt::Display for UpdateError {
13421343
Self::InvalidComponent => {
13431344
write!(f, "invalid component for operation")
13441345
}
1346+
Self::InvalidPreferredSlotId => {
1347+
write!(
1348+
f,
1349+
"updating a bootloader preferred slot is not permitted"
1350+
)
1351+
}
13451352
}
13461353
}
13471354
}

gateway-messages/tests/versioning/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ mod v15;
2424
mod v16;
2525
mod v17;
2626
mod v18;
27+
mod v19;
2728

2829
pub fn assert_serialized<T: Serialize + SerializedSize + std::fmt::Debug>(
2930
expected: &[u8],
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
//! This source file is named after the protocol version being tested,
6+
//! e.g. v01.rs implements tests for protocol version 1.
7+
//! The tested protocol version is represented by "$VERSION" below.
8+
//!
9+
//! The tests in this module check that the serialized form of messages from MGS
10+
//! protocol version $VERSION have not changed.
11+
//!
12+
//! If a test in this module fails, _do not change the test_! This means you
13+
//! have changed, deleted, or reordered an existing message type or enum
14+
//! variant, and you should revert that change. This will remain true until we
15+
//! bump the `version::MIN` to a value higher than $VERSION, at which point these
16+
//! tests can be removed as we will stop supporting $VERSION.
17+
18+
use super::assert_serialized;
19+
use gateway_messages::Fwid;
20+
use gateway_messages::ImageError;
21+
use gateway_messages::MgsRequest;
22+
use gateway_messages::RotBootInfo;
23+
use gateway_messages::RotSlotId;
24+
use gateway_messages::RotStateV3;
25+
use gateway_messages::SpResponse;
26+
use gateway_messages::SpStateV3;
27+
use gateway_messages::UpdateError;
28+
29+
#[test]
30+
fn sp_response() {
31+
let response = SpResponse::SpStateV3(SpStateV3 {
32+
hubris_archive_id: [1, 2, 3, 4, 5, 6, 7, 8],
33+
serial_number: [
34+
9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
35+
26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
36+
],
37+
model: [
38+
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
39+
58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72,
40+
],
41+
revision: 0xf0f1f2f3,
42+
base_mac_address: [73, 74, 75, 76, 77, 78],
43+
power_state: gateway_messages::PowerState::A0,
44+
});
45+
46+
#[rustfmt::skip]
47+
let expected = vec![
48+
44, // SpStateV3
49+
1, 2, 3, 4, 5, 6, 7, 8, // hubris_archive_id
50+
51+
9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
52+
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
53+
39, 40, // serial_number
54+
55+
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
56+
56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
57+
71, 72, // model
58+
59+
0xf3, 0xf2, 0xf1, 0xf0, // revision
60+
73, 74, 75, 76, 77, 78, // base_mac_address
61+
0, // power_state
62+
];
63+
64+
assert_serialized(&expected, &response);
65+
}
66+
67+
#[test]
68+
fn host_request() {
69+
let request = MgsRequest::VersionedRotBootInfo { version: 3 };
70+
71+
#[rustfmt::skip]
72+
let expected = vec![
73+
45, // VersionedRotBootInfo
74+
3, // version
75+
];
76+
77+
assert_serialized(&expected, &request);
78+
}
79+
80+
#[test]
81+
fn error_enums() {
82+
let response: [ImageError; 13] = [
83+
ImageError::Unchecked,
84+
ImageError::FirstPageErased,
85+
ImageError::PartiallyProgrammed,
86+
ImageError::InvalidLength,
87+
ImageError::HeaderNotProgrammed,
88+
ImageError::BootloaderTooSmall,
89+
ImageError::BadMagic,
90+
ImageError::HeaderImageSize,
91+
ImageError::UnalignedLength,
92+
ImageError::UnsupportedType,
93+
ImageError::ResetVectorNotThumb2,
94+
ImageError::ResetVector,
95+
ImageError::Signature,
96+
];
97+
let expected = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
98+
assert_serialized(&expected, &response);
99+
100+
let response: [UpdateError; 4] = [
101+
UpdateError::BlockOutOfOrder,
102+
UpdateError::InvalidComponent,
103+
UpdateError::InvalidSlotIdForOperation,
104+
UpdateError::InvalidPreferredSlotId,
105+
];
106+
let expected = vec![27, 28, 29, 34];
107+
assert_serialized(&expected, &response);
108+
}

gateway-sp-comms/src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ pub enum UpdateError {
116116
InvalidComponent,
117117
#[error("an image was not found")]
118118
ImageNotFound,
119+
#[error("updating a bootloader preferred slot is not permitted")]
120+
InvalidPreferredSlotId,
119121
}
120122

121123
#[derive(Debug, thiserror::Error, SlogInlineError)]

0 commit comments

Comments
 (0)