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 2B24EC001B0 for ; Sun, 23 Jul 2023 03:45:14 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9E00E86673; Sun, 23 Jul 2023 05:44:35 +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="hxNzyzn0"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D2D4286625; Sun, 23 Jul 2023 05:44:21 +0200 (CEST) Received: from mail-il1-x129.google.com (mail-il1-x129.google.com [IPv6:2607:f8b0:4864:20::129]) (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 41ADD86663 for ; Sun, 23 Jul 2023 05:44:18 +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-x129.google.com with SMTP id e9e14a558f8ab-348cd23610cso88215ab.1 for ; Sat, 22 Jul 2023 20:44:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1690083857; x=1690688657; 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=sPP92A0xJSSrIu7jOZe8wTHqtW/5tOg/4i0QUAZuznM=; b=hxNzyzn0qt7cGVJ4lJ+qW5Z1L5zve9q1NFlCzQMealLVrFvPFpDCWbXXtJ6qSoAiss 9TJLsTk11TQJbtc+oZzhvVUUKB5SaiQHa/pLz0v0jReu9WlSKTTwemsDYL+FzwT+aHgK mBB7J8PCr5OzuQW1a8+K6ANBgD+6eu3zS9kQQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690083857; x=1690688657; 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=sPP92A0xJSSrIu7jOZe8wTHqtW/5tOg/4i0QUAZuznM=; b=jiRS+dLW+tluIkhSCOdiEIPgMd77H+8s5aXCczJizK9dhrUHnqe0S/ggGrMrImCVH5 mNK4CaBOFB8t8dmwxFGfgQMm/8TFpaNgoOHWgWI8G7qnKuNgwDJDn2eVNIcv/8FrrztJ npsTLxWVBhOE2cIHPG5RjWD6Nrd23Qr676VdfLySucK2T4p06I5Bpkv8rdhnYeg8GUtP acbkXukHYC3E+BT7i7/dnv17u5ll5mYK0N12CQRjHIZNxaRBGOmkQs786X7Whswoqq+D krXF5G8/snqGu/epdOh28+ReQYu3/rIsWTuwq7ie+QdMQnPz4HVyL2DGoqknVlQMFyJx /jmQ== X-Gm-Message-State: ABy/qLbtqywj4ygABllALiJjbDhwmQh4x2u/PFF7CPAR6JnItGgD98hp Ru/RKt6U9s8D4vytw+hg/vlkMh2trwGY/0OQ744= X-Google-Smtp-Source: APBJJlFBYgR/rTAkGeyYHov7waOgdmGYEMg0goIV0Bs0w2omO2kziqDJX70+owucGcGFGKgnliqb7w== X-Received: by 2002:a05:6e02:2192:b0:346:49bd:7b6c with SMTP id j18-20020a056e02219200b0034649bd7b6cmr3728802ila.22.1690083856790; Sat, 22 Jul 2023 20:44:16 -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.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Jul 2023 20:44:16 -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 6/6] binman: Support templates containing phandles Date: Sat, 22 Jul 2023 21:43:57 -0600 Message-ID: <20230723034406.87673-7-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 This provides support for phandles to be copied over from templates. This is not quite safe, since if the template is instantiated twice (i.e. in two different nodes), then duplicate phandles will be found. This will result in an error. Signed-off-by: Simon Glass --- Changes in v2: - Refine support for phandles to deal with duplicates - Add a test that deals with duplicate phandles tools/binman/binman.rst | 18 +++++ tools/binman/control.py | 4 ++ tools/binman/ftest.py | 27 ++++++++ tools/binman/test/291_template_phandle.dts | 51 +++++++++++++++ .../binman/test/292_template_phandle_dup.dts | 65 +++++++++++++++++++ 5 files changed, 165 insertions(+) create mode 100644 tools/binman/test/291_template_phandle.dts create mode 100644 tools/binman/test/292_template_phandle_dup.dts diff --git a/tools/binman/binman.rst b/tools/binman/binman.rst index 147fbc5ff1b9..aeea33fddb95 100644 --- a/tools/binman/binman.rst +++ b/tools/binman/binman.rst @@ -1264,6 +1264,24 @@ The initial devicetree produced by the templating process is written to the 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. +Dealing with phandles +--------------------- + +Templates can contain phandles and these are copied to the destination node. +However this should be used with care, since if a template is instantiated twice +then the phandle will be copied twice, resulting in a devicetree with duplicate +phandles, i.e. the same phandle used by two different nodes. Binman detects this +situation and produces an error, for example:: + + Duplicate phandle 1 in nodes /binman/image/fit/images/atf/atf-bl31 and + /binman/image-2/fit/images/atf/atf-bl31 + +In this case an atf-bl31 node containing a phandle has been copied into two +different target nodes, resulting in the same phandle for each. See +testTemplatePhandleDup() for the test case. + +The solution is typically to put the phandles in the corresponding target nodes +(one for each) and remove the phandle from the template. Updating an ELF file ==================== diff --git a/tools/binman/control.py b/tools/binman/control.py index 3857f50e6436..6a6d247e6969 100644 --- a/tools/binman/control.py +++ b/tools/binman/control.py @@ -567,6 +567,10 @@ def PrepareImagesAndDtbs(dtb_fname, select_images, update_fdt, use_expanded): _RemoveTemplates(node) dtb.Sync(True) + + # Rescan the dtb to pick up the new phandles + dtb.Scan() + node = _FindBinmanNode(dtb) fname = tools.get_output_filename('u-boot.dtb.tmpl2') tools.write_file(fname, dtb.GetContents()) diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 7ea4797ad6ac..5a2cf9baf9cf 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -6900,6 +6900,33 @@ fdt fdtmap Extract the devicetree blob from the fdtmap # Move to next spl_data = content[:0x18] + def testTemplatePhandle(self): + """Test using a template in a node containing a phandle""" + entry_args = { + 'atf-bl31-path': 'bl31.elf', + } + data = self._DoReadFileDtb('291_template_phandle.dts', + entry_args=entry_args) + fname = tools.get_output_filename('image.bin') + out = tools.run('dumpimage', '-l', fname) + + # We should see the FIT description and one for each of the two images + lines = out.splitlines() + descs = [line.split()[-1] for line in lines if 'escription' in line] + self.assertEqual(['test-desc', 'atf', 'fdt'], descs) + + def testTemplatePhandleDup(self): + """Test using a template in a node containing a phandle""" + entry_args = { + 'atf-bl31-path': 'bl31.elf', + } + with self.assertRaises(ValueError) as e: + self._DoReadFileDtb('292_template_phandle_dup.dts', + entry_args=entry_args) + self.assertIn( + 'Duplicate phandle 1 in nodes /binman/image/fit/images/atf/atf-bl31 and /binman/image-2/fit/images/atf/atf-bl31', + str(e.exception)) + if __name__ == "__main__": unittest.main() diff --git a/tools/binman/test/291_template_phandle.dts b/tools/binman/test/291_template_phandle.dts new file mode 100644 index 000000000000..c4ec1dd41bed --- /dev/null +++ b/tools/binman/test/291_template_phandle.dts @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + multiple-images; + + ti_spl_template: template-1 { + fit { + description = "test-desc"; + #address-cells = <1>; + images { + atf { + description = "atf"; + ti-secure { + type = "collection"; + content = <&atf>; + keyfile = "key.pem"; + }; + atf: atf-bl31 { + description = "atf"; + }; + }; + }; + }; + }; + + image { + insert-template = <&ti_spl_template>; + fit { + images { + fdt-0 { + description = "fdt"; + ti-secure { + type = "collection"; + content = <&foo_dtb>; + keyfile = "key.pem"; + }; + foo_dtb: blob-ext { + filename = "vga.bin"; + }; + }; + }; + }; + }; + }; +}; diff --git a/tools/binman/test/292_template_phandle_dup.dts b/tools/binman/test/292_template_phandle_dup.dts new file mode 100644 index 000000000000..dc86f06463b7 --- /dev/null +++ b/tools/binman/test/292_template_phandle_dup.dts @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + multiple-images; + + ti_spl_template: template-1 { + fit { + description = "test-desc"; + #address-cells = <1>; + images { + atf { + description = "atf"; + ti-secure { + type = "collection"; + content = <&atf>; + keyfile = "key.pem"; + }; + atf: atf-bl31 { + description = "atf"; + }; + }; + }; + }; + }; + + image { + insert-template = <&ti_spl_template>; + fit { + images { + fdt-0 { + description = "fdt"; + ti-secure { + type = "collection"; + content = <&foo_dtb>; + keyfile = "key.pem"; + }; + foo_dtb: blob-ext { + filename = "vga.bin"; + }; + }; + }; + }; + }; + + image-2 { + insert-template = <&ti_spl_template>; + fit { + images { + fdt-0 { + description = "fdt"; + blob-ext { + filename = "vga.bin"; + }; + }; + }; + }; + }; + }; +}; -- 2.41.0.487.g6d72f3e995-goog