blob: 1b53151d41a5f061145df14bb7845e67c411cb57 [file] [log] [blame]
AKASHI Takahiro19122aa2020-11-30 18:12:15 +09001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright 2018 Linaro Limited
4 * Author: AKASHI Takahiro
5 */
6
7#include <getopt.h>
Heinrich Schuchardtbc341392024-08-14 14:33:44 +02008#include <inttypes.h>
AKASHI Takahiroc246b762022-02-09 19:10:35 +09009#include <pe.h>
AKASHI Takahiro19122aa2020-11-30 18:12:15 +090010#include <stdbool.h>
AKASHI Takahiro30fcea22022-01-18 13:39:45 +090011#include <stdint.h>
AKASHI Takahiro19122aa2020-11-30 18:12:15 +090012#include <stdio.h>
13#include <stdlib.h>
14#include <string.h>
15#include <linux/types.h>
Sughosh Ganu079fcf22020-12-30 19:26:59 +053016
AKASHI Takahiro19122aa2020-11-30 18:12:15 +090017#include <sys/stat.h>
18#include <sys/types.h>
AKASHI Takahiroba212432022-02-09 19:10:39 +090019#include <uuid/uuid.h>
AKASHI Takahiro19122aa2020-11-30 18:12:15 +090020
AKASHI Takahiroc246b762022-02-09 19:10:35 +090021#include <gnutls/gnutls.h>
22#include <gnutls/pkcs7.h>
23#include <gnutls/abstract.h>
AKASHI Takahiro19122aa2020-11-30 18:12:15 +090024
Simon Glassb0ef8612024-07-31 08:49:00 -060025#include <version.h>
26
AKASHI Takahiroc246b762022-02-09 19:10:35 +090027#include "eficapsule.h"
AKASHI Takahiro19122aa2020-11-30 18:12:15 +090028
29static const char *tool_name = "mkeficapsule";
30
31efi_guid_t efi_guid_fm_capsule = EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID;
AKASHI Takahiroc246b762022-02-09 19:10:35 +090032efi_guid_t efi_guid_cert_type_pkcs7 = EFI_CERT_TYPE_PKCS7_GUID;
33
Simon Glassb0ef8612024-07-31 08:49:00 -060034static const char *opts_short = "g:i:I:v:p:c:m:o:dhARDV";
Sughosh Ganub39405d2022-10-21 18:16:06 +053035
36enum {
37 CAPSULE_NORMAL_BLOB = 0,
38 CAPSULE_ACCEPT,
39 CAPSULE_REVERT,
40} capsule_type;
AKASHI Takahiro19122aa2020-11-30 18:12:15 +090041
42static struct option options[] = {
AKASHI Takahiroba212432022-02-09 19:10:39 +090043 {"guid", required_argument, NULL, 'g'},
AKASHI Takahiro19122aa2020-11-30 18:12:15 +090044 {"index", required_argument, NULL, 'i'},
45 {"instance", required_argument, NULL, 'I'},
Masahisa Kojimade87ca02023-06-07 14:41:56 +090046 {"fw-version", required_argument, NULL, 'v'},
AKASHI Takahiroc246b762022-02-09 19:10:35 +090047 {"private-key", required_argument, NULL, 'p'},
48 {"certificate", required_argument, NULL, 'c'},
49 {"monotonic-count", required_argument, NULL, 'm'},
50 {"dump-sig", no_argument, NULL, 'd'},
Sughosh Ganub39405d2022-10-21 18:16:06 +053051 {"fw-accept", no_argument, NULL, 'A'},
52 {"fw-revert", no_argument, NULL, 'R'},
Sughosh Ganuc0676382022-10-21 18:16:07 +053053 {"capoemflag", required_argument, NULL, 'o'},
Sughosh Ganua7d1fdc2023-10-10 14:40:54 +053054 {"dump-capsule", no_argument, NULL, 'D'},
AKASHI Takahiro19122aa2020-11-30 18:12:15 +090055 {"help", no_argument, NULL, 'h'},
56 {NULL, 0, NULL, 0},
57};
58
59static void print_usage(void)
60{
AKASHI Takahiroba212432022-02-09 19:10:39 +090061 fprintf(stderr, "Usage: %s [options] <image blob> <output file>\n"
AKASHI Takahiro30fcea22022-01-18 13:39:45 +090062 "Options:\n"
Sughosh Ganu079fcf22020-12-30 19:26:59 +053063
AKASHI Takahiroba212432022-02-09 19:10:39 +090064 "\t-g, --guid <guid string> guid for image blob type\n"
AKASHI Takahiro30fcea22022-01-18 13:39:45 +090065 "\t-i, --index <index> update image index\n"
66 "\t-I, --instance <instance> update hardware instance\n"
Masahisa Kojimade87ca02023-06-07 14:41:56 +090067 "\t-v, --fw-version <version> firmware version\n"
AKASHI Takahiroc246b762022-02-09 19:10:35 +090068 "\t-p, --private-key <privkey file> private key file\n"
69 "\t-c, --certificate <cert file> signer's certificate file\n"
70 "\t-m, --monotonic-count <count> monotonic count\n"
71 "\t-d, --dump_sig dump signature (*.p7)\n"
Sughosh Ganub39405d2022-10-21 18:16:06 +053072 "\t-A, --fw-accept firmware accept capsule, requires GUID, no image blob\n"
73 "\t-R, --fw-revert firmware revert capsule, takes no GUID, no image blob\n"
Sughosh Ganuc0676382022-10-21 18:16:07 +053074 "\t-o, --capoemflag Capsule OEM Flag, an integer between 0x0000 and 0xffff\n"
Sughosh Ganua7d1fdc2023-10-10 14:40:54 +053075 "\t-D, --dump-capsule dump the contents of the capsule headers\n"
Simon Glassb0ef8612024-07-31 08:49:00 -060076 "\t-V, --version show version number\n"
AKASHI Takahiro30fcea22022-01-18 13:39:45 +090077 "\t-h, --help print a help message\n",
78 tool_name);
AKASHI Takahiro19122aa2020-11-30 18:12:15 +090079}
80
AKASHI Takahiro30fcea22022-01-18 13:39:45 +090081/**
AKASHI Takahiroc246b762022-02-09 19:10:35 +090082 * auth_context - authentication context
83 * @key_file: Path to a private key file
84 * @cert_file: Path to a certificate file
85 * @image_data: Pointer to firmware data
86 * @image_size: Size of firmware data
87 * @auth: Authentication header
88 * @sig_data: Signature data
89 * @sig_size: Size of signature data
90 *
91 * Data structure used in create_auth_data(). @key_file through
92 * @image_size are input parameters. @auth, @sig_data and @sig_size
93 * are filled in by create_auth_data().
94 */
95struct auth_context {
96 char *key_file;
97 char *cert_file;
98 uint8_t *image_data;
99 size_t image_size;
100 struct efi_firmware_image_authentication auth;
101 uint8_t *sig_data;
102 size_t sig_size;
103};
104
105static int dump_sig;
106
107/**
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900108 * read_bin_file - read a firmware binary file
109 * @bin: Path to a firmware binary file
110 * @data: Pointer to pointer of allocated buffer
111 * @bin_size: Size of allocated buffer
112 *
113 * Read out a content of binary, @bin, into @data.
114 * A caller should free @data.
115 *
116 * Return:
117 * * 0 - on success
118 * * -1 - on failure
119 */
AKASHI Takahiroc246b762022-02-09 19:10:35 +0900120static int read_bin_file(char *bin, uint8_t **data, off_t *bin_size)
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900121{
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900122 FILE *g;
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900123 struct stat bin_stat;
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900124 void *buf;
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900125 size_t size;
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900126 int ret = 0;
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900127
128 g = fopen(bin, "r");
129 if (!g) {
AKASHI Takahiro6cf40d42022-01-18 13:39:44 +0900130 fprintf(stderr, "cannot open %s\n", bin);
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900131 return -1;
132 }
133 if (stat(bin, &bin_stat) < 0) {
AKASHI Takahiro6cf40d42022-01-18 13:39:44 +0900134 fprintf(stderr, "cannot determine the size of %s\n", bin);
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900135 ret = -1;
136 goto err;
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900137 }
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900138 if (bin_stat.st_size > SIZE_MAX) {
139 fprintf(stderr, "file size is too large for malloc: %s\n", bin);
140 ret = -1;
141 goto err;
142 }
143 buf = malloc(bin_stat.st_size);
144 if (!buf) {
AKASHI Takahiro6cf40d42022-01-18 13:39:44 +0900145 fprintf(stderr, "cannot allocate memory: %zx\n",
146 (size_t)bin_stat.st_size);
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900147 ret = -1;
148 goto err;
149 }
150
151 size = fread(buf, 1, bin_stat.st_size, g);
152 if (size < bin_stat.st_size) {
153 fprintf(stderr, "read failed (%zx)\n", size);
154 ret = -1;
155 goto err;
156 }
157
158 *data = buf;
159 *bin_size = bin_stat.st_size;
160err:
161 fclose(g);
162
163 return ret;
164}
165
166/**
167 * write_capsule_file - write a capsule file
168 * @bin: FILE stream
169 * @data: Pointer to data
170 * @bin_size: Size of data
171 *
172 * Write out data, @data, with the size @bin_size.
173 *
174 * Return:
175 * * 0 - on success
176 * * -1 - on failure
177 */
178static int write_capsule_file(FILE *f, void *data, size_t size, const char *msg)
179{
180 size_t size_written;
181
182 size_written = fwrite(data, 1, size, f);
183 if (size_written < size) {
184 fprintf(stderr, "%s: write failed (%zx != %zx)\n", msg,
185 size_written, size);
186 return -1;
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900187 }
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900188
AKASHI Takahiroc246b762022-02-09 19:10:35 +0900189 return 0;
190}
191
192/**
193 * create_auth_data - compose authentication data in capsule
194 * @auth_context: Pointer to authentication context
195 *
196 * Fill up an authentication header (.auth) and signature data (.sig_data)
197 * in @auth_context, using library functions from openssl.
198 * All the parameters in @auth_context must be filled in by a caller.
199 *
200 * Return:
201 * * 0 - on success
202 * * -1 - on failure
203 */
204static int create_auth_data(struct auth_context *ctx)
205{
206 gnutls_datum_t cert;
207 gnutls_datum_t key;
208 off_t file_size;
209 gnutls_privkey_t pkey;
210 gnutls_x509_crt_t x509;
211 gnutls_pkcs7_t pkcs7;
212 gnutls_datum_t data;
213 gnutls_datum_t signature;
214 int ret;
215
216 ret = read_bin_file(ctx->cert_file, &cert.data, &file_size);
217 if (ret < 0)
218 return -1;
219 if (file_size > UINT_MAX)
220 return -1;
221 cert.size = file_size;
222
223 ret = read_bin_file(ctx->key_file, &key.data, &file_size);
224 if (ret < 0)
225 return -1;
AKASHI Takahiroc246b762022-02-09 19:10:35 +0900226 if (file_size > UINT_MAX)
227 return -1;
228 key.size = file_size;
229
230 /*
231 * For debugging,
232 * gnutls_global_set_time_function(mytime);
233 * gnutls_global_set_log_function(tls_log_func);
234 * gnutls_global_set_log_level(6);
235 */
236
237 ret = gnutls_privkey_init(&pkey);
238 if (ret < 0) {
239 fprintf(stderr, "error in gnutls_privkey_init(): %s\n",
240 gnutls_strerror(ret));
241 return -1;
242 }
243
244 ret = gnutls_x509_crt_init(&x509);
245 if (ret < 0) {
246 fprintf(stderr, "error in gnutls_x509_crt_init(): %s\n",
247 gnutls_strerror(ret));
248 return -1;
249 }
250
251 /* load a private key */
252 ret = gnutls_privkey_import_x509_raw(pkey, &key, GNUTLS_X509_FMT_PEM,
253 0, 0);
254 if (ret < 0) {
255 fprintf(stderr,
256 "error in gnutls_privkey_import_x509_raw(): %s\n",
257 gnutls_strerror(ret));
258 return -1;
259 }
260
261 /* load x509 certificate */
262 ret = gnutls_x509_crt_import(x509, &cert, GNUTLS_X509_FMT_PEM);
263 if (ret < 0) {
264 fprintf(stderr, "error in gnutls_x509_crt_import(): %s\n",
265 gnutls_strerror(ret));
266 return -1;
267 }
268
269 /* generate a PKCS #7 structure */
270 ret = gnutls_pkcs7_init(&pkcs7);
271 if (ret < 0) {
272 fprintf(stderr, "error in gnutls_pkcs7_init(): %s\n",
273 gnutls_strerror(ret));
274 return -1;
275 }
276
277 /* sign */
278 /*
279 * Data should have
280 * * firmware image
281 * * monotonic count
282 * in this order!
283 * See EDK2's FmpAuthenticatedHandlerRsa2048Sha256()
284 */
285 data.size = ctx->image_size + sizeof(ctx->auth.monotonic_count);
286 data.data = malloc(data.size);
287 if (!data.data) {
288 fprintf(stderr, "allocating memory (0x%x) failed\n", data.size);
289 return -1;
290 }
291 memcpy(data.data, ctx->image_data, ctx->image_size);
292 memcpy(data.data + ctx->image_size, &ctx->auth.monotonic_count,
293 sizeof(ctx->auth.monotonic_count));
294
295 ret = gnutls_pkcs7_sign(pkcs7, x509, pkey, &data, NULL, NULL,
296 GNUTLS_DIG_SHA256,
297 /* GNUTLS_PKCS7_EMBED_DATA? */
298 GNUTLS_PKCS7_INCLUDE_CERT |
299 GNUTLS_PKCS7_INCLUDE_TIME);
300 if (ret < 0) {
301 fprintf(stderr, "error in gnutls_pkcs7)sign(): %s\n",
302 gnutls_strerror(ret));
303 return -1;
304 }
305
306 /* export */
307 ret = gnutls_pkcs7_export2(pkcs7, GNUTLS_X509_FMT_DER, &signature);
308 if (ret < 0) {
309 fprintf(stderr, "error in gnutls_pkcs7_export2: %s\n",
310 gnutls_strerror(ret));
311 return -1;
312 }
313 ctx->sig_data = signature.data;
314 ctx->sig_size = signature.size;
315
316 /* fill auth_info */
317 ctx->auth.auth_info.hdr.dwLength = sizeof(ctx->auth.auth_info)
318 + ctx->sig_size;
319 ctx->auth.auth_info.hdr.wRevision = WIN_CERT_REVISION_2_0;
320 ctx->auth.auth_info.hdr.wCertificateType = WIN_CERT_TYPE_EFI_GUID;
321 memcpy(&ctx->auth.auth_info.cert_type, &efi_guid_cert_type_pkcs7,
322 sizeof(efi_guid_cert_type_pkcs7));
323
324 /*
325 * For better clean-ups,
326 * gnutls_pkcs7_deinit(pkcs7);
327 * gnutls_privkey_deinit(pkey);
328 * gnutls_x509_crt_deinit(x509);
329 * free(cert.data);
330 * free(key.data);
331 * if error
332 * gnutls_free(signature.data);
333 */
334
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900335 return 0;
336}
337
338/**
AKASHI Takahiroc246b762022-02-09 19:10:35 +0900339 * dump_signature - dump out a signature
340 * @path: Path to a capsule file
341 * @signature: Signature data
342 * @sig_size: Size of signature data
343 *
344 * Signature data pointed to by @signature will be saved into
345 * a file whose file name is @path with ".p7" suffix.
346 *
347 * Return:
348 * * 0 - on success
349 * * -1 - on failure
350 */
351static int dump_signature(const char *path, uint8_t *signature, size_t sig_size)
352{
353 char *sig_path;
354 FILE *f;
355 size_t size;
356 int ret = -1;
357
358 sig_path = malloc(strlen(path) + 3 + 1);
359 if (!sig_path)
360 return ret;
361
362 sprintf(sig_path, "%s.p7", path);
363 f = fopen(sig_path, "w");
364 if (!f)
365 goto err;
366
367 size = fwrite(signature, 1, sig_size, f);
368 if (size == sig_size)
369 ret = 0;
370
371 fclose(f);
372err:
373 free(sig_path);
374 return ret;
375}
376
377/**
378 * free_sig_data - free out signature data
379 * @ctx: Pointer to authentication context
380 *
381 * Free signature data allocated in create_auth_data().
382 */
383static void free_sig_data(struct auth_context *ctx)
384{
385 if (ctx->sig_size)
386 gnutls_free(ctx->sig_data);
387}
388
389/**
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900390 * create_fwbin - create an uefi capsule file
391 * @path: Path to a created capsule file
392 * @bin: Path to a firmware binary to encapsulate
393 * @guid: GUID of related FMP driver
394 * @index: Index number in capsule
395 * @instance: Instance number in capsule
396 * @mcount: Monotonic count in authentication information
397 * @private_file: Path to a private key file
398 * @cert_file: Path to a certificate file
Sughosh Ganuc0676382022-10-21 18:16:07 +0530399 * @oemflags: Capsule OEM Flags, bits 0-15
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900400 *
401 * This function actually does the job of creating an uefi capsule file.
402 * All the arguments must be supplied.
403 * If either @private_file ror @cert_file is NULL, the capsule file
404 * won't be signed.
405 *
406 * Return:
407 * * 0 - on success
408 * * -1 - on failure
409 */
410static int create_fwbin(char *path, char *bin, efi_guid_t *guid,
AKASHI Takahiroc246b762022-02-09 19:10:35 +0900411 unsigned long index, unsigned long instance,
Masahisa Kojimade87ca02023-06-07 14:41:56 +0900412 struct fmp_payload_header_params *fmp_ph_params,
Sughosh Ganuc0676382022-10-21 18:16:07 +0530413 uint64_t mcount, char *privkey_file, char *cert_file,
414 uint16_t oemflags)
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900415{
416 struct efi_capsule_header header;
417 struct efi_firmware_management_capsule_header capsule;
418 struct efi_firmware_management_capsule_image_header image;
AKASHI Takahiroc246b762022-02-09 19:10:35 +0900419 struct auth_context auth_context;
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900420 FILE *f;
Masahisa Kojimade87ca02023-06-07 14:41:56 +0900421 uint8_t *data, *new_data, *buf;
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900422 off_t bin_size;
AKASHI Takahiroc246b762022-02-09 19:10:35 +0900423 uint64_t offset;
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900424 int ret;
Masahisa Kojimade87ca02023-06-07 14:41:56 +0900425 struct fmp_payload_header payload_header;
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900426
427#ifdef DEBUG
AKASHI Takahiroc246b762022-02-09 19:10:35 +0900428 fprintf(stderr, "For output: %s\n", path);
429 fprintf(stderr, "\tbin: %s\n\ttype: %pUl\n", bin, guid);
430 fprintf(stderr, "\tindex: %lu\n\tinstance: %lu\n", index, instance);
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900431#endif
AKASHI Takahiroc246b762022-02-09 19:10:35 +0900432 auth_context.sig_size = 0;
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900433 f = NULL;
434 data = NULL;
Masahisa Kojimade87ca02023-06-07 14:41:56 +0900435 new_data = NULL;
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900436 ret = -1;
437
438 /*
439 * read a firmware binary
440 */
441 if (read_bin_file(bin, &data, &bin_size))
442 goto err;
443
Masahisa Kojimade87ca02023-06-07 14:41:56 +0900444 buf = data;
445
446 /* insert fmp payload header right before the payload */
447 if (fmp_ph_params->have_header) {
448 new_data = malloc(bin_size + sizeof(payload_header));
449 if (!new_data)
450 goto err;
451
452 payload_header.signature = FMP_PAYLOAD_HDR_SIGNATURE;
453 payload_header.header_size = sizeof(payload_header);
454 payload_header.fw_version = fmp_ph_params->fw_version;
455 payload_header.lowest_supported_version = 0; /* not used */
456 memcpy(new_data, &payload_header, sizeof(payload_header));
457 memcpy(new_data + sizeof(payload_header), data, bin_size);
458 buf = new_data;
459 bin_size += sizeof(payload_header);
460 }
461
AKASHI Takahiroc246b762022-02-09 19:10:35 +0900462 /* first, calculate signature to determine its size */
463 if (privkey_file && cert_file) {
464 auth_context.key_file = privkey_file;
465 auth_context.cert_file = cert_file;
466 auth_context.auth.monotonic_count = mcount;
Masahisa Kojimade87ca02023-06-07 14:41:56 +0900467 auth_context.image_data = buf;
AKASHI Takahiroc246b762022-02-09 19:10:35 +0900468 auth_context.image_size = bin_size;
469
470 if (create_auth_data(&auth_context)) {
471 fprintf(stderr, "Signing firmware image failed\n");
472 goto err;
473 }
474
475 if (dump_sig &&
476 dump_signature(path, auth_context.sig_data,
477 auth_context.sig_size)) {
478 fprintf(stderr, "Creating signature file failed\n");
479 goto err;
480 }
481 }
482
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900483 /*
484 * write a capsule file
485 */
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900486 f = fopen(path, "w");
487 if (!f) {
AKASHI Takahiro6cf40d42022-01-18 13:39:44 +0900488 fprintf(stderr, "cannot open %s\n", path);
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900489 goto err;
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900490 }
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900491
492 /*
493 * capsule file header
494 */
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900495 header.capsule_guid = efi_guid_fm_capsule;
496 header.header_size = sizeof(header);
AKASHI Takahiro0f626ce2020-11-30 18:12:16 +0900497 /* TODO: The current implementation ignores flags */
498 header.flags = CAPSULE_FLAGS_PERSIST_ACROSS_RESET;
Sughosh Ganuc0676382022-10-21 18:16:07 +0530499 if (oemflags)
500 header.flags |= oemflags;
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900501 header.capsule_image_size = sizeof(header)
AKASHI Takahiroc246b762022-02-09 19:10:35 +0900502 + sizeof(capsule) + sizeof(uint64_t)
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900503 + sizeof(image)
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900504 + bin_size;
AKASHI Takahiroc246b762022-02-09 19:10:35 +0900505 if (auth_context.sig_size)
506 header.capsule_image_size += sizeof(auth_context.auth)
507 + auth_context.sig_size;
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900508 if (write_capsule_file(f, &header, sizeof(header),
509 "Capsule header"))
510 goto err;
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900511
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900512 /*
513 * firmware capsule header
514 * This capsule has only one firmware capsule image.
515 */
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900516 capsule.version = 0x00000001;
517 capsule.embedded_driver_count = 0;
518 capsule.payload_item_count = 1;
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900519 if (write_capsule_file(f, &capsule, sizeof(capsule),
520 "Firmware capsule header"))
521 goto err;
522
AKASHI Takahiroc246b762022-02-09 19:10:35 +0900523 offset = sizeof(capsule) + sizeof(uint64_t);
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900524 if (write_capsule_file(f, &offset, sizeof(offset),
525 "Offset to capsule image"))
526 goto err;
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900527
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900528 /*
529 * firmware capsule image header
530 */
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900531 image.version = 0x00000003;
532 memcpy(&image.update_image_type_id, guid, sizeof(*guid));
533 image.update_image_index = index;
AKASHI Takahiroa4c14aa2021-01-22 10:43:49 +0900534 image.reserved[0] = 0;
535 image.reserved[1] = 0;
536 image.reserved[2] = 0;
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900537 image.update_image_size = bin_size;
AKASHI Takahiroc246b762022-02-09 19:10:35 +0900538 if (auth_context.sig_size)
539 image.update_image_size += sizeof(auth_context.auth)
540 + auth_context.sig_size;
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900541 image.update_vendor_code_size = 0; /* none */
542 image.update_hardware_instance = instance;
543 image.image_capsule_support = 0;
AKASHI Takahiroc246b762022-02-09 19:10:35 +0900544 if (auth_context.sig_size)
545 image.image_capsule_support |= CAPSULE_SUPPORT_AUTHENTICATION;
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900546 if (write_capsule_file(f, &image, sizeof(image),
547 "Firmware capsule image header"))
548 goto err;
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900549
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900550 /*
AKASHI Takahiroc246b762022-02-09 19:10:35 +0900551 * signature
552 */
553 if (auth_context.sig_size) {
554 if (write_capsule_file(f, &auth_context.auth,
555 sizeof(auth_context.auth),
556 "Authentication header"))
557 goto err;
558
559 if (write_capsule_file(f, auth_context.sig_data,
560 auth_context.sig_size, "Signature"))
561 goto err;
562 }
563
564 /*
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900565 * firmware binary
566 */
Masahisa Kojimade87ca02023-06-07 14:41:56 +0900567 if (write_capsule_file(f, buf, bin_size, "Firmware binary"))
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900568 goto err;
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900569
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900570 ret = 0;
571err:
572 if (f)
573 fclose(f);
AKASHI Takahiroc246b762022-02-09 19:10:35 +0900574 free_sig_data(&auth_context);
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900575 free(data);
Masahisa Kojimade87ca02023-06-07 14:41:56 +0900576 free(new_data);
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900577
AKASHI Takahiro30fcea22022-01-18 13:39:45 +0900578 return ret;
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900579}
580
AKASHI Takahiroc246b762022-02-09 19:10:35 +0900581/**
AKASHI Takahiroba212432022-02-09 19:10:39 +0900582 * convert_uuid_to_guid() - convert UUID to GUID
583 * @buf: UUID binary
584 *
585 * UUID and GUID have the same data structure, but their binary
586 * formats are different due to the endianness. See lib/uuid.c.
587 * Since uuid_parse() can handle only UUID, this function must
588 * be called to get correct data for GUID when parsing a string.
589 *
590 * The correct data will be returned in @buf.
591 */
592void convert_uuid_to_guid(unsigned char *buf)
593{
594 unsigned char c;
595
596 c = buf[0];
597 buf[0] = buf[3];
598 buf[3] = c;
599 c = buf[1];
600 buf[1] = buf[2];
601 buf[2] = c;
602
603 c = buf[4];
604 buf[4] = buf[5];
605 buf[5] = c;
606
607 c = buf[6];
608 buf[6] = buf[7];
609 buf[7] = c;
610}
611
Sughosh Ganub39405d2022-10-21 18:16:06 +0530612static int create_empty_capsule(char *path, efi_guid_t *guid, bool fw_accept)
613{
614 struct efi_capsule_header header = { 0 };
615 FILE *f = NULL;
616 int ret = -1;
617 efi_guid_t fw_accept_guid = FW_ACCEPT_OS_GUID;
618 efi_guid_t fw_revert_guid = FW_REVERT_OS_GUID;
619 efi_guid_t capsule_guid;
620
621 f = fopen(path, "w");
622 if (!f) {
623 fprintf(stderr, "cannot open %s\n", path);
624 goto err;
625 }
626
627 capsule_guid = fw_accept ? fw_accept_guid : fw_revert_guid;
628
629 memcpy(&header.capsule_guid, &capsule_guid, sizeof(efi_guid_t));
630 header.header_size = sizeof(header);
631 header.flags = 0;
632
633 header.capsule_image_size = fw_accept ?
634 sizeof(header) + sizeof(efi_guid_t) : sizeof(header);
635
636 if (write_capsule_file(f, &header, sizeof(header),
637 "Capsule header"))
638 goto err;
639
640 if (fw_accept) {
641 if (write_capsule_file(f, guid, sizeof(*guid),
642 "FW Accept Capsule Payload"))
643 goto err;
644 }
645
646 ret = 0;
647
648err:
649 if (f)
650 fclose(f);
651
652 return ret;
653}
654
Sughosh Ganua7d1fdc2023-10-10 14:40:54 +0530655static void print_guid(void *ptr)
656{
657 int i;
658 efi_guid_t *guid = ptr;
659 const uint8_t seq[] = {
660 3, 2, 1, 0, '-', 5, 4, '-', 7, 6,
661 '-', 8, 9, '-', 10, 11, 12, 13, 14, 15 };
662
663 for (i = 0; i < ARRAY_SIZE(seq); i++) {
664 if (seq[i] == '-')
665 putchar(seq[i]);
666 else
667 printf("%02X", guid->b[seq[i]]);
668 }
669
670 printf("\n");
671}
672
673static uint32_t dump_fmp_payload_header(
674 struct fmp_payload_header *fmp_payload_hdr)
675{
676 if (fmp_payload_hdr->signature == FMP_PAYLOAD_HDR_SIGNATURE) {
677 printf("--------\n");
678 printf("FMP_PAYLOAD_HDR.SIGNATURE\t\t\t: %08X\n",
679 FMP_PAYLOAD_HDR_SIGNATURE);
680 printf("FMP_PAYLOAD_HDR.HEADER_SIZE\t\t\t: %08X\n",
681 fmp_payload_hdr->header_size);
682 printf("FMP_PAYLOAD_HDR.FW_VERSION\t\t\t: %08X\n",
683 fmp_payload_hdr->fw_version);
684 printf("FMP_PAYLOAD_HDR.LOWEST_SUPPORTED_VERSION\t: %08X\n",
685 fmp_payload_hdr->lowest_supported_version);
686 return fmp_payload_hdr->header_size;
687 }
688
689 return 0;
690}
691
692static void dump_capsule_auth_header(
693 struct efi_firmware_image_authentication *capsule_auth_hdr)
694{
Heinrich Schuchardtbc341392024-08-14 14:33:44 +0200695 printf("EFI_FIRMWARE_IMAGE_AUTH.MONOTONIC_COUNT\t\t: %08" PRIX64 "\n",
Sughosh Ganua7d1fdc2023-10-10 14:40:54 +0530696 capsule_auth_hdr->monotonic_count);
697 printf("EFI_FIRMWARE_IMAGE_AUTH.AUTH_INFO.HDR.dwLENGTH\t: %08X\n",
698 capsule_auth_hdr->auth_info.hdr.dwLength);
699 printf("EFI_FIRMWARE_IMAGE_AUTH.AUTH_INFO.HDR.wREVISION\t: %08X\n",
700 capsule_auth_hdr->auth_info.hdr.wRevision);
701 printf("EFI_FIRMWARE_IMAGE_AUTH.AUTH_INFO.HDR.wCERTTYPE\t: %08X\n",
702 capsule_auth_hdr->auth_info.hdr.wCertificateType);
703 printf("EFI_FIRMWARE_IMAGE_AUTH.AUTH_INFO.CERT_TYPE\t: ");
704 print_guid(&capsule_auth_hdr->auth_info.cert_type);
705}
706
707static void dump_fmp_capsule_image_header(
708 struct efi_firmware_management_capsule_image_header *image_hdr)
709{
710 void *capsule_auth_hdr;
711 void *fmp_payload_hdr;
712 uint64_t signature_size = 0;
713 uint32_t payload_size = 0;
714 uint32_t fmp_payload_hdr_size = 0;
715 struct efi_firmware_image_authentication *auth_hdr;
716
717 printf("--------\n");
718 printf("FMP_CAPSULE_IMAGE_HDR.VERSION\t\t\t: %08X\n",
719 image_hdr->version);
720 printf("FMP_CAPSULE_IMAGE_HDR.UPDATE_IMAGE_TYPE_ID\t: ");
721 print_guid(&image_hdr->update_image_type_id);
722 printf("FMP_CAPSULE_IMAGE_HDR.UPDATE_IMAGE_INDEX\t: %08X\n",
723 image_hdr->update_image_index);
724 printf("FMP_CAPSULE_IMAGE_HDR.UPDATE_IMAGE_SIZE\t\t: %08X\n",
725 image_hdr->update_image_size);
726 printf("FMP_CAPSULE_IMAGE_HDR.UPDATE_VENDOR_CODE_SIZE\t: %08X\n",
727 image_hdr->update_vendor_code_size);
Heinrich Schuchardtbc341392024-08-14 14:33:44 +0200728 printf("FMP_CAPSULE_IMAGE_HDR.UPDATE_HARDWARE_INSTANCE\t: %08" PRIX64 "\n",
Sughosh Ganua7d1fdc2023-10-10 14:40:54 +0530729 image_hdr->update_hardware_instance);
Heinrich Schuchardtbc341392024-08-14 14:33:44 +0200730 printf("FMP_CAPSULE_IMAGE_HDR.IMAGE_CAPSULE_SUPPORT\t: %08" PRIX64 "\n",
Sughosh Ganua7d1fdc2023-10-10 14:40:54 +0530731 image_hdr->image_capsule_support);
732
733 printf("--------\n");
734 if (image_hdr->image_capsule_support & CAPSULE_SUPPORT_AUTHENTICATION) {
735 capsule_auth_hdr = (char *)image_hdr + sizeof(*image_hdr);
736 dump_capsule_auth_header(capsule_auth_hdr);
737
738 auth_hdr = capsule_auth_hdr;
739 signature_size = sizeof(auth_hdr->monotonic_count) +
740 auth_hdr->auth_info.hdr.dwLength;
741 fmp_payload_hdr = (char *)capsule_auth_hdr + signature_size;
742 } else {
743 printf("Capsule Authentication Not Enabled\n");
744 fmp_payload_hdr = (char *)image_hdr + sizeof(*image_hdr);
745 }
746
747 fmp_payload_hdr_size = dump_fmp_payload_header(fmp_payload_hdr);
748
749 payload_size = image_hdr->update_image_size - signature_size -
750 fmp_payload_hdr_size;
751 printf("--------\n");
752 printf("Payload Image Size\t\t\t\t: %08X\n", payload_size);
753}
754
755static void dump_fmp_header(
756 struct efi_firmware_management_capsule_header *fmp_hdr)
757{
758 int i;
759 void *capsule_image_hdr;
760
761 printf("EFI_FMP_HDR.VERSION\t\t\t\t: %08X\n", fmp_hdr->version);
762 printf("EFI_FMP_HDR.EMBEDDED_DRIVER_COUNT\t\t: %08X\n",
763 fmp_hdr->embedded_driver_count);
764 printf("EFI_FMP_HDR.PAYLOAD_ITEM_COUNT\t\t\t: %08X\n",
765 fmp_hdr->payload_item_count);
766
767 /*
768 * We currently don't support Embedded Drivers.
769 * Only worry about the payload items.
770 */
771 for (i = 0; i < fmp_hdr->payload_item_count; i++) {
772 capsule_image_hdr = (char *)fmp_hdr +
773 fmp_hdr->item_offset_list[i];
774 dump_fmp_capsule_image_header(capsule_image_hdr);
775 }
776}
777
778static void dump_capsule_header(struct efi_capsule_header *capsule_hdr)
779{
780 printf("EFI_CAPSULE_HDR.CAPSULE_GUID\t\t\t: ");
781 print_guid((void *)&capsule_hdr->capsule_guid);
782 printf("EFI_CAPSULE_HDR.HEADER_SIZE\t\t\t: %08X\n",
783 capsule_hdr->header_size);
784 printf("EFI_CAPSULE_HDR.FLAGS\t\t\t\t: %08X\n", capsule_hdr->flags);
785 printf("EFI_CAPSULE_HDR.CAPSULE_IMAGE_SIZE\t\t: %08X\n",
786 capsule_hdr->capsule_image_size);
787}
788
789static void normal_capsule_dump(void *capsule_buf)
790{
791 void *fmp_hdr;
792 struct efi_capsule_header *hdr = capsule_buf;
793
794 dump_capsule_header(hdr);
795 printf("--------\n");
796
797 fmp_hdr = (char *)capsule_buf + sizeof(*hdr);
798 dump_fmp_header(fmp_hdr);
799}
800
801static void empty_capsule_dump(void *capsule_buf)
802{
803 efi_guid_t *accept_image_guid;
804 struct efi_capsule_header *hdr = capsule_buf;
805 efi_guid_t efi_empty_accept_capsule = FW_ACCEPT_OS_GUID;
806
807 dump_capsule_header(hdr);
808
809 if (!memcmp(&efi_empty_accept_capsule, &hdr->capsule_guid,
810 sizeof(efi_guid_t))) {
811 accept_image_guid = (void *)(char *)capsule_buf +
812 sizeof(struct efi_capsule_header);
813 printf("--------\n");
814 printf("ACCEPT_IMAGE_GUID\t\t\t\t: ");
815 print_guid(accept_image_guid);
816 }
817}
818
819static void dump_capsule_contents(char *capsule_file)
820{
821 int fd;
822 char *ptr;
823 efi_guid_t efi_fmp_guid = EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID;
824 efi_guid_t efi_empty_accept_capsule = FW_ACCEPT_OS_GUID;
825 efi_guid_t efi_empty_revert_capsule = FW_REVERT_OS_GUID;
826 struct stat sbuf;
827
828 if (!capsule_file) {
829 fprintf(stderr, "No capsule file provided\n");
830 exit(EXIT_FAILURE);
831 }
832
833 if ((fd = open(capsule_file, O_RDONLY)) < 0) {
834 fprintf(stderr, "Error opening capsule file: %s\n",
835 capsule_file);
836 exit(EXIT_FAILURE);
837 }
838
839 if (fstat(fd, &sbuf) < 0) {
840 fprintf(stderr, "Can't stat capsule file: %s\n", capsule_file);
841 exit(EXIT_FAILURE);
842 }
843
844 if ((ptr = mmap(0, sbuf.st_size, PROT_READ, MAP_SHARED, fd, 0))
845 == MAP_FAILED) {
846 fprintf(stderr, "Can't mmap capsule file: %s\n", capsule_file);
847 exit(EXIT_FAILURE);
848 }
849
850 if (!memcmp(&efi_fmp_guid, ptr, sizeof(efi_guid_t))) {
851 normal_capsule_dump(ptr);
852 } else if (!memcmp(&efi_empty_accept_capsule, ptr,
853 sizeof(efi_guid_t)) ||
854 !memcmp(&efi_empty_revert_capsule, ptr,
855 sizeof(efi_guid_t))) {
856 empty_capsule_dump(ptr);
857 } else {
858 fprintf(stderr, "Unable to decode the capsule file: %s\n",
859 capsule_file);
860 exit(EXIT_FAILURE);
861 }
862}
863
AKASHI Takahiroba212432022-02-09 19:10:39 +0900864/**
AKASHI Takahiroc246b762022-02-09 19:10:35 +0900865 * main - main entry function of mkeficapsule
866 * @argc: Number of arguments
867 * @argv: Array of pointers to arguments
868 *
869 * Create an uefi capsule file, optionally signing it.
870 * Parse all the arguments and pass them on to create_fwbin().
871 *
872 * Return:
873 * * 0 - on success
874 * * -1 - on failure
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900875 */
876int main(int argc, char **argv)
877{
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900878 efi_guid_t *guid;
AKASHI Takahiroba212432022-02-09 19:10:39 +0900879 unsigned char uuid_buf[16];
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900880 unsigned long index, instance;
AKASHI Takahiroc246b762022-02-09 19:10:35 +0900881 uint64_t mcount;
Sughosh Ganuc0676382022-10-21 18:16:07 +0530882 unsigned long oemflags;
Sughosh Ganua7d1fdc2023-10-10 14:40:54 +0530883 bool capsule_dump;
AKASHI Takahiroc246b762022-02-09 19:10:35 +0900884 char *privkey_file, *cert_file;
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900885 int c, idx;
Masahisa Kojimade87ca02023-06-07 14:41:56 +0900886 struct fmp_payload_header_params fmp_ph_params = { 0 };
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900887
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900888 guid = NULL;
889 index = 0;
890 instance = 0;
AKASHI Takahiroc246b762022-02-09 19:10:35 +0900891 mcount = 0;
892 privkey_file = NULL;
893 cert_file = NULL;
Sughosh Ganua7d1fdc2023-10-10 14:40:54 +0530894 capsule_dump = false;
AKASHI Takahiroc246b762022-02-09 19:10:35 +0900895 dump_sig = 0;
Sughosh Ganub39405d2022-10-21 18:16:06 +0530896 capsule_type = CAPSULE_NORMAL_BLOB;
Sughosh Ganuc0676382022-10-21 18:16:07 +0530897 oemflags = 0;
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900898 for (;;) {
AKASHI Takahiroc246b762022-02-09 19:10:35 +0900899 c = getopt_long(argc, argv, opts_short, options, &idx);
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900900 if (c == -1)
901 break;
902
903 switch (c) {
AKASHI Takahiroba212432022-02-09 19:10:39 +0900904 case 'g':
905 if (guid) {
906 fprintf(stderr,
907 "Image type already specified\n");
908 exit(EXIT_FAILURE);
909 }
910 if (uuid_parse(optarg, uuid_buf)) {
911 fprintf(stderr, "Wrong guid format\n");
912 exit(EXIT_FAILURE);
913 }
914 convert_uuid_to_guid(uuid_buf);
915 guid = (efi_guid_t *)uuid_buf;
916 break;
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900917 case 'i':
918 index = strtoul(optarg, NULL, 0);
919 break;
920 case 'I':
921 instance = strtoul(optarg, NULL, 0);
922 break;
Masahisa Kojimade87ca02023-06-07 14:41:56 +0900923 case 'v':
924 fmp_ph_params.fw_version = strtoul(optarg, NULL, 0);
925 fmp_ph_params.have_header = true;
926 break;
AKASHI Takahiroc246b762022-02-09 19:10:35 +0900927 case 'p':
928 if (privkey_file) {
929 fprintf(stderr,
930 "Private Key already specified\n");
931 exit(EXIT_FAILURE);
932 }
933 privkey_file = optarg;
934 break;
935 case 'c':
936 if (cert_file) {
937 fprintf(stderr,
938 "Certificate file already specified\n");
939 exit(EXIT_FAILURE);
940 }
941 cert_file = optarg;
942 break;
943 case 'm':
944 mcount = strtoul(optarg, NULL, 0);
945 break;
946 case 'd':
947 dump_sig = 1;
948 break;
Sughosh Ganub39405d2022-10-21 18:16:06 +0530949 case 'A':
950 if (capsule_type) {
951 fprintf(stderr,
952 "Select either of Accept or Revert capsule generation\n");
953 exit(1);
954 }
955 capsule_type = CAPSULE_ACCEPT;
956 break;
957 case 'R':
958 if (capsule_type) {
959 fprintf(stderr,
960 "Select either of Accept or Revert capsule generation\n");
961 exit(1);
962 }
963 capsule_type = CAPSULE_REVERT;
964 break;
Sughosh Ganuc0676382022-10-21 18:16:07 +0530965 case 'o':
966 oemflags = strtoul(optarg, NULL, 0);
967 if (oemflags > 0xffff) {
968 fprintf(stderr,
969 "oemflags must be between 0x0 and 0xffff\n");
970 exit(1);
971 }
972 break;
Sughosh Ganua7d1fdc2023-10-10 14:40:54 +0530973 case 'D':
974 capsule_dump = true;
975 break;
Simon Glassb0ef8612024-07-31 08:49:00 -0600976 case 'V':
977 printf("mkeficapsule version %s\n", PLAIN_VERSION);
978 exit(EXIT_SUCCESS);
Sughosh Ganub39405d2022-10-21 18:16:06 +0530979 default:
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900980 print_usage();
Simon Glass55f22b02024-07-31 08:49:03 -0600981 exit(EXIT_FAILURE);
AKASHI Takahiro19122aa2020-11-30 18:12:15 +0900982 }
983 }
984
Sughosh Ganua7d1fdc2023-10-10 14:40:54 +0530985 if (capsule_dump) {
986 if (argc != optind + 1) {
987 fprintf(stderr, "Must provide the capsule file to parse\n");
988 exit(EXIT_FAILURE);
989 }
990 dump_capsule_contents(argv[argc - 1]);
991 exit(EXIT_SUCCESS);
992 }
993
AKASHI Takahiroc246b762022-02-09 19:10:35 +0900994 /* check necessary parameters */
Sughosh Ganub39405d2022-10-21 18:16:06 +0530995 if ((capsule_type == CAPSULE_NORMAL_BLOB &&
996 ((argc != optind + 2) || !guid ||
997 ((privkey_file && !cert_file) ||
998 (!privkey_file && cert_file)))) ||
999 (capsule_type != CAPSULE_NORMAL_BLOB &&
1000 ((argc != optind + 1) ||
1001 ((capsule_type == CAPSULE_ACCEPT) && !guid) ||
1002 ((capsule_type == CAPSULE_REVERT) && guid)))) {
AKASHI Takahiro19122aa2020-11-30 18:12:15 +09001003 print_usage();
Sughosh Ganu14b44202021-01-22 20:34:56 +05301004 exit(EXIT_FAILURE);
AKASHI Takahiro19122aa2020-11-30 18:12:15 +09001005 }
1006
Sughosh Ganub39405d2022-10-21 18:16:06 +05301007 if (capsule_type != CAPSULE_NORMAL_BLOB) {
1008 if (create_empty_capsule(argv[argc - 1], guid,
1009 capsule_type == CAPSULE_ACCEPT) < 0) {
1010 fprintf(stderr, "Creating empty capsule failed\n");
1011 exit(EXIT_FAILURE);
1012 }
1013 } else if (create_fwbin(argv[argc - 1], argv[argc - 2], guid,
Masahisa Kojimade87ca02023-06-07 14:41:56 +09001014 index, instance, &fmp_ph_params, mcount, privkey_file,
Sughosh Ganuc0676382022-10-21 18:16:07 +05301015 cert_file, (uint16_t)oemflags) < 0) {
AKASHI Takahiro6cf40d42022-01-18 13:39:44 +09001016 fprintf(stderr, "Creating firmware capsule failed\n");
Sughosh Ganu14b44202021-01-22 20:34:56 +05301017 exit(EXIT_FAILURE);
AKASHI Takahiro19122aa2020-11-30 18:12:15 +09001018 }
1019
Sughosh Ganu14b44202021-01-22 20:34:56 +05301020 exit(EXIT_SUCCESS);
AKASHI Takahiro19122aa2020-11-30 18:12:15 +09001021}