Skip to content

Commit 3255cd2

Browse files
committed
services: Add the OCP Recovery Agent sequence
RecoverySequence runs the Recovery Agent steps around the push of 1 image through ImagePush. Both RECOVERY_CTRL writes carry the CMS of the push in byte 0 and image selection 0x1 in byte 1, because the OCP Recovery code on the caliptra-mcu-sw main-2.1 branch refuses an activation with image selection 0x0. A failed RECOVERY_CTRL write with the activation ends the sequence, because the device may have taken the activation before the transport failed. Signed-off-by: Christina Quast <christina.quast@9elements.com> Assisted-by: Claude Fable 5.2
1 parent fabccf4 commit 3255cd2

5 files changed

Lines changed: 1114 additions & 48 deletions

File tree

‎services/ocp-recovery/agent/src/image_push.rs‎

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -460,22 +460,21 @@ const fn agent_writes(region: FifoRegionType) -> bool {
460460

461461
#[cfg(test)]
462462
mod tests {
463-
use openprot_ocp_recovery_api::regs::ComponentMemorySpace;
463+
use openprot_ocp_recovery_api::regs::{ComponentMemorySpace, DeviceState};
464464
use openprot_ocp_recovery_api::ResponseError;
465465
use util_io::ByteReadError;
466466

467467
use super::*;
468-
use crate::script::{BrokenImage, BusFault, Expect, ScriptedDevice, SliceImage};
468+
use crate::script::{
469+
self, fifo_status_with, BrokenImage, BusFault, Expect, ScriptedDevice, SliceImage,
470+
};
469471

470472
/// The component memory space the tests push into.
471473
const CMS: ComponentMemorySpace = ComponentMemorySpace::new(2);
472474

473475
/// The max transfer size the scripted device reports.
474476
const MAX_TRANSFER_ENTRIES: u32 = 2;
475477

476-
/// The FIFO size the scripted device reports.
477-
const FIFO_SIZE_ENTRIES: u32 = 16;
478-
479478
/// An image of 1 chunk of the max transfer size, then 1 entry.
480479
const IMAGE: [u8; 12] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
481480

@@ -486,24 +485,9 @@ mod tests {
486485
/// [`IMAGE`] needs.
487486
const STEP_LIMIT: usize = 100;
488487

489-
/// `DEVICE_STATUS` bytes 0 to 6: Recovery Pending (0x4), the protocol
490-
/// error in byte 1, then no reason code, heartbeat and vendor status.
488+
/// [`script::device_status`] with Recovery Pending (0x4) and `error`.
491489
fn device_status(error: ProtocolError) -> Expect {
492-
Expect::Read(
493-
RecoveryCommand::DeviceStatus,
494-
vec![0x4, error as u8, 0, 0, 0, 0, 0],
495-
)
496-
}
497-
498-
/// `INDIRECT_FIFO_STATUS` with the empty bit (bit 0), the region type and
499-
/// the max transfer size as given, the indices at 0 and
500-
/// [`FIFO_SIZE_ENTRIES`].
501-
fn fifo_status_with(empty: bool, region: FifoRegionType, max_transfer_entries: u32) -> Expect {
502-
let mut bytes = vec![u8::from(empty), region as u8, 0, 0];
503-
for field in [0, 0, FIFO_SIZE_ENTRIES, max_transfer_entries] {
504-
bytes.extend_from_slice(&field.to_le_bytes());
505-
}
506-
Expect::Read(RecoveryCommand::IndirectFifoStatus, bytes)
490+
script::device_status(DeviceState::RecoveryPending, error)
507491
}
508492

509493
/// [`fifo_status_with`] for the code region and [`MAX_TRANSFER_ENTRIES`].

‎services/ocp-recovery/agent/src/lib.rs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,26 @@
99
//! `openprot_ocp_recovery_api`, so a read returns the decoded register or an
1010
//! [`AgentError`] that names the command. [`ImagePush`] pushes 1 image
1111
//! through the FIFO, with 1 register access per step, and a step that fails
12-
//! returns a [`PushError`].
12+
//! returns a [`PushError`]. [`RecoverySequence`] runs the Recovery Agent
13+
//! sequence around the push (the capability check, the status waits, the
14+
//! `RECOVERY_CTRL` writes and the activation) and reports the end state.
1315
1416
#![cfg_attr(not(test), no_std)]
1517
#![forbid(unsafe_code)]
1618
#![warn(missing_docs)]
1719

1820
mod error;
1921
mod image_push;
22+
mod recovery_sequence;
2023
mod register_access;
2124
mod register_reads;
2225
#[cfg(test)]
2326
mod script;
2427

2528
pub use error::AgentError;
2629
pub use image_push::{ImageMultiple, ImagePush, ImageSizeError, PushError, PushProgress};
30+
pub use recovery_sequence::{
31+
ActivationCount, RecoverySequence, SequenceError, SequenceOutcome, SequenceProgress,
32+
};
2733
pub use register_access::RegisterAccess;
2834
pub use register_reads::{read_device_status, read_prot_cap, read_recovery_status};

0 commit comments

Comments
 (0)