From c48f1e6b240b661141bd0b66557d93c6b5e707de Mon Sep 17 00:00:00 2001 From: Bryan Cantrill Date: Wed, 1 Dec 2021 19:34:33 -0800 Subject: [PATCH 1/3] first cut: ~35.4s -> ~22.6s --- Cargo.lock | 30 ++++++++++++++++++++----- Cargo.toml | 14 +----------- humility-core/Cargo.toml | 33 ++++++++++++++++++++++++++++ {src => humility-core/src}/core.rs | 0 {src => humility-core/src}/debug.rs | 9 ++++---- {src => humility-core/src}/hubris.rs | 0 src/cmd.rs | 4 ++-- src/cmd/apptable.rs | 2 +- src/cmd/diagnose.rs | 4 ++-- src/cmd/dump.rs | 2 +- src/cmd/etm.rs | 6 ++--- src/cmd/gpio.rs | 4 ++-- src/cmd/hiffy.rs | 4 ++-- src/cmd/i2c.rs | 4 ++-- src/cmd/itm.rs | 6 ++--- src/cmd/jefe.rs | 4 ++-- src/cmd/manifest.rs | 2 +- src/cmd/map.rs | 5 +++-- src/cmd/pmbus.rs | 4 ++-- src/cmd/probe.rs | 6 ++--- src/cmd/qspi.rs | 4 ++-- src/cmd/readmem.rs | 7 +++--- src/cmd/readvar.rs | 4 ++-- src/cmd/renbb.rs | 4 ++-- src/cmd/rencm.rs | 4 ++-- src/cmd/ringbuf.rs | 4 ++-- src/cmd/spd.rs | 4 ++-- src/cmd/spi.rs | 4 ++-- src/cmd/stackmargin.rs | 4 ++-- src/cmd/stmsecure.rs | 4 ++-- src/cmd/tasks.rs | 6 ++--- src/cmd/test.rs | 4 ++-- src/cmd/trace.rs | 4 ++-- src/dwt.rs | 5 +++-- src/etm.rs | 9 ++++---- src/hiffy.rs | 4 ++-- src/i2c.rs | 2 +- src/itm.rs | 12 +++++----- src/main.rs | 19 ++++++---------- src/reflect.rs | 6 ++--- src/scs.rs | 15 +++++++------ src/swo.rs | 10 ++++++--- src/test.rs | 2 +- src/tpiu.rs | 5 +++-- 44 files changed, 168 insertions(+), 121 deletions(-) create mode 100644 humility-core/Cargo.toml rename {src => humility-core/src}/core.rs (100%) rename {src => humility-core/src}/debug.rs (98%) rename {src => humility-core/src}/hubris.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 376680660..a3a58b792 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -536,14 +536,12 @@ version = "0.5.0" dependencies = [ "anyhow", "bitfield", - "capstone", "clap", "colored", "csv", "fallible-iterator", - "gimli 0.20.0", - "goblin", "hif", + "humility-core", "humility_load_derive", "idt8a3xxxx", "indexmap", @@ -558,13 +556,35 @@ dependencies = [ "paste", "pmbus", "postcard", + "scroll", + "serde", + "spd", + "structopt", + "toml", +] + +[[package]] +name = "humility-core" +version = "0.1.0" +dependencies = [ + "anyhow", + "bitfield", + "capstone", + "fallible-iterator", + "gimli 0.20.0", + "goblin", + "indexmap", + "indicatif", + "log", + "multimap", + "num-derive", + "num-traits", + "parse_int", "probe-rs", "rusb 0.5.5", "rustc-demangle", "scroll", "serde", - "spd", - "structopt", "toml", "zip", ] diff --git a/Cargo.toml b/Cargo.toml index 5ee3b6edd..9365906c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,33 +14,21 @@ hif = { path = "./hif" } spd = { path = "./spd" } idt8a3xxxx = { path = "./idt8a3xxxx" } humility_load_derive = {path = "./load_derive"} +humility = { path = "./humility-core", package = "humility-core" } -gimli = "0.20.0" fallible-iterator = "0.2.0" - -# -# We depend on the oxide-stable branch of Oxide's fork of probe-rs to assure -# that we can float necessary patches on probe-rs. -# -probe-rs = { git = "https://github.com/oxidecomputer/probe-rs.git", branch = "oxide-stable" } - log = {version = "0.4.8", features = ["std"]} bitfield = "0.13.2" clap = "2.33.0" csv = "1.1.3" serde = "1.0.126" parse_int = "0.4.0" -goblin = "0.2.1" -capstone = "0.8.0" -rustc-demangle = "0.1.21" structopt = "0.3" multimap = "0.8.1" -rusb = "0.5.5" num-traits = "0.2" num-derive = "0.3" paste = "0.1" jep106 = "0.2" -zip = "0.5" toml = "0.5" anyhow = { version = "1.0.44", features = ["backtrace"] } scroll = "0.10" diff --git a/humility-core/Cargo.toml b/humility-core/Cargo.toml new file mode 100644 index 000000000..d943d4234 --- /dev/null +++ b/humility-core/Cargo.toml @@ -0,0 +1,33 @@ +[package] +name = "humility-core" +version = "0.1.0" +edition = "2021" +license = "MPL-2.0" + +[dependencies] +serde = { version = "1.0.126", features = ["derive"] } +goblin = "0.2.1" +capstone = "0.8.0" +rustc-demangle = "0.1.21" +anyhow = { version = "1.0.44", features = ["backtrace"] } +gimli = "0.20.0" +fallible-iterator = "0.2.0" +indexmap = { version = "1.7", features = ["serde-1"] } +scroll = "0.10" +multimap = "0.8.1" +num-traits = "0.2" +num-derive = "0.3" +indicatif = "0.15" +toml = "0.5" +bitfield = "0.13.2" +log = {version = "0.4.8", features = ["std"]} +zip = "0.5" +rusb = "0.5.5" +parse_int = "0.4.0" + +# +# We depend on the oxide-stable branch of Oxide's fork of probe-rs to assure +# that we can float necessary patches on probe-rs. +# +probe-rs = { git = "https://github.com/oxidecomputer/probe-rs.git", branch = "oxide-stable" } + diff --git a/src/core.rs b/humility-core/src/core.rs similarity index 100% rename from src/core.rs rename to humility-core/src/core.rs diff --git a/src/debug.rs b/humility-core/src/debug.rs similarity index 98% rename from src/debug.rs rename to humility-core/src/debug.rs index 6e84cd4f4..9b21da562 100644 --- a/src/debug.rs +++ b/humility-core/src/debug.rs @@ -5,6 +5,7 @@ use anyhow::{anyhow, Result}; use crate::hubris::*; +use crate::core::Core; use bitfield::bitfield; pub trait Register: @@ -40,14 +41,14 @@ macro_rules! register { impl $reg { pub fn read( - core: &mut dyn crate::core::Core + core: &mut dyn Core ) -> anyhow::Result<$reg> { Ok(Self(core.read_word_32($addr)?)) } pub fn write( &self, - core: &mut dyn crate::core::Core + core: &mut dyn Core ) -> anyhow::Result<()> { core.write_word_32($addr, self.0.into())?; Ok(()) @@ -95,7 +96,7 @@ macro_rules! register_offs { impl $reg { #[allow(dead_code)] pub fn read( - core: &mut dyn crate::core::Core, + core: &mut dyn Core, base: u32 ) -> anyhow::Result<$reg> { Ok(Self { @@ -109,7 +110,7 @@ macro_rules! register_offs { #[allow(dead_code)] pub fn write( &self, - core: &mut dyn crate::core::Core + core: &mut dyn Core ) -> anyhow::Result<()> { core.write_word_32( self.base + $offs, diff --git a/src/hubris.rs b/humility-core/src/hubris.rs similarity index 100% rename from src/hubris.rs rename to humility-core/src/hubris.rs diff --git a/src/cmd.rs b/src/cmd.rs index afac4d6a1..537024218 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -29,11 +29,11 @@ mod tasks; mod test; mod trace; -use crate::core::Core; -use crate::hubris::*; use crate::Args; use crate::{attach_dump, attach_live}; use anyhow::{bail, Result}; +use humility::core::Core; +use humility::hubris::*; use std::collections::HashMap; use std::convert::TryInto; use structopt::clap::App; diff --git a/src/cmd/apptable.rs b/src/cmd/apptable.rs index 5fb4e1ea8..1ae8b7a70 100644 --- a/src/cmd/apptable.rs +++ b/src/cmd/apptable.rs @@ -3,9 +3,9 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use crate::cmd::{Archive, Command}; -use crate::hubris::{HubrisArchive, HubrisPrintFormat}; use crate::Args; use anyhow::{bail, Result}; +use humility::hubris::{HubrisArchive, HubrisPrintFormat}; use std::convert::TryInto; use structopt::clap::App; use structopt::StructOpt; diff --git a/src/cmd/diagnose.rs b/src/cmd/diagnose.rs index bca12f3b6..936d683bf 100644 --- a/src/cmd/diagnose.rs +++ b/src/cmd/diagnose.rs @@ -16,12 +16,12 @@ use crate::cmd::jefe; use crate::cmd::*; -use crate::core::Core; use crate::doppel::{GenOrRestartCount, Task, TaskDesc, TaskState}; -use crate::hubris::*; use crate::reflect; use crate::Args; use anyhow::Result; +use humility::core::Core; +use humility::hubris::*; use std::num::NonZeroU32; use std::time::Duration; use structopt::clap::App; diff --git a/src/cmd/dump.rs b/src/cmd/dump.rs index a833ee5f7..ffcc554ff 100644 --- a/src/cmd/dump.rs +++ b/src/cmd/dump.rs @@ -3,9 +3,9 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use crate::cmd::*; -use crate::hubris::*; use crate::Args; use anyhow::Result; +use humility::hubris::*; use structopt::clap::App; use structopt::StructOpt; diff --git a/src/cmd/etm.rs b/src/cmd/etm.rs index 27ebfacc0..60b70b9b2 100644 --- a/src/cmd/etm.rs +++ b/src/cmd/etm.rs @@ -4,14 +4,14 @@ use crate::attach_live; use crate::cmd::{Archive, Command}; -use crate::core::Core; -use crate::debug::*; use crate::etm::*; -use crate::hubris::*; use crate::scs::*; use crate::tpiu::*; use crate::Args; use anyhow::{bail, Result}; +use humility::core::Core; +use humility::debug::*; +use humility::hubris::*; use std::fs::File; use std::time::Instant; use structopt::clap::App; diff --git a/src/cmd/gpio.rs b/src/cmd/gpio.rs index e2d9f2063..74a8a0720 100644 --- a/src/cmd/gpio.rs +++ b/src/cmd/gpio.rs @@ -3,10 +3,10 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use crate::cmd::{Archive, Attach, Validate}; -use crate::core::Core; use crate::hiffy::*; -use crate::hubris::*; use crate::Args; +use humility::core::Core; +use humility::hubris::*; use std::str; use std::thread; diff --git a/src/cmd/hiffy.rs b/src/cmd/hiffy.rs index 4c9f94109..5f38b6115 100644 --- a/src/cmd/hiffy.rs +++ b/src/cmd/hiffy.rs @@ -3,11 +3,11 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use crate::cmd::*; -use crate::core::Core; use crate::hiffy::*; -use crate::hubris::*; use crate::Args; use anyhow::Result; +use humility::core::Core; +use humility::hubris::*; use structopt::clap::App; use structopt::StructOpt; diff --git a/src/cmd/i2c.rs b/src/cmd/i2c.rs index dabba2616..ef60dadff 100644 --- a/src/cmd/i2c.rs +++ b/src/cmd/i2c.rs @@ -3,12 +3,12 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use crate::cmd::*; -use crate::core::Core; use crate::hiffy::*; -use crate::hubris::*; use crate::Args; use anyhow::{anyhow, bail, Result}; use hif::*; +use humility::core::Core; +use humility::hubris::*; use std::thread; use std::time::Duration; use structopt::clap::App; diff --git a/src/cmd/itm.rs b/src/cmd/itm.rs index 38c50107b..d0c64b3c7 100644 --- a/src/cmd/itm.rs +++ b/src/cmd/itm.rs @@ -4,15 +4,15 @@ use crate::attach_live; use crate::cmd::{Archive, Command}; -use crate::core::Core; -use crate::debug::*; use crate::dwt::*; -use crate::hubris::*; use crate::itm::*; use crate::scs::*; use crate::tpiu::*; use crate::Args; use anyhow::{bail, Result}; +use humility::core::Core; +use humility::debug::*; +use humility::hubris::*; use std::fs::File; use std::io::Read; use std::time::Instant; diff --git a/src/cmd/jefe.rs b/src/cmd/jefe.rs index 6cb935b38..fc9159052 100644 --- a/src/cmd/jefe.rs +++ b/src/cmd/jefe.rs @@ -3,10 +3,10 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use crate::cmd::*; -use crate::core::Core; -use crate::hubris::*; use crate::Args; use anyhow::{anyhow, bail, Context, Result}; +use humility::core::Core; +use humility::hubris::*; use std::num::NonZeroU32; use std::thread; use std::time::Duration; diff --git a/src/cmd/manifest.rs b/src/cmd/manifest.rs index e28c647bb..8dc4baff6 100644 --- a/src/cmd/manifest.rs +++ b/src/cmd/manifest.rs @@ -3,9 +3,9 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use crate::cmd::{Archive, Command}; -use crate::hubris::HubrisArchive; use crate::Args; use anyhow::Result; +use humility::hubris::HubrisArchive; use structopt::clap::App; use structopt::StructOpt; diff --git a/src/cmd/map.rs b/src/cmd/map.rs index 496de41a4..c5c8a8111 100644 --- a/src/cmd/map.rs +++ b/src/cmd/map.rs @@ -3,9 +3,10 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use crate::cmd::*; -use crate::hubris::*; use crate::Args; use anyhow::Result; +use humility::core::Core; +use humility::hubris::*; use structopt::clap::App; use structopt::StructOpt; @@ -18,7 +19,7 @@ struct MapArgs {} fn mapcmd( hubris: &mut HubrisArchive, - core: &mut dyn crate::core::Core, + core: &mut dyn Core, _args: &Args, _subargs: &Vec, ) -> Result<()> { diff --git a/src/cmd/pmbus.rs b/src/cmd/pmbus.rs index b41ff5656..c5fbc54a2 100644 --- a/src/cmd/pmbus.rs +++ b/src/cmd/pmbus.rs @@ -3,11 +3,11 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use crate::cmd::{Archive, Attach, Validate}; -use crate::core::Core; use crate::hiffy::*; -use crate::hubris::*; use crate::Args; use colored::Colorize; +use humility::core::Core; +use humility::hubris::*; use std::thread; use anyhow::{anyhow, bail, Result}; diff --git a/src/cmd/probe.rs b/src/cmd/probe.rs index a9e15d5f0..8ca581443 100644 --- a/src/cmd/probe.rs +++ b/src/cmd/probe.rs @@ -3,13 +3,13 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use crate::cmd::*; -use crate::core::Core; -use crate::debug::*; -use crate::hubris::*; use crate::itm::*; use crate::scs::*; use crate::Args; use anyhow::Result; +use humility::core::Core; +use humility::debug::*; +use humility::hubris::*; use structopt::clap::App; use structopt::StructOpt; diff --git a/src/cmd/qspi.rs b/src/cmd/qspi.rs index 8aaf1e0a9..a9980adaa 100644 --- a/src/cmd/qspi.rs +++ b/src/cmd/qspi.rs @@ -4,10 +4,10 @@ use crate::cmd::printmem; use crate::cmd::{Archive, Attach, Validate}; -use crate::core::Core; use crate::hiffy::*; -use crate::hubris::*; use crate::Args; +use humility::core::Core; +use humility::hubris::*; use std::fs; use std::fs::File; use std::io::Read; diff --git a/src/cmd/readmem.rs b/src/cmd/readmem.rs index a0cd11178..c243ec88e 100644 --- a/src/cmd/readmem.rs +++ b/src/cmd/readmem.rs @@ -3,9 +3,10 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use crate::cmd::*; -use crate::hubris::*; use crate::Args; use anyhow::{bail, Result}; +use humility::core::Core; +use humility::hubris::*; use std::convert::TryInto; use structopt::clap::App; use structopt::StructOpt; @@ -35,12 +36,12 @@ struct ReadmemArgs { fn readmem( hubris: &mut HubrisArchive, - core: &mut dyn crate::core::Core, + core: &mut dyn Core, _args: &Args, subargs: &Vec, ) -> Result<()> { let subargs = ReadmemArgs::from_iter_safe(subargs)?; - let max = crate::core::CORE_MAX_READSIZE; + let max = humility::core::CORE_MAX_READSIZE; let size = if subargs.word || subargs.symbol { 4 } else if subargs.halfword { diff --git a/src/cmd/readvar.rs b/src/cmd/readvar.rs index d8f5e8cd1..676008ca1 100644 --- a/src/cmd/readvar.rs +++ b/src/cmd/readvar.rs @@ -3,10 +3,10 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use crate::cmd::*; -use crate::core::Core; -use crate::hubris::*; use crate::Args; use anyhow::{bail, Result}; +use humility::core::Core; +use humility::hubris::*; use structopt::clap::App; use structopt::StructOpt; diff --git a/src/cmd/renbb.rs b/src/cmd/renbb.rs index a52622640..b0f05abb4 100644 --- a/src/cmd/renbb.rs +++ b/src/cmd/renbb.rs @@ -3,10 +3,10 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use crate::cmd::{Archive, Attach, Validate}; -use crate::core::Core; use crate::hiffy::*; -use crate::hubris::*; use crate::Args; +use humility::core::Core; +use humility::hubris::*; use std::thread; use anyhow::{anyhow, bail, Result}; diff --git a/src/cmd/rencm.rs b/src/cmd/rencm.rs index b0481a3e6..6f55c0d6e 100644 --- a/src/cmd/rencm.rs +++ b/src/cmd/rencm.rs @@ -3,10 +3,10 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use crate::cmd::{Archive, Attach, Validate}; -use crate::core::Core; use crate::hiffy::*; -use crate::hubris::*; use crate::Args; +use humility::core::Core; +use humility::hubris::*; use std::thread; use itertools::Itertools; diff --git a/src/cmd/ringbuf.rs b/src/cmd/ringbuf.rs index c261ac60e..fe60dbd1f 100644 --- a/src/cmd/ringbuf.rs +++ b/src/cmd/ringbuf.rs @@ -3,12 +3,12 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use crate::cmd::*; -use crate::core::Core; use crate::doppel::{Ringbuf, StaticCell}; -use crate::hubris::*; use crate::reflect::{self, Format, Load, Value}; use crate::Args; use anyhow::{bail, Result}; +use humility::core::Core; +use humility::hubris::*; use structopt::clap::App; use structopt::StructOpt; diff --git a/src/cmd/spd.rs b/src/cmd/spd.rs index d9be565a9..c15eaf4d9 100644 --- a/src/cmd/spd.rs +++ b/src/cmd/spd.rs @@ -3,10 +3,10 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use crate::cmd::{Archive, Attach, Validate}; -use crate::core::Core; use crate::hiffy::*; -use crate::hubris::*; use crate::Args; +use humility::core::Core; +use humility::hubris::*; use std::str; use std::thread; diff --git a/src/cmd/spi.rs b/src/cmd/spi.rs index 5af1be33b..1b740d06d 100644 --- a/src/cmd/spi.rs +++ b/src/cmd/spi.rs @@ -3,10 +3,10 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use crate::cmd::{Archive, Attach, Validate}; -use crate::core::Core; use crate::hiffy::*; -use crate::hubris::*; use crate::Args; +use humility::core::Core; +use humility::hubris::*; use std::convert::TryInto; use std::str; use std::thread; diff --git a/src/cmd/stackmargin.rs b/src/cmd/stackmargin.rs index 9da72490b..eee7e4afc 100644 --- a/src/cmd/stackmargin.rs +++ b/src/cmd/stackmargin.rs @@ -3,10 +3,10 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use crate::cmd::*; -use crate::core::Core; -use crate::hubris::*; use crate::Args; use anyhow::{bail, Result}; +use humility::core::Core; +use humility::hubris::*; use std::convert::TryInto; use structopt::clap::App; use structopt::StructOpt; diff --git a/src/cmd/stmsecure.rs b/src/cmd/stmsecure.rs index 0e656dfa4..4c9443b72 100644 --- a/src/cmd/stmsecure.rs +++ b/src/cmd/stmsecure.rs @@ -3,10 +3,10 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use crate::cmd::*; -use crate::core::Core; -use crate::debug::ARMRegister; use crate::Args; use anyhow::{anyhow, Result}; +use humility::core::Core; +use humility::debug::ARMRegister; use structopt::clap::App; use structopt::StructOpt; diff --git a/src/cmd/tasks.rs b/src/cmd/tasks.rs index 677008f9e..cd566754d 100644 --- a/src/cmd/tasks.rs +++ b/src/cmd/tasks.rs @@ -3,13 +3,13 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use crate::cmd::*; -use crate::core::Core; -use crate::debug::*; use crate::doppel::{self, Task, TaskDesc, TaskId, TaskState}; -use crate::hubris::*; use crate::reflect::{self, Format, Load}; use crate::Args; use anyhow::{bail, Result}; +use humility::core::Core; +use humility::debug::*; +use humility::hubris::*; use num_traits::FromPrimitive; use std::collections::HashMap; use structopt::clap::App; diff --git a/src/cmd/test.rs b/src/cmd/test.rs index c34ff6910..12aa65d7b 100644 --- a/src/cmd/test.rs +++ b/src/cmd/test.rs @@ -3,12 +3,12 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use crate::cmd::*; -use crate::core::Core; -use crate::hubris::*; use crate::itm::*; use crate::test::*; use crate::Args; use anyhow::{bail, Context, Result}; +use humility::core::Core; +use humility::hubris::*; use std::cell::RefCell; use std::collections::VecDeque; use std::time::Instant; diff --git a/src/cmd/trace.rs b/src/cmd/trace.rs index adeadbcf3..7c62f16db 100644 --- a/src/cmd/trace.rs +++ b/src/cmd/trace.rs @@ -3,11 +3,11 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use crate::cmd::*; -use crate::core::Core; -use crate::hubris::*; use crate::itm::*; use crate::Args; use anyhow::{anyhow, Result}; +use humility::core::Core; +use humility::hubris::*; use std::collections::HashMap; use std::convert::TryInto; use std::time::Instant; diff --git a/src/dwt.rs b/src/dwt.rs index 5d6e76bb1..75833b4ad 100644 --- a/src/dwt.rs +++ b/src/dwt.rs @@ -2,9 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::debug::Register; -use crate::register; use bitfield::bitfield; +use humility::core::Core; +use humility::debug::Register; +use humility::register; /* * DWT Control Register diff --git a/src/etm.rs b/src/etm.rs index f5ce07b34..d9c14068b 100644 --- a/src/etm.rs +++ b/src/etm.rs @@ -2,11 +2,12 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::debug::Register; -use crate::register; use crate::tpiu::*; use anyhow::Result; use bitfield::bitfield; +use humility::core::Core; +use humility::debug::Register; +use humility::register; macro_rules! etm_register { ($reg:ty, $offs:expr, $($arg:tt)*) => ( @@ -221,7 +222,7 @@ etm_register!(ETMLAR, 0x3ec, ); impl ETMLAR { - pub fn unlock(core: &mut dyn crate::core::Core) -> Result<()> { + pub fn unlock(core: &mut dyn humility::core::Core) -> Result<()> { /* * To unlock, we write "CoreSight Access" in l33t */ @@ -230,7 +231,7 @@ impl ETMLAR { Ok(()) } - pub fn lock(core: &mut dyn crate::core::Core) -> Result<()> { + pub fn lock(core: &mut dyn humility::core::Core) -> Result<()> { let val: u32 = 0x1de_c0de; core.write_word_32(ETMLAR::ADDRESS, val)?; Ok(()) diff --git a/src/hiffy.rs b/src/hiffy.rs index 593b488b8..ce558288d 100644 --- a/src/hiffy.rs +++ b/src/hiffy.rs @@ -2,10 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::core::Core; -use crate::hubris::*; use anyhow::{anyhow, bail, Context, Result}; use hif::*; +use humility::core::Core; +use humility::hubris::*; use postcard::{take_from_bytes, to_slice}; use std::collections::HashMap; use std::convert::TryFrom; diff --git a/src/i2c.rs b/src/i2c.rs index 315c8895e..6711f3a35 100644 --- a/src/i2c.rs +++ b/src/i2c.rs @@ -2,8 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::hubris::*; use anyhow::{bail, Context, Result}; +use humility::hubris::*; use std::fmt; pub struct I2cArgs<'a> { diff --git a/src/itm.rs b/src/itm.rs index 5e7da42d0..f878e0a80 100644 --- a/src/itm.rs +++ b/src/itm.rs @@ -2,16 +2,16 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::core::Core; -use crate::debug::*; use crate::dwt::*; -use crate::hubris::HubrisArchive; -use crate::register; use crate::scs::*; use crate::swo::*; use crate::tpiu::*; use anyhow::Result; use bitfield::bitfield; +use humility::core::Core; +use humility::debug::*; +use humility::hubris::HubrisArchive; +use humility::register; /* * ITM Trace Enable Register @@ -77,7 +77,7 @@ register!(ITM_LSR, 0xe000_0fb4, ); impl ITM_LAR { - pub fn unlock(core: &mut dyn crate::core::Core) -> Result<()> { + pub fn unlock(core: &mut dyn humility::core::Core) -> Result<()> { /* * To unlock, we write "CoreSight Access" in l33t */ @@ -86,7 +86,7 @@ impl ITM_LAR { Ok(()) } - pub fn lock(core: &mut dyn crate::core::Core) -> Result<()> { + pub fn lock(core: &mut dyn humility::core::Core) -> Result<()> { let val: u32 = 0x1de_c0de; core.write_word_32(ITM_LAR::ADDRESS, val)?; Ok(()) diff --git a/src/main.rs b/src/main.rs index c115c3c76..9681af504 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,12 +12,10 @@ use anyhow::{bail, Result}; use structopt::StructOpt; -mod hubris; -use hubris::*; +use humility::core::Core; +use humility::hubris::*; mod cmd; -mod core; -mod debug; mod dwt; mod etm; mod hiffy; @@ -49,7 +47,7 @@ pub struct HumilityLog { fn is_humility(metadata: &log::Metadata) -> bool { if let Some(metadata) = metadata.target().split("::").next() { - metadata == "humility" + metadata.starts_with("humility") } else { false } @@ -93,7 +91,7 @@ impl HumilityLog { } } -fn attach_live(args: &Args) -> Result> { +fn attach_live(args: &Args) -> Result> { if args.dump.is_some() { bail!("must be run against a live system"); } else { @@ -102,16 +100,13 @@ fn attach_live(args: &Args) -> Result> { None => "auto", }; - crate::core::attach(probe, &args.chip) + humility::core::attach(probe, &args.chip) } } -fn attach_dump( - args: &Args, - hubris: &HubrisArchive, -) -> Result> { +fn attach_dump(args: &Args, hubris: &HubrisArchive) -> Result> { if let Some(dump) = &args.dump { - crate::core::attach_dump(dump, hubris) + humility::core::attach_dump(dump, hubris) } else { bail!("must be run against a dump"); } diff --git a/src/reflect.rs b/src/reflect.rs index ddd66d361..2ac5cf351 100644 --- a/src/reflect.rs +++ b/src/reflect.rs @@ -81,8 +81,8 @@ use std::convert::TryInto; use anyhow::{anyhow, bail, Result}; -use crate::core::Core; -use crate::hubris::{ +use humility::core::Core; +use humility::hubris::{ HubrisArchive, HubrisArray, HubrisBasetype, HubrisEnum, HubrisGoff, HubrisPrintFormat, HubrisStruct, HubrisType, }; @@ -802,7 +802,7 @@ pub fn load_base(buf: &[u8], ty: &HubrisBasetype, addr: usize) -> Result { anyhow!("address {} out of range for type {:?}", addr, ty) })?; - use crate::hubris::HubrisEncoding::*; + use humility::hubris::HubrisEncoding::*; let v = match (ty.encoding, ty.size) { (Signed, 1) => Base::I8(buf[0] as i8), (Signed, 2) => Base::I16(i16::from_le_bytes(buf.try_into().unwrap())), diff --git a/src/scs.rs b/src/scs.rs index f82681e73..621dd9b10 100644 --- a/src/scs.rs +++ b/src/scs.rs @@ -2,11 +2,12 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::debug::*; -use crate::register; -use crate::register_offs; use anyhow::{bail, Result}; use bitfield::bitfield; +use humility::core::Core; +use humility::debug::*; +use humility::register; +use humility::register_offs; use multimap::MultiMap; use std::mem::size_of; @@ -106,7 +107,7 @@ pub struct CoreSightPage { } impl CoreSightPage { - pub fn new(core: &mut dyn crate::core::Core, base: u32) -> Result { + pub fn new(core: &mut dyn humility::core::Core, base: u32) -> Result { let cidr0 = &CIDR0::read(core, base)?.register; let cidr1 = &CIDR1::read(core, base)?.register; let cidr2 = &CIDR2::read(core, base)?.register; @@ -177,7 +178,7 @@ pub enum CoreSightComponent { impl CoreSightComponent { pub fn new( - core: &mut dyn crate::core::Core, + core: &mut dyn humility::core::Core, page: &CoreSightPage, ) -> Result { let base = page.base; @@ -334,7 +335,7 @@ impl CoreSightROMEntry { } pub fn read_rom( - core: &mut dyn crate::core::Core, + core: &mut dyn humility::core::Core, base: u32, components: &mut MultiMap, ) -> Result<()> { @@ -407,7 +408,7 @@ pub struct CoreInfo { } impl CoreInfo { - pub fn read(core: &mut dyn crate::core::Core) -> Result { + pub fn read(core: &mut dyn humility::core::Core) -> Result { use num_traits::FromPrimitive; let cpuid = CPUID::read(core)?; diff --git a/src/swo.rs b/src/swo.rs index a300b5248..d680840f0 100644 --- a/src/swo.rs +++ b/src/swo.rs @@ -4,7 +4,8 @@ use anyhow::Result; -use crate::register_offs; +use humility::core::Core; +use humility::register_offs; use num_traits::FromPrimitive; use num_traits::ToPrimitive; @@ -59,7 +60,10 @@ register_offs!(SWO_LAR, 0xfb0, ); impl SWO_LAR { - pub fn unlock(core: &mut dyn crate::core::Core, base: u32) -> Result<()> { + pub fn unlock( + core: &mut dyn humility::core::Core, + base: u32, + ) -> Result<()> { /* * To unlock, we write "CoreSight Access" in l33t */ @@ -69,7 +73,7 @@ impl SWO_LAR { } #[allow(dead_code)] - pub fn lock(core: &mut dyn crate::core::Core, base: u32) -> Result<()> { + pub fn lock(core: &mut dyn humility::core::Core, base: u32) -> Result<()> { let val: u32 = 0x1de_c0de; core.write_word_32(SWO_LAR::address(base), val)?; Ok(()) diff --git a/src/test.rs b/src/test.rs index 7fc30c1d1..b0e9ae75e 100644 --- a/src/test.rs +++ b/src/test.rs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::hubris::*; use anyhow::{bail, Result}; use colored::Colorize; +use humility::hubris::*; use std::fmt; use std::fs; use std::fs::OpenOptions; diff --git a/src/tpiu.rs b/src/tpiu.rs index 8f129b230..a2982cbcb 100644 --- a/src/tpiu.rs +++ b/src/tpiu.rs @@ -2,10 +2,11 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::debug::Register; -use crate::register; use anyhow::Result; use bitfield::bitfield; +use humility::core::Core; +use humility::debug::Register; +use humility::register; register!(TPIU_SSPSR, 0xe004_0000, #[derive(Copy, Clone)] From 406c24b79262a5c8eb833e9848fddb163addf672 Mon Sep 17 00:00:00 2001 From: Bryan Cantrill Date: Wed, 1 Dec 2021 23:06:33 -0800 Subject: [PATCH 2/3] second cut: wip --- Cargo.lock | 63 ++++---- Cargo.toml | 12 +- cmd/apptable/Cargo.toml | 11 ++ .../apptable.rs => cmd/apptable/src/lib.rs | 3 +- humility-arch-cortex/Cargo.toml | 15 ++ .../src/debug.rs | 70 +-------- {src => humility-arch-cortex/src}/dwt.rs | 4 +- {src => humility-arch-cortex/src}/etm.rs | 4 +- {src => humility-arch-cortex/src}/itm.rs | 4 +- humility-arch-cortex/src/lib.rs | 17 +++ {src => humility-arch-cortex/src}/scs.rs | 6 +- {src => humility-arch-cortex/src}/swo.rs | 2 +- {src => humility-arch-cortex/src}/tpiu.rs | 4 +- humility-core/Cargo.toml | 2 +- humility-core/src/arch.rs | 67 +++++++++ humility-core/src/core.rs | 2 +- humility-core/src/hubris.rs | 2 +- humility-core/src/lib.rs | 13 ++ src/cmd.rs | 136 ++---------------- src/cmd/etm.rs | 8 +- src/cmd/itm.rs | 10 +- src/cmd/probe.rs | 7 +- src/cmd/stmsecure.rs | 2 +- src/cmd/tasks.rs | 2 +- src/cmd/test.rs | 2 +- src/cmd/trace.rs | 2 +- src/main.rs | 57 +------- 27 files changed, 218 insertions(+), 309 deletions(-) create mode 100644 cmd/apptable/Cargo.toml rename src/cmd/apptable.rs => cmd/apptable/src/lib.rs (98%) create mode 100644 humility-arch-cortex/Cargo.toml rename {humility-core => humility-arch-cortex}/src/debug.rs (90%) rename {src => humility-arch-cortex/src}/dwt.rs (96%) rename {src => humility-arch-cortex/src}/etm.rs (99%) rename {src => humility-arch-cortex/src}/itm.rs (99%) create mode 100644 humility-arch-cortex/src/lib.rs rename {src => humility-arch-cortex/src}/scs.rs (99%) rename {src => humility-arch-cortex/src}/swo.rs (98%) rename {src => humility-arch-cortex/src}/tpiu.rs (99%) create mode 100644 humility-core/src/arch.rs create mode 100644 humility-core/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index a3a58b792..bf0ce4a6f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -42,10 +42,14 @@ dependencies = [ ] [[package]] -name = "arrayvec" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" +name = "apptable" +version = "0.1.0" +dependencies = [ + "anyhow", + "humility-cmd", + "humility-core", + "structopt", +] [[package]] name = "atomic-polyfill" @@ -423,20 +427,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "gimli" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81dd6190aad0f05ddbbf3245c54ed14ca4aa6dd32f22312b70d8f168c3e3e633" -dependencies = [ - "arrayvec", - "byteorder", - "fallible-iterator", - "indexmap", - "smallvec", - "stable_deref_trait", -] - [[package]] name = "gimli" version = "0.22.0" @@ -535,13 +525,16 @@ name = "humility" version = "0.5.0" dependencies = [ "anyhow", + "apptable", "bitfield", "clap", "colored", "csv", "fallible-iterator", "hif", + "humility-cmd", "humility-core", + "humility-cortex", "humility_load_derive", "idt8a3xxxx", "indexmap", @@ -553,7 +546,6 @@ dependencies = [ "num-derive", "num-traits", "parse_int", - "paste", "pmbus", "postcard", "scroll", @@ -563,6 +555,16 @@ dependencies = [ "toml", ] +[[package]] +name = "humility-cmd" +version = "0.1.0" +dependencies = [ + "anyhow", + "clap", + "humility-core", + "structopt", +] + [[package]] name = "humility-core" version = "0.1.0" @@ -571,7 +573,7 @@ dependencies = [ "bitfield", "capstone", "fallible-iterator", - "gimli 0.20.0", + "gimli 0.22.0", "goblin", "indexmap", "indicatif", @@ -589,6 +591,21 @@ dependencies = [ "zip", ] +[[package]] +name = "humility-cortex" +version = "0.1.0" +dependencies = [ + "anyhow", + "bitfield", + "humility-core", + "jep106", + "log", + "multimap", + "num-derive", + "num-traits", + "paste", +] + [[package]] name = "humility_load_derive" version = "0.1.0" @@ -1205,12 +1222,6 @@ dependencies = [ "yaml-rust", ] -[[package]] -name = "smallvec" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" - [[package]] name = "spd" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 9365906c0..fb81aca50 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,14 @@ authors = ["Bryan Cantrill "] edition = "2018" license = "MPL-2.0" +[workspace] +members = [ + "humility-core", + "humility-cmd", + "humility-arch-cortex", + "cmd/apptable" +] + [profile.release] debug = true @@ -15,6 +23,9 @@ spd = { path = "./spd" } idt8a3xxxx = { path = "./idt8a3xxxx" } humility_load_derive = {path = "./load_derive"} humility = { path = "./humility-core", package = "humility-core" } +humility-cortex = { path = "./humility-arch-cortex" } +humility-cmd = { path = "./humility-cmd" } +cmd-apptable = { path = "./cmd/apptable", package = "apptable" } fallible-iterator = "0.2.0" log = {version = "0.4.8", features = ["std"]} @@ -27,7 +38,6 @@ structopt = "0.3" multimap = "0.8.1" num-traits = "0.2" num-derive = "0.3" -paste = "0.1" jep106 = "0.2" toml = "0.5" anyhow = { version = "1.0.44", features = ["backtrace"] } diff --git a/cmd/apptable/Cargo.toml b/cmd/apptable/Cargo.toml new file mode 100644 index 000000000..e97d85811 --- /dev/null +++ b/cmd/apptable/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "apptable" +version = "0.1.0" +edition = "2021" + +[dependencies] +humility = { path = "../../humility-core", package = "humility-core" } +humility-cmd = { path = "../../humility-cmd" } +structopt = "0.3" +anyhow = { version = "1.0.44", features = ["backtrace"] } + diff --git a/src/cmd/apptable.rs b/cmd/apptable/src/lib.rs similarity index 98% rename from src/cmd/apptable.rs rename to cmd/apptable/src/lib.rs index 1ae8b7a70..c19174a10 100644 --- a/src/cmd/apptable.rs +++ b/cmd/apptable/src/lib.rs @@ -2,8 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::cmd::{Archive, Command}; -use crate::Args; +use humility_cmd::{Args, Archive, Command}; use anyhow::{bail, Result}; use humility::hubris::{HubrisArchive, HubrisPrintFormat}; use std::convert::TryInto; diff --git a/humility-arch-cortex/Cargo.toml b/humility-arch-cortex/Cargo.toml new file mode 100644 index 000000000..3d90f2996 --- /dev/null +++ b/humility-arch-cortex/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "humility-cortex" +version = "0.1.0" +edition = "2021" + +[dependencies] +humility = { path = "../humility-core", package = "humility-core" } +anyhow = { version = "1.0.44", features = ["backtrace"] } +bitfield = "0.13.2" +multimap = "0.8.1" +paste = "0.1" +num-traits = "0.2" +num-derive = "0.3" +jep106 = "0.2" +log = {version = "0.4.8", features = ["std"]} diff --git a/humility-core/src/debug.rs b/humility-arch-cortex/src/debug.rs similarity index 90% rename from humility-core/src/debug.rs rename to humility-arch-cortex/src/debug.rs index 9b21da562..1ef5143e2 100644 --- a/humility-core/src/debug.rs +++ b/humility-arch-cortex/src/debug.rs @@ -4,8 +4,8 @@ use anyhow::{anyhow, Result}; -use crate::hubris::*; -use crate::core::Core; +use humility::hubris::*; +use humility::core::Core; use bitfield::bitfield; pub trait Register: @@ -414,70 +414,6 @@ pub enum ARMCore { CortexR52 = 0xd13, } -#[allow(non_camel_case_types)] -#[derive( - Copy, Clone, Debug, Hash, FromPrimitive, ToPrimitive, PartialEq, Eq, -)] -pub enum ARMRegister { - R0 = 0, - R1, - R2, - R3, - R4, - R5, - R6, - R7, - R8, - R9, - R10, - R11, - R12, - SP = 0b1101, - LR = 0b1110, - PC = 0b1111, - xPSR = 0b1_0000, - MSP = 0b1_0001, - PSP = 0b1_0010, - SPR = 0b1_0100, - FPSCR = 0b10_0001, -} - -use capstone::prelude::*; - -impl From for ARMRegister { - fn from(reg: RegId) -> Self { - use arch::arm::ArmReg::*; - - match reg.0 as u32 { - ARM_REG_R0 => ARMRegister::R0, - ARM_REG_R1 => ARMRegister::R1, - ARM_REG_R2 => ARMRegister::R2, - ARM_REG_R3 => ARMRegister::R3, - ARM_REG_R4 => ARMRegister::R4, - ARM_REG_R5 => ARMRegister::R5, - ARM_REG_R6 => ARMRegister::R6, - ARM_REG_R7 => ARMRegister::R7, - ARM_REG_R8 => ARMRegister::R8, - ARM_REG_R9 => ARMRegister::R9, - ARM_REG_R10 => ARMRegister::R10, - ARM_REG_R11 => ARMRegister::R11, - ARM_REG_R12 => ARMRegister::R12, - ARM_REG_SP => ARMRegister::SP, - ARM_REG_PC => ARMRegister::PC, - ARM_REG_LR => ARMRegister::LR, - _ => { - panic!("unrecognized register {:x}", reg.0); - } - } - } -} - -impl std::fmt::Display for ARMRegister { - fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - formatter.pad(&format!("{:?}", self)) - } -} - pub fn corename(partno: ARMCore) -> String { match partno { ARMCore::CortexA5 => "Cortex-A5", @@ -577,7 +513,7 @@ pub fn stm32_chipname(partno: u32) -> String { pub fn swoscaler( hubris: &HubrisArchive, - core: &mut dyn crate::core::Core, + core: &mut dyn Core, ) -> Result { let debug_clock_mhz = 2_000_000; diff --git a/src/dwt.rs b/humility-arch-cortex/src/dwt.rs similarity index 96% rename from src/dwt.rs rename to humility-arch-cortex/src/dwt.rs index 75833b4ad..22ccb678e 100644 --- a/src/dwt.rs +++ b/humility-arch-cortex/src/dwt.rs @@ -4,8 +4,8 @@ use bitfield::bitfield; use humility::core::Core; -use humility::debug::Register; -use humility::register; +use crate::debug::Register; +use crate::register; /* * DWT Control Register diff --git a/src/etm.rs b/humility-arch-cortex/src/etm.rs similarity index 99% rename from src/etm.rs rename to humility-arch-cortex/src/etm.rs index d9c14068b..2d102bd66 100644 --- a/src/etm.rs +++ b/humility-arch-cortex/src/etm.rs @@ -6,8 +6,8 @@ use crate::tpiu::*; use anyhow::Result; use bitfield::bitfield; use humility::core::Core; -use humility::debug::Register; -use humility::register; +use crate::debug::Register; +use crate::register; macro_rules! etm_register { ($reg:ty, $offs:expr, $($arg:tt)*) => ( diff --git a/src/itm.rs b/humility-arch-cortex/src/itm.rs similarity index 99% rename from src/itm.rs rename to humility-arch-cortex/src/itm.rs index f878e0a80..7ada8b7be 100644 --- a/src/itm.rs +++ b/humility-arch-cortex/src/itm.rs @@ -9,9 +9,9 @@ use crate::tpiu::*; use anyhow::Result; use bitfield::bitfield; use humility::core::Core; -use humility::debug::*; +use crate::debug::*; use humility::hubris::HubrisArchive; -use humility::register; +use crate::register; /* * ITM Trace Enable Register diff --git a/humility-arch-cortex/src/lib.rs b/humility-arch-cortex/src/lib.rs new file mode 100644 index 000000000..72fdc0f27 --- /dev/null +++ b/humility-arch-cortex/src/lib.rs @@ -0,0 +1,17 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +pub mod debug; +pub mod dwt; +pub mod etm; +pub mod itm; +pub mod scs; +pub mod swo; +pub mod tpiu; + +#[macro_use] +extern crate num_derive; + +#[macro_use] +extern crate log; diff --git a/src/scs.rs b/humility-arch-cortex/src/scs.rs similarity index 99% rename from src/scs.rs rename to humility-arch-cortex/src/scs.rs index 621dd9b10..29c2979f6 100644 --- a/src/scs.rs +++ b/humility-arch-cortex/src/scs.rs @@ -5,9 +5,9 @@ use anyhow::{bail, Result}; use bitfield::bitfield; use humility::core::Core; -use humility::debug::*; -use humility::register; -use humility::register_offs; +use crate::debug::*; +use crate::register; +use crate::register_offs; use multimap::MultiMap; use std::mem::size_of; diff --git a/src/swo.rs b/humility-arch-cortex/src/swo.rs similarity index 98% rename from src/swo.rs rename to humility-arch-cortex/src/swo.rs index d680840f0..941f10027 100644 --- a/src/swo.rs +++ b/humility-arch-cortex/src/swo.rs @@ -5,7 +5,7 @@ use anyhow::Result; use humility::core::Core; -use humility::register_offs; +use crate::register_offs; use num_traits::FromPrimitive; use num_traits::ToPrimitive; diff --git a/src/tpiu.rs b/humility-arch-cortex/src/tpiu.rs similarity index 99% rename from src/tpiu.rs rename to humility-arch-cortex/src/tpiu.rs index a2982cbcb..80da8741a 100644 --- a/src/tpiu.rs +++ b/humility-arch-cortex/src/tpiu.rs @@ -5,8 +5,8 @@ use anyhow::Result; use bitfield::bitfield; use humility::core::Core; -use humility::debug::Register; -use humility::register; +use crate::debug::Register; +use crate::register; register!(TPIU_SSPSR, 0xe004_0000, #[derive(Copy, Clone)] diff --git a/humility-core/Cargo.toml b/humility-core/Cargo.toml index d943d4234..f313c2b95 100644 --- a/humility-core/Cargo.toml +++ b/humility-core/Cargo.toml @@ -10,7 +10,7 @@ goblin = "0.2.1" capstone = "0.8.0" rustc-demangle = "0.1.21" anyhow = { version = "1.0.44", features = ["backtrace"] } -gimli = "0.20.0" +gimli = "0.22.0" fallible-iterator = "0.2.0" indexmap = { version = "1.7", features = ["serde-1"] } scroll = "0.10" diff --git a/humility-core/src/arch.rs b/humility-core/src/arch.rs new file mode 100644 index 000000000..2bac6f30c --- /dev/null +++ b/humility-core/src/arch.rs @@ -0,0 +1,67 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#[allow(non_camel_case_types)] +#[derive( + Copy, Clone, Debug, Hash, FromPrimitive, ToPrimitive, PartialEq, Eq, +)] +pub enum ARMRegister { + R0 = 0, + R1, + R2, + R3, + R4, + R5, + R6, + R7, + R8, + R9, + R10, + R11, + R12, + SP = 0b1101, + LR = 0b1110, + PC = 0b1111, + xPSR = 0b1_0000, + MSP = 0b1_0001, + PSP = 0b1_0010, + SPR = 0b1_0100, + FPSCR = 0b10_0001, +} + +use capstone::prelude::*; + +impl From for ARMRegister { + fn from(reg: RegId) -> Self { + use arch::arm::ArmReg::*; + + match reg.0 as u32 { + ARM_REG_R0 => ARMRegister::R0, + ARM_REG_R1 => ARMRegister::R1, + ARM_REG_R2 => ARMRegister::R2, + ARM_REG_R3 => ARMRegister::R3, + ARM_REG_R4 => ARMRegister::R4, + ARM_REG_R5 => ARMRegister::R5, + ARM_REG_R6 => ARMRegister::R6, + ARM_REG_R7 => ARMRegister::R7, + ARM_REG_R8 => ARMRegister::R8, + ARM_REG_R9 => ARMRegister::R9, + ARM_REG_R10 => ARMRegister::R10, + ARM_REG_R11 => ARMRegister::R11, + ARM_REG_R12 => ARMRegister::R12, + ARM_REG_SP => ARMRegister::SP, + ARM_REG_PC => ARMRegister::PC, + ARM_REG_LR => ARMRegister::LR, + _ => { + panic!("unrecognized register {:x}", reg.0); + } + } + } +} + +impl std::fmt::Display for ARMRegister { + fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + formatter.pad(&format!("{:?}", self)) + } +} diff --git a/humility-core/src/core.rs b/humility-core/src/core.rs index 5ca189af4..34afc1a79 100644 --- a/humility-core/src/core.rs +++ b/humility-core/src/core.rs @@ -7,7 +7,7 @@ use probe_rs::Probe; use anyhow::{anyhow, bail, ensure, Result}; -use crate::debug::*; +use crate::arch::ARMRegister; use crate::hubris::*; use std::collections::BTreeMap; use std::collections::HashMap; diff --git a/humility-core/src/hubris.rs b/humility-core/src/hubris.rs index 341cde16f..f6dff5aa1 100644 --- a/humility-core/src/hubris.rs +++ b/humility-core/src/hubris.rs @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::debug::*; +use crate::arch::ARMRegister; use capstone::prelude::*; use indexmap::IndexMap; use serde::Deserialize; diff --git a/humility-core/src/lib.rs b/humility-core/src/lib.rs new file mode 100644 index 000000000..6214bbd3e --- /dev/null +++ b/humility-core/src/lib.rs @@ -0,0 +1,13 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +pub mod hubris; +pub mod core; +pub mod arch; + +#[macro_use] +extern crate num_derive; + +#[macro_use] +extern crate log; diff --git a/src/cmd.rs b/src/cmd.rs index 537024218..fb35b8545 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -2,7 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -mod apptable; +// mod apptable; +/* mod diagnose; mod dump; mod etm; @@ -28,60 +29,18 @@ mod stmsecure; mod tasks; mod test; mod trace; +*/ -use crate::Args; +use humility_cmd::Args; use crate::{attach_dump, attach_live}; use anyhow::{bail, Result}; use humility::core::Core; use humility::hubris::*; +use humility_cmd::{Archive, Attach, Validate, Command}; use std::collections::HashMap; use std::convert::TryInto; use structopt::clap::App; -#[allow(dead_code)] -#[derive(Copy, Clone, Debug)] -pub enum Archive { - Required, - Optional, - Prohibited, -} - -#[allow(dead_code)] -#[derive(Copy, Clone, Debug)] -pub enum Attach { - LiveOnly, - DumpOnly, - Any, -} - -#[allow(dead_code)] -#[derive(Copy, Clone, Debug)] -pub enum Validate { - Match, - Booted, - None, -} - -pub enum Command { - Attached { - name: &'static str, - archive: Archive, - attach: Attach, - validate: Validate, - run: fn( - &mut HubrisArchive, - &mut dyn Core, - &Args, - &Vec, - ) -> Result<()>, - }, - Unattached { - name: &'static str, - archive: Archive, - run: fn(&mut HubrisArchive, &Args, &Vec) -> Result<()>, - }, -} - pub fn init<'a, 'b>( app: App<'a, 'b>, ) -> (HashMap<&'static str, Command>, App<'a, 'b>) { @@ -89,7 +48,8 @@ pub fn init<'a, 'b>( let mut rval = app; let dcmds = [ - apptable::init, + cmd_apptable::init, + /* diagnose::init, dump::init, etm::init, @@ -115,6 +75,7 @@ pub fn init<'a, 'b>( test::init, trace::init, stmsecure::init, + */ ]; for dcmd in &dcmds { @@ -190,84 +151,3 @@ pub fn subcommand( bail!("command {} not found", subargs[0]); } } - -fn printmem(bytes: &[u8], addr: u32, size: usize, width: usize) { - let mut addr = addr; - - let print = |line: &[u8], addr, offs| { - print!("0x{:08x} | ", addr); - - for i in (0..width).step_by(size) { - if i < offs || i - offs >= line.len() { - print!(" {:width$}", "", width = size * 2); - continue; - } - - let slice = &line[i - offs..i - offs + size]; - - print!( - "{:0width$x} ", - match size { - 1 => line[i - offs] as u32, - 2 => u16::from_le_bytes(slice.try_into().unwrap()) as u32, - 4 => u32::from_le_bytes(slice.try_into().unwrap()) as u32, - _ => { - panic!("invalid size"); - } - }, - width = size * 2 - ); - } - - print!("| "); - - for i in 0..width { - if i < offs || i - offs >= line.len() { - print!(" "); - } else { - let c = line[i - offs] as char; - - if c.is_ascii() && !c.is_ascii_control() { - print!("{}", c); - } else { - print!("."); - } - } - } - - println!(); - }; - - let offs = (addr & (width - 1) as u32) as usize; - addr -= offs as u32; - - /* - * Print out header line, OpenBoot PROM style - */ - print!(" {:8} ", ""); - - for i in (0..width).step_by(size) { - if i == offs { - print!(" {:>width$}", "\\/", width = size * 2); - } else { - print!(" {:>width$x}", i, width = size * 2); - } - } - - println!(); - - /* - * Print our first line. - */ - let lim = std::cmp::min(width - offs, bytes.len()); - print(&bytes[0..lim], addr, offs); - - if lim < bytes.len() { - let lines = bytes[lim..].chunks(width); - - for line in lines { - addr += width as u32; - print(line, addr, 0); - } - } -} diff --git a/src/cmd/etm.rs b/src/cmd/etm.rs index 60b70b9b2..1f333f440 100644 --- a/src/cmd/etm.rs +++ b/src/cmd/etm.rs @@ -4,13 +4,13 @@ use crate::attach_live; use crate::cmd::{Archive, Command}; -use crate::etm::*; -use crate::scs::*; -use crate::tpiu::*; +use humility_cortex::etm::*; +use humility_cortex::scs::*; +use humility_cortex::tpiu::*; use crate::Args; use anyhow::{bail, Result}; use humility::core::Core; -use humility::debug::*; +use humility_cortex::debug::*; use humility::hubris::*; use std::fs::File; use std::time::Instant; diff --git a/src/cmd/itm.rs b/src/cmd/itm.rs index d0c64b3c7..2b5706fd4 100644 --- a/src/cmd/itm.rs +++ b/src/cmd/itm.rs @@ -4,14 +4,14 @@ use crate::attach_live; use crate::cmd::{Archive, Command}; -use crate::dwt::*; -use crate::itm::*; -use crate::scs::*; -use crate::tpiu::*; +use humility_cortex::dwt::*; +use humility_cortex::itm::*; +use humility_cortex::scs::*; +use humility_cortex::tpiu::*; use crate::Args; use anyhow::{bail, Result}; use humility::core::Core; -use humility::debug::*; +use humility_cortex::debug::*; use humility::hubris::*; use std::fs::File; use std::io::Read; diff --git a/src/cmd/probe.rs b/src/cmd/probe.rs index 8ca581443..5fe0d4e3d 100644 --- a/src/cmd/probe.rs +++ b/src/cmd/probe.rs @@ -3,12 +3,13 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use crate::cmd::*; -use crate::itm::*; -use crate::scs::*; +use humility_cortex::itm::*; +use humility_cortex::scs::*; use crate::Args; use anyhow::Result; use humility::core::Core; -use humility::debug::*; +use humility::arch::ARMRegister; +use humility_cortex::debug::*; use humility::hubris::*; use structopt::clap::App; use structopt::StructOpt; diff --git a/src/cmd/stmsecure.rs b/src/cmd/stmsecure.rs index 4c9443b72..45d8dd681 100644 --- a/src/cmd/stmsecure.rs +++ b/src/cmd/stmsecure.rs @@ -6,7 +6,7 @@ use crate::cmd::*; use crate::Args; use anyhow::{anyhow, Result}; use humility::core::Core; -use humility::debug::ARMRegister; +use humility::arch::ARMRegister; use structopt::clap::App; use structopt::StructOpt; diff --git a/src/cmd/tasks.rs b/src/cmd/tasks.rs index cd566754d..ccb602302 100644 --- a/src/cmd/tasks.rs +++ b/src/cmd/tasks.rs @@ -8,7 +8,7 @@ use crate::reflect::{self, Format, Load}; use crate::Args; use anyhow::{bail, Result}; use humility::core::Core; -use humility::debug::*; +use humility::arch::ARMRegister; use humility::hubris::*; use num_traits::FromPrimitive; use std::collections::HashMap; diff --git a/src/cmd/test.rs b/src/cmd/test.rs index 12aa65d7b..4e40428a7 100644 --- a/src/cmd/test.rs +++ b/src/cmd/test.rs @@ -3,7 +3,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use crate::cmd::*; -use crate::itm::*; +use humility_cortex::itm::*; use crate::test::*; use crate::Args; use anyhow::{bail, Context, Result}; diff --git a/src/cmd/trace.rs b/src/cmd/trace.rs index 7c62f16db..dd2d59129 100644 --- a/src/cmd/trace.rs +++ b/src/cmd/trace.rs @@ -3,7 +3,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use crate::cmd::*; -use crate::itm::*; +use humility_cortex::itm::*; use crate::Args; use anyhow::{anyhow, Result}; use humility::core::Core; diff --git a/src/main.rs b/src/main.rs index 9681af504..057ab1b85 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,26 +5,18 @@ #[macro_use] extern crate log; -#[macro_use] -extern crate num_derive; - use anyhow::{bail, Result}; -use structopt::StructOpt; - use humility::core::Core; use humility::hubris::*; +use humility_cmd::{Args, Subcommand}; + +use structopt::StructOpt; mod cmd; -mod dwt; -mod etm; mod hiffy; mod i2c; -mod itm; -mod scs; -mod swo; mod test; -mod tpiu; mod doppel; mod reflect; @@ -112,49 +104,6 @@ fn attach_dump(args: &Args, hubris: &HubrisArchive) -> Result> { } } -#[derive(StructOpt)] -#[structopt(name = "humility", max_term_width = 80)] -pub struct Args { - /// verbose messages - #[structopt(long, short)] - verbose: bool, - - /// specific chip on attached device - #[structopt( - long, - short, - env = "HUMILITY_CHIP", - default_value = "STM32F407VGTx" - )] - chip: String, - - /// chip probe to use - #[structopt(long, short, env = "HUMILITY_PROBE", conflicts_with = "dump")] - probe: Option, - - /// Hubris archive - #[structopt( - long, - short, - env = "HUMILITY_ARCHIVE", - conflicts_with = "dump" - )] - archive: Option, - - /// Hubris dump - #[structopt(long, short, env = "HUMILITY_DUMP")] - dump: Option, - - #[structopt(subcommand)] - cmd: Subcommand, -} - -#[derive(StructOpt)] -enum Subcommand { - #[structopt(external_subcommand)] - Other(Vec), -} - fn main() { /* * This isn't hugely efficient, but we actually parse our arguments From 90fb49e96573f2337c8490e73c5ecc9932380c8d Mon Sep 17 00:00:00 2001 From: Bryan Cantrill Date: Thu, 2 Dec 2021 00:48:16 -0800 Subject: [PATCH 3/3] second cut: ~22.6s -> ~6.3s --- Cargo.lock | 365 +++++++++++++++++- Cargo.toml | 58 ++- cmd/apptable/Cargo.toml | 3 +- cmd/apptable/src/lib.rs | 2 +- cmd/diagnose/Cargo.toml | 11 + .../diagnose.rs => cmd/diagnose/src/lib.rs | 11 +- cmd/dump/Cargo.toml | 11 + src/cmd/dump.rs => cmd/dump/src/lib.rs | 7 +- cmd/etm/Cargo.toml | 14 + src/cmd/etm.rs => cmd/etm/src/lib.rs | 17 +- cmd/gpio/Cargo.toml | 12 + src/cmd/gpio.rs => cmd/gpio/src/lib.rs | 9 +- cmd/hiffy/Cargo.toml | 12 + src/cmd/hiffy.rs => cmd/hiffy/src/lib.rs | 7 +- cmd/i2c/Cargo.toml | 14 + src/cmd/i2c.rs => cmd/i2c/src/lib.rs | 18 +- cmd/itm/Cargo.toml | 14 + src/cmd/itm.rs => cmd/itm/src/lib.rs | 16 +- cmd/jefe/Cargo.toml | 12 + cmd/jefe/src/lib.rs | 101 +++++ cmd/manifest/Cargo.toml | 10 + .../manifest.rs => cmd/manifest/src/lib.rs | 3 +- cmd/map/Cargo.toml | 10 + src/cmd/map.rs => cmd/map/src/lib.rs | 3 +- cmd/pmbus/Cargo.toml | 16 + src/cmd/pmbus.rs => cmd/pmbus/src/lib.rs | 29 +- cmd/probe/Cargo.toml | 13 + src/cmd/probe.rs => cmd/probe/src/lib.rs | 14 +- cmd/qspi/Cargo.toml | 14 + src/cmd/qspi.rs => cmd/qspi/src/lib.rs | 14 +- cmd/readmem/Cargo.toml | 11 + src/cmd/readmem.rs => cmd/readmem/src/lib.rs | 4 +- cmd/readvar/Cargo.toml | 10 + src/cmd/readvar.rs => cmd/readvar/src/lib.rs | 3 +- cmd/renbb/Cargo.toml | 15 + src/cmd/renbb.rs => cmd/renbb/src/lib.rs | 17 +- cmd/rencm/Cargo.toml | 15 + src/cmd/rencm.rs => cmd/rencm/src/lib.rs | 15 +- cmd/ringbuf/Cargo.toml | 11 + src/cmd/ringbuf.rs => cmd/ringbuf/src/lib.rs | 10 +- cmd/spd/Cargo.toml | 15 + src/cmd/spd.rs => cmd/spd/src/lib.rs | 15 +- cmd/spi/Cargo.toml | 13 + src/cmd/spi.rs => cmd/spi/src/lib.rs | 15 +- cmd/stackmargin/Cargo.toml | 10 + .../stackmargin/src/lib.rs | 3 +- cmd/stmsecure/Cargo.toml | 11 + .../stmsecure.rs => cmd/stmsecure/src/lib.rs | 6 +- cmd/tasks/Cargo.toml | 11 + src/cmd/tasks.rs => cmd/tasks/src/lib.rs | 15 +- cmd/test/Cargo.toml | 11 + src/cmd/test.rs => cmd/test/src/lib.rs | 7 +- cmd/trace/Cargo.toml | 11 + src/cmd/trace.rs => cmd/trace/src/lib.rs | 5 +- humility-arch-cortex/src/debug.rs | 9 +- humility-arch-cortex/src/dwt.rs | 4 +- humility-arch-cortex/src/etm.rs | 4 +- humility-arch-cortex/src/itm.rs | 4 +- humility-arch-cortex/src/scs.rs | 6 +- humility-arch-cortex/src/swo.rs | 2 +- humility-arch-cortex/src/tpiu.rs | 4 +- {src => humility-cmd/src}/doppel.rs | 0 {src => humility-cmd/src}/hiffy.rs | 0 {src => humility-cmd/src}/i2c.rs | 0 {src => humility-cmd/src}/reflect.rs | 0 {src => humility-cmd/src}/test.rs | 0 humility-core/src/lib.rs | 4 +- load_derive/src/lib.rs | 51 ++- src/cmd.rs | 90 ++--- src/cmd/jefe.rs | 241 ------------ src/main.rs | 33 -- 71 files changed, 1031 insertions(+), 520 deletions(-) create mode 100644 cmd/diagnose/Cargo.toml rename src/cmd/diagnose.rs => cmd/diagnose/src/lib.rs (98%) create mode 100644 cmd/dump/Cargo.toml rename src/cmd/dump.rs => cmd/dump/src/lib.rs (90%) create mode 100644 cmd/etm/Cargo.toml rename src/cmd/etm.rs => cmd/etm/src/lib.rs (99%) create mode 100644 cmd/gpio/Cargo.toml rename src/cmd/gpio.rs => cmd/gpio/src/lib.rs (97%) create mode 100644 cmd/hiffy/Cargo.toml rename src/cmd/hiffy.rs => cmd/hiffy/src/lib.rs (94%) create mode 100644 cmd/i2c/Cargo.toml rename src/cmd/i2c.rs => cmd/i2c/src/lib.rs (98%) create mode 100644 cmd/itm/Cargo.toml rename src/cmd/itm.rs => cmd/itm/src/lib.rs (98%) create mode 100644 cmd/jefe/Cargo.toml create mode 100644 cmd/jefe/src/lib.rs create mode 100644 cmd/manifest/Cargo.toml rename src/cmd/manifest.rs => cmd/manifest/src/lib.rs (93%) create mode 100644 cmd/map/Cargo.toml rename src/cmd/map.rs => cmd/map/src/lib.rs (96%) create mode 100644 cmd/pmbus/Cargo.toml rename src/cmd/pmbus.rs => cmd/pmbus/src/lib.rs (98%) create mode 100644 cmd/probe/Cargo.toml rename src/cmd/probe.rs => cmd/probe/src/lib.rs (98%) create mode 100644 cmd/qspi/Cargo.toml rename src/cmd/qspi.rs => cmd/qspi/src/lib.rs (97%) create mode 100644 cmd/readmem/Cargo.toml rename src/cmd/readmem.rs => cmd/readmem/src/lib.rs (97%) create mode 100644 cmd/readvar/Cargo.toml rename src/cmd/readvar.rs => cmd/readvar/src/lib.rs (97%) create mode 100644 cmd/renbb/Cargo.toml rename src/cmd/renbb.rs => cmd/renbb/src/lib.rs (96%) create mode 100644 cmd/rencm/Cargo.toml rename src/cmd/rencm.rs => cmd/rencm/src/lib.rs (98%) create mode 100644 cmd/ringbuf/Cargo.toml rename src/cmd/ringbuf.rs => cmd/ringbuf/src/lib.rs (95%) create mode 100644 cmd/spd/Cargo.toml rename src/cmd/spd.rs => cmd/spd/src/lib.rs (97%) create mode 100644 cmd/spi/Cargo.toml rename src/cmd/spi.rs => cmd/spi/src/lib.rs (96%) create mode 100644 cmd/stackmargin/Cargo.toml rename src/cmd/stackmargin.rs => cmd/stackmargin/src/lib.rs (98%) create mode 100644 cmd/stmsecure/Cargo.toml rename src/cmd/stmsecure.rs => cmd/stmsecure/src/lib.rs (99%) create mode 100644 cmd/tasks/Cargo.toml rename src/cmd/tasks.rs => cmd/tasks/src/lib.rs (98%) create mode 100644 cmd/test/Cargo.toml rename src/cmd/test.rs => cmd/test/src/lib.rs (98%) create mode 100644 cmd/trace/Cargo.toml rename src/cmd/trace.rs => cmd/trace/src/lib.rs (99%) rename {src => humility-cmd/src}/doppel.rs (100%) rename {src => humility-cmd/src}/hiffy.rs (100%) rename {src => humility-cmd/src}/i2c.rs (100%) rename {src => humility-cmd/src}/reflect.rs (100%) rename {src => humility-cmd/src}/test.rs (100%) delete mode 100644 src/cmd/jefe.rs diff --git a/Cargo.lock b/Cargo.lock index bf0ce4a6f..5045b2ae5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -41,16 +41,6 @@ dependencies = [ "backtrace", ] -[[package]] -name = "apptable" -version = "0.1.0" -dependencies = [ - "anyhow", - "humility-cmd", - "humility-core", - "structopt", -] - [[package]] name = "atomic-polyfill" version = "0.1.2" @@ -525,7 +515,6 @@ name = "humility" version = "0.5.0" dependencies = [ "anyhow", - "apptable", "bitfield", "clap", "colored", @@ -533,13 +522,36 @@ dependencies = [ "fallible-iterator", "hif", "humility-cmd", + "humility-cmd-apptable", + "humility-cmd-diagnose", + "humility-cmd-dump", + "humility-cmd-etm", + "humility-cmd-gpio", + "humility-cmd-hiffy", + "humility-cmd-i2c", + "humility-cmd-itm", + "humility-cmd-jefe", + "humility-cmd-manifest", + "humility-cmd-map", + "humility-cmd-pmbus", + "humility-cmd-probe", + "humility-cmd-qspi", + "humility-cmd-readmem", + "humility-cmd-readvar", + "humility-cmd-renbb", + "humility-cmd-rencm", + "humility-cmd-ringbuf", + "humility-cmd-spd", + "humility-cmd-spi", + "humility-cmd-stackmargin", + "humility-cmd-stmsecure", + "humility-cmd-tasks", + "humility-cmd-test", + "humility-cmd-trace", "humility-core", "humility-cortex", - "humility_load_derive", - "idt8a3xxxx", "indexmap", "indicatif", - "itertools", "jep106", "log", "multimap", @@ -547,7 +559,6 @@ dependencies = [ "num-traits", "parse_int", "pmbus", - "postcard", "scroll", "serde", "spd", @@ -561,10 +572,334 @@ version = "0.1.0" dependencies = [ "anyhow", "clap", + "colored", + "hif", + "humility-core", + "humility_load_derive", + "indexmap", + "log", + "parse_int", + "postcard", + "structopt", +] + +[[package]] +name = "humility-cmd-apptable" +version = "0.1.0" +dependencies = [ + "anyhow", + "humility-cmd", + "humility-core", + "structopt", +] + +[[package]] +name = "humility-cmd-diagnose" +version = "0.1.0" +dependencies = [ + "anyhow", + "humility-cmd", + "humility-core", + "parse_int", + "structopt", +] + +[[package]] +name = "humility-cmd-dump" +version = "0.1.0" +dependencies = [ + "anyhow", + "humility-cmd", + "humility-core", + "log", + "structopt", +] + +[[package]] +name = "humility-cmd-etm" +version = "0.1.0" +dependencies = [ + "anyhow", + "csv", + "humility-cmd", + "humility-core", + "humility-cortex", + "log", + "parse_int", + "structopt", +] + +[[package]] +name = "humility-cmd-gpio" +version = "0.1.0" +dependencies = [ + "anyhow", + "hif", + "humility-cmd", + "humility-core", + "parse_int", + "structopt", +] + +[[package]] +name = "humility-cmd-hiffy" +version = "0.1.0" +dependencies = [ + "anyhow", + "hif", + "humility-cmd", + "humility-core", + "parse_int", + "structopt", +] + +[[package]] +name = "humility-cmd-i2c" +version = "0.1.0" +dependencies = [ + "anyhow", + "hif", + "humility-cmd", + "humility-core", + "indicatif", + "log", + "parse_int", + "structopt", +] + +[[package]] +name = "humility-cmd-itm" +version = "0.1.0" +dependencies = [ + "anyhow", + "csv", + "humility-cmd", + "humility-core", + "humility-cortex", + "log", + "parse_int", + "structopt", +] + +[[package]] +name = "humility-cmd-jefe" +version = "0.1.0" +dependencies = [ + "anyhow", + "humility-cmd", + "humility-core", + "log", + "parse_int", + "structopt", +] + +[[package]] +name = "humility-cmd-manifest" +version = "0.1.0" +dependencies = [ + "anyhow", + "humility-cmd", "humility-core", "structopt", ] +[[package]] +name = "humility-cmd-map" +version = "0.1.0" +dependencies = [ + "anyhow", + "humility-cmd", + "humility-core", + "structopt", +] + +[[package]] +name = "humility-cmd-pmbus" +version = "0.1.0" +dependencies = [ + "anyhow", + "colored", + "hif", + "humility-cmd", + "humility-core", + "indexmap", + "log", + "parse_int", + "pmbus", + "structopt", +] + +[[package]] +name = "humility-cmd-probe" +version = "0.1.0" +dependencies = [ + "anyhow", + "humility-cmd", + "humility-core", + "humility-cortex", + "log", + "num-traits", + "structopt", +] + +[[package]] +name = "humility-cmd-qspi" +version = "0.1.0" +dependencies = [ + "anyhow", + "hif", + "humility-cmd", + "humility-core", + "indicatif", + "log", + "parse_int", + "structopt", +] + +[[package]] +name = "humility-cmd-readmem" +version = "0.1.0" +dependencies = [ + "anyhow", + "humility-cmd", + "humility-core", + "parse_int", + "structopt", +] + +[[package]] +name = "humility-cmd-readvar" +version = "0.1.0" +dependencies = [ + "anyhow", + "humility-cmd", + "humility-core", + "structopt", +] + +[[package]] +name = "humility-cmd-renbb" +version = "0.1.0" +dependencies = [ + "anyhow", + "hif", + "humility-cmd", + "humility-core", + "indicatif", + "log", + "parse_int", + "pmbus", + "structopt", +] + +[[package]] +name = "humility-cmd-rencm" +version = "0.1.0" +dependencies = [ + "anyhow", + "hif", + "humility-cmd", + "humility-core", + "idt8a3xxxx", + "itertools", + "log", + "parse_int", + "structopt", +] + +[[package]] +name = "humility-cmd-ringbuf" +version = "0.1.0" +dependencies = [ + "anyhow", + "humility-cmd", + "humility-core", + "log", + "structopt", +] + +[[package]] +name = "humility-cmd-spd" +version = "0.1.0" +dependencies = [ + "anyhow", + "hif", + "humility-cmd", + "humility-core", + "jep106", + "log", + "parse_int", + "spd", + "structopt", +] + +[[package]] +name = "humility-cmd-spi" +version = "0.1.0" +dependencies = [ + "anyhow", + "hif", + "humility-cmd", + "humility-core", + "log", + "parse_int", + "structopt", +] + +[[package]] +name = "humility-cmd-stackmargin" +version = "0.1.0" +dependencies = [ + "anyhow", + "humility-cmd", + "humility-core", + "structopt", +] + +[[package]] +name = "humility-cmd-stmsecure" +version = "0.1.0" +dependencies = [ + "anyhow", + "humility-cmd", + "humility-core", + "parse_int", + "structopt", +] + +[[package]] +name = "humility-cmd-tasks" +version = "0.1.0" +dependencies = [ + "anyhow", + "humility-cmd", + "humility-core", + "num-traits", + "structopt", +] + +[[package]] +name = "humility-cmd-test" +version = "0.1.0" +dependencies = [ + "anyhow", + "humility-cmd", + "humility-core", + "humility-cortex", + "structopt", +] + +[[package]] +name = "humility-cmd-trace" +version = "0.1.0" +dependencies = [ + "anyhow", + "humility-cmd", + "humility-core", + "humility-cortex", + "structopt", +] + [[package]] name = "humility-core" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index fb81aca50..612a6735e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,32 @@ members = [ "humility-core", "humility-cmd", "humility-arch-cortex", - "cmd/apptable" + "cmd/apptable", + "cmd/diagnose", + "cmd/dump", + "cmd/etm", + "cmd/gpio", + "cmd/hiffy", + "cmd/i2c", + "cmd/itm", + "cmd/jefe", + "cmd/manifest", + "cmd/map", + "cmd/pmbus", + "cmd/probe", + "cmd/qspi", + "cmd/readmem", + "cmd/readvar", + "cmd/renbb", + "cmd/rencm", + "cmd/ringbuf", + "cmd/spd", + "cmd/spi", + "cmd/stackmargin", + "cmd/stmsecure", + "cmd/tasks", + "cmd/test", + "cmd/trace", ] [profile.release] @@ -20,12 +45,35 @@ debug = true pmbus = { path = "./pmbus" } hif = { path = "./hif" } spd = { path = "./spd" } -idt8a3xxxx = { path = "./idt8a3xxxx" } -humility_load_derive = {path = "./load_derive"} humility = { path = "./humility-core", package = "humility-core" } humility-cortex = { path = "./humility-arch-cortex" } humility-cmd = { path = "./humility-cmd" } -cmd-apptable = { path = "./cmd/apptable", package = "apptable" } +cmd-apptable = { path = "./cmd/apptable", package = "humility-cmd-apptable" } +cmd-diagnose = { path = "./cmd/diagnose", package = "humility-cmd-diagnose" } +cmd-dump = { path = "./cmd/dump", package = "humility-cmd-dump" } +cmd-etm = { path = "./cmd/etm", package = "humility-cmd-etm" } +cmd-gpio = { path = "./cmd/gpio", package = "humility-cmd-gpio" } +cmd-hiffy = { path = "./cmd/hiffy", package = "humility-cmd-hiffy" } +cmd-i2c = { path = "./cmd/i2c", package = "humility-cmd-i2c" } +cmd-itm = { path = "./cmd/itm", package = "humility-cmd-itm" } +cmd-jefe = { path = "./cmd/jefe", package = "humility-cmd-jefe" } +cmd-manifest = { path = "./cmd/manifest", package = "humility-cmd-manifest" } +cmd-map = { path = "./cmd/map", package = "humility-cmd-map" } +cmd-pmbus = { path = "./cmd/pmbus", package = "humility-cmd-pmbus" } +cmd-probe = { path = "./cmd/probe", package = "humility-cmd-probe" } +cmd-qspi = { path = "./cmd/qspi", package = "humility-cmd-qspi" } +cmd-readmem = { path = "./cmd/readmem", package = "humility-cmd-readmem" } +cmd-readvar = { path = "./cmd/readvar", package = "humility-cmd-readvar" } +cmd-renbb = { path = "./cmd/renbb", package = "humility-cmd-renbb" } +cmd-rencm = { path = "./cmd/rencm", package = "humility-cmd-rencm" } +cmd-ringbuf = { path = "./cmd/ringbuf", package = "humility-cmd-ringbuf" } +cmd-spd = { path = "./cmd/spd", package = "humility-cmd-spd" } +cmd-spi = { path = "./cmd/spi", package = "humility-cmd-spi" } +cmd-stackmargin = { path = "./cmd/stackmargin", package = "humility-cmd-stackmargin" } +cmd-stmsecure = { path = "./cmd/stmsecure", package = "humility-cmd-stmsecure" } +cmd-tasks = { path = "./cmd/tasks", package = "humility-cmd-tasks" } +cmd-test = { path = "./cmd/test", package = "humility-cmd-test" } +cmd-trace = { path = "./cmd/trace", package = "humility-cmd-trace" } fallible-iterator = "0.2.0" log = {version = "0.4.8", features = ["std"]} @@ -44,6 +92,4 @@ anyhow = { version = "1.0.44", features = ["backtrace"] } scroll = "0.10" indicatif = "0.15" colored = "2.0.0" -postcard = "0.7.0" -itertools = "0.10.1" indexmap = { version = "1.7", features = ["serde-1"] } diff --git a/cmd/apptable/Cargo.toml b/cmd/apptable/Cargo.toml index e97d85811..ecb30afd9 100644 --- a/cmd/apptable/Cargo.toml +++ b/cmd/apptable/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "apptable" +name = "humility-cmd-apptable" version = "0.1.0" edition = "2021" @@ -8,4 +8,3 @@ humility = { path = "../../humility-core", package = "humility-core" } humility-cmd = { path = "../../humility-cmd" } structopt = "0.3" anyhow = { version = "1.0.44", features = ["backtrace"] } - diff --git a/cmd/apptable/src/lib.rs b/cmd/apptable/src/lib.rs index c19174a10..c26ff0e63 100644 --- a/cmd/apptable/src/lib.rs +++ b/cmd/apptable/src/lib.rs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use humility_cmd::{Args, Archive, Command}; use anyhow::{bail, Result}; use humility::hubris::{HubrisArchive, HubrisPrintFormat}; +use humility_cmd::{Archive, Args, Command}; use std::convert::TryInto; use structopt::clap::App; use structopt::StructOpt; diff --git a/cmd/diagnose/Cargo.toml b/cmd/diagnose/Cargo.toml new file mode 100644 index 000000000..fd4bce1f4 --- /dev/null +++ b/cmd/diagnose/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "humility-cmd-diagnose" +version = "0.1.0" +edition = "2021" + +[dependencies] +humility = { path = "../../humility-core", package = "humility-core" } +humility-cmd = { path = "../../humility-cmd" } +structopt = "0.3" +anyhow = { version = "1.0.44", features = ["backtrace"] } +parse_int = "0.4.0" diff --git a/src/cmd/diagnose.rs b/cmd/diagnose/src/lib.rs similarity index 98% rename from src/cmd/diagnose.rs rename to cmd/diagnose/src/lib.rs index 936d683bf..020059720 100644 --- a/src/cmd/diagnose.rs +++ b/cmd/diagnose/src/lib.rs @@ -14,14 +14,13 @@ //! into things the _application_ may think are fishy -- only general behaviors //! at the OS level, like faults. -use crate::cmd::jefe; -use crate::cmd::*; -use crate::doppel::{GenOrRestartCount, Task, TaskDesc, TaskState}; -use crate::reflect; -use crate::Args; -use anyhow::Result; +use anyhow::{bail, Result}; use humility::core::Core; use humility::hubris::*; +use humility_cmd::doppel::{GenOrRestartCount, Task, TaskDesc, TaskState}; +use humility_cmd::jefe; +use humility_cmd::reflect; +use humility_cmd::{Archive, Args, Attach, Command, Validate}; use std::num::NonZeroU32; use std::time::Duration; use structopt::clap::App; diff --git a/cmd/dump/Cargo.toml b/cmd/dump/Cargo.toml new file mode 100644 index 000000000..4222ac216 --- /dev/null +++ b/cmd/dump/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "humility-cmd-dump" +version = "0.1.0" +edition = "2021" + +[dependencies] +humility = { path = "../../humility-core", package = "humility-core" } +humility-cmd = { path = "../../humility-cmd" } +structopt = "0.3" +anyhow = { version = "1.0.44", features = ["backtrace"] } +log = {version = "0.4.8", features = ["std"]} diff --git a/src/cmd/dump.rs b/cmd/dump/src/lib.rs similarity index 90% rename from src/cmd/dump.rs rename to cmd/dump/src/lib.rs index ffcc554ff..f4960f1c1 100644 --- a/src/cmd/dump.rs +++ b/cmd/dump/src/lib.rs @@ -2,10 +2,13 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::cmd::*; -use crate::Args; +#[macro_use] +extern crate log; + use anyhow::Result; +use humility::core::Core; use humility::hubris::*; +use humility_cmd::{Archive, Args, Attach, Command, Validate}; use structopt::clap::App; use structopt::StructOpt; diff --git a/cmd/etm/Cargo.toml b/cmd/etm/Cargo.toml new file mode 100644 index 000000000..64191196a --- /dev/null +++ b/cmd/etm/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "humility-cmd-etm" +version = "0.1.0" +edition = "2021" + +[dependencies] +humility = { path = "../../humility-core", package = "humility-core" } +humility-cortex = { path = "../../humility-arch-cortex" } +humility-cmd = { path = "../../humility-cmd" } +structopt = "0.3" +anyhow = { version = "1.0.44", features = ["backtrace"] } +csv = "1.1.3" +parse_int = "0.4.0" +log = {version = "0.4.8", features = ["std"]} diff --git a/src/cmd/etm.rs b/cmd/etm/src/lib.rs similarity index 99% rename from src/cmd/etm.rs rename to cmd/etm/src/lib.rs index 1f333f440..e25869d8c 100644 --- a/src/cmd/etm.rs +++ b/cmd/etm/src/lib.rs @@ -2,21 +2,24 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::attach_live; -use crate::cmd::{Archive, Command}; -use humility_cortex::etm::*; -use humility_cortex::scs::*; -use humility_cortex::tpiu::*; -use crate::Args; use anyhow::{bail, Result}; use humility::core::Core; -use humility_cortex::debug::*; use humility::hubris::*; +use humility_cmd::attach_live; +use humility_cmd::Args; +use humility_cmd::{Archive, Command}; +use humility_cortex::debug::*; +use humility_cortex::etm::*; +use humility_cortex::scs::*; +use humility_cortex::tpiu::*; use std::fs::File; use std::time::Instant; use structopt::clap::App; use structopt::StructOpt; +#[macro_use] +extern crate log; + #[derive(StructOpt, Debug)] #[structopt( name = "etm", diff --git a/cmd/gpio/Cargo.toml b/cmd/gpio/Cargo.toml new file mode 100644 index 000000000..b4846b91d --- /dev/null +++ b/cmd/gpio/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "humility-cmd-gpio" +version = "0.1.0" +edition = "2021" + +[dependencies] +humility = { path = "../../humility-core", package = "humility-core" } +humility-cmd = { path = "../../humility-cmd" } +hif = { path = "../../hif" } +structopt = "0.3" +anyhow = { version = "1.0.44", features = ["backtrace"] } +parse_int = "0.4.0" diff --git a/src/cmd/gpio.rs b/cmd/gpio/src/lib.rs similarity index 97% rename from src/cmd/gpio.rs rename to cmd/gpio/src/lib.rs index 74a8a0720..d319ac7b5 100644 --- a/src/cmd/gpio.rs +++ b/cmd/gpio/src/lib.rs @@ -2,11 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::cmd::{Archive, Attach, Validate}; -use crate::hiffy::*; -use crate::Args; use humility::core::Core; use humility::hubris::*; +use humility_cmd::hiffy::*; +use humility_cmd::{Archive, Args, Attach, Command, Validate}; use std::str; use std::thread; @@ -270,9 +269,9 @@ fn gpio( Ok(()) } -pub fn init<'a, 'b>() -> (crate::cmd::Command, App<'a, 'b>) { +pub fn init<'a, 'b>() -> (Command, App<'a, 'b>) { ( - crate::cmd::Command::Attached { + Command::Attached { name: "gpio", archive: Archive::Required, attach: Attach::LiveOnly, diff --git a/cmd/hiffy/Cargo.toml b/cmd/hiffy/Cargo.toml new file mode 100644 index 000000000..f8915f9ff --- /dev/null +++ b/cmd/hiffy/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "humility-cmd-hiffy" +version = "0.1.0" +edition = "2021" + +[dependencies] +humility = { path = "../../humility-core", package = "humility-core" } +humility-cmd = { path = "../../humility-cmd" } +hif = { path = "../../hif" } +structopt = "0.3" +anyhow = { version = "1.0.44", features = ["backtrace"] } +parse_int = "0.4.0" diff --git a/src/cmd/hiffy.rs b/cmd/hiffy/src/lib.rs similarity index 94% rename from src/cmd/hiffy.rs rename to cmd/hiffy/src/lib.rs index 5f38b6115..7f55acc80 100644 --- a/src/cmd/hiffy.rs +++ b/cmd/hiffy/src/lib.rs @@ -2,12 +2,11 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::cmd::*; -use crate::hiffy::*; -use crate::Args; -use anyhow::Result; +use anyhow::{bail, Result}; use humility::core::Core; use humility::hubris::*; +use humility_cmd::hiffy::*; +use humility_cmd::{Archive, Args, Attach, Command, Validate}; use structopt::clap::App; use structopt::StructOpt; diff --git a/cmd/i2c/Cargo.toml b/cmd/i2c/Cargo.toml new file mode 100644 index 000000000..7c17aeb77 --- /dev/null +++ b/cmd/i2c/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "humility-cmd-i2c" +version = "0.1.0" +edition = "2021" + +[dependencies] +humility = { path = "../../humility-core", package = "humility-core" } +humility-cmd = { path = "../../humility-cmd" } +hif = { path = "../../hif" } +structopt = "0.3" +anyhow = { version = "1.0.44", features = ["backtrace"] } +parse_int = "0.4.0" +indicatif = "0.15" +log = {version = "0.4.8", features = ["std"]} diff --git a/src/cmd/i2c.rs b/cmd/i2c/src/lib.rs similarity index 98% rename from src/cmd/i2c.rs rename to cmd/i2c/src/lib.rs index ef60dadff..b88223e64 100644 --- a/src/cmd/i2c.rs +++ b/cmd/i2c/src/lib.rs @@ -2,18 +2,19 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::cmd::*; -use crate::hiffy::*; -use crate::Args; use anyhow::{anyhow, bail, Result}; use hif::*; use humility::core::Core; use humility::hubris::*; +use humility_cmd::hiffy::*; +use humility_cmd::printmem; +use humility_cmd::{Archive, Args, Attach, Command, Validate}; use std::thread; use std::time::Duration; use structopt::clap::App; use structopt::StructOpt; +use std::collections::HashMap; use std::fs; use std::fs::File; use std::io::Read; @@ -22,6 +23,9 @@ use std::time::Instant; use indicatif::{HumanBytes, HumanDuration}; use indicatif::{ProgressBar, ProgressStyle}; +#[macro_use] +extern crate log; + #[derive(StructOpt, Debug, Default)] #[structopt(name = "i2c", about = "scan for and read I2C devices")] pub struct I2cArgs { @@ -115,7 +119,7 @@ pub struct I2cArgs { fn i2c_done( subargs: &I2cArgs, - hargs: &crate::i2c::I2cArgs, + hargs: &humility_cmd::i2c::I2cArgs, results: &[Result, u32>], func: &HiffyFunction, ) -> Result<()> { @@ -268,7 +272,7 @@ fn i2c_done( Ok(val) => match subargs.nbytes { Some(n) if n > 2 => { println!(); - crate::cmd::printmem(val, 0, 1, 16); + printmem(val, 0, 1, 16); } Some(2) => { println!("0x{:02x} 0x{:02x}", val[0], val[1]); @@ -313,7 +317,7 @@ fn i2c_done( Ok(val) => match subargs.nbytes { Some(n) if n > 2 => { println!(); - crate::cmd::printmem(val, 0, 1, 16); + printmem(val, 0, 1, 16); } Some(2) => { println!("0x{:02x} 0x{:02x}", val[0], val[1]) @@ -382,7 +386,7 @@ fn i2c( bail!("mismatched function signature on {}", fname); } - let hargs = crate::i2c::I2cArgs::parse( + let hargs = humility_cmd::i2c::I2cArgs::parse( hubris, &subargs.bus, subargs.controller, diff --git a/cmd/itm/Cargo.toml b/cmd/itm/Cargo.toml new file mode 100644 index 000000000..c2decef8b --- /dev/null +++ b/cmd/itm/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "humility-cmd-itm" +version = "0.1.0" +edition = "2021" + +[dependencies] +humility = { path = "../../humility-core", package = "humility-core" } +humility-cortex = { path = "../../humility-arch-cortex" } +humility-cmd = { path = "../../humility-cmd" } +structopt = "0.3" +anyhow = { version = "1.0.44", features = ["backtrace"] } +csv = "1.1.3" +parse_int = "0.4.0" +log = {version = "0.4.8", features = ["std"]} diff --git a/src/cmd/itm.rs b/cmd/itm/src/lib.rs similarity index 98% rename from src/cmd/itm.rs rename to cmd/itm/src/lib.rs index 2b5706fd4..a43296e89 100644 --- a/src/cmd/itm.rs +++ b/cmd/itm/src/lib.rs @@ -2,23 +2,25 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::attach_live; -use crate::cmd::{Archive, Command}; +use anyhow::{bail, Result}; +use humility::core::Core; +use humility::hubris::*; +use humility_cmd::attach_live; +use humility_cmd::{Archive, Args, Command}; +use humility_cortex::debug::*; use humility_cortex::dwt::*; use humility_cortex::itm::*; use humility_cortex::scs::*; use humility_cortex::tpiu::*; -use crate::Args; -use anyhow::{bail, Result}; -use humility::core::Core; -use humility_cortex::debug::*; -use humility::hubris::*; use std::fs::File; use std::io::Read; use std::time::Instant; use structopt::clap::App; use structopt::StructOpt; +#[macro_use] +extern crate log; + const ITM_TRACEID_MAX: u8 = 0x7f; #[derive(StructOpt, Debug)] diff --git a/cmd/jefe/Cargo.toml b/cmd/jefe/Cargo.toml new file mode 100644 index 000000000..fcee7c3ac --- /dev/null +++ b/cmd/jefe/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "humility-cmd-jefe" +version = "0.1.0" +edition = "2021" + +[dependencies] +humility = { path = "../../humility-core", package = "humility-core" } +humility-cmd = { path = "../../humility-cmd" } +structopt = "0.3" +anyhow = { version = "1.0.44", features = ["backtrace"] } +parse_int = "0.4.0" +log = {version = "0.4.8", features = ["std"]} diff --git a/cmd/jefe/src/lib.rs b/cmd/jefe/src/lib.rs new file mode 100644 index 000000000..9cafe3a73 --- /dev/null +++ b/cmd/jefe/src/lib.rs @@ -0,0 +1,101 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +use anyhow::{anyhow, bail, Result}; +use humility::core::Core; +use humility::hubris::*; +use humility_cmd::jefe::{send_request, JefeRequest}; +use humility_cmd::{Archive, Args, Attach, Command, Validate}; +use std::num::NonZeroU32; +use structopt::clap::App; +use structopt::StructOpt; + +#[macro_use] +extern crate log; + +#[derive(StructOpt, Debug)] +#[structopt(name = "jefe", about = "influence jefe externally")] +struct JefeArgs { + /// sets timeout + #[structopt( + long, short, default_value = "5000", value_name = "timeout_ms", + parse(try_from_str = parse_int::parse) + )] + timeout: u32, + + /// fault the specified task + #[structopt(long, short, conflicts_with_all = &["start", "release", "hold"])] + fault: bool, + + /// start the specified task + #[structopt(long, short, conflicts_with_all = &["release", "hold"])] + start: bool, + + /// hold the specified task + #[structopt(long, short, conflicts_with = "release")] + hold: bool, + + /// release the specified task + #[structopt(long, short)] + release: bool, + + task: String, +} + +fn jefe( + hubris: &mut HubrisArchive, + core: &mut dyn Core, + _args: &Args, + subargs: &Vec, +) -> Result<()> { + let subargs = JefeArgs::from_iter_safe(subargs)?; + + let request = if subargs.fault { + JefeRequest::Fault + } else if subargs.start { + JefeRequest::Start + } else if subargs.hold { + JefeRequest::Hold + } else if subargs.release { + JefeRequest::Release + } else { + bail!("one of fault, start, hold, or release must be specified"); + }; + + let task = hubris + .lookup_task(&subargs.task) + .ok_or_else(|| anyhow!("couldn't find task {}", subargs.task))?; + + let id = match task { + HubrisTask::Kernel => { + bail!("cannot change disposition of kernel"); + } + HubrisTask::Task(id) => { + if let Some(id) = NonZeroU32::new(*id) { + id + } else { + bail!("cannot change disposition of supervisor task"); + } + } + }; + + send_request(hubris, core, request, id, subargs.timeout)?; + + info!("successfully changed disposition for {}", subargs.task); + + Ok(()) +} + +pub fn init<'a, 'b>() -> (Command, App<'a, 'b>) { + ( + Command::Attached { + name: "jefe", + archive: Archive::Required, + attach: Attach::LiveOnly, + validate: Validate::Booted, + run: jefe, + }, + JefeArgs::clap(), + ) +} diff --git a/cmd/manifest/Cargo.toml b/cmd/manifest/Cargo.toml new file mode 100644 index 000000000..879bf2f3e --- /dev/null +++ b/cmd/manifest/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "humility-cmd-manifest" +version = "0.1.0" +edition = "2021" + +[dependencies] +humility = { path = "../../humility-core", package = "humility-core" } +humility-cmd = { path = "../../humility-cmd" } +structopt = "0.3" +anyhow = { version = "1.0.44", features = ["backtrace"] } diff --git a/src/cmd/manifest.rs b/cmd/manifest/src/lib.rs similarity index 93% rename from src/cmd/manifest.rs rename to cmd/manifest/src/lib.rs index 8dc4baff6..2e9ee2b04 100644 --- a/src/cmd/manifest.rs +++ b/cmd/manifest/src/lib.rs @@ -2,10 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::cmd::{Archive, Command}; -use crate::Args; use anyhow::Result; use humility::hubris::HubrisArchive; +use humility_cmd::{Archive, Args, Command}; use structopt::clap::App; use structopt::StructOpt; diff --git a/cmd/map/Cargo.toml b/cmd/map/Cargo.toml new file mode 100644 index 000000000..1c100ade2 --- /dev/null +++ b/cmd/map/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "humility-cmd-map" +version = "0.1.0" +edition = "2021" + +[dependencies] +humility = { path = "../../humility-core", package = "humility-core" } +humility-cmd = { path = "../../humility-cmd" } +structopt = "0.3" +anyhow = { version = "1.0.44", features = ["backtrace"] } diff --git a/src/cmd/map.rs b/cmd/map/src/lib.rs similarity index 96% rename from src/cmd/map.rs rename to cmd/map/src/lib.rs index c5c8a8111..3f1c2417e 100644 --- a/src/cmd/map.rs +++ b/cmd/map/src/lib.rs @@ -2,11 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::cmd::*; -use crate::Args; use anyhow::Result; use humility::core::Core; use humility::hubris::*; +use humility_cmd::{Archive, Args, Attach, Command, Validate}; use structopt::clap::App; use structopt::StructOpt; diff --git a/cmd/pmbus/Cargo.toml b/cmd/pmbus/Cargo.toml new file mode 100644 index 000000000..b65999646 --- /dev/null +++ b/cmd/pmbus/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "humility-cmd-pmbus" +version = "0.1.0" +edition = "2021" + +[dependencies] +humility = { path = "../../humility-core", package = "humility-core" } +humility-cmd = { path = "../../humility-cmd" } +hif = { path = "../../hif" } +pmbus = { path = "../../pmbus" } +structopt = "0.3" +anyhow = { version = "1.0.44", features = ["backtrace"] } +colored = "2.0.0" +indexmap = { version = "1.7", features = ["serde-1"] } +log = {version = "0.4.8", features = ["std"]} +parse_int = "0.4.0" diff --git a/src/cmd/pmbus.rs b/cmd/pmbus/src/lib.rs similarity index 98% rename from src/cmd/pmbus.rs rename to cmd/pmbus/src/lib.rs index c5fbc54a2..1a2c6c1a0 100644 --- a/src/cmd/pmbus.rs +++ b/cmd/pmbus/src/lib.rs @@ -2,12 +2,12 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::cmd::{Archive, Attach, Validate}; -use crate::hiffy::*; -use crate::Args; use colored::Colorize; use humility::core::Core; use humility::hubris::*; +use humility_cmd::hiffy::*; +use humility_cmd::i2c::I2cArgs; +use humility_cmd::{Archive, Args, Attach, Command, Validate}; use std::thread; use anyhow::{anyhow, bail, Result}; @@ -21,6 +21,9 @@ use std::time::Duration; use structopt::clap::App; use structopt::StructOpt; +#[macro_use] +extern crate log; + #[derive(StructOpt, Debug)] #[structopt(name = "pmbus", about = "scan for and read PMBus devices")] struct PmbusArgs { @@ -694,7 +697,7 @@ fn summarize( None => pmbus::Device::Common, }; - let harg = crate::i2c::I2cArgs::from_device(device); + let harg = I2cArgs::from_device(device); ops.push(Op::Push(harg.controller)); ops.push(Op::Push(harg.port.index)); @@ -802,7 +805,7 @@ fn summarize( fn find_rail<'a>( hubris: &'a HubrisArchive, rail: &str, -) -> Result<(crate::i2c::I2cArgs<'a>, Option)> { +) -> Result<(I2cArgs<'a>, Option)> { let mut found = None; for device in &hubris.manifest.i2c_devices { @@ -831,9 +834,7 @@ fn find_rail<'a>( None => { bail!("rail {} not found", rail); } - Some((device, rail)) => { - Ok((crate::i2c::I2cArgs::from_device(device), rail)) - } + Some((device, rail)) => Ok((I2cArgs::from_device(device), rail)), } } @@ -976,10 +977,10 @@ fn writes( (Some(rails), None) => rails .iter() .map(|rail| find_rail(hubris, rail)) - .collect::)>>>(), + .collect::)>>>(), (_, _) => Ok(vec![( - crate::i2c::I2cArgs::parse( + I2cArgs::parse( hubris, &subargs.bus, subargs.controller, @@ -1387,7 +1388,7 @@ fn pmbus( find_rail(hubris, &rails[0])?.0 } - (_, _) => crate::i2c::I2cArgs::parse( + (_, _) => I2cArgs::parse( hubris, &subargs.bus, subargs.controller, @@ -1562,7 +1563,7 @@ fn pmbus( } } - let mut addcmd = |cmd: &dyn Command, code| { + let mut addcmd = |cmd: &dyn pmbus::Command, code| { let op = match cmd.read_op() { pmbus::Operation::ReadByte => Op::Push(1), pmbus::Operation::ReadWord => Op::Push(2), @@ -1668,9 +1669,9 @@ fn pmbus( Ok(()) } -pub fn init<'a, 'b>() -> (crate::cmd::Command, App<'a, 'b>) { +pub fn init<'a, 'b>() -> (Command, App<'a, 'b>) { ( - crate::cmd::Command::Attached { + Command::Attached { name: "pmbus", archive: Archive::Required, attach: Attach::LiveOnly, diff --git a/cmd/probe/Cargo.toml b/cmd/probe/Cargo.toml new file mode 100644 index 000000000..654507bba --- /dev/null +++ b/cmd/probe/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "humility-cmd-probe" +version = "0.1.0" +edition = "2021" + +[dependencies] +humility = { path = "../../humility-core", package = "humility-core" } +humility-cortex = { path = "../../humility-arch-cortex" } +humility-cmd = { path = "../../humility-cmd" } +structopt = "0.3" +anyhow = { version = "1.0.44", features = ["backtrace"] } +log = {version = "0.4.8", features = ["std"]} +num-traits = "0.2" diff --git a/src/cmd/probe.rs b/cmd/probe/src/lib.rs similarity index 98% rename from src/cmd/probe.rs rename to cmd/probe/src/lib.rs index 5fe0d4e3d..cae88374f 100644 --- a/src/cmd/probe.rs +++ b/cmd/probe/src/lib.rs @@ -2,18 +2,20 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::cmd::*; -use humility_cortex::itm::*; -use humility_cortex::scs::*; -use crate::Args; use anyhow::Result; -use humility::core::Core; use humility::arch::ARMRegister; -use humility_cortex::debug::*; +use humility::core::Core; use humility::hubris::*; +use humility_cmd::{Archive, Args, Attach, Command, Validate}; +use humility_cortex::debug::*; +use humility_cortex::itm::*; +use humility_cortex::scs::*; use structopt::clap::App; use structopt::StructOpt; +#[macro_use] +extern crate log; + #[derive(StructOpt, Debug)] #[structopt(name = "probe", about = "probe for any attached devices")] struct ProbeArgs {} diff --git a/cmd/qspi/Cargo.toml b/cmd/qspi/Cargo.toml new file mode 100644 index 000000000..54b19bfa7 --- /dev/null +++ b/cmd/qspi/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "humility-cmd-qspi" +version = "0.1.0" +edition = "2021" + +[dependencies] +humility = { path = "../../humility-core", package = "humility-core" } +humility-cmd = { path = "../../humility-cmd" } +hif = { path = "../../hif" } +structopt = "0.3" +anyhow = { version = "1.0.44", features = ["backtrace"] } +parse_int = "0.4.0" +indicatif = "0.15" +log = {version = "0.4.8", features = ["std"]} diff --git a/src/cmd/qspi.rs b/cmd/qspi/src/lib.rs similarity index 97% rename from src/cmd/qspi.rs rename to cmd/qspi/src/lib.rs index a9980adaa..ee8aa73ff 100644 --- a/src/cmd/qspi.rs +++ b/cmd/qspi/src/lib.rs @@ -2,12 +2,11 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::cmd::printmem; -use crate::cmd::{Archive, Attach, Validate}; -use crate::hiffy::*; -use crate::Args; use humility::core::Core; use humility::hubris::*; +use humility_cmd::hiffy::*; +use humility_cmd::printmem; +use humility_cmd::{Archive, Args, Attach, Command, Validate}; use std::fs; use std::fs::File; use std::io::Read; @@ -22,6 +21,9 @@ use structopt::{clap::App, clap::ArgGroup, StructOpt}; use indicatif::{HumanBytes, HumanDuration}; use indicatif::{ProgressBar, ProgressStyle}; +#[macro_use] +extern crate log; + #[derive(StructOpt, Debug)] #[structopt( name = "qspi", about = "QSPI status, reading and writing", @@ -370,9 +372,9 @@ fn qspi( Ok(()) } -pub fn init<'a, 'b>() -> (crate::cmd::Command, App<'a, 'b>) { +pub fn init<'a, 'b>() -> (Command, App<'a, 'b>) { ( - crate::cmd::Command::Attached { + Command::Attached { name: "qspi", archive: Archive::Required, attach: Attach::LiveOnly, diff --git a/cmd/readmem/Cargo.toml b/cmd/readmem/Cargo.toml new file mode 100644 index 000000000..8df40d798 --- /dev/null +++ b/cmd/readmem/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "humility-cmd-readmem" +version = "0.1.0" +edition = "2021" + +[dependencies] +humility = { path = "../../humility-core", package = "humility-core" } +humility-cmd = { path = "../../humility-cmd" } +structopt = "0.3" +anyhow = { version = "1.0.44", features = ["backtrace"] } +parse_int = "0.4.0" diff --git a/src/cmd/readmem.rs b/cmd/readmem/src/lib.rs similarity index 97% rename from src/cmd/readmem.rs rename to cmd/readmem/src/lib.rs index c243ec88e..e91ba0933 100644 --- a/src/cmd/readmem.rs +++ b/cmd/readmem/src/lib.rs @@ -2,11 +2,11 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::cmd::*; -use crate::Args; use anyhow::{bail, Result}; use humility::core::Core; use humility::hubris::*; +use humility_cmd::printmem; +use humility_cmd::{Archive, Args, Attach, Command, Validate}; use std::convert::TryInto; use structopt::clap::App; use structopt::StructOpt; diff --git a/cmd/readvar/Cargo.toml b/cmd/readvar/Cargo.toml new file mode 100644 index 000000000..fe0560873 --- /dev/null +++ b/cmd/readvar/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "humility-cmd-readvar" +version = "0.1.0" +edition = "2021" + +[dependencies] +humility = { path = "../../humility-core", package = "humility-core" } +humility-cmd = { path = "../../humility-cmd" } +structopt = "0.3" +anyhow = { version = "1.0.44", features = ["backtrace"] } diff --git a/src/cmd/readvar.rs b/cmd/readvar/src/lib.rs similarity index 97% rename from src/cmd/readvar.rs rename to cmd/readvar/src/lib.rs index 676008ca1..20e74856c 100644 --- a/src/cmd/readvar.rs +++ b/cmd/readvar/src/lib.rs @@ -2,11 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::cmd::*; -use crate::Args; use anyhow::{bail, Result}; use humility::core::Core; use humility::hubris::*; +use humility_cmd::{Archive, Args, Attach, Command, Validate}; use structopt::clap::App; use structopt::StructOpt; diff --git a/cmd/renbb/Cargo.toml b/cmd/renbb/Cargo.toml new file mode 100644 index 000000000..e0866ad6f --- /dev/null +++ b/cmd/renbb/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "humility-cmd-renbb" +version = "0.1.0" +edition = "2021" + +[dependencies] +humility = { path = "../../humility-core", package = "humility-core" } +humility-cmd = { path = "../../humility-cmd" } +hif = { path = "../../hif" } +pmbus = { path = "../../pmbus" } +structopt = "0.3" +anyhow = { version = "1.0.44", features = ["backtrace"] } +indicatif = "0.15" +log = {version = "0.4.8", features = ["std"]} +parse_int = "0.4.0" diff --git a/src/cmd/renbb.rs b/cmd/renbb/src/lib.rs similarity index 96% rename from src/cmd/renbb.rs rename to cmd/renbb/src/lib.rs index b0f05abb4..b96704ad8 100644 --- a/src/cmd/renbb.rs +++ b/cmd/renbb/src/lib.rs @@ -2,11 +2,11 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::cmd::{Archive, Attach, Validate}; -use crate::hiffy::*; -use crate::Args; use humility::core::Core; use humility::hubris::*; +use humility_cmd::hiffy::*; +use humility_cmd::i2c::I2cArgs; +use humility_cmd::{Archive, Args, Attach, Command, Validate}; use std::thread; use anyhow::{anyhow, bail, Result}; @@ -19,6 +19,9 @@ use std::time::Duration; use structopt::clap::App; use structopt::StructOpt; +#[macro_use] +extern crate log; + #[derive(StructOpt, Debug)] #[structopt(name = "rencm", about = "Renesas black box operations")] struct RenbbArgs { @@ -128,11 +131,11 @@ fn renbb( None => { bail!("rail {} not found", rail); } - Some(device) => crate::i2c::I2cArgs::from_device(device), + Some(device) => I2cArgs::from_device(device), } } - (_, _) => crate::i2c::I2cArgs::parse( + (_, _) => I2cArgs::parse( hubris, &subargs.bus, subargs.controller, @@ -307,9 +310,9 @@ fn renbb( Ok(()) } -pub fn init<'a, 'b>() -> (crate::cmd::Command, App<'a, 'b>) { +pub fn init<'a, 'b>() -> (Command, App<'a, 'b>) { ( - crate::cmd::Command::Attached { + Command::Attached { name: "renbb", archive: Archive::Required, attach: Attach::LiveOnly, diff --git a/cmd/rencm/Cargo.toml b/cmd/rencm/Cargo.toml new file mode 100644 index 000000000..a06d91f02 --- /dev/null +++ b/cmd/rencm/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "humility-cmd-rencm" +version = "0.1.0" +edition = "2021" + +[dependencies] +humility = { path = "../../humility-core", package = "humility-core" } +humility-cmd = { path = "../../humility-cmd" } +hif = { path = "../../hif" } +idt8a3xxxx = { path = "../../idt8a3xxxx" } +structopt = "0.3" +anyhow = { version = "1.0.44", features = ["backtrace"] } +itertools = "0.10.1" +parse_int = "0.4.0" +log = {version = "0.4.8", features = ["std"]} diff --git a/src/cmd/rencm.rs b/cmd/rencm/src/lib.rs similarity index 98% rename from src/cmd/rencm.rs rename to cmd/rencm/src/lib.rs index 6f55c0d6e..423212ad2 100644 --- a/src/cmd/rencm.rs +++ b/cmd/rencm/src/lib.rs @@ -2,11 +2,11 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::cmd::{Archive, Attach, Validate}; -use crate::hiffy::*; -use crate::Args; use humility::core::Core; use humility::hubris::*; +use humility_cmd::hiffy::*; +use humility_cmd::i2c::I2cArgs; +use humility_cmd::{Archive, Args, Attach, Command, Validate}; use std::thread; use itertools::Itertools; @@ -18,6 +18,9 @@ use std::time::Duration; use structopt::clap::App; use structopt::StructOpt; +#[macro_use] +extern crate log; + #[derive(StructOpt, Debug)] #[structopt(name = "rencm", about = "query Renesas 8A3400X ClockMatrix parts")] struct RencmArgs { @@ -99,7 +102,7 @@ fn rencm( bail!("mismatched function signature on I2cWrite"); } - let hargs = crate::i2c::I2cArgs::parse( + let hargs = I2cArgs::parse( hubris, &subargs.bus, subargs.controller, @@ -465,9 +468,9 @@ fn rencm( Ok(()) } -pub fn init<'a, 'b>() -> (crate::cmd::Command, App<'a, 'b>) { +pub fn init<'a, 'b>() -> (Command, App<'a, 'b>) { ( - crate::cmd::Command::Attached { + Command::Attached { name: "rencm", archive: Archive::Required, attach: Attach::LiveOnly, diff --git a/cmd/ringbuf/Cargo.toml b/cmd/ringbuf/Cargo.toml new file mode 100644 index 000000000..afcf02311 --- /dev/null +++ b/cmd/ringbuf/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "humility-cmd-ringbuf" +version = "0.1.0" +edition = "2021" + +[dependencies] +humility = { path = "../../humility-core", package = "humility-core" } +humility-cmd = { path = "../../humility-cmd" } +structopt = "0.3" +anyhow = { version = "1.0.44", features = ["backtrace"] } +log = {version = "0.4.8", features = ["std"]} diff --git a/src/cmd/ringbuf.rs b/cmd/ringbuf/src/lib.rs similarity index 95% rename from src/cmd/ringbuf.rs rename to cmd/ringbuf/src/lib.rs index fe60dbd1f..d5f6fd126 100644 --- a/src/cmd/ringbuf.rs +++ b/cmd/ringbuf/src/lib.rs @@ -2,16 +2,18 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::cmd::*; -use crate::doppel::{Ringbuf, StaticCell}; -use crate::reflect::{self, Format, Load, Value}; -use crate::Args; use anyhow::{bail, Result}; use humility::core::Core; use humility::hubris::*; +use humility_cmd::doppel::{Ringbuf, StaticCell}; +use humility_cmd::reflect::{self, Format, Load, Value}; +use humility_cmd::{Archive, Args, Attach, Command, Validate}; use structopt::clap::App; use structopt::StructOpt; +#[macro_use] +extern crate log; + #[derive(StructOpt, Debug)] #[structopt( name = "ringbuf", diff --git a/cmd/spd/Cargo.toml b/cmd/spd/Cargo.toml new file mode 100644 index 000000000..857c8b419 --- /dev/null +++ b/cmd/spd/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "humility-cmd-spd" +version = "0.1.0" +edition = "2021" + +[dependencies] +humility = { path = "../../humility-core", package = "humility-core" } +humility-cmd = { path = "../../humility-cmd" } +hif = { path = "../../hif" } +spd = { path = "../../spd" } +structopt = "0.3" +anyhow = { version = "1.0.44", features = ["backtrace"] } +jep106 = "0.2" +parse_int = "0.4.0" +log = {version = "0.4.8", features = ["std"]} diff --git a/src/cmd/spd.rs b/cmd/spd/src/lib.rs similarity index 97% rename from src/cmd/spd.rs rename to cmd/spd/src/lib.rs index c15eaf4d9..c70c4ae16 100644 --- a/src/cmd/spd.rs +++ b/cmd/spd/src/lib.rs @@ -2,11 +2,11 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::cmd::{Archive, Attach, Validate}; -use crate::hiffy::*; -use crate::Args; use humility::core::Core; use humility::hubris::*; +use humility_cmd::hiffy::*; +use humility_cmd::i2c::I2cArgs; +use humility_cmd::{Archive, Args, Attach, Command, Validate}; use std::str; use std::thread; @@ -16,6 +16,9 @@ use std::time::Duration; use structopt::clap::App; use structopt::StructOpt; +#[macro_use] +extern crate log; + #[derive(StructOpt, Debug)] #[structopt(name = "spd", about = "scan for and read SPD devices")] struct SpdArgs { @@ -230,7 +233,7 @@ fn spd( bail!("mismatched function signature on I2cRead"); } - let hargs = crate::i2c::I2cArgs::parse( + let hargs = I2cArgs::parse( hubris, &subargs.bus, subargs.controller, @@ -381,9 +384,9 @@ fn spd( Ok(()) } -pub fn init<'a, 'b>() -> (crate::cmd::Command, App<'a, 'b>) { +pub fn init<'a, 'b>() -> (Command, App<'a, 'b>) { ( - crate::cmd::Command::Attached { + Command::Attached { name: "spd", archive: Archive::Required, attach: Attach::Any, diff --git a/cmd/spi/Cargo.toml b/cmd/spi/Cargo.toml new file mode 100644 index 000000000..a1222c375 --- /dev/null +++ b/cmd/spi/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "humility-cmd-spi" +version = "0.1.0" +edition = "2021" + +[dependencies] +humility = { path = "../../humility-core", package = "humility-core" } +humility-cmd = { path = "../../humility-cmd" } +hif = { path = "../../hif" } +structopt = "0.3" +anyhow = { version = "1.0.44", features = ["backtrace"] } +parse_int = "0.4.0" +log = {version = "0.4.8", features = ["std"]} diff --git a/src/cmd/spi.rs b/cmd/spi/src/lib.rs similarity index 96% rename from src/cmd/spi.rs rename to cmd/spi/src/lib.rs index 1b740d06d..899d60c40 100644 --- a/src/cmd/spi.rs +++ b/cmd/spi/src/lib.rs @@ -2,11 +2,11 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::cmd::{Archive, Attach, Validate}; -use crate::hiffy::*; -use crate::Args; use humility::core::Core; use humility::hubris::*; +use humility_cmd::hiffy::*; +use humility_cmd::printmem; +use humility_cmd::{Archive, Args, Attach, Command, Validate}; use std::convert::TryInto; use std::str; use std::thread; @@ -17,6 +17,9 @@ use std::time::Duration; use structopt::clap::App; use structopt::StructOpt; +#[macro_use] +extern crate log; + #[derive(StructOpt, Debug)] #[structopt(name = "spi", about = "SPI reading and writing")] struct SpiArgs { @@ -258,7 +261,7 @@ fn spi( } let size = if subargs.word { 4 } else { 1 }; - crate::cmd::printmem(&results[discard..], addr, size, 16); + printmem(&results[discard..], addr, size, 16); return Ok(()); } } @@ -268,9 +271,9 @@ fn spi( Ok(()) } -pub fn init<'a, 'b>() -> (crate::cmd::Command, App<'a, 'b>) { +pub fn init<'a, 'b>() -> (Command, App<'a, 'b>) { ( - crate::cmd::Command::Attached { + Command::Attached { name: "spi", archive: Archive::Required, attach: Attach::LiveOnly, diff --git a/cmd/stackmargin/Cargo.toml b/cmd/stackmargin/Cargo.toml new file mode 100644 index 000000000..6e1d89870 --- /dev/null +++ b/cmd/stackmargin/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "humility-cmd-stackmargin" +version = "0.1.0" +edition = "2021" + +[dependencies] +humility = { path = "../../humility-core", package = "humility-core" } +humility-cmd = { path = "../../humility-cmd" } +structopt = "0.3" +anyhow = { version = "1.0.44", features = ["backtrace"] } diff --git a/src/cmd/stackmargin.rs b/cmd/stackmargin/src/lib.rs similarity index 98% rename from src/cmd/stackmargin.rs rename to cmd/stackmargin/src/lib.rs index eee7e4afc..4d5c8ffe7 100644 --- a/src/cmd/stackmargin.rs +++ b/cmd/stackmargin/src/lib.rs @@ -2,11 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::cmd::*; -use crate::Args; use anyhow::{bail, Result}; use humility::core::Core; use humility::hubris::*; +use humility_cmd::{Archive, Args, Attach, Command, Validate}; use std::convert::TryInto; use structopt::clap::App; use structopt::StructOpt; diff --git a/cmd/stmsecure/Cargo.toml b/cmd/stmsecure/Cargo.toml new file mode 100644 index 000000000..b0008e51a --- /dev/null +++ b/cmd/stmsecure/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "humility-cmd-stmsecure" +version = "0.1.0" +edition = "2021" + +[dependencies] +humility = { path = "../../humility-core", package = "humility-core" } +humility-cmd = { path = "../../humility-cmd" } +structopt = "0.3" +anyhow = { version = "1.0.44", features = ["backtrace"] } +parse_int = "0.4.0" diff --git a/src/cmd/stmsecure.rs b/cmd/stmsecure/src/lib.rs similarity index 99% rename from src/cmd/stmsecure.rs rename to cmd/stmsecure/src/lib.rs index 45d8dd681..9ff2a8117 100644 --- a/src/cmd/stmsecure.rs +++ b/cmd/stmsecure/src/lib.rs @@ -2,11 +2,11 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::cmd::*; -use crate::Args; use anyhow::{anyhow, Result}; -use humility::core::Core; use humility::arch::ARMRegister; +use humility::core::Core; +use humility::hubris::*; +use humility_cmd::{Archive, Args, Attach, Command, Validate}; use structopt::clap::App; use structopt::StructOpt; diff --git a/cmd/tasks/Cargo.toml b/cmd/tasks/Cargo.toml new file mode 100644 index 000000000..2970df9c0 --- /dev/null +++ b/cmd/tasks/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "humility-cmd-tasks" +version = "0.1.0" +edition = "2021" + +[dependencies] +humility = { path = "../../humility-core", package = "humility-core" } +humility-cmd = { path = "../../humility-cmd" } +structopt = "0.3" +anyhow = { version = "1.0.44", features = ["backtrace"] } +num-traits = "0.2" diff --git a/src/cmd/tasks.rs b/cmd/tasks/src/lib.rs similarity index 98% rename from src/cmd/tasks.rs rename to cmd/tasks/src/lib.rs index ccb602302..c313e4fc7 100644 --- a/src/cmd/tasks.rs +++ b/cmd/tasks/src/lib.rs @@ -2,14 +2,13 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::cmd::*; -use crate::doppel::{self, Task, TaskDesc, TaskId, TaskState}; -use crate::reflect::{self, Format, Load}; -use crate::Args; use anyhow::{bail, Result}; -use humility::core::Core; use humility::arch::ARMRegister; +use humility::core::Core; use humility::hubris::*; +use humility_cmd::doppel::{self, Task, TaskDesc, TaskId, TaskState}; +use humility_cmd::reflect::{self, Format, Load}; +use humility_cmd::{Archive, Args, Attach, Command, Validate}; use num_traits::FromPrimitive; use std::collections::HashMap; use structopt::clap::App; @@ -314,7 +313,7 @@ fn explain_sched_state( timer: Option<(i64, u32)>, e: doppel::SchedState, ) -> Result<()> { - use crate::doppel::SchedState; + use doppel::SchedState; match e { SchedState::Stopped => print!("not started"), @@ -359,9 +358,9 @@ fn explain_fault_info( hubris: &HubrisArchive, core: &mut dyn Core, task_index: u32, - fi: crate::doppel::FaultInfo, + fi: doppel::FaultInfo, ) -> Result<()> { - use crate::doppel::FaultInfo; + use doppel::FaultInfo; print!("FAULT: "); match fi { diff --git a/cmd/test/Cargo.toml b/cmd/test/Cargo.toml new file mode 100644 index 000000000..5d5b7ca1c --- /dev/null +++ b/cmd/test/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "humility-cmd-test" +version = "0.1.0" +edition = "2021" + +[dependencies] +humility = { path = "../../humility-core", package = "humility-core" } +humility-cortex = { path = "../../humility-arch-cortex" } +humility-cmd = { path = "../../humility-cmd" } +structopt = "0.3" +anyhow = { version = "1.0.44", features = ["backtrace"] } diff --git a/src/cmd/test.rs b/cmd/test/src/lib.rs similarity index 98% rename from src/cmd/test.rs rename to cmd/test/src/lib.rs index 4e40428a7..06390d743 100644 --- a/src/cmd/test.rs +++ b/cmd/test/src/lib.rs @@ -2,13 +2,12 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::cmd::*; -use humility_cortex::itm::*; -use crate::test::*; -use crate::Args; use anyhow::{bail, Context, Result}; use humility::core::Core; use humility::hubris::*; +use humility_cmd::test::*; +use humility_cmd::{Archive, Args, Attach, Command, Validate}; +use humility_cortex::itm::*; use std::cell::RefCell; use std::collections::VecDeque; use std::time::Instant; diff --git a/cmd/trace/Cargo.toml b/cmd/trace/Cargo.toml new file mode 100644 index 000000000..bbcc6dc7e --- /dev/null +++ b/cmd/trace/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "humility-cmd-trace" +version = "0.1.0" +edition = "2021" + +[dependencies] +humility = { path = "../../humility-core", package = "humility-core" } +humility-cortex = { path = "../../humility-arch-cortex" } +humility-cmd = { path = "../../humility-cmd" } +structopt = "0.3" +anyhow = { version = "1.0.44", features = ["backtrace"] } diff --git a/src/cmd/trace.rs b/cmd/trace/src/lib.rs similarity index 99% rename from src/cmd/trace.rs rename to cmd/trace/src/lib.rs index dd2d59129..3b5bd816c 100644 --- a/src/cmd/trace.rs +++ b/cmd/trace/src/lib.rs @@ -2,12 +2,11 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use crate::cmd::*; -use humility_cortex::itm::*; -use crate::Args; use anyhow::{anyhow, Result}; use humility::core::Core; use humility::hubris::*; +use humility_cmd::{Archive, Args, Attach, Command, Validate}; +use humility_cortex::itm::*; use std::collections::HashMap; use std::convert::TryInto; use std::time::Instant; diff --git a/humility-arch-cortex/src/debug.rs b/humility-arch-cortex/src/debug.rs index 1ef5143e2..c0a70a4d1 100644 --- a/humility-arch-cortex/src/debug.rs +++ b/humility-arch-cortex/src/debug.rs @@ -4,9 +4,9 @@ use anyhow::{anyhow, Result}; -use humility::hubris::*; -use humility::core::Core; use bitfield::bitfield; +use humility::core::Core; +use humility::hubris::*; pub trait Register: Clone + From + Into + Sized + std::fmt::Debug @@ -511,10 +511,7 @@ pub fn stm32_chipname(partno: u32) -> String { .to_string() } -pub fn swoscaler( - hubris: &HubrisArchive, - core: &mut dyn Core, -) -> Result { +pub fn swoscaler(hubris: &HubrisArchive, core: &mut dyn Core) -> Result { let debug_clock_mhz = 2_000_000; match hubris.clock(core)? { diff --git a/humility-arch-cortex/src/dwt.rs b/humility-arch-cortex/src/dwt.rs index 22ccb678e..d6866de71 100644 --- a/humility-arch-cortex/src/dwt.rs +++ b/humility-arch-cortex/src/dwt.rs @@ -2,10 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use bitfield::bitfield; -use humility::core::Core; use crate::debug::Register; use crate::register; +use bitfield::bitfield; +use humility::core::Core; /* * DWT Control Register diff --git a/humility-arch-cortex/src/etm.rs b/humility-arch-cortex/src/etm.rs index 2d102bd66..4a0bfccd1 100644 --- a/humility-arch-cortex/src/etm.rs +++ b/humility-arch-cortex/src/etm.rs @@ -2,12 +2,12 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +use crate::debug::Register; +use crate::register; use crate::tpiu::*; use anyhow::Result; use bitfield::bitfield; use humility::core::Core; -use crate::debug::Register; -use crate::register; macro_rules! etm_register { ($reg:ty, $offs:expr, $($arg:tt)*) => ( diff --git a/humility-arch-cortex/src/itm.rs b/humility-arch-cortex/src/itm.rs index 7ada8b7be..8169052fd 100644 --- a/humility-arch-cortex/src/itm.rs +++ b/humility-arch-cortex/src/itm.rs @@ -2,16 +2,16 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +use crate::debug::*; use crate::dwt::*; +use crate::register; use crate::scs::*; use crate::swo::*; use crate::tpiu::*; use anyhow::Result; use bitfield::bitfield; use humility::core::Core; -use crate::debug::*; use humility::hubris::HubrisArchive; -use crate::register; /* * ITM Trace Enable Register diff --git a/humility-arch-cortex/src/scs.rs b/humility-arch-cortex/src/scs.rs index 29c2979f6..7ea041ae8 100644 --- a/humility-arch-cortex/src/scs.rs +++ b/humility-arch-cortex/src/scs.rs @@ -2,12 +2,12 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -use anyhow::{bail, Result}; -use bitfield::bitfield; -use humility::core::Core; use crate::debug::*; use crate::register; use crate::register_offs; +use anyhow::{bail, Result}; +use bitfield::bitfield; +use humility::core::Core; use multimap::MultiMap; use std::mem::size_of; diff --git a/humility-arch-cortex/src/swo.rs b/humility-arch-cortex/src/swo.rs index 941f10027..10014a4ed 100644 --- a/humility-arch-cortex/src/swo.rs +++ b/humility-arch-cortex/src/swo.rs @@ -4,8 +4,8 @@ use anyhow::Result; -use humility::core::Core; use crate::register_offs; +use humility::core::Core; use num_traits::FromPrimitive; use num_traits::ToPrimitive; diff --git a/humility-arch-cortex/src/tpiu.rs b/humility-arch-cortex/src/tpiu.rs index 80da8741a..e457fecd9 100644 --- a/humility-arch-cortex/src/tpiu.rs +++ b/humility-arch-cortex/src/tpiu.rs @@ -2,11 +2,11 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +use crate::debug::Register; +use crate::register; use anyhow::Result; use bitfield::bitfield; use humility::core::Core; -use crate::debug::Register; -use crate::register; register!(TPIU_SSPSR, 0xe004_0000, #[derive(Copy, Clone)] diff --git a/src/doppel.rs b/humility-cmd/src/doppel.rs similarity index 100% rename from src/doppel.rs rename to humility-cmd/src/doppel.rs diff --git a/src/hiffy.rs b/humility-cmd/src/hiffy.rs similarity index 100% rename from src/hiffy.rs rename to humility-cmd/src/hiffy.rs diff --git a/src/i2c.rs b/humility-cmd/src/i2c.rs similarity index 100% rename from src/i2c.rs rename to humility-cmd/src/i2c.rs diff --git a/src/reflect.rs b/humility-cmd/src/reflect.rs similarity index 100% rename from src/reflect.rs rename to humility-cmd/src/reflect.rs diff --git a/src/test.rs b/humility-cmd/src/test.rs similarity index 100% rename from src/test.rs rename to humility-cmd/src/test.rs diff --git a/humility-core/src/lib.rs b/humility-core/src/lib.rs index 6214bbd3e..da47ad733 100644 --- a/humility-core/src/lib.rs +++ b/humility-core/src/lib.rs @@ -2,9 +2,9 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -pub mod hubris; -pub mod core; pub mod arch; +pub mod core; +pub mod hubris; #[macro_use] extern crate num_derive; diff --git a/load_derive/src/lib.rs b/load_derive/src/lib.rs index f41d5be85..186d8397f 100644 --- a/load_derive/src/lib.rs +++ b/load_derive/src/lib.rs @@ -10,16 +10,20 @@ pub fn load_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream { let input = syn::parse_macro_input!(input as syn::DeriveInput); let ts = match &input.data { - syn::Data::Struct(data) => { - match &data.fields { - syn::Fields::Named(fields) => gen_named_struct(&input.ident, fields), - syn::Fields::Unnamed(fields) => gen_unnamed_struct(&input.ident, fields), - syn::Fields::Unit => { - unimplemented!("unit struct not implemented as DWARF rep \ - not clear at time of writing"); - } + syn::Data::Struct(data) => match &data.fields { + syn::Fields::Named(fields) => { + gen_named_struct(&input.ident, fields) } - } + syn::Fields::Unnamed(fields) => { + gen_unnamed_struct(&input.ident, fields) + } + syn::Fields::Unit => { + unimplemented!( + "unit struct not implemented as DWARF rep \ + not clear at time of writing" + ); + } + }, syn::Data::Enum(data) => gen_enum(&input.ident, data), _ => unimplemented!("unsupported type for derive"), }; @@ -49,13 +53,19 @@ fn gen_enum( let #name: #fty = crate::reflect::Load::from_value(&contents[#i])?; ) }); - let field_lets = field_lets.collect::(); - - let field_uses = fields.unnamed.iter().enumerate().map(|(i, fld)| { - let name = syn::Ident::new(&format!("field_{}", i), fld.span()); - quote_spanned!(fld.span()=> #name,) - }); - let field_uses = field_uses.collect::(); + let field_lets = + field_lets.collect::(); + + let field_uses = + fields.unnamed.iter().enumerate().map(|(i, fld)| { + let name = syn::Ident::new( + &format!("field_{}", i), + fld.span(), + ); + quote_spanned!(fld.span()=> #name,) + }); + let field_uses = + field_uses.collect::(); arms.push(quote_spanned!(variant.ident.span()=> (stringify!(#var_ident), Some(contents)) => { @@ -74,7 +84,8 @@ fn gen_enum( let name = fld.ident.as_ref().unwrap(); quote_spanned!(fld.span()=> stringify!(#name), ) }); - let field_name_strs = field_name_strs.collect::(); + let field_name_strs = + field_name_strs.collect::(); let field_defs = fields.named.iter().map(|fld| { let name = &fld.ident; @@ -82,8 +93,9 @@ fn gen_enum( #name: crate::reflect::Load::from_value(&contents[stringify!(#name)])?, ) }); - let field_defs = field_defs.collect::(); - + let field_defs = + field_defs.collect::(); + arms.push(quote_spanned!(variant.ident.span()=> (stringify!(#var_ident), Some(contents)) => { let contents = contents.as_struct()?; @@ -179,4 +191,3 @@ fn gen_unnamed_struct( } ) } - diff --git a/src/cmd.rs b/src/cmd.rs index fb35b8545..7d72f53a6 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -2,43 +2,12 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -// mod apptable; -/* -mod diagnose; -mod dump; -mod etm; -mod gpio; -mod hiffy; -mod i2c; -mod itm; -mod jefe; -mod manifest; -mod map; -mod pmbus; -mod probe; -mod qspi; -mod readmem; -mod readvar; -mod renbb; -mod rencm; -mod ringbuf; -mod spd; -mod spi; -mod stackmargin; -mod stmsecure; -mod tasks; -mod test; -mod trace; -*/ - -use humility_cmd::Args; -use crate::{attach_dump, attach_live}; use anyhow::{bail, Result}; -use humility::core::Core; use humility::hubris::*; -use humility_cmd::{Archive, Attach, Validate, Command}; +use humility_cmd::Args; +use humility_cmd::{attach_dump, attach_live}; +use humility_cmd::{Archive, Attach, Command, Validate}; use std::collections::HashMap; -use std::convert::TryInto; use structopt::clap::App; pub fn init<'a, 'b>( @@ -49,33 +18,32 @@ pub fn init<'a, 'b>( let dcmds = [ cmd_apptable::init, - /* - diagnose::init, - dump::init, - etm::init, - gpio::init, - hiffy::init, - i2c::init, - itm::init, - jefe::init, - manifest::init, - map::init, - pmbus::init, - probe::init, - qspi::init, - readmem::init, - readvar::init, - renbb::init, - rencm::init, - ringbuf::init, - spd::init, - spi::init, - stackmargin::init, - tasks::init, - test::init, - trace::init, - stmsecure::init, - */ + cmd_etm::init, + cmd_diagnose::init, + cmd_dump::init, + cmd_etm::init, + cmd_gpio::init, + cmd_hiffy::init, + cmd_i2c::init, + cmd_itm::init, + cmd_jefe::init, + cmd_manifest::init, + cmd_map::init, + cmd_pmbus::init, + cmd_probe::init, + cmd_qspi::init, + cmd_readmem::init, + cmd_readvar::init, + cmd_renbb::init, + cmd_rencm::init, + cmd_ringbuf::init, + cmd_spd::init, + cmd_spi::init, + cmd_stackmargin::init, + cmd_tasks::init, + cmd_test::init, + cmd_trace::init, + cmd_stmsecure::init, ]; for dcmd in &dcmds { diff --git a/src/cmd/jefe.rs b/src/cmd/jefe.rs deleted file mode 100644 index fc9159052..000000000 --- a/src/cmd/jefe.rs +++ /dev/null @@ -1,241 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -use crate::cmd::*; -use crate::Args; -use anyhow::{anyhow, bail, Context, Result}; -use humility::core::Core; -use humility::hubris::*; -use std::num::NonZeroU32; -use std::thread; -use std::time::Duration; -use std::time::Instant; -use structopt::clap::App; -use structopt::StructOpt; - -#[derive(StructOpt, Debug)] -#[structopt(name = "jefe", about = "influence jefe externally")] -struct JefeArgs { - /// sets timeout - #[structopt( - long, short, default_value = "5000", value_name = "timeout_ms", - parse(try_from_str = parse_int::parse) - )] - timeout: u32, - - /// fault the specified task - #[structopt(long, short, conflicts_with_all = &["start", "release", "hold"])] - fault: bool, - - /// start the specified task - #[structopt(long, short, conflicts_with_all = &["release", "hold"])] - start: bool, - - /// hold the specified task - #[structopt(long, short, conflicts_with = "release")] - hold: bool, - - /// release the specified task - #[structopt(long, short)] - release: bool, - - task: String, -} - -#[derive(Debug)] -#[allow(dead_code)] -pub struct JefeVariables<'a> { - hubris: &'a HubrisArchive, - ready: &'a HubrisVariable, - kick: &'a HubrisVariable, - request: &'a HubrisVariable, - requests: &'a HubrisVariable, - errors: &'a HubrisVariable, - task: &'a HubrisVariable, - cached: Option<(u32, u32)>, - kicked: Option, - timeout: u32, - timedout: bool, -} - -#[derive(Copy, Clone, Debug)] -#[repr(u32)] -pub enum JefeRequest { - Start = 1, - Hold = 2, - Release = 3, - Fault = 4, -} - -impl<'a> JefeVariables<'a> { - fn variable( - hubris: &'a HubrisArchive, - name: &str, - wordsize: bool, - ) -> Result<&'a HubrisVariable> { - let v = hubris - .lookup_variable(name) - .context("expected jefe external interface not found")?; - - if wordsize && v.size != 4 { - bail!("expected {} to be size 4, found {}", name, v.size); - } - - Ok(v) - } - - pub fn new( - hubris: &'a HubrisArchive, - timeout: u32, - ) -> Result { - Ok(Self { - hubris, - ready: Self::variable(hubris, "JEFE_EXTERNAL_READY", true)?, - kick: Self::variable(hubris, "JEFE_EXTERNAL_KICK", true)?, - request: Self::variable(hubris, "JEFE_EXTERNAL_REQUEST", true)?, - requests: Self::variable(hubris, "JEFE_EXTERNAL_REQUESTS", true)?, - errors: Self::variable(hubris, "JEFE_EXTERNAL_ERRORS", true)?, - task: Self::variable(hubris, "JEFE_EXTERNAL_TASKINDEX", true)?, - cached: None, - kicked: None, - timeout, - timedout: false, - }) - } - - fn kickit( - &mut self, - core: &mut dyn Core, - request: JefeRequest, - taskid: NonZeroU32, - ) -> Result<()> { - if core.read_word_32(self.ready.addr)? != 1 { - bail!("jefe external control facility unavailable"); - } - - core.halt()?; - - core.write_word_32(self.request.addr, request as u32)?; - core.write_word_32(self.task.addr, taskid.into())?; - - core.write_word_32(self.kick.addr, 1)?; - - self.cached = Some(( - core.read_word_32(self.requests.addr)?, - core.read_word_32(self.errors.addr)?, - )); - - self.kicked = Some(Instant::now()); - - core.run()?; - Ok(()) - } - - fn done(&mut self, core: &mut dyn Core) -> Result { - core.halt()?; - - let vars = ( - core.read_word_32(self.requests.addr)?, - core.read_word_32(self.errors.addr)?, - ); - - core.run()?; - - if let Some(kicked) = self.kicked { - if kicked.elapsed().as_millis() > self.timeout.into() { - bail!("operation timed out"); - } - } - - if let Some(cached) = self.cached { - if vars.0 != cached.0 { - Ok(true) - } else if vars.1 != cached.1 { - bail!("request failed"); - } else { - Ok(false) - } - } else { - Ok(false) - } - } -} - -fn jefe( - hubris: &mut HubrisArchive, - core: &mut dyn Core, - _args: &Args, - subargs: &Vec, -) -> Result<()> { - let subargs = JefeArgs::from_iter_safe(subargs)?; - - let request = if subargs.fault { - JefeRequest::Fault - } else if subargs.start { - JefeRequest::Start - } else if subargs.hold { - JefeRequest::Hold - } else if subargs.release { - JefeRequest::Release - } else { - bail!("one of fault, start, hold, or release must be specified"); - }; - - let task = hubris - .lookup_task(&subargs.task) - .ok_or_else(|| anyhow!("couldn't find task {}", subargs.task))?; - - let id = match task { - HubrisTask::Kernel => { - bail!("cannot change disposition of kernel"); - } - HubrisTask::Task(id) => { - if let Some(id) = NonZeroU32::new(*id) { - id - } else { - bail!("cannot change disposition of supervisor task"); - } - } - }; - - send_request(hubris, core, request, id, subargs.timeout)?; - - info!("successfully changed disposition for {}", subargs.task); - - Ok(()) -} - -pub fn send_request( - hubris: &mut HubrisArchive, - core: &mut dyn Core, - request: JefeRequest, - id: NonZeroU32, - timeout: u32, -) -> Result<()> { - let mut vars = JefeVariables::new(hubris, timeout)?; - - vars.kickit(core, request, id)?; - - loop { - thread::sleep(Duration::from_millis(100)); - if vars.done(core)? { - break; - } - } - - Ok(()) -} - -pub fn init<'a, 'b>() -> (Command, App<'a, 'b>) { - ( - Command::Attached { - name: "jefe", - archive: Archive::Required, - attach: Attach::LiveOnly, - validate: Validate::Booted, - run: jefe, - }, - JefeArgs::clap(), - ) -} diff --git a/src/main.rs b/src/main.rs index 057ab1b85..c67e9ef4c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,24 +2,12 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -#[macro_use] -extern crate log; - -use anyhow::{bail, Result}; - -use humility::core::Core; use humility::hubris::*; use humility_cmd::{Args, Subcommand}; use structopt::StructOpt; mod cmd; -mod hiffy; -mod i2c; -mod test; - -mod doppel; -mod reflect; macro_rules! fatal { ($fmt:expr) => ({ @@ -83,27 +71,6 @@ impl HumilityLog { } } -fn attach_live(args: &Args) -> Result> { - if args.dump.is_some() { - bail!("must be run against a live system"); - } else { - let probe = match &args.probe { - Some(p) => p, - None => "auto", - }; - - humility::core::attach(probe, &args.chip) - } -} - -fn attach_dump(args: &Args, hubris: &HubrisArchive) -> Result> { - if let Some(dump) = &args.dump { - humility::core::attach_dump(dump, hubris) - } else { - bail!("must be run against a dump"); - } -} - fn main() { /* * This isn't hugely efficient, but we actually parse our arguments