Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0FFE1EB64DA for ; Wed, 28 Jun 2023 11:44:57 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6224786652; Wed, 28 Jun 2023 13:44:38 +0200 (CEST) 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="FnrcS8CV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id ACBDD86624; Wed, 28 Jun 2023 13:42:56 +0200 (CEST) Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) (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 95C8886622 for ; Wed, 28 Jun 2023 13:42:30 +0200 (CEST) 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-lj1-x231.google.com with SMTP id 38308e7fff4ca-2b698937f85so64503001fa.2 for ; Wed, 28 Jun 2023 04:42:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1687952549; x=1690544549; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hOWb5g8MiTYO06mPs6bfr0j3EEevtfMyGo8LFQei9tw=; b=FnrcS8CVOzTxZujaiERG9keHVsn82IduifUsb4V1QVDjI2M6lTLxbSkoLwRfdIVrLN dvtErvePXLfZUJRIoAUw9929REH8mGPUzsjAYrXDfZ8I9qqiL3z6shDu1b+ENPvwdvlo 1nzU18orKHj0+v1AJR8Vmnj7clo893Wm+WQUI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687952549; x=1690544549; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hOWb5g8MiTYO06mPs6bfr0j3EEevtfMyGo8LFQei9tw=; b=j0iEnsdIe3M0ROXljWqr5BkxwbnObS24aaZJbiVAaQflrL4xz1QqcviBEOfvX8gvhK GCD77pR8M6hJneRfPnVpRzBJjbxLHTFDKiP4g/U1cyRcONigFPO+7L0w5AJuIglK6EfN otLssudP1hnx9C3XImpWSa2bBKKjznTGhAZbbG2aW3zEsc4ZlL2TrBDaW2sXbPsfXfoo LFZJC0ed73/l9tto5ObPjEVSVLmLtDds+9hDKNgx44WQqgXJoPGKkvskk1LIXrEDwGPG GFkk0N64oRxxFkCrx6ZVSzAegQIa9dyGeJKf4zWpPg6E7Boqwa/VplPLKV9v7ly0Qo+x ifnA== X-Gm-Message-State: AC+VfDxJ1dfACo1lrIzKMoYSFBslMKa7XIw8JGNamXDTKhjqNU8fEpNN MQCE+sssii4eddzAuwFPHRrm8pR4wjFkF1DM3GWxjw== X-Google-Smtp-Source: ACHHUZ6XK1mt0dG+C0NXNHNrSFVps62S3E6C1fbACBcvGn5SN7hu9qWw6TYRJC1nAGiSFICOuJviog== X-Received: by 2002:a2e:7c09:0:b0:2b5:80c9:1261 with SMTP id x9-20020a2e7c09000000b002b580c91261mr15287533ljc.48.1687952549201; Wed, 28 Jun 2023 04:42:29 -0700 (PDT) Received: from sjg1.praguecc.cz ([193.85.242.128]) by smtp.gmail.com with ESMTPSA id r18-20020aa7cb92000000b0051bec856cb4sm4676423edt.50.2023.06.28.04.42.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jun 2023 04:42:28 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Jan Kiszka , Simon Glass , Alper Nebi Yasak , Ivan Mikhaylov , Jonas Karlman , Neha Malcom Francis , Peng Fan , Philippe Reynes , Stefan Herbrechtsmeier Subject: [PATCH 12/12] binman: Support simple templates Date: Wed, 28 Jun 2023 12:41:45 +0100 Message-ID: <20230628114149.439723-13-sjg@chromium.org> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog In-Reply-To: <20230628114149.439723-1-sjg@chromium.org> References: <20230628114149.439723-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Collections can used to collect the contents of other entries into a single entry, but they result in a single entry, with the original entries 'left behind' in their old place. It is useful to be able to specific a set of entries ones and have it used in multiple images, or parts of an image. Implement this mechanism. Signed-off-by: Simon Glass --- tools/binman/binman.rst | 80 ++++++++++++++++++++++++ tools/binman/control.py | 9 +++ tools/binman/etype/section.py | 3 +- tools/binman/ftest.py | 8 +++ tools/binman/test/286_entry_template.dts | 42 +++++++++++++ 5 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 tools/binman/test/286_entry_template.dts diff --git a/tools/binman/binman.rst b/tools/binman/binman.rst index a4b31fe5397b..9be979ae1c5b 100644 --- a/tools/binman/binman.rst +++ b/tools/binman/binman.rst @@ -727,6 +727,13 @@ optional: Note that missing, optional blobs do not produce a non-zero exit code from binman, although it does show a warning about the missing external blob. +insert-template: + This is not strictly speaking an entry property, since it is processed early + in Binman before the entries are read. It is a list of phandles of nodes to + include in the current (target) node. For each node, its subnodes and their + properties are brought into the target node. See Templates_ below for + more information. + The attributes supported for images and sections are described below. Several are similar to those for entries. @@ -1172,6 +1179,79 @@ If you are having trouble figuring out what is going on, you can use arch/arm/dts/u-boot.dtsi ... found: "arch/arm/dts/juno-r2-u-boot.dtsi" +Templates +========= + +Sometimes multiple images need to be created which have all have a common +part. For example, a board may generate SPI and eMMC images which both include +a FIT. Since the FIT includes many entries, it is tedious to repeat them twice +in the image description. + +Templates provide a simple way to handle this:: + + binman { + multiple-images; + common_part: template-1 { + fit { + ... lots of entries in here + }; + + text { + text = "base image"; + }; + }; + + spi-image { + filename = "image-spi.bin"; + insert-template = <&fit>; + + /* things specific to SPI follow */ + header { + ]; + + text { + text = "SPI image"; + }; + }; + + mmc-image { + filename = "image-mmc.bin"; + insert-template = <&fit>; + + /* things specific to MMC follow */ + header { + ]; + + text { + text = "MMC image"; + }; + }; + }; + +The template node name must start with 'template', so it is not considered to be +an image itself. + +The mechanism is very simple. For each phandle in the 'insert-templates' +property, the source node is looked up. Then the subnodes of that source node +are copied into the target node, i.e. the one containing the `insert-template` +property. + +If the target node has a node with the same name as a template, its properties +override corresponding properties in the template. This allows the template to +be uses as a base, with the node providing updates to the properties as needed. +The overriding happens recursively. + +At present there is an unpleasant limitation on this feature: it works by +appending the template nodes after any existing subnodes to the target node. +This means that if the target node includes any subnodes, these appear in order +before the template node. In the above example, 'header' becomes the first +subnode of each image, followed by `fit` and `text`. If this is not what is +desired, there is no way to adjust it. + +Note: The above limitation will likely be removed in future, so that the +template subnodes appear before the target subnodes. + + Updating an ELF file ==================== diff --git a/tools/binman/control.py b/tools/binman/control.py index 68597c4e7792..e7faca78e9aa 100644 --- a/tools/binman/control.py +++ b/tools/binman/control.py @@ -22,6 +22,7 @@ from binman import bintool from binman import cbfs_util from binman import elf from binman import entry +from dtoc import fdt_util from u_boot_pylib import command from u_boot_pylib import tools from u_boot_pylib import tout @@ -478,6 +479,12 @@ def SignEntries(image_fname, input_fname, privatekey_fname, algo, entry_paths, AfterReplace(image, allow_resize=True, write_map=write_map) +def _ProcessTemplates(parent): + for node in parent.subnodes: + tmpl = fdt_util.GetPhandleList(node, 'insert-template') + if tmpl: + node.copy_subnodes_from_phandles(tmpl) + def PrepareImagesAndDtbs(dtb_fname, select_images, update_fdt, use_expanded): """Prepare the images to be processed and select the device tree @@ -520,6 +527,8 @@ def PrepareImagesAndDtbs(dtb_fname, select_images, update_fdt, use_expanded): raise ValueError("Device tree '%s' does not have a 'binman' " "node" % dtb_fname) + _ProcessTemplates(node) + images = _ReadImageDesc(node, use_expanded) if select_images: diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py index d56cc11d1023..adac2ff7fa87 100644 --- a/tools/binman/etype/section.py +++ b/tools/binman/etype/section.py @@ -179,7 +179,8 @@ class Entry_section(Entry): Returns: bool: True if the node is a special one, else False """ - return node.name.startswith('hash') or node.name.startswith('signature') + start_list = ('hash', 'signature', 'template') + return any(node.name.startswith(name) for name in start_list) def ReadNode(self): """Read properties from the section node""" diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 4db54c69682c..9d9e47ce26b0 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -6763,6 +6763,14 @@ fdt fdtmap Extract the devicetree blob from the fdtmap data = self._DoReadFileDtb('285_spl_expand.dts', use_expanded=True, entry_args=entry_args)[0] + def testEntryTemplate(self): + """Test using a template""" + TestFunctional._MakeInputFile('vga2.bin', b'#' + VGA_DATA) + data = self._DoReadFile('286_entry_template.dts') + first = U_BOOT_DTB_DATA + U_BOOT_DATA + VGA_DATA + second = U_BOOT_DTB_DATA + b'#' + VGA_DATA + U_BOOT_DATA + self.assertEqual(U_BOOT_IMG_DATA + first + second, data) + if __name__ == "__main__": unittest.main() diff --git a/tools/binman/test/286_entry_template.dts b/tools/binman/test/286_entry_template.dts new file mode 100644 index 000000000000..6980dbfafcc6 --- /dev/null +++ b/tools/binman/test/286_entry_template.dts @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + u-boot-img { + }; + + common_part: template { + u-boot { + }; + + intel-vga { + filename = "vga.bin"; + }; + }; + + first { + type = "section"; + insert-template = <&common_part>; + + u-boot-dtb { + }; + }; + + second { + type = "section"; + insert-template = <&common_part>; + + u-boot-dtb { + }; + + intel-vga { + filename = "vga2.bin"; + }; + }; + }; +}; -- 2.41.0.162.gfafddb0af9-goog