Skip to content

Commit f65ee99

Browse files
Sughosh Ganutrini
authored andcommitted
mkeficapsule: Add support for setting OEM flags in capsule header
Add support for setting OEM flags in the capsule header. As per the UEFI specification, bits 0-15 of the flags member of the capsule header can be defined per capsule GUID. The oemflags will be used for the FWU Multi Bank update feature, as specified by the Dependable Boot specification[1]. Bit 15 of the flags member will be used to determine if the acceptance/rejection of the updated images is to be done by the firmware or an external component like the OS. [1] - https://git.codelinaro.org/linaro/dependable-boot/mbfw/uploads/6f7ddfe3be24e18d4319e108a758d02e/mbfw.pdf Signed-off-by: Sughosh Ganu <[email protected]> Reviewed-by: Ilias Apalodimas <[email protected]> Acked-by: Etienne Carriere <[email protected]>
1 parent 6da9271 commit f65ee99

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

doc/mkeficapsule.1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ Generate a firmware acceptance empty capsule
7272
.BI "-R\fR,\fB --fw-revert "
7373
Generate a firmware revert empty capsule
7474

75+
.TP
76+
.BI "-o\fR,\fB --capoemflag "
77+
Capsule OEM flag, value between 0x0000 to 0xffff
78+
7579
.TP
7680
.BR -h ", " --help
7781
Print a help message

tools/mkeficapsule.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static const char *tool_name = "mkeficapsule";
2929
efi_guid_t efi_guid_fm_capsule = EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID;
3030
efi_guid_t efi_guid_cert_type_pkcs7 = EFI_CERT_TYPE_PKCS7_GUID;
3131

32-
static const char *opts_short = "g:i:I:v:p:c:m:dhAR";
32+
static const char *opts_short = "g:i:I:v:p:c:m:o:dhAR";
3333

3434
enum {
3535
CAPSULE_NORMAL_BLOB = 0,
@@ -47,6 +47,7 @@ static struct option options[] = {
4747
{"dump-sig", no_argument, NULL, 'd'},
4848
{"fw-accept", no_argument, NULL, 'A'},
4949
{"fw-revert", no_argument, NULL, 'R'},
50+
{"capoemflag", required_argument, NULL, 'o'},
5051
{"help", no_argument, NULL, 'h'},
5152
{NULL, 0, NULL, 0},
5253
};
@@ -65,6 +66,7 @@ static void print_usage(void)
6566
"\t-d, --dump_sig dump signature (*.p7)\n"
6667
"\t-A, --fw-accept firmware accept capsule, requires GUID, no image blob\n"
6768
"\t-R, --fw-revert firmware revert capsule, takes no GUID, no image blob\n"
69+
"\t-o, --capoemflag Capsule OEM Flag, an integer between 0x0000 and 0xffff\n"
6870
"\t-h, --help print a help message\n",
6971
tool_name);
7072
}
@@ -387,6 +389,7 @@ static void free_sig_data(struct auth_context *ctx)
387389
* @mcount: Monotonic count in authentication information
388390
* @private_file: Path to a private key file
389391
* @cert_file: Path to a certificate file
392+
* @oemflags: Capsule OEM Flags, bits 0-15
390393
*
391394
* This function actually does the job of creating an uefi capsule file.
392395
* All the arguments must be supplied.
@@ -399,7 +402,8 @@ static void free_sig_data(struct auth_context *ctx)
399402
*/
400403
static int create_fwbin(char *path, char *bin, efi_guid_t *guid,
401404
unsigned long index, unsigned long instance,
402-
uint64_t mcount, char *privkey_file, char *cert_file)
405+
uint64_t mcount, char *privkey_file, char *cert_file,
406+
uint16_t oemflags)
403407
{
404408
struct efi_capsule_header header;
405409
struct efi_firmware_management_capsule_header capsule;
@@ -464,6 +468,8 @@ static int create_fwbin(char *path, char *bin, efi_guid_t *guid,
464468
header.header_size = sizeof(header);
465469
/* TODO: The current implementation ignores flags */
466470
header.flags = CAPSULE_FLAGS_PERSIST_ACROSS_RESET;
471+
if (oemflags)
472+
header.flags |= oemflags;
467473
header.capsule_image_size = sizeof(header)
468474
+ sizeof(capsule) + sizeof(uint64_t)
469475
+ sizeof(image)
@@ -635,6 +641,7 @@ int main(int argc, char **argv)
635641
unsigned char uuid_buf[16];
636642
unsigned long index, instance;
637643
uint64_t mcount;
644+
unsigned long oemflags;
638645
char *privkey_file, *cert_file;
639646
int c, idx;
640647

@@ -646,6 +653,7 @@ int main(int argc, char **argv)
646653
cert_file = NULL;
647654
dump_sig = 0;
648655
capsule_type = CAPSULE_NORMAL_BLOB;
656+
oemflags = 0;
649657
for (;;) {
650658
c = getopt_long(argc, argv, opts_short, options, &idx);
651659
if (c == -1)
@@ -709,6 +717,14 @@ int main(int argc, char **argv)
709717
}
710718
capsule_type = CAPSULE_REVERT;
711719
break;
720+
case 'o':
721+
oemflags = strtoul(optarg, NULL, 0);
722+
if (oemflags > 0xffff) {
723+
fprintf(stderr,
724+
"oemflags must be between 0x0 and 0xffff\n");
725+
exit(1);
726+
}
727+
break;
712728
default:
713729
print_usage();
714730
exit(EXIT_SUCCESS);
@@ -736,7 +752,7 @@ int main(int argc, char **argv)
736752
}
737753
} else if (create_fwbin(argv[argc - 1], argv[argc - 2], guid,
738754
index, instance, mcount, privkey_file,
739-
cert_file) < 0) {
755+
cert_file, (uint16_t)oemflags) < 0) {
740756
fprintf(stderr, "Creating firmware capsule failed\n");
741757
exit(EXIT_FAILURE);
742758
}

0 commit comments

Comments
 (0)