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
// Copyright (C) 2026 Piers Finlayson <piers@piers.rocks>
//
// MIT License
//! Argument definitions for `onerom program`.
use crate::args::CommandTrait;
use clap::Args;
use onerom_cli::usb::RebootArgs;
// See Commands::Program in args/mod.rs for the top-level documentation of
// this command and examples.
#[derive(Debug, Args)]
pub struct ProgramArgs {
/// ROM configuration JSON file. Mutually exclusive with --slot,
/// --config-name, --config-description, --save-config, --no-config,
/// and --firmware.
#[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", "firmware"]
)]
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, --no-config, and --firmware.
#[arg(
long,
value_name = "SPEC",
visible_alias = "rom",
conflicts_with_all = ["config_file", "no_config", "firmware"]
)]
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>,
/// Flash a pre-built complete firmware binary directly.
///
/// Mutually exclusive with --config-file, --slot, --base-firmware,
/// and --version.
#[arg(
long,
value_name = "FILE",
visible_alias = "fw",
conflicts_with_all = ["config_file", "slot", "base_firmware", "version"]
)]
pub firmware: Option<String>,
/// Use a local minimal firmware binary instead of downloading from the
/// release server.
///
/// When used with --slot, the ROM images are built into this firmware.
/// When used alone, requires --no-config to confirm flashing without
/// ROM images.
///
/// Must be built with EXCLUDE_METADATA=1 and ROM_CONFIGS= in order to
/// be suitable.
#[arg(
long,
value_name = "FILE",
conflicts_with_all = ["firmware", "version"]
)]
pub base_firmware: Option<String>,
/// Confirm flashing a base firmware with no ROM configuration.
///
/// Only valid with --config-name and/or --config-description.
/// Mutually exclusive with --config-file, --slot, and --firmware.
#[arg(
long,
conflicts_with_all = ["config_file", "slot", "firmware"]
)]
pub no_config: bool,
/// Target board type (e.g. fire-24-e). Inferred from connected device
/// if not specified.
#[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",
conflicts_with_all = ["firmware", "base_firmware"]
)]
pub version: Option<String>,
/// Write the built firmware to this file in addition to flashing it.
#[arg(long, short, visible_alias = "out", value_name = "FILE")]
pub output: Option<String>,
/// After flashing, reboot the device into stopped mode instead of running.
#[arg(long, short = 'p', conflicts_with = "running")]
pub stopped: bool,
/// After flashing, reboot the device into running mode (the default).
#[arg(long, short = 'r', conflicts_with = "stopped")]
pub running: bool,
/// Do not reboot the device after flashing.
#[arg(long, conflicts_with = "stopped")]
pub no_reboot: bool,
/// Verify flash contents after programming by reading back. (Not yet supported.)
#[arg(long)]
pub verify: bool,
/// Continue even if the assembled firmware has parse errors.
#[arg(long, short)]
pub force: bool,
/// Mount mass storage device when rebooting into stopped mode.
#[arg(long, short = 'm')]
pub msd: bool,
/// Don't pause after final reboot for the device to re-enumerate.
#[arg(long, conflicts_with = "no_reboot")]
pub fast: bool,
/// Program multiple devices, with a pause for user confirmation between
/// each one.
///
/// Note that each board will be progammed with the same firmware config,
/// including board config, as the first board.
#[arg(long, visible_aliases = ["multiple", "multi"])]
pub batch: bool,
/// After programming, automatically run `onerom scan --slots` to output
/// the contents of the programmed One ROM.
#[arg(long, conflicts_with = "fast")]
pub scan_slots: bool,
}
impl CommandTrait for ProgramArgs {
fn requires_device(&self) -> bool {
true
}
}
impl From<&ProgramArgs> for RebootArgs {
fn from(args: &ProgramArgs) -> Self {
if args.no_reboot {
RebootArgs::none()
} else if args.stopped {
RebootArgs::stopped(args.msd, args.fast)
} else {
RebootArgs::running(args.fast, false)
}
}
}