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 696ADEB64DC for ; Fri, 21 Jul 2023 16:08:26 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BF664867DD; Fri, 21 Jul 2023 18:07:45 +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="XyGvZGKZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 24B6E867D5; Fri, 21 Jul 2023 18:07:35 +0200 (CEST) Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) (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 E9D44867CF for ; Fri, 21 Jul 2023 18:07:31 +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-io1-xd2b.google.com with SMTP id ca18e2360f4ac-786f25bcb40so94258439f.3 for ; Fri, 21 Jul 2023 09:07:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1689955650; x=1690560450; 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=l5WRLPuWMphk4VxYWqAy0I6wi6oX+IdvwFETUhkaazc=; b=XyGvZGKZHV4+DgkdyvMKYL3DaK1lO+zDuHC04WOR7u3TQcvbhABWdgSs4aQjZNawct C/YPwlxKDLj0DY6EvQuyAZ3u+RbaS1obyxvbhVgpJysx7zDJJZa2pEcMUYLqwqc8cDxa Hc3mIZ3zxJWdmcARB0/LlYKrAqHvNNfW/M5UA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689955650; x=1690560450; 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=l5WRLPuWMphk4VxYWqAy0I6wi6oX+IdvwFETUhkaazc=; b=cgsshGooLuqPu8WnPEcxkpbPfhMRC7g9ktXcJnhi33O8wpC5dYL2rMHTXHm0kQ1rPW wSRn08Dc44r0Nc4s9yCnFpXfXgOheGDuXbJIfbsJ8bKbVsZhjgo6gzkgCDFhRodW55sp Bhmbf2FaiTtoZnHofr9cq9yS+bVt4w6bpLtqg1zpUEcF1gRdo6tghfBx0mUvVGje6nkX MeM/raojriHj5mjVAHaLNu8WGEeK5qtWsbIW7OLxaSDVEpDItnYXLApSkZDwuC5tLglS 2cUZ08E5S1NKfUo1Trdpiw2XyZMZeYpVRk+xFZfpScjdPk7cRguTTrhJaPPGpVuwNrFa yDMQ== X-Gm-Message-State: ABy/qLa1msJxH/OdsQUA6VrMC+bwk1wIcchGmfdRC1g0eDpn6E/mbUIR gBf7WffpTOkoc9Xd/aypHOd7a49u5fzlsp1bElg= X-Google-Smtp-Source: APBJJlHyGn4zDuz2TFD1M+CShvd29mpf2xpooJYzNhHLN1bl9i6X6JyCt7CPaCWvuu2P9N8EZC8gsA== X-Received: by 2002:a6b:e808:0:b0:787:34d:f1ea with SMTP id f8-20020a6be808000000b00787034df1eamr453551ioh.8.1689955650498; Fri, 21 Jul 2023 09:07:30 -0700 (PDT) Received: from sjg1.lan (c-73-14-173-85.hsd1.co.comcast.net. [73.14.173.85]) by smtp.gmail.com with ESMTPSA id r17-20020a6bd911000000b0078680780694sm1158685ioc.34.2023.07.21.09.07.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jul 2023 09:07:30 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Alper Nebi Yasak , Neha Malcom Francis , Stefan Herbrechtsmeier , Philippe Reynes , Peng Fan , Simon Glass Subject: [PATCH 5/6] binman: Remove templates after use Date: Fri, 21 Jul 2023 10:07:05 -0600 Message-ID: <20230721160710.968748-6-sjg@chromium.org> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog In-Reply-To: <20230721160710.968748-1-sjg@chromium.org> References: <20230721160710.968748-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 It is not necessary to keep templates around after they have been processed. They can cause confusion and potentially duplicate phandles. Remove them. Use the same means of detecting a template node in _ReadImageDesc so that the two places are consistent. Signed-off-by: Simon Glass --- tools/binman/binman.rst | 8 +++++--- tools/binman/control.py | 14 +++++++++++++- tools/binman/ftest.py | 7 +++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/tools/binman/binman.rst b/tools/binman/binman.rst index 67bc3e87531b..147fbc5ff1b9 100644 --- a/tools/binman/binman.rst +++ b/tools/binman/binman.rst @@ -1256,11 +1256,13 @@ Properties in the template node are inserted into the destination node if they do not exist there. In the example above, `some-property` is added to each of `spi-image` and `mmc-image`. +Note that template nodes are removed from the binman description after +processing and before binman builds the image descriptions. + The initial devicetree produced by the templating process is written to the `u-boot.dtb.tmpl1` file. This can be useful to see what is going on if there is -a failure before the final `u-boot.dtb.out` file is written. - -Note that template nodes are not removed from the binman description at present. +a failure before the final `u-boot.dtb.out` file is written. A second +`u-boot.dtb.tmpl2` file is written when the templates themselves are removed. Updating an ELF file diff --git a/tools/binman/control.py b/tools/binman/control.py index 9a9a4817eeaf..3857f50e6436 100644 --- a/tools/binman/control.py +++ b/tools/binman/control.py @@ -57,7 +57,7 @@ def _ReadImageDesc(binman_node, use_expanded): images = OrderedDict() if 'multiple-images' in binman_node.props: for node in binman_node.subnodes: - if 'template' not in node.name: + if not node.name.startswith('template'): images[node.name] = Image(node.name, node, use_expanded=use_expanded) else: @@ -511,6 +511,13 @@ def _ProcessTemplates(parent): found |= _ProcessTemplates(node) return found +def _RemoveTemplates(parent): + """Remove any templates in the binman description + """ + for node in parent.subnodes: + if node.name.startswith('template'): + node.Delete() + def PrepareImagesAndDtbs(dtb_fname, select_images, update_fdt, use_expanded): """Prepare the images to be processed and select the device tree @@ -558,6 +565,11 @@ def PrepareImagesAndDtbs(dtb_fname, select_images, update_fdt, use_expanded): fname = tools.get_output_filename('u-boot.dtb.tmpl1') tools.write_file(fname, dtb.GetContents()) + _RemoveTemplates(node) + dtb.Sync(True) + fname = tools.get_output_filename('u-boot.dtb.tmpl2') + tools.write_file(fname, dtb.GetContents()) + images = _ReadImageDesc(node, use_expanded) if select_images: diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 80d41cf5c35f..7ea4797ad6ac 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -6802,6 +6802,13 @@ fdt fdtmap Extract the devicetree blob from the fdtmap vga = dtb.GetNode('/binman/first/intel-vga') self.assertTrue(vga) + dtb_fname2 = tools.get_output_filename('u-boot.dtb.tmpl2') + self.assertTrue(os.path.exists(dtb_fname2)) + dtb2 = fdt.Fdt.FromData(tools.read_file(dtb_fname2)) + dtb2.Scan() + node2 = dtb2.GetNode('/binman/template') + self.assertFalse(node2) + def testTemplateBlobMulti(self): """Test using a template with 'multiple-images' enabled""" TestFunctional._MakeInputFile('my-blob.bin', b'blob') -- 2.41.0.487.g6d72f3e995-goog