From patchwork Tue Feb 8 18:50:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1590050 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=VlV0UJDs; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JtXGg7557z9s0B for ; Wed, 9 Feb 2022 05:53:47 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E402983E2D; Tue, 8 Feb 2022 19:51:20 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="VlV0UJDs"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6AF4B83D8B; Tue, 8 Feb 2022 19:50:54 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x12a.google.com (mail-il1-x12a.google.com [IPv6:2607:f8b0:4864:20::12a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B026383D8A for ; Tue, 8 Feb 2022 19:50:44 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x12a.google.com with SMTP id f13so2550358ilq.5 for ; Tue, 08 Feb 2022 10:50:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+4IdX5ofSV8OHbRvIrPp1oIo+kG+nqK6YcXLIdSPmNc=; b=VlV0UJDsJBnF2JN9Xd8mKIiCoILdhB1B+C+6+v3cQqgVFVcX4m87M07TxIA9bKf18M gJluLtA8eh45hCRzUQmPaBnGeYpMxRkGqf4jZMvyQVDBR+ARZ2nnlPa/t3dvC5/9/YPr U/8iIGcwtJAUb8etTGlLQF4f31qM81G6d0u5s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+4IdX5ofSV8OHbRvIrPp1oIo+kG+nqK6YcXLIdSPmNc=; b=YM0QnHoUujfi/eZpG2xN8ow8QFEVbmzEAxbzMPy+Chh5OuPG5IFV373mLcimld0GCh liiy8sms5NBYAzMvRmXjiBT50pgpsO+E8C7hjRj6OxqDleGrTRHFBxnwwukLTpKlV+bG WD69N4XThGILmz5E4vqIIWyrMs0wU5/y+bZuMs7eIOg+Ai+fC3NV8zUloKSNA7CacR3w avFnmd4j7k+T95hVf2p9X+P1l4yNRR0PLm03Uyl/cW44QGEfzFkcWYQe6bBbje2V5u3O QpbVKKLd6Lhk03F09xLkLmCqfTE/2GRYA926eCiQEOROeV1Q4KqXT0EOdPZ9HuRid20m lM7A== X-Gm-Message-State: AOAM532YA4ci6xvEOeiZTAwa3zN6VGc4jxzQs5gxTdzyChTz3OJbwpdH Z6etaNIZKLAUNkQDit67VIh/WoPMDmphnQ== X-Google-Smtp-Source: ABdhPJyTYnrkZ/AIIvAIJiSpofVO+My9/PUii3ws0rOPFLQXkDe+vg/hV01API3HV/Zw1wG/+pKbEQ== X-Received: by 2002:a05:6e02:1c84:: with SMTP id w4mr2923039ill.223.1644346243008; Tue, 08 Feb 2022 10:50:43 -0800 (PST) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id q2sm2911844ilt.33.2022.02.08.10.50.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 10:50:42 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: huang lin , Jeffy Chen , Simon Glass , Kever Yang , Philipp Tomsich , Alper Nebi Yasak , Tom Rini , Roger Quadros , Philippe Reynes , Ivan Mikhaylov , Jan Kiszka Subject: [PATCH 19/24] binman: Allow different operations in FIT generator nodes Date: Tue, 8 Feb 2022 11:50:03 -0700 Message-Id: <20220208114935.19.I656d3463d2fb7d63526527b17a2cf91bd910ca9a@changeid> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220208185008.35843-1-sjg@chromium.org> References: <20220208185008.35843-1-sjg@chromium.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.5 at phobos.denx.de X-Virus-Status: Clean At present we only support expanding out FDT nodes. Make the operation into an @operation property, so that others can be supported. Re-arrange and tidy up the documentation so that it has separate headings for each topic. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- tools/binman/entries.rst | 85 +++++++++++----- tools/binman/etype/fit.py | 136 ++++++++++++++++++++----- tools/binman/ftest.py | 7 ++ tools/binman/test/220_fit_bad_oper.dts | 27 +++++ 4 files changed, 206 insertions(+), 49 deletions(-) create mode 100644 tools/binman/test/220_fit_bad_oper.dts diff --git a/tools/binman/entries.rst b/tools/binman/entries.rst index d4a1f333dc..d483169712 100644 --- a/tools/binman/entries.rst +++ b/tools/binman/entries.rst @@ -553,6 +553,68 @@ For example, this creates an image containing a FIT with U-Boot SPL:: }; }; +More complex setups can be created, with generated nodes, as described +below. + +Properties (in the 'fit' node itself) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Special properties have a `fit,` prefix, indicating that they should be +processed but not included in the final FIT. + +The top-level 'fit' node supports the following special properties: + + fit,external-offset + Indicates that the contents of the FIT are external and provides the + external offset. This is passed to mkimage via the -E and -p flags. + + fit,fdt-list + Indicates the entry argument which provides the list of device tree + files for the gen-fdt-nodes operation (as below). This is often + `of-list` meaning that `-a of-list="dtb1 dtb2..."` should be passed + to binman. + +Substitutions +~~~~~~~~~~~~~ + +Node names and property values support a basic string-substitution feature. +Available substitutions for '@' nodes (and property values) are: + +SEQ: + Sequence number of the generated fdt (1, 2, ...) +NAME + Name of the dtb as provided (i.e. without adding '.dtb') + +The `default` property, if present, will be automatically set to the name +if of configuration whose devicetree matches the `default-dt` entry +argument, e.g. with `-a default-dt=sun50i-a64-pine64-lts`. + +Available substitutions for property values in these nodes are: + +DEFAULT-SEQ: + Sequence number of the default fdt, as provided by the 'default-dt' + entry argument + +Available operations +~~~~~~~~~~~~~~~~~~~~ + +You can add an operation to an '@' node to indicate which operation is +required:: + + @fdt-SEQ { + fit,operation = "gen-fdt-nodes"; + ... + }; + +Available operations are: + +gen-fdt-nodes + Generate FDT nodes as above. This is the default if there is no + `fit,operation` property. + +Generating nodes from an FDT list (gen-fdt-nodes) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + U-Boot supports creating fdt and config nodes automatically. To do this, pass an `of-list` property (e.g. `-a of-list=file1 file2`). This tells binman that you want to generates nodes for two files: `file1.dtb` and @@ -590,32 +652,9 @@ You can create config nodes in a similar way:: This tells binman to create nodes `config-1` and `config-2`, i.e. a config for each of your two files. -Available substitutions for '@' nodes are: - -SEQ: - Sequence number of the generated fdt (1, 2, ...) -NAME - Name of the dtb as provided (i.e. without adding '.dtb') - Note that if no devicetree files are provided (with '-a of-list' as above) then no nodes will be generated. -The 'default' property, if present, will be automatically set to the name -if of configuration whose devicetree matches the 'default-dt' entry -argument, e.g. with '-a default-dt=sun50i-a64-pine64-lts'. - -Available substitutions for '@' property values are - -DEFAULT-SEQ: - Sequence number of the default fdt,as provided by the 'default-dt' entry - argument - -Properties (in the 'fit' node itself): - fit,external-offset: Indicates that the contents of the FIT are external - and provides the external offset. This is passsed to mkimage via - the -E and -p flags. - - Entry: fmap: An entry which contains an Fmap section diff --git a/tools/binman/etype/fit.py b/tools/binman/etype/fit.py index bf84246904..6210deeef7 100644 --- a/tools/binman/etype/fit.py +++ b/tools/binman/etype/fit.py @@ -13,6 +13,12 @@ from dtoc import fdt_util from dtoc.fdt import Fdt from patman import tools +# Supported operations, with the fit,operation property +OP_GEN_FDT_NODES = range(1) +OPERATIONS = { + 'gen-fdt-nodes': OP_GEN_FDT_NODES, + } + class Entry_fit(Entry): """Flat Image Tree (FIT) @@ -46,6 +52,68 @@ class Entry_fit(Entry): }; }; + More complex setups can be created, with generated nodes, as described + below. + + Properties (in the 'fit' node itself) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + Special properties have a `fit,` prefix, indicating that they should be + processed but not included in the final FIT. + + The top-level 'fit' node supports the following special properties: + + fit,external-offset + Indicates that the contents of the FIT are external and provides the + external offset. This is passed to mkimage via the -E and -p flags. + + fit,fdt-list + Indicates the entry argument which provides the list of device tree + files for the gen-fdt-nodes operation (as below). This is often + `of-list` meaning that `-a of-list="dtb1 dtb2..."` should be passed + to binman. + + Substitutions + ~~~~~~~~~~~~~ + + Node names and property values support a basic string-substitution feature. + Available substitutions for '@' nodes (and property values) are: + + SEQ: + Sequence number of the generated fdt (1, 2, ...) + NAME + Name of the dtb as provided (i.e. without adding '.dtb') + + The `default` property, if present, will be automatically set to the name + if of configuration whose devicetree matches the `default-dt` entry + argument, e.g. with `-a default-dt=sun50i-a64-pine64-lts`. + + Available substitutions for property values in these nodes are: + + DEFAULT-SEQ: + Sequence number of the default fdt, as provided by the 'default-dt' + entry argument + + Available operations + ~~~~~~~~~~~~~~~~~~~~ + + You can add an operation to an '@' node to indicate which operation is + required:: + + @fdt-SEQ { + fit,operation = "gen-fdt-nodes"; + ... + }; + + Available operations are: + + gen-fdt-nodes + Generate FDT nodes as above. This is the default if there is no + `fit,operation` property. + + Generating nodes from an FDT list (gen-fdt-nodes) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + U-Boot supports creating fdt and config nodes automatically. To do this, pass an `of-list` property (e.g. `-a of-list=file1 file2`). This tells binman that you want to generates nodes for two files: `file1.dtb` and @@ -83,31 +151,8 @@ class Entry_fit(Entry): This tells binman to create nodes `config-1` and `config-2`, i.e. a config for each of your two files. - Available substitutions for '@' nodes are: - - SEQ: - Sequence number of the generated fdt (1, 2, ...) - NAME - Name of the dtb as provided (i.e. without adding '.dtb') - Note that if no devicetree files are provided (with '-a of-list' as above) then no nodes will be generated. - - The 'default' property, if present, will be automatically set to the name - if of configuration whose devicetree matches the 'default-dt' entry - argument, e.g. with '-a default-dt=sun50i-a64-pine64-lts'. - - Available substitutions for '@' property values are - - DEFAULT-SEQ: - Sequence number of the default fdt,as provided by the 'default-dt' entry - argument - - Properties (in the 'fit' node itself): - fit,external-offset: Indicates that the contents of the FIT are external - and provides the external offset. This is passsed to mkimage via - the -E and -p flags. - """ def __init__(self, section, etype, node): """ @@ -141,6 +186,26 @@ class Entry_fit(Entry): self.ReadEntries() super().ReadNode() + def _get_operation(self, subnode): + """Get the operation referenced by a subnode + + Args: + subnode (Node): Subnode (of the FIT) to check + + Returns: + int: Operation to perform + + Raises: + ValueError: Invalid operation name + """ + oper_name = subnode.props.get('fit,operation') + if not oper_name: + return OP_GEN_FDT_NODES + oper = OPERATIONS.get(oper_name.value) + if not oper: + self.Raise(f"Unknown operation '{oper_name.value}'") + return oper + def ReadEntries(self): def _process_prop(pname, prop): """Process special properties @@ -171,8 +236,8 @@ class Entry_fit(Entry): return fsw.property(pname, prop.bytes) - def _generate_node(subnode, depth, in_images): - """Generate nodes from a template + def _scan_gen_fdt_nodes(subnode, depth, in_images): + """Generate FDT nodes This creates one node for each member of self._fdts using the provided template. If a property value contains 'NAME' it is @@ -212,6 +277,25 @@ class Entry_fit(Entry): else: self.Raise("Generator node requires 'fit,fdt-list' property") + def _scan_node(subnode, depth, in_images): + """Generate nodes from a template + + This creates one node for each member of self._fdts using the + provided template. If a property value contains 'NAME' it is + replaced with the filename of the FDT. If a property value contains + SEQ it is replaced with the node sequence number, where 1 is the + first. + + Args: + subnode (None): Generator node to process + depth: Current node depth (0 is the base 'fit' node) + in_images: True if this is inside the 'images' node, so that + 'data' properties should be generated + """ + oper = self._get_operation(subnode) + if oper == OP_GEN_FDT_NODES: + _scan_gen_fdt_nodes(subnode, depth, in_images) + def _AddNode(base_node, depth, node): """Add a node to the FIT @@ -250,7 +334,7 @@ class Entry_fit(Entry): # fsw.add_node() or _AddNode() for it. pass elif self.GetImage().generate and subnode.name.startswith('@'): - _generate_node(subnode, depth, in_images) + _scan_node(subnode, depth, in_images) else: with fsw.add_node(subnode.name): _AddNode(base_node, depth + 1, subnode) diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 5400f76c67..5a0dc70ed9 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -5118,6 +5118,13 @@ fdt fdtmap Extract the devicetree blob from the fdtmap finally: shutil.rmtree(tmpdir) + def testFitFdtBadOper(self): + """Check handling of an FDT map when the section cannot be found""" + with self.assertRaises(ValueError) as exc: + self._DoReadFileDtb('220_fit_bad_oper.dts') + self.assertIn("Node '/binman/fit': Unknown operation 'unknown'", + str(exc.exception)) + if __name__ == "__main__": unittest.main() diff --git a/tools/binman/test/220_fit_bad_oper.dts b/tools/binman/test/220_fit_bad_oper.dts new file mode 100644 index 0000000000..cee801e2ea --- /dev/null +++ b/tools/binman/test/220_fit_bad_oper.dts @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + fit { + description = "test-desc"; + #address-cells = <1>; + fit,fdt-list = "of-list"; + + images { + @fdt-SEQ { + fit,operation = "unknown"; + description = "fdt-NAME.dtb"; + type = "flat_dt"; + compression = "none"; + }; + }; + }; + fdtmap { + }; + }; +};