[PATCH 3/8] binman: capsule: Generate capsules through config file
Sughosh Ganu
sughosh.ganu at linaro.org
Fri Sep 8 13:59:57 CEST 2023
Add support in binman for generating capsules by reading the capsule
parameters through a config file. Also add a test case in binman for
this mode of capsule generation.
Signed-off-by: Sughosh Ganu <sughosh.ganu at linaro.org>
---
tools/binman/entries.rst | 35 ++++++++++++
tools/binman/etype/efi_capsule_cfg_file.py | 66 ++++++++++++++++++++++
tools/binman/ftest.py | 29 ++++++++++
tools/binman/test/319_capsule_cfg.dts | 15 +++++
4 files changed, 145 insertions(+)
create mode 100644 tools/binman/etype/efi_capsule_cfg_file.py
create mode 100644 tools/binman/test/319_capsule_cfg.dts
diff --git a/tools/binman/entries.rst b/tools/binman/entries.rst
index 801bd94674..a68ea2cb21 100644
--- a/tools/binman/entries.rst
+++ b/tools/binman/entries.rst
@@ -532,6 +532,41 @@ payload using the blob-ext subnode.
+.. _etype_efi_capsule_cfg_file:
+
+Entry: capsule: Entry for generating EFI Capsule files through config file
+--------------------------------------------------------------------------
+
+This is an entry for generating EFI capsules through a config
+file. The parameters needed for generation of the capsules are
+provided through a config file. This results in generation of one or
+multiple capsules, corresponding to the entries in the config file.
+
+Properties / Entry arguments:
+ - cfg-file: Config file for providing capsule parameters. These are
+ parameters needed for generating the capsules. The parameters can
+ be listed by running the './tools/mkeficapsule -h' command.
+
+For more details on the description of the capsule format, and the capsule
+update functionality, refer Section 8.5 and Chapter 23 in the `UEFI
+specification`_.
+
+A typical capsule entry node would then look something like this::
+
+ capsule {
+ type = "efi-capsule-cfg-file";
+ cfg-file = "path/to/the/config/file";
+ };
+
+In the above example, the entry only contains the path to the config file.
+All parameters needed for generation of the capsule, including the input
+payload image and the output capsule file are specified through the entries
+in the config file.
+
+.. _`UEFI specification`: https://uefi.org/sites/default/files/resources/UEFI_Spec_2_10_Aug29.pdf
+
+
+
.. _etype_encrypted:
Entry: encrypted: Externally built encrypted binary blob
diff --git a/tools/binman/etype/efi_capsule_cfg_file.py b/tools/binman/etype/efi_capsule_cfg_file.py
new file mode 100644
index 0000000000..ccf27077ec
--- /dev/null
+++ b/tools/binman/etype/efi_capsule_cfg_file.py
@@ -0,0 +1,66 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (c) 2023 Linaro Limited
+#
+# Entry-type module for producing a EFI capsule through a
+# config file.
+#
+
+import os
+
+from binman.entry import Entry
+from dtoc import fdt_util
+from u_boot_pylib import tools
+
+class Entry_efi_capsule_cfg_file(Entry):
+ """Entry for generating EFI capsules through config file
+
+ This is an entry for generating EFI capsules through a
+ config file.
+
+ The parameters needed for generation of the capsules are
+ provided through a config file. This results in generation
+ of one or multiple capsules, corresponding to the entries
+ in the config file.
+
+ Properties / Entry arguments:
+ - cfg-file: Config file for providing capsule parameters. These are
+ parameters needed for generating the capsules. The parameters can
+ be listed by running the './tools/mkeficapsule -h' command.
+
+ For more details on the description of the capsule format, and the capsule
+ update functionality, refer Section 8.5 and Chapter 23 in the `UEFI
+ specification`_.
+
+ A typical capsule entry node would then look something like this
+
+ capsule {
+ type = "efi-capsule-cfg-file";
+ cfg-file = "path/to/the/config/file";
+ };
+
+ In the above example, the entry only contains the path to the config file.
+ All parameters needed for generation of the capsule, including the input
+ payload image and the output capsule file are specified through the entries
+ in the config file.
+
+ .. _`UEFI specification`: https://uefi.org/sites/default/files/resources/UEFI_Spec_2_10_Aug29.pdf
+"""
+ def __init__(self, section, etype, node):
+ super().__init__(section, etype, node)
+ self.required_props = ['cfg-file']
+
+ def ReadNode(self):
+ super().ReadNode()
+
+ self.cfg_file = fdt_util.GetString(self._node, 'cfg-file')
+ if not os.path.isabs(self.cfg_file):
+ self.cfg_file = tools.get_input_filename(self.cfg_file)
+
+ def _GenCapsule(self):
+ self.mkeficapsule.generate_capsule_cfg_file(self.cfg_file)
+
+ def ObtainContents(self):
+ self._GenCapsule()
+
+ def AddBintools(self, btools):
+ self.mkeficapsule = self.AddBintool(btools, 'mkeficapsule')
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 8e419645a6..654af2c617 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -7334,5 +7334,34 @@ fdt fdtmap Extract the devicetree blob from the fdtmap
self.assertIn("entry is missing properties: image-guid",
str(e.exception))
+ def _SetupTmpOutDir(self, outfname):
+ self.tmpdir = tempfile.mkdtemp(prefix='binman.')
+ self.capsule_fname = os.path.join(self.tmpdir, outfname)
+
+ def _BuildCapsuleCfgFile(self):
+ cfg_file = self._MakeInputFile('capsule_cfg_file.txt', b'')
+ payload_fname = self._MakeInputFile('capsule_input.bin', EFI_CAPSULE_DATA)
+ self._SetupTmpOutDir('image.bin')
+
+ with open(f'{cfg_file}', 'w') as fd:
+ fd.write('{\n')
+ fd.write('\timage-index: 0x1\n')
+ fd.write('\timage-guid: 09d7cf52-0720-4710-91d1-08469b7fe9c8\n')
+ fd.write(f'\tpayload: {payload_fname}\n')
+ fd.write(f'\tcapsule: {self.capsule_fname}\n')
+ fd.write('}\n')
+
+ def testCapsuleGenCfgFile(self):
+ """Test generation of EFI capsule through config file"""
+ self._BuildCapsuleCfgFile()
+
+ self._DoReadFile('319_capsule_cfg.dts')
+
+ data = tools.read_file(self.capsule_fname)
+ self._CheckCapsule(data)
+
+ if not self.preserve_outdirs:
+ shutil.rmtree(self.tmpdir)
+
if __name__ == "__main__":
unittest.main()
diff --git a/tools/binman/test/319_capsule_cfg.dts b/tools/binman/test/319_capsule_cfg.dts
new file mode 100644
index 0000000000..3e07bdd962
--- /dev/null
+++ b/tools/binman/test/319_capsule_cfg.dts
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ binman {
+ efi-capsule {
+ type = "efi-capsule-cfg-file";
+ cfg-file = "capsule_cfg_file.txt";
+ };
+ };
+};
--
2.34.1
More information about the U-Boot
mailing list