Skip to content

Commit ef7ce28

Browse files
committed
add errors for redundant and missing image preference settings
1 parent 1dacd04 commit ef7ce28

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

gateway-messages/src/sp_to_mgs.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,8 @@ pub enum UpdateError {
12981298
SignatureNotValidated,
12991299
VersionNotSupported,
13001300
InvalidPreferredSlotId,
1301+
AlreadyPending,
1302+
NonePending,
13011303
}
13021304

13031305
impl fmt::Display for UpdateError {
@@ -1358,10 +1360,13 @@ impl fmt::Display for UpdateError {
13581360
write!(f, "invalid component for operation")
13591361
}
13601362
Self::InvalidPreferredSlotId => {
1361-
write!(
1362-
f,
1363-
"updating a bootloader preferred slot is not permitted"
1364-
)
1363+
write!(f, "specified slot ID is not valid for this operation")
1364+
}
1365+
Self::AlreadyPending => {
1366+
write!(f, "pending preference must be canceled first")
1367+
}
1368+
Self::NonePending => {
1369+
write!(f, "no pending preference to cancel")
13651370
}
13661371
}
13671372
}

gateway-messages/tests/versioning/v21.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,21 @@
1616
use gateway_messages::MgsRequest;
1717
use gateway_messages::SpComponent;
1818
use gateway_messages::SpResponse;
19+
use gateway_messages::UpdateError;
1920

2021
use super::assert_serialized;
2122

2223
#[test]
2324
fn mgs_request() {
2425
let request = MgsRequest::ComponentCancelPendingActiveSlot {
25-
component: SpComponent::SP_ITSELF,
26+
component: SpComponent::ROT,
2627
slot: 0x0102,
2728
persist: true,
2829
};
2930
#[rustfmt::skip]
3031
let expected = &[
3132
50, // ComponentCancelPendingActiveSlot
32-
b's', b'p', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // SP_ITSELF
33+
b'r', b'o', b't', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ROT
3334
2, 1, // slot
3435
1, // persist = true
3536
];
@@ -42,3 +43,11 @@ fn sp_response() {
4243
let expected = &[52];
4344
assert_serialized(expected, &response);
4445
}
46+
47+
#[test]
48+
fn error_enums() {
49+
let response: [UpdateError; 2] =
50+
[UpdateError::AlreadyPending, UpdateError::NonePending];
51+
let expected = vec![35, 36];
52+
assert_serialized(&expected, &response);
53+
}

gateway-sp-comms/src/error.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ pub enum UpdateError {
116116
InvalidComponent,
117117
#[error("an image was not found")]
118118
ImageNotFound,
119+
#[error("cannot update preferred boot image")]
120+
InvalidPreferredSlotId,
121+
#[error("pending preference must be canceled first")]
122+
AlreadyPending,
123+
#[error("no pending preference to cancel")]
124+
NonePending,
119125
}
120126

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

0 commit comments

Comments
 (0)