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
// Copyright (C) 2026 Piers Finlayson <piers@piers.rocks>
//
// MIT License
//! Argument definitions for `onerom firmware`.
use crate::args::{CommandTrait, program::ProgramArgs};
use clap::{Args, Subcommand};
use enum_dispatch::enum_dispatch;
#[derive(Debug, Args)]
pub struct FirmwareArgs {
#[command(subcommand)]
pub command: FirmwareCommands,
}
impl CommandTrait for FirmwareArgs {
fn requires_device(&self) -> bool {
self.command.requires_device()
}
}
#[enum_dispatch(CommandTrait)]
#[derive(Debug, Subcommand)]
pub enum FirmwareCommands {
/// Build a One ROM firmware binary from a ROM configuration.
///
/// Produces a flashable firmware binary for the specified board and MCU.
/// ROM images and configuration are supplied either via a JSON config
/// file or individual --slot arguments.
///
/// Examples:
///
/// onerom firmware build --config-file c64.json --board fire-24-e --out firmware.bin
///
/// onerom firmware build --board fire-24-e \
/// --slot file=kernal.bin,type=2364,cs1=active_low \
/// --out firmware.bin
Build(FirmwareBuildArgs),
/// Inspect the contents of a One ROM firmware binary.
///
/// Displays the firmware version, board type, MCU, and details of any
/// embedded ROM images and metadata.
///
/// Example:
///
/// onerom firmware inspect firmware.bin
Inspect(FirmwareInspectArgs),
/// List available One ROM firmware releases.
///
/// Fetches the release manifest from the network and displays available
/// firmware versions with their supported board types and MCUs.
///
/// Example:
///
/// onerom firmware releases
Releases(FirmwareReleasesArgs),
/// Download a specific release of One ROM firmware.
///
/// Downloads the base (ROM-less) firmware binary for the specified
/// version, board, and MCU.
///
/// Use `program` to build and flash a complete firmware with ROM images in one step.
///
/// Use `firmware build` to build a complete firmware with ROM images
/// from a config, but without flashing.
///
/// Example:
///
/// onerom firmware download --version 0.6.5 --board fire-24-e --out firmware.bin
Download(FirmwareDownloadArgs),
/// List supported chip types.
///
/// Displays the chip types supported by a specific board, or all chip types
/// grouped by pin count.
///
/// Examples:
///
/// onerom firmware chips --board fire-24-e
///
/// onerom firmware chips --all
Chips(FirmwareChipsArgs),
/// Build firmware and program One ROM in one step.
///
/// This is an alias for `onerom program`. Use `onerom program --help` for
/// more details and examples.
Program(ProgramArgs),
}
#[derive(Debug, Args)]
pub struct FirmwareBuildArgs {
/// ROM configuration JSON file. Mutually exclusive with --slot,
/// --config-name, --config-description, --save-config, and --no-config.
#[arg(
long,
short='j',
visible_aliases = ["config-json", "config", "json"],
value_name = "FILE",
conflicts_with_all = ["slot", "config_name", "config_description", "save_config", "no_config"]
)]
pub config_file: Option<String>,
/// ROM slot specification. May be repeated for multiple slots.
///
/// Format: file=<path_or_url>,type=<romtype>[,cs1=<logic>][,cs2=<logic>][,cs3=<logic>][,size_handling=<handling>][,cpu-freq=<freq>][,cpu-vreg=<voltage>][,led=<bool>][,force_16bit=<bool>]
///
/// CS logic values: active_low (or 0), active_high (or 1).
///
/// Required CS lines depend on chip type (e.g. 2332 requires cs1 and cs2).
///
/// Size handling values: none, duplicate (or dup), truncate (or trunc), pad.
///
/// CPU frequency: e.g. 150, 150mhz, 150MHz. Values above 150MHz require
/// confirmation (suppressed with --yes). Sets overclock automatically.
///
/// Vreg voltage: e.g. 1.1, 1.10, 1.10v, 1.10V. Values above 1.10V require
/// confirmation (suppressed with --yes). Must be a supported voltage level.
///
/// Boolean values (led, force_16bit): on/off, true/false, 1/0.
/// force_16bit is only valid on 40-pin boards.
///
/// Examples:
///
/// --slot file=kernal.bin,type=2364,cs1=active_low
///
/// --slot file=chargen.bin,type=2332,cs1=active_low,cs2=active_high
///
/// --slot file=https://example.com/basic.bin,type=2716
///
/// --slot file=small.bin,type=2364,cs1=active_low,size_handling=duplicate
///
/// --slot file=kernal.bin,type=2364,cs1=active_low,cpu-freq=200MHz,cpu-vreg=1.2V
///
/// --slot file=char.bin,type=2332,cs1=active_low,cs2=active_high,led=off
///
/// --slot file=amiga.bin,type=27C400,force_16bit=true
///
/// Mutually exclusive with --config-file and --no-config.
#[arg(
long,
value_name = "SPEC",
visible_alias = "rom",
conflicts_with_all = ["config_file", "no_config"]
)]
pub slot: Vec<String>,
/// Plugin specification. May be repeated for multiple plugins.
///
/// A maximum of one system plugin and one user plugin is supported.
/// A user plugin requires a system plugin.
/// System plugins are always placed in slot 0, user plugins in slot 1.
///
/// Mutually exclusive with --config-file.
///
/// Forms:
/// --plugin usb latest compatible version by name
/// --plugin system/usb with explicit type
/// --plugin usb,version=0.1.0 pinned version
/// --plugin file=path/to/plugin.bin local or remote file
/// --plugin file=https://example.com/plugin.bin
///
#[arg(long, value_name = "SPEC", conflicts_with = "config_file")]
pub plugin: Vec<String>,
/// Name for the generated ROM configuration.
///
/// Mutually exclusive with --config-file.
#[arg(
long,
value_name = "NAME",
visible_alias = "name",
conflicts_with = "config_file"
)]
pub config_name: Option<String>,
/// Description for the generated ROM configuration. Defaults to
/// "Created by the One ROM CLI" if not specified.
///
/// Mutually exclusive with --config-file.
#[arg(long, value_name = "DESC", visible_aliases=["desc", "description"], conflicts_with = "config_file")]
pub config_description: Option<String>,
/// Save the generated ROM configuration to a JSON file.
///
/// Only valid with --slot or --no-config. Mutually exclusive with
/// --config-file.
#[arg(long, value_name = "FILE", conflicts_with = "config_file")]
pub save_config: Option<String>,
/// Target board type (e.g. fire-24-e). Required when not inferrable
/// from a connected One ROM.
#[arg(long, short, value_name = "BOARD")]
pub board: Option<String>,
/// Firmware version to build against. Defaults to the latest release.
#[arg(long, value_name = "VERSION")]
pub version: Option<String>,
/// Output file path. Defaults to onerom-<board>-<version>.bin.
#[arg(
long,
short,
visible_alias = "out",
value_name = "FILE",
conflicts_with = "path"
)]
pub output: Option<String>,
/// Output directory. Uses the default filename within the given directory.
#[arg(long, value_name = "DIR", conflicts_with = "output")]
pub path: Option<String>,
/// Use a local minimal firmware binary instead of downloading from the
/// release server.
///
/// This must be built with EXCLUDE_METADATA=1 and ROM_CONFIGS= in order to
/// be suitable for then constructing a complete firmware image with this
/// command.
#[arg(long, value_name = "FILE", conflicts_with = "version")]
pub base_firmware: Option<String>,
/// Continue even if the assembled firmware has parse errors.
#[arg(long, short)]
pub force: bool,
/// Confirm building a firmware with no ROM configuration.
///
/// Only valid with --config-name and/or --config-description.
/// Mutually exclusive with --config-file and --slot.
#[arg(
long,
conflicts_with_all = ["config_file", "slot"]
)]
pub no_config: bool,
}
impl CommandTrait for FirmwareBuildArgs {
fn requires_device(&self) -> bool {
false
}
}
#[derive(Debug, Args)]
pub struct FirmwareInspectArgs {
/// Firmware binary file to inspect.
#[arg(long, visible_aliases = [ "fw", "in", "input" ], value_name = "FILE")]
pub firmware: Option<String>,
/// Inspect release firmware for this board type.
#[arg(long, short, value_name = "BOARD", conflicts_with = "firmware")]
pub board: Option<String>,
/// Firmware version to inspect. Defaults to latest.
#[arg(long, value_name = "VERSION", conflicts_with = "firmware")]
pub version: Option<String>,
}
impl CommandTrait for FirmwareInspectArgs {
fn requires_device(&self) -> bool {
false
}
}
#[derive(Debug, Args)]
pub struct FirmwareReleasesArgs {
/// Show only releases for this board type.
#[arg(long, short, value_name = "BOARD")]
pub board: Option<String>,
/// Show all releases, even if a device is attached and detected
#[arg(long, short, conflicts_with = "board")]
pub all: bool,
}
impl CommandTrait for FirmwareReleasesArgs {
fn requires_device(&self) -> bool {
false
}
}
#[derive(Debug, Args)]
pub struct FirmwareDownloadArgs {
/// Firmware version to download (e.g. 0.6.5). Defaults to latest.
#[arg(long, value_name = "VERSION")]
pub version: Option<String>,
/// Target board type (e.g. fire-24-e).
///
/// Will be inferred from device if not included.
#[arg(long, short, value_name = "BOARD")]
pub board: Option<String>,
/// Output file path. Defaults to onerom_<board>_<version>.bin.
#[arg(
long,
short,
visible_alias = "out",
value_name = "FILE",
conflicts_with = "path"
)]
pub output: Option<String>,
/// Output directory. Uses the default filename within the given directory.
#[arg(long, value_name = "DIR", conflicts_with = "output")]
pub path: Option<String>,
}
impl CommandTrait for FirmwareDownloadArgs {
fn requires_device(&self) -> bool {
false
}
}
#[derive(Debug, Args)]
pub struct FirmwareChipsArgs {
/// Show supported chip types for this board type.
#[arg(long, short, value_name = "BOARD", conflicts_with = "all")]
pub board: Option<String>,
/// Show all supported chip types grouped by pin count.
#[arg(long, short, conflicts_with = "board")]
pub all: bool,
}
impl CommandTrait for FirmwareChipsArgs {
fn requires_device(&self) -> bool {
false
}
}