CycloneBOOT
2.6.6
Secure Bootloader for ARM Cortex-M MCU
Loading...
Searching...
No Matches
cli.h
Go to the documentation of this file.
1
29
#ifndef __CLI_H
30
#define __CLI_H
31
32
#include <stdbool.h>
33
#include <stdlib.h>
34
#include <string.h>
35
#include "lib/cargs/include/cargs.h"
36
#include "
utils.h
"
37
38
39
// Error code to signify a 'correct' CLI config, even when 'required' options are not present.
40
// For example, -v or --version and -h or --help
41
#define CLI_OK 2
42
43
// Alignment the --vtor-align flag pads the binary to, in bytes
44
#define VTOR_ALIGN_BYTES 1024
45
46
// Shortest authentication key accepted, in bytes
47
#define AUTH_KEY_MIN_SIZE 16
48
53
struct
builder_cli_configuration
{
54
const
char
*input;
// Required
55
const
char
*output;
// Required
56
const
char
*firmware_index;
// Optional
57
const
char
*header_version;
// Optional, generates a backward compatible header (defaults to latest)
58
bool
vtor_align;
// Optional, pads before the binary so the vector table is aligned
59
const
char
*firmware_version;
// Optional, unless using anti-rollback
60
const
char
*encryption_algo;
// Optional, unless encryption is required. AES-CBC by default as of v1
61
const
char
*encryption_key_ascii;
// Optional
62
const
char
*encryption_key_hex;
// Optional
63
uint8_t *encryption_key;
// Optional
64
size_t
encryption_key_len;
// Optional
65
const
char
*authentication_algo;
// Optional, unless authentication is required. Supported algorithms: HMAC-[md5,sha256,sha512]
66
const
char
*authentication_key_ascii;
// Optional
67
const
char
*authentication_key_hex;
// Optional
68
uint8_t *authentication_key;
// Optional
69
size_t
authentication_key_len;
// Optional
70
const
char
*signature_algo;
// Optional
71
const
char
*signature_key;
// Optional, unless a signature is required. Supported algorithms: ecdsa-sha256, rsa-sha256,
72
const
char
*integrity_algo;
// Optional. CRC32 is chosen by default. Supported algorithms: MD5, SHA26, SHA512
73
const
char
*update_type;
// Optional. app is chosen by default. Supported types: app, boot
74
const
char
*runtime_signature_algo;
// Optional, unless a runtime signature is required. Supported algorithms: ecdsa-sha256, rsa-sha256,
75
const
char
*runtime_signature_key;
// Key generation mode
76
const
char
*runtime_integrity_algo;
// Optional. Embeds a runtime integrity digest in the image data. Supported: md5, sha1, sha224, sha256, sha384, sha512
77
bool
keygen;
// Specifies we are in key generator mode
78
const
char
*keygen_keytype;
// In keygen mode, the type of key that's generated
79
const
char
*keygen_publickey;
// In keygen mode, path to the public key that's generated
80
const
char
*keygen_privatekey;
// In keygen mode, path to the private key that's generated
81
bool
verbose;
// if passed, extra output will be passed to STDOUT
82
bool
version;
// if passed, CLI version will be passed to STDOUT
83
bool
help;
// if passed, a help message will be passed to STDOUT
84
const
char
*build_time;
// Optional, Unix epoch (seconds) for reproducible images. Defaults to current time
85
const
char
*keygen_keysize;
// In keygen mode, the RSA key size in bits: 2048 (default), 3072 or 4096
86
const
char
*keygen_curve;
// In keygen mode, the ECDSA curve: p256 (default), p384 or p521
87
};
88
89
// The options the tool accepts and the help prints, per edition
90
static
struct
cag_option cli_option_table[] = {
91
92
{
93
.identifier =
'i'
,
94
.access_letters =
"iI"
,
95
.access_name =
"input"
,
96
.value_name =
"<firmware.bin>"
,
97
.description =
"[REQUIRED] Path to firmware binary"
98
},
99
100
{
101
.identifier =
'o'
,
102
.access_letters =
"oO"
,
103
.access_name =
"output"
,
104
.value_name =
"<firmware_update.img>"
,
105
.description =
"[REQUIRED] Path to save firmware update image"
106
},
107
108
{
109
.identifier =
'm'
,
110
.access_letters = NULL,
111
.access_name =
"header-version"
,
112
.value_name =
"X.X.X"
,
113
.description =
114
"[OPTIONAL] Specify a specific header version to generate a backward compatible firmware update image."
115
},
116
117
{
118
.identifier =
'f'
,
119
.access_letters = NULL,
120
.access_name =
"firmware-version"
,
121
.value_name =
"X.X.X"
,
122
.description =
"[OPTIONAL] Firmware Version, mandatory for anti-rollback support"
123
},
124
125
{
126
.identifier =
'T'
,
127
.access_letters = NULL,
128
.access_name =
"build-time"
,
129
.value_name =
"<unix_epoch_seconds>"
,
130
.description =
131
"[OPTIONAL] Image build time (Unix epoch seconds) for reproducible images. Defaults to the current time."
132
},
133
134
{
135
.identifier =
'n'
,
136
.access_letters = NULL,
137
.access_name =
"integrity-algo"
,
138
.value_name =
"<crc32|md5|sha1|sha224|sha256|sha384|sha512>"
,
139
.description =
140
"[OPTIONAL] Integrity Algorithm to be used if integrity check is chosen. Defaults to CRC32"
141
},
142
143
// Editions that carry a bootloader
144
#if defined(VARIANT_OPEN) || defined(VARIANT_EVAL) || defined(VARIANT_PRO) || \
145
defined(VARIANT_ULTIMATE)
146
147
{
148
.identifier =
't'
,
149
.access_letters = NULL,
150
.access_name =
"update-type"
,
151
.value_name =
"<app|boot>"
,
152
.description =
153
"[OPTIONAL] Specify whether firmware update image generated is an app update or bootloader update. Defaults to app"
154
},
155
156
{
157
.identifier =
'x'
,
158
.access_letters =
"xX"
,
159
.access_name =
"image-index"
,
160
.value_name =
"<numeric value>"
,
161
.description =
"[OPTIONAL] Index of an image written straight to flash. Defaults to 0"
162
},
163
164
{
165
.identifier =
'p'
,
166
.access_letters = NULL,
167
.access_name =
"vtor-align"
,
168
.value_name = NULL,
169
.description =
"[OPTIONAL] Set the vector table alignment when necessary"
170
},
171
172
{
173
.identifier =
'z'
,
174
.access_letters = NULL,
175
.access_name =
"runtime-integrity-algo"
,
176
.value_name =
"<crc32|md5|sha1|sha224|sha256|sha384|sha512>"
,
177
.description =
178
"[OPTIONAL] Hash algorithm whose digest is embedded in the image data for runtime integrity verification"
179
},
180
181
#endif
182
183
// Editions that carry encryption and signatures
184
#if defined(VARIANT_OPEN) || defined(VARIANT_EVAL) || defined(VARIANT_ULTIMATE)
185
186
{
187
.identifier =
'e'
,
188
.access_letters = NULL,
189
.access_name =
"enc-algo"
,
190
.value_name =
"<aes-cbc>"
,
191
.description =
"[OPTIONAL] Encryption Algorithm to be used if encryption is required"
192
},
193
194
{
195
.identifier =
'k'
,
196
.access_letters = NULL,
197
.access_name =
"enc-key-ascii"
,
198
.value_name =
"<encryption_key_in_ascii>"
,
199
.description =
"[OPTIONAL] Encryption Key if encryption is required"
200
},
201
202
{
203
.identifier =
'd'
,
204
.access_letters = NULL,
205
.access_name =
"enc-key-hex"
,
206
.value_name =
"<encryption_key_in_hex>"
,
207
.description =
"[OPTIONAL] Encryption Key if encryption is required"
208
},
209
210
{
211
.identifier =
'a'
,
212
.access_letters = NULL,
213
.access_name =
"auth-algo"
,
214
.value_name =
"<hmac-md5|hmac-sha256|hmac-sha512>"
,
215
.description =
"[OPTIONAL] Authentication Algorithm to be used if authentication is chosen"
216
},
217
218
{
219
.identifier =
'u'
,
220
.access_letters = NULL,
221
.access_name =
"auth-key-ascii"
,
222
.value_name =
"<auth_key_in_ascii>"
,
223
.description =
"[OPTIONAL] Authentication Key if authentication is chosen"
224
},
225
226
{
227
.identifier =
'j'
,
228
.access_letters = NULL,
229
.access_name =
"auth-key-hex"
,
230
.value_name =
"<my_auth_key_in_hex>"
,
231
.description =
"[OPTIONAL] Authentication Key if authentication is chosen"
232
},
233
234
{
235
.identifier =
's'
,
236
.access_letters = NULL,
237
.access_name =
"sign-algo"
,
238
.value_name =
"<ecdsa-sha256|rsa-sha256>"
,
239
.description =
"[OPTIONAL] Signature Algorithm to be used if signature is chosen"
240
},
241
242
{
243
.identifier =
'g'
,
244
.access_letters = NULL,
245
.access_name =
"sign-key"
,
246
.value_name =
"<sign_key.pem>"
,
247
.description =
"[OPTIONAL] Private Signature Key if signature is chosen"
248
},
249
250
{
251
.identifier =
'y'
,
252
.access_letters = NULL,
253
.access_name =
"keygen"
,
254
.value_name = NULL,
255
.description =
"[OPTIONAL] Enter sign key generation mode"
256
},
257
258
{
259
.identifier =
'c'
,
260
.access_letters = NULL,
261
.access_name =
"key-type"
,
262
.value_name =
"<rsa|ecdsa>"
,
263
.description =
"[REQUIRED in Keygen Mode] Enter sign key type"
264
},
265
266
{
267
.identifier =
'S'
,
268
.access_letters = NULL,
269
.access_name =
"key-size"
,
270
.value_name =
"<2048|3072|4096>"
,
271
.description =
"[OPTIONAL in Keygen Mode] RSA key size in bits. Defaults to 2048"
272
},
273
274
{
275
.identifier =
'C'
,
276
.access_letters = NULL,
277
.access_name =
"curve"
,
278
.value_name =
"<p256|p384|p521>"
,
279
.description =
"[OPTIONAL in Keygen Mode] ECDSA curve. Defaults to p256"
280
},
281
282
{
283
.identifier =
'q'
,
284
.access_letters = NULL,
285
.access_name =
"public-key"
,
286
.value_name =
"<public_key.pem>"
,
287
.description =
"[REQUIRED in Keygen Mode] Path to public key in PEM format"
288
},
289
290
{
291
.identifier =
'w'
,
292
.access_letters = NULL,
293
.access_name =
"private-key"
,
294
.value_name =
"<private_key.pem>"
,
295
.description =
"[REQUIRED in Keygen Mode] Path to private key in PEM format"
296
},
297
298
{
299
.identifier =
'r'
,
300
.access_letters = NULL,
301
.access_name =
"runtime-sign-algo"
,
302
.value_name =
"<ecdsa-sha256|rsa-sha256>"
,
303
.description =
304
"[OPTIONAL] Signature Algorithm to be used if runtime signature verification is chosen"
305
},
306
307
{
308
.identifier =
'l'
,
309
.access_letters = NULL,
310
.access_name =
"runtime-sign-key"
,
311
.value_name =
"<runtime_sign_key.pem>"
,
312
.description =
"[OPTIONAL] Private Signature Key if runtime signature verification is chosen"
313
},
314
315
#endif
316
317
{
318
.identifier =
'b'
,
319
.access_letters = NULL,
320
.access_name =
"verbose"
,
321
.value_name = NULL,
322
.description =
"[OPTIONAL] Verbose mode"
323
},
324
325
{
326
.identifier =
'v'
,
327
.access_letters =
"vV"
,
328
.access_name =
"version"
,
329
.value_name = NULL,
330
.description =
"Show CLI version"
331
},
332
333
{
334
.identifier =
'h'
,
335
.access_letters =
"h"
,
336
.access_name =
"help"
,
337
.description =
"Show the help message"
338
}
339
};
340
341
// function to iterate over user parameters and copy to those to a struct
342
int
parse_options
(
int
argc,
char
**argv,
struct
builder_cli_configuration
*cli_options);
343
344
#endif
// __CLI_H
parse_options
int parse_options(int argc, char **argv, struct builder_cli_configuration *cli_options)
Parse the CLI options provided by the user.
Definition
cli.c:373
builder_cli_configuration
Definition
cli.h:53
utils.h
Utility functions used throughout the application.
ImageBuilder
inc
cli.h
Generated by
1.9.8