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
// Copyright (C) 2026 Piers Finlayson <piers@piers.rocks>
//
// MIT License
//! Argument definitions for `onerom inspect`.
use crate::args::CommandTrait;
use crate::utils::parse_u32;
use clap::{Args, Subcommand};
use enum_dispatch::enum_dispatch;
#[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),
/// Read the current state of the One ROM GPIO pins (not yet supported).
///
/// Displays the direction and logic level of each exposed GPIO pin.
///
/// Example:
///
/// onerom inspect gpio
Gpio(InspectGpioArgs),
}
#[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 (0-15). Reads the currently active slot if omitted.
#[arg(long, short='l', value_name = "INDEX", value_parser = parse_u32)]
pub slot: Option<u8>,
/// Save the image data to this file.
#[arg(long, short, visible_alias = "out", value_name = "FILE", value_parser = parse_u32)]
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 specific pin.
#[arg(long, value_name = "PIN")]
pub pin: Option<u8>,
}
impl CommandTrait for InspectGpioArgs {
fn requires_device(&self) -> bool {
true
}
}