Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 74 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,60 @@
This repository contains a libraries and example programs for interacting with
a hoth-class root of trust.

# Build via meson
## Prerequisites

To build libhoth, you will need `meson`, `ninja`, and several development libraries. On Ubuntu/Debian, you can install them with:

```bash
sudo apt-get update
sudo apt-get install meson libusb-1.0-0-dev libsystemd-dev libcap-dev libgtest-dev
```

## Build via Meson

```bash
meson build
ninja -C build
./build/examples/htool
```

### Running Tests (Meson)

```bash
meson test -C build
```

### Optional: D-Bus Backend (Meson)

To enable the D-Bus backend:

```bash
meson build -Ddbus_backend=true
ninja -C build
```
$ meson build
$ (cd build && ninja)
$ build/examples/htool

## Build via Bazel

```bash
bazel build //...
./bazel-bin/examples/htool
```

# Build via Bazel
### Running Tests (Bazel)

```bash
bazel test //...
```
$ bazel build ...
$ bazel-bin/examples/htool

### Optional: D-Bus Backend (Bazel)

To enable the D-Bus backend:

```bash
bazel build --define dbus_backend=true //examples:htool
```

# examples/htool
## examples/htool

htool is a command line tool for performing basic actions against a hoth RoT.

Expand All @@ -31,34 +69,41 @@ Available subcommands: (append --help to subcommand for details)
show chipinfo - Return details about this specific RoT chip.
spi read - Read from SPI flash into a file
spi update - Write a file to SPI flash (erase + program).
target reset on - Put the target device into reset.
target reset off - Take the target device out of reset
target reset pulse - Quickly put the target device in and out of reset
console - Open a console for communicating with the RoT or devices attached to the RoT.
payload status - Show payload status
spi passthrough on/off - Enable/Disable SPS->SPI passthrough.
target reset on/off/pulse - Control the target device reset pin.
console - Open a console for communicating with the RoT.
payload status/update/read/info - Manage Titan payload images.
dfu update/check - Directly install or verify PIE-RoT firmware updates.
flash_spi_info - Get SPI NOR flash info.
statistics - Show statistics
statistics - Show statistics.
get_panic - Retrieve or clear the stored panic record.
authz_record read - Read the current authorization record
authz_record erase - Erase the current authorization record
authz_record build - Build an empty authorization record for the chip
authz_record set - Upload an authorization record to the chip
authz_record read/erase/build/set - Manage authorization records.
i2c detect/read/write/muxctrl - Perform I2C transactions or control I2C mux.
rot_usb muxctrl - Control USB mux select.
jtag read_idcode/test_bypass/verify_pld - Perform JTAG operations.
storage read/write/delete - Manage controlled storage.

Global flags:
--transport (default: "")
The method of connecting to the RoT; for example 'spidev'/'usb'/'mtd'
The method of connecting to the RoT; for example 'spidev'/'usb'/'mtd'/'dbus'
--usb_loc (default: "")
The full bus-portlist location of the RoT; for example '1-10.4.4.1'.
--usb_product (default: "")
If there is a single USB RoT with this substring in the USB product string, use it.
--spidev_path (default: "")
The full SPIDEV path of the RoT; for example '/dev/spidev0.0'.
--spidev_atomic (default: "false")
If true, force spidev to use a single atomic ioctl.
--mtddev_path (default: "")
The full MTD path of the RoT mailbox; for example '/dev/mtd0'. If unspecified, will attempt to detect the correct device automatically
The full MTD path of the RoT mailbox; for example '/dev/mtd0'.
--mtddev_name (default: "hoth-mailbox")
The MTD name of the RoT mailbox; for example 'hoth-mailbox'.
The MTD name of the RoT mailbox.
--mailbox_location (default: "0")
The location of the mailbox on the RoT, for 'spidev' or 'mtd' transports; for example '0x900000'.
The location of the mailbox on the RoT.
--dbus_hoth_id (default: "")
The hoth ID associated with the RoT's hothd service.
--connect_timeout (default: "10s")
Maximum duration to retry opening a busy transport.
```

```
Expand All @@ -72,6 +117,7 @@ Usage: spi update <source-file>
-s --start (default: "0")
start address
-v --verify (default: "true")
-a --address_mode (default: "3B/4B")

$ echo "Hello world" > /tmp/hello
$ htool spi update -s 0x5000 /tmp/hello
Expand All @@ -85,6 +131,7 @@ Usage: spi read <dest-file>
-s --start (default: "0")
start address
-n --length
-a --address_mode (default: "3B/4B")

$ htool spi read -s 0x5000 -n 16 /dev/stdout | hexdump -C
Reading: 100% - 0kB / 0kB 514 kB/sec; 0.0 s remaining
Expand All @@ -101,5 +148,10 @@ Usage: console
Drive the UART's TX net even if Hoth isn't sure whether some other device else is driving it. Only use this option if you are CERTAIN there is no debugging hardware attached.
-h --history (default: "false")
Include data bufferred before the current time.
-n --onlcr (default: "false")
Translate received "\n" to "\r\n".
-b --baud_rate (default: "0")
-s --snapshot (default: "false")
Print a snapshot of most recent console messages.
```

3 changes: 3 additions & 0 deletions examples/htool.c
Original file line number Diff line number Diff line change
Expand Up @@ -1846,6 +1846,9 @@ static const struct htool_param GLOBAL_FLAGS[] = {
.default_value = "100",
.desc = "Interval duration (in microseconds) to wait before checking SPI "
"device status again when it indicates that the device is busy"},
// TODO(michaelfield) : b/346345769 - enable spidev mode auto-detection
{HTOOL_FLAG_VALUE, .name = "spidev_mode", .default_value = "single",
.desc = "SPI mode toggles (single|dual|quad)."},
{HTOOL_FLAG_VALUE, .name = "mtddev_path", .default_value = "",
.desc = "The full MTD path of the RoT mailbox; for example "
"'/dev/mtd0'. If unspecified, will attempt to detect "
Expand Down
15 changes: 15 additions & 0 deletions examples/htool_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ struct libhoth_device* htool_libhoth_spi_device(void) {

int rv;
const char* spidev_path_str;
const char* mode_str;
uint32_t mailbox_location;
bool atomic;
uint32_t spidev_speed_hz;
uint32_t spidev_device_busy_wait_timeout;
uint32_t spidev_device_busy_wait_check_interval;
rv = htool_get_param_string(htool_global_flags(), "spidev_path",
&spidev_path_str) ||
htool_get_param_string(htool_global_flags(), "spidev_mode", &mode_str) ||
htool_get_param_u32(htool_global_flags(), "mailbox_location",
&mailbox_location) ||
htool_get_param_bool(htool_global_flags(), "spidev_atomic", &atomic) ||
Expand All @@ -54,6 +56,18 @@ struct libhoth_device* htool_libhoth_spi_device(void) {
return NULL;
}

enum libhoth_spi_mode operation_mode;
if (!strcmp(mode_str, "single")) {
operation_mode = LIBHOTH_SPI_MODE_SINGLE;
} else if (!strcmp(mode_str, "dual")) {
operation_mode = LIBHOTH_SPI_MODE_DUAL;
} else if (!strcmp(mode_str, "quad")) {
operation_mode = LIBHOTH_SPI_MODE_QUAD;
} else {
fprintf(stderr, "Invalid spidev mode: %s\n", mode_str);
return NULL;
}

if (strlen(spidev_path_str) <= 0) {
fprintf(stderr, "Invalid spidev path: %s\n", spidev_path_str);
return NULL;
Expand All @@ -78,6 +92,7 @@ struct libhoth_device* htool_libhoth_spi_device(void) {
.mailbox = mailbox_location,
.atomic = atomic,
.speed = spidev_speed_hz,
.operation_mode = operation_mode,
.device_busy_wait_timeout = spidev_device_busy_wait_timeout,
.device_busy_wait_check_interval = spidev_device_busy_wait_check_interval,
.timeout_us = timeout_us,
Expand Down
Loading