Skip to content

Commit eac26b2

Browse files
committed
wip - TODO: remove patch. added InvalidPreferredSlotId
1 parent 5f348c0 commit eac26b2

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ path = "sys/abi"
4444
[patch."https://github.com/oxidecomputer/hubris".counters]
4545
path = "lib/counters"
4646

47+
[patch."https://github.com/oxidecomputer/management-gateway-service".gateway-messages]
48+
path = "/home/stoltz/Oxide/src/management-gateway-service/gateway-messages"
49+
4750
[workspace.dependencies]
4851
anyhow = { version = "1.0.31", default-features = false, features = ["std"] }
4952
array-init = { version = "2.1.0" }

drv/lpc55-update-server/src/main.rs

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -498,22 +498,46 @@ impl idl::InOrderUpdateImpl for ServerImpl<'_> {
498498
UpdateState::Finished | UpdateState::NoUpdate => (),
499499
}
500500

501-
self.image = match (component, slot) {
501+
let image = match (component, slot) {
502502
(RotComponent::Hubris, SlotId::A)
503-
| (RotComponent::Hubris, SlotId::B)
504-
| (RotComponent::Stage0, SlotId::B) => Some((component, slot)),
503+
| (RotComponent::Hubris, SlotId::B) => {
504+
let active = match bootstate().map_err(|_| UpdateError::MissingHandoffData)?.active {
505+
stage0_handoff::RotSlot::A => SlotId::A,
506+
stage0_handoff::RotSlot::B => SlotId::B,
507+
};
508+
if active == slot {
509+
return Err(UpdateError::InvalidSlotIdForOperation.into());
510+
}
511+
// Since we will be enforcing rollback protection at the time when the
512+
// boot preference is set, we cannot yet have the alternate image as the
513+
// preferred image. The full image needs to be in place in order to
514+
// evaluate the policy.
515+
let (persistent, pending_persistent, transient) = self.boot_preferences()?;
516+
if let Some(pref) = transient {
517+
if active != pref {
518+
return Err(UpdateError::InvalidPreferredSlotId.into());
519+
}
520+
}
521+
if let Some(pref) = pending_persistent {
522+
if active != pref {
523+
return Err(UpdateError::InvalidPreferredSlotId.into())
524+
}
525+
}
526+
if active != persistent {
527+
return Err(UpdateError::InvalidPreferredSlotId.into())
528+
}
529+
Some((component, slot))
530+
}
531+
(RotComponent::Stage0, SlotId::B) => Some((component, slot)),
505532
_ => return Err(UpdateError::InvalidSlotIdForOperation.into()),
506533
};
534+
535+
536+
self.image = image;
507537
self.state = UpdateState::InProgress;
508538
ringbuf_entry!(Trace::State(self.state));
509539
self.next_block = None;
510540
self.fw_cache.fill(0);
511-
// The sequence: [update, set transient preference, update] is legal.
512-
// Clear any stale transient preference before update.
513-
// Stage0 doesn't support transient override.
514-
if component == RotComponent::Hubris {
515-
set_hubris_transient_override(None);
516-
}
517541
Ok(())
518542
}
519543

drv/update-api/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ pub enum UpdateError {
6565
ImageMismatch,
6666
SignatureNotValidated,
6767
VersionNotSupported,
68+
69+
InvalidPreferredSlotId,
6870
}
6971

7072
impl From<UpdateError> for GwUpdateError {
@@ -103,6 +105,7 @@ impl From<UpdateError> for GwUpdateError {
103105
UpdateError::ImageMismatch => Self::ImageMismatch,
104106
UpdateError::SignatureNotValidated => Self::SignatureNotValidated,
105107
UpdateError::VersionNotSupported => Self::VersionNotSupported,
108+
UpdateError::InvalidPreferredSlotId => Self::InvalidPreferredSlotId,
106109
}
107110
}
108111
}

0 commit comments

Comments
 (0)