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 59C42C433FE for ; Tue, 8 Feb 2022 18:51:27 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 64A9583DD5; Tue, 8 Feb 2022 19:50:50 +0100 (CET) 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="AJl7W+fv"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 855DB83D8B; Tue, 8 Feb 2022 19:50:39 +0100 (CET) Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) (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 05A1083D8B for ; Tue, 8 Feb 2022 19:50:33 +0100 (CET) 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-x12e.google.com with SMTP id z18so7269282iln.2 for ; Tue, 08 Feb 2022 10:50:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eDmEYX8HfxDRtumNAxAHAs4V3/ioTnGDb5+Q4UfoWrQ=; b=AJl7W+fvUKrN4lcrZIy0XZcPabQIW5zhlLH4VgpFlZBsKQKyL1CesPNvLbeRSOghiE ywCun/jxaTjpP+L2YaAvhmBQDdrTAMEIYMMdsGTWwkVuF9kdTeg1BtOoLcykYeWWhqBA rwsyD7Nt6TC804ft81LB9GMSac0hK/SA01eKU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eDmEYX8HfxDRtumNAxAHAs4V3/ioTnGDb5+Q4UfoWrQ=; b=ZxXLp+PRNaUmnC78mn0lQM9WD+PmVIejpVbRg7uqH8uKI4Sx08wHKrLJ0iQsKwbmWv vHc4WvyYy1WfHfaW6sz9mekb4DuDDo9uaT3wJmEl3VSFh0NJyC3QxTDMtyDO1gX0B093 Q5Ma24JpfPuqMtB4xSuZlSEa8YZ7pvyeoNoDdpkkC2JpW4lt48qqBlNoMekosQXoMgMi r0Xi1f8kp2kafHS1vKL01BXxpGJhmfqHJ1iv8k2CwYKomGKpltXvQDR/SsZFwA7fqcD6 r2qgNbuvJbInpKpbISRp/RcWUKUV+o2aJfS0CzyeTfk96GegHaTzHTggugHEcV+qoHdU qzTA== X-Gm-Message-State: AOAM533m/AtZC+1E0XOoj5zqScUzn/E6J7dDJgIr1beMtIrXPHdOrX9K mzounKkoiU2gAI1UA1kEDrqELDBV8QRN5g== X-Google-Smtp-Source: ABdhPJy6FSp6np22bYInr2VLXpY1jDNZvqyW5ULNKuEXZ0rzRLNn0pec0F8NzZxMV+uwNn3pTxD9Ng== X-Received: by 2002:a05:6e02:1a05:: with SMTP id s5mr2922096ild.231.1644346231741; Tue, 08 Feb 2022 10:50:31 -0800 (PST) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id q2sm2911844ilt.33.2022.02.08.10.50.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 10:50:31 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: huang lin , Jeffy Chen , Simon Glass , Kever Yang , Philipp Tomsich , Alper Nebi Yasak , Tom Rini , Roger Quadros , Philippe Reynes , Ivan Mikhaylov , Walter Lozano Subject: [PATCH 07/24] dtoc: Support deleting a node Date: Tue, 8 Feb 2022 11:49:51 -0700 Message-Id: <20220208185008.35843-6-sjg@chromium.org> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog In-Reply-To: <20220208185008.35843-1-sjg@chromium.org> References: <20220208185008.35843-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.5 at phobos.denx.de X-Virus-Status: Clean Add a function to delete a node. This is synced to the tree when requested. Signed-off-by: Simon Glass --- tools/dtoc/fdt.py | 17 +++++++++++++++++ tools/dtoc/test_fdt.py | 9 +++++++++ 2 files changed, 26 insertions(+) diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py index e7197f8f12..8108a86c09 100644 --- a/tools/dtoc/fdt.py +++ b/tools/dtoc/fdt.py @@ -548,6 +548,23 @@ class Node: self.subnodes.append(subnode) return subnode + def Delete(self): + """Delete a node + + The node is deleted and the offset cache is invalidated. + + Args: + node (Node): Node to delete + + Raises: + ValueError if the node does not exist + """ + CheckErr(self._fdt._fdt_obj.del_node(self.Offset()), + "Node '%s': delete" % self.path) + parent = self.parent + self._fdt.Invalidate() + parent.subnodes.remove(self) + def Sync(self, auto_resize=False): """Sync node changes back to the device tree diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py index 1a7e73ffce..22e23c40f5 100755 --- a/tools/dtoc/test_fdt.py +++ b/tools/dtoc/test_fdt.py @@ -539,6 +539,15 @@ class TestProp(unittest.TestCase): data = self.fdt.getprop(self.node.Offset(), 'stringlist') self.assertEqual(b'123\x00456\0', data) + def test_delete_node(self): + """Test deleting a node""" + old_offset = self.fdt.path_offset('/spl-test') + self.assertGreater(old_offset, 0) + self.node.Delete() + self.dtb.Sync() + new_offset = self.fdt.path_offset('/spl-test', libfdt.QUIET_NOTFOUND) + self.assertEqual(-libfdt.NOTFOUND, new_offset) + def testFromData(self): dtb2 = fdt.Fdt.FromData(self.dtb.GetContents()) self.assertEqual(dtb2.GetContents(), self.dtb.GetContents()) -- 2.35.0.263.gb82422642f-goog