Skip to content

Commit

Permalink
Switch to active / inactive / scratch pages
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeeter committed Sep 7, 2023
1 parent db88706 commit 39455d6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
9 changes: 6 additions & 3 deletions faux-mgs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ enum LedCommand {
#[derive(ValueEnum, Debug, Clone)]
enum CfpaSlot {
Active,
Pending,
Inactive,
Scratch,
}

impl std::fmt::Display for CfpaSlot {
Expand All @@ -389,7 +390,8 @@ impl std::fmt::Display for CfpaSlot {
"{}",
match self {
CfpaSlot::Active => "active",
CfpaSlot::Pending => "pending",
CfpaSlot::Inactive => "inactive",
CfpaSlot::Scratch => "scratch",
}
)
}
Expand Down Expand Up @@ -1266,7 +1268,8 @@ async fn run_command(
Command::ReadCfpa { out, slot } => {
let data = match slot {
CfpaSlot::Active => sp.read_rot_active_cfpa().await,
CfpaSlot::Pending => sp.read_rot_pending_cfpa().await,
CfpaSlot::Inactive => sp.read_rot_inactive_cfpa().await,
CfpaSlot::Scratch => sp.read_rot_scratch_cfpa().await,
}?;
handle_cxpa("cfpa", data, out, json)
}
Expand Down
7 changes: 4 additions & 3 deletions gateway-messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,10 @@ pub enum RotRequest {
pub enum CfpaPage {
/// Currently active page
Active,
/// Page that will become active on reset
Pending,
// We could add variants for ping/pong/scratch pages here if needed
/// Currently inactive page
Inactive,
/// Page that may become active upon reset
Scratch,
}

#[derive(
Expand Down
3 changes: 2 additions & 1 deletion gateway-messages/tests/versioning/v9.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ fn cfpa_page() {
let mut out = [0; CfpaPage::MAX_SIZE];

assert_serialized(&mut out, &[0], &CfpaPage::Active);
assert_serialized(&mut out, &[1], &CfpaPage::Pending);
assert_serialized(&mut out, &[1], &CfpaPage::Inactive);
assert_serialized(&mut out, &[2], &CfpaPage::Scratch);
}
10 changes: 8 additions & 2 deletions gateway-sp-comms/src/single_sp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,8 +830,14 @@ impl SingleSp {
.and_then(expect_read_rot)
}

pub async fn read_rot_pending_cfpa(&self) -> Result<[u8; ROT_PAGE_SIZE]> {
self.rpc(MgsRequest::ReadRot(RotRequest::ReadCfpa(CfpaPage::Pending)))
pub async fn read_rot_inactive_cfpa(&self) -> Result<[u8; ROT_PAGE_SIZE]> {
self.rpc(MgsRequest::ReadRot(RotRequest::ReadCfpa(CfpaPage::Inactive)))
.await
.and_then(expect_read_rot)
}

pub async fn read_rot_scratch_cfpa(&self) -> Result<[u8; ROT_PAGE_SIZE]> {
self.rpc(MgsRequest::ReadRot(RotRequest::ReadCfpa(CfpaPage::Scratch)))
.await
.and_then(expect_read_rot)
}
Expand Down

0 comments on commit 39455d6

Please sign in to comment.