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 5CD24EB64D7 for ; Wed, 28 Jun 2023 11:44:34 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7A89486658; Wed, 28 Jun 2023 13:44:22 +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="cPNgAjK4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 98C848662E; Wed, 28 Jun 2023 13:42:50 +0200 (CEST) Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) (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 54CC686641 for ; Wed, 28 Jun 2023 13:42:29 +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-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-51d95aed33aso3794537a12.3 for ; Wed, 28 Jun 2023 04:42:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1687952548; x=1690544548; 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=IPhg07PNdSrCQovYL0qkSyuHgMnfojw/YGm++aJgCVY=; b=cPNgAjK404rPD18/61HfBwdodp17sqgPR4nmVlPWIS4BlsX2u7g0AoJKJX92s/IKSs /KPeBVwrQ5wQdXDGhnYiTVui7Gsy8QsLARPjSmowKKNn8jI+LOAQzwKTyykN03OAKsU0 lvNCqbLy/Uo32vaxcfS3sjBM/pD3jcUrnkb5s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687952548; x=1690544548; 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=IPhg07PNdSrCQovYL0qkSyuHgMnfojw/YGm++aJgCVY=; b=WwSizedRggKhwIa12+Y7oHz+87sb7sY/2/MiUjVL+HyXzv9wPL7HRLknErzor6CT2Q 3HbKqA9fqZo2OVbyeAW/2RZTjfPITyV8mGKo4gVDRCm0IPr41x7sxdh2Q9ZhnLE+/BS0 t6WkfOwwfcVw0Uvx+DK/lPZPqLbMDKDBzQN9Vk9RWbwBs5ud9AjzdOqJFjZOEg+5NbiT Yq7Ll15biWZaXOc21QVV0N7g/yiXiyoxy7KzDIThq9cOhWgcHv7+9947UUE3IOVtj0O7 +a2nN6nmkdU/0o/3O8KPbfc7B9hYvJ1Gl1RePOOxllV/xmF2MNRSpPMGtwiGPD0N/A8q xWEw== X-Gm-Message-State: AC+VfDyPUkUvBWzEaBNYrBSTbDT1GnuEWWbPOsMUs1jnQtKJTvBFKYJc lOuRQW271103mF58RGOyuPVPY0Qx6r40ssaCRxVMXQ== X-Google-Smtp-Source: ACHHUZ7oyBFh8UkzTBEMEp9bngtraD9oW/a7wga3+2EJM4FsdBPFKclBf5AohivDEqePreJlzmSv7A== X-Received: by 2002:aa7:d351:0:b0:51d:9737:5257 with SMTP id m17-20020aa7d351000000b0051d97375257mr5517280edr.40.1687952548226; Wed, 28 Jun 2023 04:42:28 -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.27 (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 , Heinrich Schuchardt Subject: [PATCH 11/12] dtoc: Allow inserting a list of nodes into another Date: Wed, 28 Jun 2023 12:41:44 +0100 Message-ID: <20230628114149.439723-12-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 Provide a way to specify a phandle list of nodes which are to be inserted into an existing node. Signed-off-by: Simon Glass --- tools/dtoc/fdt.py | 16 ++++++++++++++++ tools/dtoc/test/dtoc_test_simple.dts | 10 ++++++++-- tools/dtoc/test_fdt.py | 18 ++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py index fcf229f83036..4ff55a47b6f1 100644 --- a/tools/dtoc/fdt.py +++ b/tools/dtoc/fdt.py @@ -657,6 +657,22 @@ class Node: for node in src.subnodes: dst.copy_node(node) + def copy_subnodes_from_phandles(self, phandle_list): + """Copy subnodes of a list of nodes into another node + + Args: + phandle_list (list of int): List of phandles of nodes to copy + + For each node in the phandle list, its subnodes and their properties are + copied recursively. Note that it does not copy the node itself, nor its + properties. + """ + for phandle in phandle_list: + parent = self.GetFdt().LookupPhandle(phandle) + tout.debug(f'adding template {parent.path} to node {self.path}') + for node in parent.subnodes: + self.copy_node(node) + class Fdt: """Provides simple access to a flat device tree blob using libfdts. diff --git a/tools/dtoc/test/dtoc_test_simple.dts b/tools/dtoc/test/dtoc_test_simple.dts index c51f1a5908ce..f7ad445574d2 100644 --- a/tools/dtoc/test/dtoc_test_simple.dts +++ b/tools/dtoc/test/dtoc_test_simple.dts @@ -50,7 +50,7 @@ }; }; - i2c@0 { + i2c: i2c@0 { compatible = "sandbox,i2c"; bootph-all; #address-cells = <1>; @@ -63,10 +63,16 @@ }; }; - orig-node { + orig: orig-node { orig = <1 23 4>; args = "-n first", "second", "-p", "123,456", "-x"; args2 = "a space", "there"; args3 = "-n first second -p 123,456 -x"; + + copy-list = <&i2c &orig>; + + subnode { + a-prop; + }; }; }; diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py index 5d9d99eb384b..6d96270d539e 100755 --- a/tools/dtoc/test_fdt.py +++ b/tools/dtoc/test_fdt.py @@ -349,6 +349,24 @@ class TestNode(unittest.TestCase): self.dtb.Sync(auto_resize=True) + def test_copy_subnodes_from_phandles(self): + """Test copy_node() function""" + pmic = self.dtb.GetNode('/spl-test3/i2c@0/pmic@9') + self.assertIsNone(pmic) + + orig = self.dtb.GetNode('/orig-node') + node_list = fdt_util.GetPhandleList(orig, 'copy-list') + + dst = self.dtb.GetNode('/spl-test3') + dst.copy_subnodes_from_phandles(node_list) + + pmic = self.dtb.GetNode('/spl-test3/pmic@9') + self.assertTrue(pmic) + + subn = self.dtb.GetNode('/spl-test3/subnode') + self.assertTrue(subn) + self.assertEqual({'a-prop'}, subn.props.keys()) + class TestProp(unittest.TestCase): """Test operation of the Prop class""" -- 2.41.0.162.gfafddb0af9-goog