blob: 61179747ffad34f154b76ad3c25a26b0e28bc68a [file] [log] [blame]
Sughosh Ganub29136b2023-08-22 23:09:58 +05301# SPDX-License-Identifier: GPL-2.0+
2# Copyright 2023 Linaro Limited
3#
4"""Bintool implementation for mkeficapsule tool
5
6mkeficapsule is a tool used for generating EFI capsules.
7
8The following are the commandline options to be provided
9to the tool
10Usage: mkeficapsule [options] <image blob> <output file>
11Options:
12 -g, --guid <guid string> guid for image blob type
13 -i, --index <index> update image index
14 -I, --instance <instance> update hardware instance
15 -v, --fw-version <version> firmware version
16 -p, --private-key <privkey file> private key file
17 -c, --certificate <cert file> signer's certificate file
18 -m, --monotonic-count <count> monotonic count
19 -d, --dump_sig dump signature (*.p7)
20 -A, --fw-accept firmware accept capsule, requires GUID, no image blob
21 -R, --fw-revert firmware revert capsule, takes no GUID, no image blob
22 -o, --capoemflag Capsule OEM Flag, an integer between 0x0000 and 0xffff
23 -h, --help print a help message
24"""
25
26from binman import bintool
27
28class Bintoolmkeficapsule(bintool.Bintool):
29 """Handles the 'mkeficapsule' tool
30
31 This bintool is used for generating the EFI capsules. The
32 capsule generation parameters can either be specified through
33 commandline, or through a config file.
34 """
35 def __init__(self, name):
36 super().__init__(name, 'mkeficapsule tool for generating capsules')
37
38 def generate_capsule(self, image_index, image_guid, hardware_instance,
39 payload, output_fname, priv_key, pub_key,
40 monotonic_count=0, version=0, oemflags=0):
41 """Generate a capsule through commandline-provided parameters
42
43 Args:
44 image_index (int): Unique number for identifying payload image
45 image_guid (str): GUID used for identifying the image
46 hardware_instance (int): Optional unique hardware instance of
47 a device in the system. 0 if not being used
48 payload (str): Path to the input payload image
49 output_fname (str): Path to the output capsule file
50 priv_key (str): Path to the private key
51 pub_key(str): Path to the public key
52 monotonic_count (int): Count used when signing an image
53 version (int): Image version (Optional)
54 oemflags (int): Optional 16 bit OEM flags
55
56 Returns:
57 str: Tool output
58 """
59 args = [
60 f'--index={image_index}',
61 f'--guid={image_guid}',
62 f'--instance={hardware_instance}'
63 ]
64
65 if version:
66 args += [f'--fw-version={version}']
67 if oemflags:
68 args += [f'--capoemflag={oemflags}']
69 if priv_key and pub_key:
70 args += [
71 f'--monotonic-count={monotonic_count}',
72 f'--private-key={priv_key}',
73 f'--certificate={pub_key}'
74 ]
75
76 args += [
77 payload,
78 output_fname
79 ]
80
81 return self.run_cmd(*args)
82
83 def fetch(self, method):
84 """Fetch handler for mkeficapsule
85
86 This builds the tool from source
87
88 Returns:
89 tuple:
90 str: Filename of fetched file to copy to a suitable directory
91 str: Name of temp directory to remove, or None
92 """
93 if method != bintool.FETCH_BUILD:
94 return None
95
96 cmd = ['tools-only_defconfig', 'tools']
97 result = self.build_from_git(
98 'https://source.denx.de/u-boot/u-boot.git',
99 cmd,
100 'tools/mkeficapsule')
101 return result