From fdd149f10a4089def6fd8656c9e91d80e6dbc79d Mon Sep 17 00:00:00 2001 From: "Jes B. Klinke" Date: Mon, 22 Jan 2024 11:03:30 -0800 Subject: [PATCH] [opentitantool] Finish renaming legacy Google rescue protocol Previous generation of Google Titan security chips supported a UART "rescue" bootstrapping protocol. This PR ensures that that protocol is exclusively referred to as the "legacy rescue" protocol. This makes room for an implementation of the OpenTitan UART rescue protocol to be invoked by the short form `--protocol=rescue`. Change-Id: Ice36b21e1a44b55a32be963c8c47934a6799bf81 Signed-off-by: Jes B. Klinke --- sw/host/opentitanlib/BUILD | 2 +- .../bootstrap/{rescue.rs => legacy_rescue.rs} | 22 +++++++++---------- sw/host/opentitanlib/src/bootstrap/mod.rs | 9 +++----- sw/host/opentitanlib/src/proxy/errors.rs | 2 +- 4 files changed, 16 insertions(+), 19 deletions(-) rename sw/host/opentitanlib/src/bootstrap/{rescue.rs => legacy_rescue.rs} (96%) diff --git a/sw/host/opentitanlib/BUILD b/sw/host/opentitanlib/BUILD index a1c778ed3f8c7..eb1d5d17709f5 100644 --- a/sw/host/opentitanlib/BUILD +++ b/sw/host/opentitanlib/BUILD @@ -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", diff --git a/sw/host/opentitanlib/src/bootstrap/rescue.rs b/sw/host/opentitanlib/src/bootstrap/legacy_rescue.rs similarity index 96% rename from sw/host/opentitanlib/src/bootstrap/rescue.rs rename to sw/host/opentitanlib/src/bootstrap/legacy_rescue.rs index 1c155594f111c..3118479845832 100644 --- a/sw/host/opentitanlib/src/bootstrap/rescue.rs +++ b/sw/host/opentitanlib/src/bootstrap/legacy_rescue.rs @@ -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 @@ -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. @@ -160,7 +160,7 @@ 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")] @@ -168,19 +168,19 @@ pub enum RescueError { #[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 {} } @@ -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 @@ -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, @@ -360,7 +360,7 @@ impl UpdateProtocol for Rescue { } } } - bail!(RescueError::RepeatedErrors); + bail!(LegacyRescueError::RepeatedErrors); } // Reset, in order to leave rescue mode. diff --git a/sw/host/opentitanlib/src/bootstrap/mod.rs b/sw/host/opentitanlib/src/bootstrap/mod.rs index fa0e88ccf7b82..8c01ddbbd2640 100644 --- a/sw/host/opentitanlib/src/bootstrap/mod.rs +++ b/sw/host/opentitanlib/src/bootstrap/mod.rs @@ -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 { @@ -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. @@ -47,7 +46,6 @@ pub enum BootstrapProtocol { Legacy, LegacyRescue, Eeprom, - Rescue, Emulator, } @@ -147,8 +145,7 @@ impl<'a> Bootstrap<'a> { let updater: Box = 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. diff --git a/sw/host/opentitanlib/src/proxy/errors.rs b/sw/host/opentitanlib/src/proxy/errors.rs index d6ab91df4d10f..94f654aee3b59 100644 --- a/sw/host/opentitanlib/src/proxy/errors.rs +++ b/sw/host/opentitanlib/src/proxy/errors.rs @@ -111,7 +111,7 @@ impl From 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,