Add `boot` command to opentitantool - Add a `boot` command, which sets pin strapping to the `RUN` config, and toggles reset. This is intended to work around Nexus having pull-ups on the bootstrap lines, which means someone needs to drive the SW_STRAP pins low during reset for a "normal" boot. Change-Id: I97b6a3df1b43713328e22c2520de17bd212d77e7
diff --git a/sw/host/opentitanlib/src/app/config/nexus.json b/sw/host/opentitanlib/src/app/config/nexus.json index e34a640..70235c7 100644 --- a/sw/host/opentitanlib/src/app/config/nexus.json +++ b/sw/host/opentitanlib/src/app/config/nexus.json
@@ -53,6 +53,27 @@ "level": false } ] + }, + { + "name": "RUN", + "pins": [ + { + "name": "RESET", + "level": true + }, + { + "name": "SW_STRAP0", + "level": false + }, + { + "name": "SW_STRAP1", + "level": false + }, + { + "name": "SW_STRAP2", + "level": false + } + ] } ], "spi": [
diff --git a/sw/host/opentitantool/BUILD b/sw/host/opentitantool/BUILD index 599f1e2..d0918ae 100644 --- a/sw/host/opentitantool/BUILD +++ b/sw/host/opentitantool/BUILD
@@ -10,6 +10,7 @@ rust_binary( name = "opentitantool", srcs = [ + "src/command/boot.rs", "src/command/bootstrap.rs", "src/command/clear_bitstream.rs", "src/command/console.rs",
diff --git a/sw/host/opentitantool/src/command/boot.rs b/sw/host/opentitantool/src/command/boot.rs new file mode 100644 index 0000000..d26879d --- /dev/null +++ b/sw/host/opentitantool/src/command/boot.rs
@@ -0,0 +1,34 @@ +// Copyright lowRISC contributors. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 + +use anyhow::Result; +use serde_annotate::Annotate; +use std::any::Any; +use std::time::Duration; +use structopt::StructOpt; + +use opentitanlib::app::TransportWrapper; +use opentitanlib::app::command::CommandDispatch; + +/// Boot the target device. +#[derive(Debug, StructOpt)] +pub struct BootCommand { +} + +impl CommandDispatch for BootCommand { + fn run( + &self, + _context: &dyn Any, + transport: &TransportWrapper, + ) -> Result<Option<Box<dyn Annotate>>> { + let reset_pin = transport.gpio_pin("RESET")?; + transport.apply_pin_strapping("RUN")?; + // Active-low RESET + reset_pin.write(true)?; + reset_pin.write(false)?; + reset_pin.write(true)?; + std::thread::sleep(Duration::from_millis(1000)); + Ok(None) + } +}
diff --git a/sw/host/opentitantool/src/command/mod.rs b/sw/host/opentitantool/src/command/mod.rs index 3e8c715..2f88e7f 100644 --- a/sw/host/opentitantool/src/command/mod.rs +++ b/sw/host/opentitantool/src/command/mod.rs
@@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0, see LICENSE for details. // SPDX-License-Identifier: Apache-2.0 +pub mod boot; pub mod bootstrap; pub mod clear_bitstream; pub mod console;
diff --git a/sw/host/opentitantool/src/main.rs b/sw/host/opentitantool/src/main.rs index 4515a83..4c2f1f6 100644 --- a/sw/host/opentitantool/src/main.rs +++ b/sw/host/opentitantool/src/main.rs
@@ -25,6 +25,7 @@ #[allow(clippy::large_enum_variant)] #[derive(Debug, StructOpt, CommandDispatch)] enum RootCommandHierarchy { + Boot(command::boot::BootCommand), // Not flattened because `Bootstrap` is a leaf command. Bootstrap(command::bootstrap::BootstrapCommand), // Not flattened because `Console` is a leaf command.