Commit 8f0fb59
authored
Revamp how attaching works (#652)
## Overview
The `CommandKind` type has confusing, non-orthogonal behavior.
It combines two ideas:
- Do we need a `HubrisArchive`, and if so, does it need to be fully loaded
("cooked") or do we just need the raw ZIP data?
- Do we need to attach to a system (called a "core")?
- If so, what kind of attachments are valid?
- Live system (debugger)
- Live system (network)
- Dump (RAM)
- Archive (flash only)
- How should we validate any attached system?
These two big ideas ("do we need an archive" and "do we need a core") are
combined in unintuitive ways. For example, `CommandKind::Unattached { archive:
Archive::Required }` tries to attach to both a dump and an archive, but does not
fail if the archive is absent (see
#564 (comment)).
It's also unfortunate that it's defined at the `Command` level, because commands
may not have consistent behavior across all of their subcommands. For example,
`humility hiffy -l` just lists Hiffy APIs from an archive, and does not require
attaching to a system. Indeed, if you run `humility hiffy -l` with an archive
**and** you have a probe attached to an SP running a different image, it will
fail:
```console
$ humility --archive=build-cosmo-b-dev-image-default.zip hiffy -l
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.15s
Running `target/debug/humility hiffy -l`
humility: attached via ST-Link V3
humility hiffy failed: image ID in archive ([bd, 1b, fb, 72, 35, 4b, a7, 48]) does not equal ID at 0x8004f50 ([7c, 56, 0, 8, 38, 54, 0, 8])
# this is an attached Grapefruit, why is it interfering with hiffy -l?
```
Some commands work around this by doing an extra parse of the arguments in their
`init` function, then return a different `Command` depending on arguments:
https://github.com/oxidecomputer/humility/blob/27d1f1549e58a54538657ab5359be9a5ae856de1/cmd/monorail/src/lib.rs#L1186-L1221
This works, but is annoying to have to do!
I have one more complaint, which is improved but not entirely fixed in this PR:
the `HubrisArchive` is default-constructed, then _actually_ populated based on
`archive` or `dump` arguments; if neither is present, then archive is not valid!
Commands have to work around this (with varying degrees of incredulity), e.g.
https://github.com/oxidecomputer/humility/blob/27d1f1549e58a54538657ab5359be9a5ae856de1/cmd/reset/src/lib.rs#L33-L37
## So, what's to be done?
This PR removes `CommandKind` entirely. It is replaced with a set of functions
on `Cli` to build archives and cores, which can be called by commands when they
are needed (instead of before the command is invoked).
### Archive handling
- `archive` returns the archive (if available); it **does not** ever return a
default-constructed archive
- `try_archive` returns an optional archive
- `raw_archive` returns the bytes of the ZIP file
All of these return a full `HubrisArchive`; it is the caller's responsibility to
store it somewhere and hand out references.
### Attachment
- `attach_live` attaches to a live system (debugger or `net`-based)
- `attach_live_or_dump` attaches to a live system or dump
- `attach_archive` attaches to an archive
There are also additional small wrapper functions with suffixes for validation,
e.g. `attach_live_booted` checks that the live system has booted. Each of these
functions returns a `Box<dyn Core>` directly, instead of stashing it in the
`ExecutionContext`.
## Changes to commands
Each command is updated to construct its archive and/or core on-demand. It's
mostly mechanical porting, e.g.
```rust
CommandKind::Attached {
archive: Archive::Required,
attach: Attach::LiveOnly,
validate: Validate::Booted,
}
```
becomes
```rust
let hubris = &context.cli.archive()?;
let core = &mut *context.cli.attach_live_booted(hubris)?;
```
...but there are a few weird edge cases – for example, `humility probe` now uses
`attach_probe` directly.1 parent beb5a08 commit 8f0fb59
426 files changed
Lines changed: 1809 additions & 1551 deletions
File tree
- cmd
- auxflash/src
- console-proxy/src
- counters/src
- dashboard/src
- debugmailbox/src
- diagnose/src
- discover/src
- doc/src
- dump/src
- ereport/src
- exec/src
- extract/src
- flash/src
- gimlet/src
- gpio/src
- hash/src
- hiffy/src
- host/src
- hydrate/src
- i2c/src
- ibc/src
- jefe/src
- lpc55gpio/src
- lsusb/src
- manifest/src
- map/src
- monorail/src
- mwocp/src
- net/src
- pmbus/src
- powershelf/src
- power/src
- probe
- src
- qspi/src
- readmem/src
- readvar/src
- rebootleby/src
- registers
- src
- rencm/src
- rendmp/src
- reset/src
- ringbuf/src
- sbrmi/src
- sensors/src
- spctrl/src
- spd/src
- spi/src
- stackmargin/src
- stmsecure
- src
- tasks/src
- test/src
- tofino-eeprom/src
- validate/src
- vpd/src
- writeword
- src
- humility-bin
- src
- tests/cmd
- counters-arg
- counters-csv-full
- counters-csv
- counters-full
- counters-json
- counters-list
- counters
- hiffy-list
- manifest
- map
- readvar-list
- ringbuf-arg
- sensors-read
- sensors
- humility-cli
- src
- humility-cmd
- src
- humility-core/src
- humility-hiffy/src
- humility-probes-core/src
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
117 | | - | |
| 116 | + | |
| 117 | + | |
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
42 | | - | |
| 41 | + | |
43 | 42 | | |
44 | 43 | | |
45 | 44 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | 16 | | |
18 | 17 | | |
19 | | - | |
| 18 | + | |
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
| |||
99 | 98 | | |
100 | 99 | | |
101 | 100 | | |
102 | | - | |
103 | 101 | | |
104 | | - | |
| 102 | + | |
| 103 | + | |
105 | 104 | | |
106 | 105 | | |
107 | 106 | | |
| |||
132 | 131 | | |
133 | 132 | | |
134 | 133 | | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
| 134 | + | |
145 | 135 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | 116 | | |
122 | 117 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
314 | 314 | | |
315 | 315 | | |
316 | 316 | | |
317 | | - | |
318 | 317 | | |
319 | | - | |
| 318 | + | |
| 319 | + | |
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
209 | | - | |
| 209 | + | |
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
| |||
324 | 324 | | |
325 | 325 | | |
326 | 326 | | |
327 | | - | |
328 | | - | |
329 | | - | |
| 327 | + | |
330 | 328 | | |
331 | 329 | | |
332 | 330 | | |
| 331 | + | |
333 | 332 | | |
334 | 333 | | |
335 | 334 | | |
| |||
428 | 427 | | |
429 | 428 | | |
430 | 429 | | |
| 430 | + | |
431 | 431 | | |
432 | 432 | | |
433 | 433 | | |
| |||
623 | 623 | | |
624 | 624 | | |
625 | 625 | | |
626 | | - | |
627 | | - | |
628 | | - | |
629 | | - | |
630 | | - | |
631 | | - | |
632 | | - | |
633 | | - | |
634 | | - | |
635 | | - | |
| 626 | + | |
636 | 627 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| |||
736 | 736 | | |
737 | 737 | | |
738 | 738 | | |
739 | | - | |
740 | | - | |
741 | | - | |
742 | | - | |
743 | 739 | | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
744 | 743 | | |
745 | 744 | | |
746 | 745 | | |
| |||
767 | 766 | | |
768 | 767 | | |
769 | 768 | | |
770 | | - | |
771 | | - | |
772 | | - | |
773 | | - | |
774 | | - | |
775 | | - | |
776 | | - | |
777 | | - | |
778 | | - | |
779 | | - | |
| 769 | + | |
780 | 770 | | |
781 | 771 | | |
782 | 772 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| |||
464 | 464 | | |
465 | 465 | | |
466 | 466 | | |
467 | | - | |
468 | 467 | | |
469 | 468 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | | - | |
| 22 | + | |
24 | 23 | | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
| 29 | + | |
40 | 30 | | |
41 | 31 | | |
42 | 32 | | |
| |||
83 | 73 | | |
84 | 74 | | |
85 | 75 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | 76 | | |
| 77 | + | |
| 78 | + | |
90 | 79 | | |
91 | 80 | | |
92 | 81 | | |
| |||
0 commit comments