1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
// Copyright (C) 2026 Piers Finlayson <piers@piers.rocks>
//
// MIT License
//! Argument definitions for `onerom inspect`.
use crate::args::CommandTrait;
use crate::utils::{parse_u8, parse_u32};
use clap::{Args, Subcommand};
use enum_dispatch::enum_dispatch;
use onerom_cli::pin::{Pin, parse_pin};
#[derive(Debug, Args)]
pub struct InspectArgs {
#[command(subcommand)]
pub command: InspectCommands,
}
impl CommandTrait for InspectArgs {
fn requires_device(&self) -> bool {
self.command.requires_device()
}
}
#[enum_dispatch(CommandTrait)]
#[derive(Debug, Subcommand)]
pub enum InspectCommands {
/// Display identity and configuration information for a One ROM.
///
/// Shows the device's serial number, user-assigned name, board type,
/// MCU, firmware version, and hardware revision.
///
/// Example:
/// onerom inspect info
///
/// onerom --serial 1234abcd inspect info
Info(InspectInfoArgs),
/// Display runtime telemetry from a One ROM (not yet supported).
///
/// Shows access counts, timing statistics, and other runtime metrics
/// collected by the device firmware.
///
/// Example:
/// onerom inspect telemetry
Telemetry(InspectTelemetryArgs),
/// List the ROM image slots (formerly sets) stored on a One ROM.
///
/// Displays the index, ROM type, size, and description of each
/// configured image slot, and indicates which slot is currently active.
///
/// Example:
///
/// onerom inspect slots
Slots(InspectSlotsArgs),
/// Read and display the ROM image currently loaded in a slot (not yet supported).
///
/// Displays or saves the ROM image data from the specified slot.
/// If no slot is specified, reads the image currently being served.
///
/// Examples:
///
/// onerom inspect image --slot 2
///
/// onerom inspect image --slot 2 --output kernal-backup.bin
Image(InspectImageArgs),
/// Read data from One ROM's SRAM or the live ROM image.
///
/// Peek provides read access to device memory. Use `inspect peek memory`
/// for SRAM reads and `inspect peek live` for reads from the ROM image
/// currently being served.
///
/// Examples:
///
/// onerom inspect peek memory --address 0x20000000 --length 128
///
/// onerom inspect peek live --address 0x100 --length 64
#[command(
subcommand_value_name = "COMMAND",
subcommand_help_heading = "Commands"
)]
Peek(InspectPeekArgs),
/// Show what every One ROM GPIO is, and what it is doing.
///
/// One row per MCU GPIO: everything the GPIO is - its signal under the ROM
/// currently being served, the board peripheral it drives, the header pad
/// it surfaces on - plus its direction and level, whether it is
/// 5V-tolerant, and what One ROM itself is using it for.
///
/// Only GPIOs connected to something are listed; --all adds the rest.
/// --verbose adds a legend explaining where each column comes from.
///
/// The device reports only a coarse category - free, read by serving,
/// driven by serving, or a system pin - along with the level and
/// direction. Every name in the table comes from this CLI's board and chip
/// metadata, not from the device.
///
/// Examples:
///
/// onerom inspect gpio
///
/// onerom inspect gpio --all
///
/// onerom inspect gpio --pin gpio9
///
/// onerom inspect gpio --pin x1
Gpio(InspectGpioArgs),
/// Draw the connected One ROM's pin (jumper / programming) header as ASCII.
///
/// Shows the 2xN header along the board's top edge, pad by pad, with the
/// MCU GPIO behind each image-select and X pad and — on RP2350 (Fire)
/// boards — whether that GPIO is 5V-tolerant or 3.3V-only (an ADC pin). The
/// board is inferred from the connected device, or taken from --board.
///
/// Examples:
///
/// onerom inspect header
///
/// onerom inspect header --board fire-24-f
Header(InspectHeaderArgs),
/// Draw the connected One ROM's ROM socket pinout as ASCII.
///
/// Without --chip-type each socket pin is labelled with the GPIO(s) behind it;
/// with --chip-type <chip> the pins show that ROM's functions (address / data /
/// chip-select / …), and --gpio overlays both. The board is inferred from
/// the connected device, or taken from --board.
///
/// Examples:
///
/// onerom inspect socket
///
/// onerom inspect socket --chip-type 2364 --gpio
Socket(InspectSocketArgs),
}
#[derive(Debug, Args)]
pub struct InspectInfoArgs {}
impl CommandTrait for InspectInfoArgs {
fn requires_device(&self) -> bool {
true
}
}
#[derive(Debug, Args)]
pub struct InspectTelemetryArgs {
/// Output telemetry in JSON format.
#[arg(long)]
pub json: bool,
}
impl CommandTrait for InspectTelemetryArgs {
fn requires_device(&self) -> bool {
true
}
}
#[derive(Debug, Args)]
pub struct InspectSlotsArgs {}
impl CommandTrait for InspectSlotsArgs {
fn requires_device(&self) -> bool {
true
}
}
#[derive(Debug, Args)]
pub struct InspectImageArgs {
/// Slot index to read. Reads the currently active slot if omitted.
#[arg(long, value_name = "INDEX", value_parser = parse_u8)]
pub slot: Option<u8>,
/// Save the image data to this file.
#[arg(long, short, visible_alias = "out", value_name = "FILE")]
pub output: Option<String>,
}
impl CommandTrait for InspectImageArgs {
fn requires_device(&self) -> bool {
true
}
}
#[derive(Debug, Args)]
pub struct InspectPeekArgs {
#[command(subcommand)]
pub command: InspectPeekCommands,
}
impl CommandTrait for InspectPeekArgs {
fn requires_device(&self) -> bool {
self.command.requires_device()
}
}
#[enum_dispatch(CommandTrait)]
#[derive(Debug, Subcommand)]
pub enum InspectPeekCommands {
/// Read and display the live ROM image.
///
/// Can be used to read what byte One ROM will serve if queried for a
/// particular address. This is a live read of the currently active image.
///
/// The address is a logical ROM offset starting from 0, not a physical
/// memory address. The device must be in the running state.
///
/// Example:
/// onerom inspect peek live --address 0x100 --length 64
/// onerom inspect peek live --address 0 --length 8192 --output rom-image.bin
Live(InspectPeekLiveArgs),
/// Read and display One ROM's SRAM contents.
///
/// Can be used to read the SRAM from a One ROM. Note that when
/// used on a device in the "Stopped" state, SRAM will not contain
/// meaningful information.
///
/// Most addresses that can be queried via the PICOBOOT protocol can be
/// queried. When in "Stopped" state, flash reads must be performed
/// aligned to flash page boundaries.
///
/// Example:
/// onerom inspect peek memory --address 0x20000000 --length 128
/// onerom inspect peek memory --address 0x10000000 --length 8192 --output flash-start.bin
Memory(InspectPeekMemoryArgs),
}
#[derive(Debug, Args)]
pub struct InspectPeekLiveArgs {
/// Read from the ROM image at this logical address, starting from 0.
///
/// Accepts decimal and hexadecimal (0x prefix) formats.
#[arg(long, short, value_name = "ADDRESS", visible_alias = "addr", value_parser = parse_u32, default_value = "0")]
pub address: u32,
/// Read this many bytes of data from the ROM image.
///
/// Accepts decimal and hexadecimal (0x prefix) formats.
///
/// If not specified the command reads from the --address to the end of
/// the live ROM image
#[arg(long, short, visible_aliases = ["len", "size"], value_name = "LENGTH", value_parser = parse_u32)]
pub length: Option<u32>,
/// Save the image data to this file.
#[arg(long, short, visible_alias = "out", value_name = "FILE")]
pub output: Option<String>,
}
impl CommandTrait for InspectPeekLiveArgs {
fn requires_device(&self) -> bool {
true
}
}
#[derive(Debug, Args)]
pub struct InspectPeekMemoryArgs {
/// Read from this address.
///
/// Accepts decimal and hexadecimal (0x prefix) formats.
#[arg(long, short, visible_alias = "addr", value_name = "ADDRESS", value_parser = parse_u32)]
pub address: u32,
/// Read this many bytes of data.
///
/// Accepts decimal and hexadecimal (0x prefix) formats.
#[arg(long, short, visible_aliases = ["len", "size"], value_name = "LENGTH", value_parser = parse_u32)]
pub length: u32,
/// Save the data to this file.
#[arg(long, short, visible_alias = "out", value_name = "FILE")]
pub output: Option<String>,
}
impl CommandTrait for InspectPeekMemoryArgs {
fn requires_device(&self) -> bool {
true
}
}
#[derive(Debug, Args)]
pub struct InspectGpioArgs {
/// Show only this pin: an MCU GPIO written gpio<N>, or a header pad name
/// (sel_a..sel_e, x1, x2).
///
/// A bare number is rejected - see 'onerom inspect header' for the GPIO
/// behind each header pad.
#[arg(long, value_name = "PIN", value_parser = parse_pin)]
pub pin: Option<Pin>,
/// Board type, overriding what the connected One ROM reports.
///
/// Only needed to resolve a header pad name on a One ROM whose board type
/// this build does not recognise. A GPIO named as gpio<N> needs no board.
#[arg(long, short, value_name = "BOARD")]
pub board: Option<String>,
/// Also show GPIOs with no function at all.
///
/// By default only GPIOs connected to something - a ROM socket signal, a
/// board peripheral or a header pad - are listed. On a 48-GPIO board a
/// quarter of them are connected to nothing, and listing them buries the
/// rest.
#[arg(long, short, conflicts_with = "pin")]
pub all: bool,
}
impl CommandTrait for InspectGpioArgs {
fn requires_device(&self) -> bool {
true
}
}
#[derive(Debug, Args)]
pub struct InspectHeaderArgs {
/// Board type, overriding what the connected One ROM reports.
///
/// Only needed on a One ROM whose board type this build does not
/// recognise. To draw a board by name with no One ROM connected, use
/// 'onerom board header --board <board>'.
#[arg(long, short, value_name = "BOARD")]
pub board: Option<String>,
}
impl CommandTrait for InspectHeaderArgs {
fn requires_device(&self) -> bool {
true
}
}
#[derive(Debug, Args)]
pub struct InspectSocketArgs {
/// Board type, overriding what the connected One ROM reports.
///
/// Only needed on a One ROM whose board type this build does not
/// recognise. To draw a board by name with no One ROM connected, use
/// 'onerom board socket --board <board>'.
#[arg(long, short, value_name = "BOARD")]
pub board: Option<String>,
/// Show ROM pin functions for this chip type (e.g. 2364) instead of GPIOs.
#[arg(long, short = 'c', value_name = "CHIP")]
pub chip_type: Option<String>,
/// Overlay the GPIO(s) behind each pin onto the --chip-type function view.
#[arg(long, requires = "chip_type")]
pub gpio: bool,
}
impl CommandTrait for InspectSocketArgs {
fn requires_device(&self) -> bool {
true
}
}