Skip to content
Draft
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
427 changes: 407 additions & 20 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ rust-version = "1.91" # if this changes, edit ci.yaml as well!
# `git`-based deps
gimlet-inspector-protocol = { git = "https://github.com/oxidecomputer/gimlet-inspector-protocol" }
hif = { git = "https://github.com/oxidecomputer/hif" }
hubtools = { git = "https://github.com/oxidecomputer/hubtools.git" }
humpty = { git = "https://github.com/oxidecomputer/humpty", version = "0.1.5" }
idol = { git = "https://github.com/oxidecomputer/idolatry.git" }
idt8a3xxxx = { git = "https://github.com/oxidecomputer/idt8a3xxxx" }
Expand All @@ -113,8 +114,8 @@ humility = { path = "./humility-core", package = "humility-core" }
humility-arch-arm = { path = "./humility-arch-arm" }
humility-auxflash = { path = "./humility-auxflash" }
humility-cortex = { path = "./humility-arch-cortex" }
humility-cmd = { path = "./humility-cmd", default-features = false }
humility-cli = { path = "./humility-cli" }
humility-cmd = { path = "./humility-cmd" }
humility-cli = { path = "./humility-cli", default-features = false }
humility-dump-agent = { path = "./humility-dump-agent" }
humility-doppel = { path = "./humility-doppel" }
humility-hiffy = { path = "./humility-hiffy" }
Expand Down Expand Up @@ -170,7 +171,7 @@ cmd-registers = { path = "./cmd/registers", package = "humility-cmd-registers" }
cmd-reset = { path = "./cmd/reset", package = "humility-cmd-reset" }
cmd-rencm = { path = "./cmd/rencm", package = "humility-cmd-rencm" }
cmd-rendmp = { path = "./cmd/rendmp", package = "humility-cmd-rendmp" }
cmd-ringbuf = { path = "./cmd/ringbuf", package = "humility-cmd-ringbuf" }
cmd-hacking-ringbuf = { path = "./cmd/ringbuf", package = "humility-hacking-ringbuf" }
cmd-sbrmi = { path = "./cmd/sbrmi", package = "humility-cmd-sbrmi" }
cmd-sensors = { path = "./cmd/sensors", package = "humility-cmd-sensors" }
cmd-spctrl = { path = "./cmd/spctrl", package = "humility-cmd-spctrl" }
Expand Down
18 changes: 4 additions & 14 deletions cmd/auxflash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ use anyhow::Result;
use clap::{CommandFactory, Parser};
use colored::Colorize;
use humility_cli::ExecutionContext;
use humility_cmd::CommandKind;

use humility_auxflash::AuxFlashHandler;
use humility_cmd::{Archive, Attach, Command, Validate};
use humility_cmd::Command;

#[derive(Parser, Debug)]
#[clap(name = "auxflash", about = env!("CARGO_PKG_DESCRIPTION"))]
Expand Down Expand Up @@ -99,9 +98,9 @@ fn auxflash_status(mut worker: AuxFlashHandler, verbose: bool) -> Result<()> {
}

fn auxflash(context: &mut ExecutionContext) -> Result<()> {
let core = &mut **context.core.as_mut().unwrap();
let subargs = AuxFlashArgs::try_parse_from(&context.cli.cmd)?;
let hubris = context.archive.as_ref().unwrap();
let hubris = &context.cli.archive()?;
let core = &mut *context.cli.attach_live_booted(hubris)?;
let mut worker = AuxFlashHandler::new(hubris, core, subargs.timeout)?;

match subargs.cmd {
Expand Down Expand Up @@ -132,14 +131,5 @@ fn auxflash(context: &mut ExecutionContext) -> Result<()> {
}

pub fn init() -> Command {
Command {
app: AuxFlashArgs::command(),
name: "auxflash",
run: auxflash,
kind: CommandKind::Attached {
archive: Archive::Required,
attach: Attach::LiveOnly,
validate: Validate::Booted,
},
}
Command { app: AuxFlashArgs::command(), name: "auxflash", run: auxflash }
}
7 changes: 1 addition & 6 deletions cmd/console-proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::path::PathBuf;

use clap::{CommandFactory, Parser};

use humility_cmd::{Archive, Attach, Command, CommandKind, Validate};
use humility_cmd::Command;

#[cfg(not(windows))]
mod posix;
Expand Down Expand Up @@ -113,10 +113,5 @@ pub fn init() -> Command {
app: UartConsoleArgs::command(),
name: "console-proxy",
run: console_proxy,
kind: CommandKind::Attached {
archive: Archive::Required,
attach: Attach::LiveOnly,
validate: Validate::Booted,
},
}
}
45 changes: 8 additions & 37 deletions cmd/console-proxy/src/posix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::os::unix::io::AsRawFd;
use std::time::Duration;
use std::{io, thread};

use anyhow::{Context, Result, anyhow, bail};
use anyhow::{Context, Result};
use clap::Parser;
use crossbeam_channel::{Sender, select};
use picocom_map::RemapRules;
Expand Down Expand Up @@ -53,7 +53,7 @@ impl<'a> UartConsoleHandler<'a> {
fn uart_read(&mut self, buf: &mut [u8]) -> Result<usize> {
let op = self.hubris.get_idol_command("ControlPlaneAgent.uart_read")?;

let value = humility_hiffy::hiffy_call(
let v = humility_hiffy::hiffy_call::<u32>(
self.hubris,
self.core,
&mut self.context,
Expand All @@ -63,14 +63,6 @@ impl<'a> UartConsoleHandler<'a> {
Some(buf),
)?;

let v = match value {
Ok(v) => v,
Err(e) => bail!("Got Hiffy error: {e}"),
};

let v =
v.as_base()?.as_u32().ok_or_else(|| anyhow!("Couldn't get U32"))?;

Ok(v as usize)
}

Expand All @@ -80,7 +72,7 @@ impl<'a> UartConsoleHandler<'a> {

let buf = &buf[..usize::min(buf.len(), HIFFY_BUF_SIZE)];

let value = humility_hiffy::hiffy_call(
let v = humility_hiffy::hiffy_call::<u32>(
self.hubris,
self.core,
&mut self.context,
Expand All @@ -90,14 +82,6 @@ impl<'a> UartConsoleHandler<'a> {
None,
)?;

let v = match value {
Ok(v) => v,
Err(e) => bail!("Got Hiffy error: {e}"),
};

let v =
v.as_base()?.as_u32().ok_or_else(|| anyhow!("Couldn't get U32"))?;

Ok(v as usize)
}

Expand Down Expand Up @@ -180,7 +164,7 @@ impl<'a> UartConsoleHandler<'a> {
.hubris
.get_idol_command("ControlPlaneAgent.set_humility_uart_client")?;

let value = humility_hiffy::hiffy_call(
humility_hiffy::hiffy_call::<()>(
self.hubris,
self.core,
&mut self.context,
Expand All @@ -189,19 +173,15 @@ impl<'a> UartConsoleHandler<'a> {
None,
None,
)?;

match value {
Ok(_) => Ok(()),
Err(e) => bail!("Got Hiffy error: {e}"),
}
Ok(())
}

fn current_client(&mut self) -> Result<()> {
let op = self
.hubris
.get_idol_command("ControlPlaneAgent.get_uart_client")?;

let value = humility_hiffy::hiffy_call(
let value = humility_hiffy::hiffy_call::<humility::reflect::Enum>(
self.hubris,
self.core,
&mut self.context,
Expand All @@ -211,15 +191,6 @@ impl<'a> UartConsoleHandler<'a> {
None,
)?;

let value = match value {
Ok(v) => v,
Err(e) => bail!("Got Hiffy error: {e}"),
};

let value = value
.as_enum()
.context("get_uart_client did not return an enum")?;

println!("Current console client: {}", value.disc());
Ok(())
}
Expand Down Expand Up @@ -314,9 +285,9 @@ impl UnrawTermiosGuard {
}

pub(super) fn console_proxy(context: &mut ExecutionContext) -> Result<()> {
let core = &mut **context.core.as_mut().unwrap();
let subargs = UartConsoleArgs::try_parse_from(&context.cli.cmd)?;
let hubris = context.archive.as_ref().unwrap();
let hubris = &context.cli.archive()?;
let core = &mut *context.cli.attach_live_booted(hubris)?;
let mut worker = UartConsoleHandler::new(
hubris,
core,
Expand Down
19 changes: 5 additions & 14 deletions cmd/counters/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ use humility::core::Core;
use humility::hubris::*;
use humility::reflect::{self, Load, Value};
use humility_cli::ExecutionContext;
use humility_cmd::{Archive, Attach, Command, CommandKind, Validate};
use humility_cmd::Command;
use humility_doppel::{CountedRingbuf, CounterVariant, Counters};
use indexmap::IndexMap;
use std::collections::BTreeMap;
Expand Down Expand Up @@ -324,12 +324,11 @@ const LIST_HINT: &str = "use `humility counters list` to list all \
available counters";

fn counters(context: &mut ExecutionContext) -> Result<()> {
let core = &mut **context.core.as_mut().unwrap();
let hubris = context.archive.as_ref().unwrap();

let hubris = &context.cli.archive()?;
let subargs = CountersArgs::try_parse_from(&context.cli.cmd)?;

if let Some(Subcmd::Ipc(ipc)) = subargs.command {
let core = &mut *context.cli.attach_live_or_dump_match(hubris)?;
return ipc.ipc_counter_dump(hubris, core);
}
let name = subargs.name();
Expand Down Expand Up @@ -428,6 +427,7 @@ fn counters(context: &mut ExecutionContext) -> Result<()> {
}

let mut json: IndexMap<&str, IndexMap<_, _>> = IndexMap::new();
let core = &mut *context.cli.attach_live_or_dump_match(hubris)?;
for (t, ctrs) in counters {
// Try not to use `?` here, because it causes one bad counter to make
// them all unavailable. Instead, construct an iterator of
Expand Down Expand Up @@ -623,14 +623,5 @@ fn hint() -> impl std::fmt::Display {
}

pub fn init() -> Command {
Command {
app: CountersArgs::command(),
name: "counters",
run: counters,
kind: CommandKind::Attached {
archive: Archive::Required,
attach: Attach::Any,
validate: Validate::Match,
},
}
Command { app: CountersArgs::command(), name: "counters", run: counters }
}
20 changes: 5 additions & 15 deletions cmd/dashboard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use hif::*;
use humility::core::Core;
use humility::hubris::*;
use humility_cli::ExecutionContext;
use humility_cmd::{Archive, Attach, Command, CommandKind, Validate};
use humility_cmd::Command;
use humility_hiffy::*;
use humility_idol::{self as idol, HubrisIdol};
use ratatui::{
Expand Down Expand Up @@ -736,11 +736,10 @@ where
}

fn dashboard(context: &mut ExecutionContext) -> Result<()> {
let hubris = context.archive.as_ref().unwrap();

let core = &mut **context.core.as_mut().unwrap();

let subargs = DashboardArgs::try_parse_from(&context.cli.cmd)?;
let hubris = &context.cli.archive()?;
let core = &mut *context.cli.attach_live_booted(hubris)?;

let dashboard = Dashboard::new(hubris, core, &subargs)?;

// setup terminal
Expand All @@ -767,16 +766,7 @@ fn dashboard(context: &mut ExecutionContext) -> Result<()> {
}

pub fn init() -> Command {
Command {
app: DashboardArgs::command(),
name: "dashboard",
run: dashboard,
kind: CommandKind::Attached {
archive: Archive::Required,
attach: Attach::LiveOnly,
validate: Validate::Booted,
},
}
Command { app: DashboardArgs::command(), name: "dashboard", run: dashboard }
}

fn sensor_ops(
Expand Down
3 changes: 1 addition & 2 deletions cmd/debugmailbox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use anyhow::{Context, Result, bail};
use byteorder::{ByteOrder, LittleEndian, WriteBytesExt};
use clap::{CommandFactory, Parser};
use humility_cli::ExecutionContext;
use humility_cmd::{Archive, Command, CommandKind};
use humility_cmd::Command;
use probe_rs::{
DebugProbeError, DebugProbeSelector, Probe,
architecture::arm::{ApAddress, ArmProbeInterface, DapError, DpAddress},
Expand Down Expand Up @@ -464,6 +464,5 @@ pub fn init() -> Command {
app: DebugMailboxArgs::command(),
name: "debugmailbox",
run: debugmailboxcmd,
kind: CommandKind::Unattached { archive: Archive::Ignored },
}
}
19 changes: 4 additions & 15 deletions cmd/diagnose/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,14 @@ use clap::{CommandFactory, Parser};
use humility::core::Core;
use humility::hubris::*;
use humility_cli::ExecutionContext;
use humility_cmd::CommandKind;
use humility_cmd::{Archive, Attach, Command, Validate};
use humility_cmd::Command;
use humility_doppel::{GenOrRestartCount, Task, TaskDesc, TaskState};
use std::num::NonZeroU32;
use std::time::Duration;

/// Command registration.
pub fn init() -> Command {
Command {
app: DiagnoseArgs::command(),
name: "diagnose",
run: diagnose,
kind: CommandKind::Attached {
archive: Archive::Required,
attach: Attach::Any,
validate: Validate::Booted,
},
}
Command { app: DiagnoseArgs::command(), name: "diagnose", run: diagnose }
}

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -83,10 +73,9 @@ fn section(title: &str) {
}

fn diagnose(context: &mut ExecutionContext) -> Result<()> {
let core = &mut **context.core.as_mut().unwrap();
let hubris = context.archive.as_ref().unwrap();

let subargs = DiagnoseArgs::try_parse_from(&context.cli.cmd)?;
let hubris = &context.cli.archive()?;
let core = &mut *context.cli.attach_live_or_dump_booted(hubris)?;

section("Initial Inspection");

Expand Down
7 changes: 3 additions & 4 deletions cmd/discover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use colored::Colorize;
use hubpack::SerializedSize;
use humility::net::decode_iface;
use humility_cli::ExecutionContext;
use humility_cmd::{Archive, Command, CommandKind};
use humility_cmd::Command;
use serde::{Deserialize, Serialize};

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -313,9 +313,9 @@ fn discover_dump(seen: BTreeSet<Target>, image_id: Option<&[u8]>) {

fn discover_run(context: &mut ExecutionContext) -> Result<()> {
let subargs = DiscoverArgs::try_parse_from(&context.cli.cmd)?;
let hubris = context.archive.as_ref().unwrap();
let hubris = &context.cli.try_archive()?;

let image_id = hubris.image_id();
let image_id = hubris.as_ref().map(|h| h.image_id());
if image_id.is_none() {
humility::warn!("no archive provided; not checking for compatibility");
}
Expand All @@ -330,6 +330,5 @@ pub fn init() -> Command {
app: DiscoverArgs::command(),
name: "discover",
run: discover_run,
kind: CommandKind::Detached { archive: Archive::Optional },
}
}
9 changes: 2 additions & 7 deletions cmd/doc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use anyhow::{Result, bail};
use clap::{CommandFactory, Parser};
use humility_cli::ExecutionContext;
use humility_cmd::{Archive, Command, CommandKind};
use humility_cmd::Command;
use std::collections::HashMap;
use termimad::*;

Expand Down Expand Up @@ -64,10 +64,5 @@ fn doc(context: &mut ExecutionContext) -> Result<()> {
}

pub fn init() -> Command {
Command {
app: DocArgs::command(),
name: "doc",
run: doc,
kind: CommandKind::Unattached { archive: Archive::Ignored },
}
Command { app: DocArgs::command(), name: "doc", run: doc }
}
Loading
Loading