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 683F1C001E0 for ; Sun, 23 Jul 2023 03:45:04 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4BB0F867B5; Sun, 23 Jul 2023 05:44:27 +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="Ocfae22q"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8757F86687; Sun, 23 Jul 2023 05:44:19 +0200 (CEST) Received: from mail-il1-x12b.google.com (mail-il1-x12b.google.com [IPv6:2607:f8b0:4864:20::12b]) (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 EA4228661B for ; Sun, 23 Jul 2023 05:44:16 +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-il1-x12b.google.com with SMTP id e9e14a558f8ab-3463de183b0so18436125ab.2 for ; Sat, 22 Jul 2023 20:44:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1690083855; x=1690688655; 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=t6JoYJSEelsnb8VOoFVJQwPGT9FsKX+2zzqGeOfmtMo=; b=Ocfae22qgMRlAGAU9IXkYHSObD5bFWDhs0k9KUomxXr5/koVVGxzoHGeezyS/S7OoO ignftf2fov6j0URbOlk4dSoZDXNpXdVBqKVZBqPCahJQ4Lmqou/iOl9mYnlhr0R0K26q C3d8yXH5WjNGaBaJoY+Xtm+53KAnDnwm7/ldY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690083855; x=1690688655; 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=t6JoYJSEelsnb8VOoFVJQwPGT9FsKX+2zzqGeOfmtMo=; b=B/LgAQWhmiBk9FU3Bi8muRSi/z33XqVd+LGVZGtGCjiw+WSapASK1lVcAQtkhJfAGS AHHXmgQiSTsEG4uLMHVy8XGRV0SixN0mus9ik/u0OpKNQe2aG/Nko41zTu4Wyz59wiDG t3nsKG+e1x/8p0BmnDzfDEaNqt64JUcyAOSnIU9BpNNlx6rhZSPAQyZQz0wQrKHkIT5p 501yhuCc8kNLM9A3HjU19+3sJL+zFwqp+5mJ0xFrhrVhJA+nA9jEUZ8LSi5oQECZbXcK KOLmSP9kF8GvrfPwRHJhuafJ1cV5/D+t+eewpwCOHPeRtqRfc36uGSYWnzrb+Wz+gnnE rHXw== X-Gm-Message-State: ABy/qLb1q37yh97x+CNaI+eFDJezuk4oovd7chcQU6Wd3almbrfum7XP fWFG1vSAvY9S/0uw3ThnaIEl8o/qlg6+vvO0mLM= X-Google-Smtp-Source: APBJJlHfhi8klb8sFn+8oY8HhtePCdo8HGLm6Ff4Zo9Ld/1EBwNaVN+NIIUVbBdVOQ+KNwAoYBfQiA== X-Received: by 2002:a92:c564:0:b0:348:797d:441a with SMTP id b4-20020a92c564000000b00348797d441amr4738403ilj.8.1690083855582; Sat, 22 Jul 2023 20:44:15 -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 a11-20020a056638018b00b0042b3e04510asm2077384jaq.98.2023.07.22.20.44.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Jul 2023 20:44:15 -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 v2 5/6] binman: Remove templates after use Date: Sat, 22 Jul 2023 21:43:56 -0600 Message-ID: <20230723034406.87673-6-sjg@chromium.org> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog In-Reply-To: <20230723034406.87673-1-sjg@chromium.org> References: <20230723034406.87673-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 --- (no changes since v1) 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