From patchwork Fri Sep 8 11:59:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 720807 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp720269wrp; Fri, 8 Sep 2023 05:01:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFJP9TrkFPixoZcrLOeYyS7IKlu8fLnaHp9Wu+HdqpS3jXTd/QC0nZtzmLVB1KJxbECRWrk X-Received: by 2002:a05:600c:2206:b0:402:e68f:8894 with SMTP id z6-20020a05600c220600b00402e68f8894mr1969329wml.0.1694174462195; Fri, 08 Sep 2023 05:01:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694174462; cv=none; d=google.com; s=arc-20160816; b=e5LO3pseKw7Xyj2BRIg1CO3E0EKHVL6MmS8IVK5I3820gzMBv3TP6W8zyC0c06wIPo Yz+H27t7CpDUcxVV7EmXGl5DklokqVZsIE69m0dqj59ypa7g+dcBTvhUZRRyeQgGGfDB aOrye7l5HWDuhdqiyMjw5Oxpvo2AxACuyeGg7w3V1IEyC90pTKuKiw3sRnwqln8lHAVe OY2CW61cCvhc0iA3MFrWGoVMUxUu9tw4Fb0CXpMuFRp0VpBof7MyjytoyvQ2xOU9otuQ Hmq4GrFw7bXpJl6XZ2xerFjaz64BY39r7cnR6GMXRypcbjOpKp/0i47qwL1Z38wZ79Qh 9+fQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=VTU9zGJ5M7QvRGJPs+H5K4PuJwqgxCsrx0HPypf3ZGw=; fh=lo2Vjgyv/ggZk8yIty16CtyHjEqk0MugRW6STG9XbrI=; b=P3TIa6Pt8KjZVwXRJATIEqY1OR6x7hqLdE3b/oER6TOXCuPBa8CUDYBEquOKwuaO5x cu/0X1d9fWrlcnf/CtDwL4YpJ7150YZfyjwk3/HhOXQ1TMQHX+ydphVCUNB4Uc0XWCGT IeAt/C8KtjEpaGFG/W0eLt7NT32OR2CDwQYaPel0qA/nUel0pLZW5Sbf08ttiALYhK61 cwFJxlKLg2XAXdKk9Kqa0R0lCXB5kqCIGwYGBtZ7Dglnu+GThSEWKB5wao2U2DxJog81 3A22WdgczPRqcsK/KGOQCpDhUQwJP3s1ls5dnb4elpxrlTz6p6sjO02hMURhTxX3ebdJ P/fw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id m4-20020a05600c4f4400b00401fceb834bsi2204395wmq.19.2023.09.08.05.01.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 05:01:02 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7FAD586A33; Fri, 8 Sep 2023 14:00:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 11B9E86A24; Fri, 8 Sep 2023 14:00:38 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id B489E86A3A for ; Fri, 8 Sep 2023 14:00:34 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 387D8D75; Fri, 8 Sep 2023 05:01:12 -0700 (PDT) Received: from a076522.blr.arm.com (a076522.blr.arm.com [10.162.46.7]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C354C3F67D; Fri, 8 Sep 2023 05:00:31 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Tom Rini , Malte Schmidt , Sughosh Ganu Subject: [PATCH 3/8] binman: capsule: Generate capsules through config file Date: Fri, 8 Sep 2023 17:29:57 +0530 Message-Id: <20230908120002.29851-4-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230908120002.29851-1-sughosh.ganu@linaro.org> References: <20230908120002.29851-1-sughosh.ganu@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean 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 --- 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"; + }; + }; +};