Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[opentitantool] Finish renaming legacy Google rescue protocol #20921

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sw/host/opentitanlib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ rust_library(
"src/backend/verilator.rs",
"src/bootstrap/eeprom.rs",
"src/bootstrap/legacy.rs",
"src/bootstrap/legacy_rescue.rs",
"src/bootstrap/mod.rs",
"src/bootstrap/primitive.rs",
"src/bootstrap/rescue.rs",
"src/chip/alert.rs",
"src/chip/autogen/mod.rs",
"src/chip/boolean.rs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl Frame {

ensure!(
payload.starts_with(&Self::MAGIC_HEADER),
RescueError::ImageFormatError
LegacyRescueError::ImageFormatError
);

// Find second occurrence of magic value, not followed by signature of encrypted
Expand All @@ -92,7 +92,7 @@ impl Frame {
.position(|c| c[0..4] == Self::MAGIC_HEADER && c[4..8] != Self::CRYPTOLIB_TELL)
{
Some(n) => (n + 1) * Self::HEADER_ALIGNMENT,
None => bail!(RescueError::ImageFormatError),
None => bail!(LegacyRescueError::ImageFormatError),
};

// Inspect the length field of the RW header.
Expand Down Expand Up @@ -160,27 +160,27 @@ impl Frame {
}

#[derive(Debug, Error, serde::Serialize, serde::Deserialize)]
pub enum RescueError {
pub enum LegacyRescueError {
#[error("Unrecognized image file format")]
ImageFormatError,
#[error("Synchronization error communicating with boot rom")]
SyncError,
#[error("Repeated errors communicating with boot rom")]
RepeatedErrors,
}
impl_serializable_error!(RescueError);
impl_serializable_error!(LegacyRescueError);

/// Implements the UART rescue protocol of Google Ti50 firmware.
pub struct Rescue {}
pub struct LegacyRescue {}

impl Rescue {
impl LegacyRescue {
/// Abort if a block has not been accepted after this number of retries.
const MAX_CONSECUTIVE_ERRORS: u32 = 50;
/// Take some measure to regain protocol synchronization, in case of this number of retries
/// of the same block.
const RESYNC_AFTER_CONSECUTIVE_ERRORS: u32 = 3;

/// Creates a new `Rescue` protocol updater from `options`.
/// Creates a new `LegacyRescue` protocol updater from `options`.
pub fn new(_options: &BootstrapOptions) -> Self {
Self {}
}
Expand Down Expand Up @@ -248,7 +248,7 @@ impl Rescue {
}
}
}
Err(RescueError::SyncError.into())
Err(LegacyRescueError::SyncError.into())
}

/// Reset the chip and send the magic 'r' character at the opportune moment during boot in
Expand Down Expand Up @@ -286,11 +286,11 @@ impl Rescue {
}
eprintln!(" Failed to enter rescue mode.");
}
Err(RescueError::RepeatedErrors.into())
Err(LegacyRescueError::RepeatedErrors.into())
}
}

impl UpdateProtocol for Rescue {
impl UpdateProtocol for LegacyRescue {
fn verify_capabilities(
&self,
_container: &Bootstrap,
Expand Down Expand Up @@ -360,7 +360,7 @@ impl UpdateProtocol for Rescue {
}
}
}
bail!(RescueError::RepeatedErrors);
bail!(LegacyRescueError::RepeatedErrors);
}

// Reset, in order to leave rescue mode.
Expand Down
9 changes: 3 additions & 6 deletions sw/host/opentitanlib/src/bootstrap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ use crate::transport::{Capability, ProgressIndicator};

mod eeprom;
mod legacy;
mod legacy_rescue;
mod primitive;
mod rescue;

pub use legacy::LegacyBootstrapError;
pub use rescue::RescueError;
pub use legacy_rescue::LegacyRescueError;

#[derive(Debug, Error, Serialize, Deserialize)]
pub enum BootstrapError {
Expand All @@ -37,7 +37,6 @@ impl_serializable_error!(BootstrapError);
/// The `Legacy` SPI protocol is used by previous generations of Google Titan-class chips.
/// The `LegacyRescue` UART protocol is used by previous generations of Google Titan-class chips.
/// The `Eeprom` SPI protocol is planned to be implemented for OpenTitan.
/// The `Rescue` value is a deprecated alias for `LegacyRescue`.
/// The 'Emulator' value indicates that this tool has a direct way
/// of communicating with the OpenTitan emulator, to replace the
/// contents of the emulated flash storage.
Expand All @@ -47,7 +46,6 @@ pub enum BootstrapProtocol {
Legacy,
LegacyRescue,
Eeprom,
Rescue,
Emulator,
}

Expand Down Expand Up @@ -147,8 +145,7 @@ impl<'a> Bootstrap<'a> {
let updater: Box<dyn UpdateProtocol> = match options.protocol {
BootstrapProtocol::Primitive => Box::new(primitive::Primitive::new(options)),
BootstrapProtocol::Legacy => Box::new(legacy::Legacy::new(options)),
BootstrapProtocol::LegacyRescue => Box::new(rescue::Rescue::new(options)),
BootstrapProtocol::Rescue => Box::new(rescue::Rescue::new(options)),
BootstrapProtocol::LegacyRescue => Box::new(legacy_rescue::LegacyRescue::new(options)),
BootstrapProtocol::Eeprom => Box::new(eeprom::Eeprom::new()),
BootstrapProtocol::Emulator => {
// Not intended to be implemented by this struct.
Expand Down
2 changes: 1 addition & 1 deletion sw/host/opentitanlib/src/proxy/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl From<anyhow::Error> for SerializedError {
Box::new,
crate::bootstrap::BootstrapError,
crate::bootstrap::LegacyBootstrapError,
crate::bootstrap::RescueError,
crate::bootstrap::LegacyRescueError,
crate::io::console::ConsoleError,
crate::io::emu::EmuError,
crate::io::gpio::GpioError,
Expand Down
Loading