From patchwork Fri Jul 6 16:27:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 940609 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41MgQB1nbxz9s4c for ; Sat, 7 Jul 2018 02:38:10 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id B32E1C21C3F; Fri, 6 Jul 2018 16:35:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: * X-Spam-Status: No, score=1.5 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, TVD_PH_BODY_ACCOUNTS_PRE autolearn=no autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id F2C3BC220A5; Fri, 6 Jul 2018 16:29:15 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id C9A72C21F49; Fri, 6 Jul 2018 16:28:38 +0000 (UTC) Received: from mail-vk0-f74.google.com (mail-vk0-f74.google.com [209.85.213.74]) by lists.denx.de (Postfix) with ESMTPS id B3463C22082 for ; Fri, 6 Jul 2018 16:28:32 +0000 (UTC) Received: by mail-vk0-f74.google.com with SMTP id w73-v6so4305053vkd.9 for ; Fri, 06 Jul 2018 09:28:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:date:in-reply-to:message-id :references:subject:from:to:cc; bh=TberxEOHaB0GJYylQnroor0b0DKMKyOZbX2JwgaMoVg=; b=N1/WqG+gQXw62uuCDfwFhs0UxTQKZozqLSxZ/bYJcvncRpX7uPs03euii98bGXQLsA HJtw0b/qsZEH5uGPyiE+xlVX6SpSeIfl/2KUrrPA7tBQ+zwyzLot7LZi5x1lJsXAO0U0 eDQZiouxYawWKBedeZgZNHtRT6DQ2ogJSkM+VU9zolmHReaCHVjRQSYgeq/cRrHtFhR5 v2kcIr+P2AjiGengjteE5pSj4dq8MewaN0e28ssGiBFf5SmrYRi4Lti/UZHMfphFYCYH htQEpDxJJ0YtBEMLfzdYfCit24iYpFbBNR3xq4aXzFY49gBIt291GjL5WNGfogXIz9h+ hp6Q== X-Gm-Message-State: APt69E2Oiz5yW+Ryzm9rEHbucVxnSvc3U84mqqQaursN23DmtfYAHeZE IlCVdgVVy3YwwbomaZSSlmE0J24= X-Google-Smtp-Source: AAOMgpeHHLl8zrw1Oi6XvmRSPGqj/2W2VjqUHY/Xfk3MMdwK88/Zjfz1gCAxROM8eIDnLC3L8xsbeJo= MIME-Version: 1.0 X-Received: by 2002:ab0:4741:: with SMTP id i1-v6mr4761181uac.116.1530894511878; Fri, 06 Jul 2018 09:28:31 -0700 (PDT) Date: Fri, 6 Jul 2018 10:27:27 -0600 In-Reply-To: <20180706162742.186950-1-sjg@chromium.org> Message-Id: <20180706162742.186950-15-sjg@chromium.org> References: <20180706162742.186950-1-sjg@chromium.org> X-Mailer: git-send-email 2.18.0.203.gfac676dfb9-goog From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini Subject: [U-Boot] [PATCH v2 14/29] dtoc: Drop use of a local dtb buffer X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" At present the Fdt class has its own copy of the device tree. This is confusing an unnecessary now that pylibfdt has its own. Drop it and provide access functions to the buffer. This allows us to move the rest of the implementation to use pylibfdt methods instead of directly calling libfdt stubs. Signed-off-by: Simon Glass --- Changes in v2: None tools/dtoc/fdt.py | 16 ++++++++-------- tools/dtoc/test_fdt.py | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py index 18cde2604f..e24acf1280 100644 --- a/tools/dtoc/fdt.py +++ b/tools/dtoc/fdt.py @@ -235,12 +235,13 @@ class Node: Note: This does not take account of property offsets - these will not be updated. """ + fdt_obj = self._fdt._fdt_obj if self._offset != my_offset: self._offset = my_offset - offset = libfdt.fdt_first_subnode(self._fdt.GetFdt(), self._offset) + offset = fdt_obj.first_subnode(self._offset, QUIET_NOTFOUND) for subnode in self.subnodes: subnode.Refresh(offset) - offset = libfdt.fdt_next_subnode(self._fdt.GetFdt(), offset) + offset = fdt_obj.next_subnode(offset, QUIET_NOTFOUND) def DeleteProp(self, prop_name): """Delete a property of a node @@ -252,7 +253,7 @@ class Node: Raises: ValueError if the property does not exist """ - CheckErr(libfdt.fdt_delprop(self._fdt.GetFdt(), self.Offset(), prop_name), + CheckErr(self._fdt._fdt_obj.delprop(self.Offset(), prop_name), "Node '%s': delete property: '%s'" % (self.path, prop_name)) del self.props[prop_name] self._fdt.Invalidate() @@ -272,8 +273,7 @@ class Fdt: self._fname = fdt_util.EnsureCompiled(self._fname) with open(self._fname) as fd: - self._fdt = bytearray(fd.read()) - self._fdt_obj = libfdt.Fdt(self._fdt) + self._fdt_obj = libfdt.Fdt(fd.read()) def Scan(self, root='/'): """Scan a device tree, building up a tree of Node objects @@ -317,7 +317,7 @@ class Fdt: If the device tree has changed in memory, write it back to the file. """ with open(self._fname, 'wb') as fd: - fd.write(self._fdt) + fd.write(self._fdt_obj.as_bytearray()) def Pack(self): """Pack the device tree down to its minimum size @@ -328,13 +328,13 @@ class Fdt: CheckErr(self._fdt_obj.pack(), 'pack') self.Invalidate() - def GetFdt(self): + def GetContents(self): """Get the contents of the FDT Returns: The FDT contents as a string of bytes """ - return self._fdt + return self._fdt_obj.as_bytearray() def GetFdtObj(self): """Get the contents of the FDT diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py index ba660ca9b7..daa9d128b5 100755 --- a/tools/dtoc/test_fdt.py +++ b/tools/dtoc/test_fdt.py @@ -72,7 +72,7 @@ class TestFdt(unittest.TestCase): def testGetFdt(self): """Tetst that we can access the raw device-tree data""" - self.assertTrue(isinstance(self.dtb.GetFdt(), bytearray)) + self.assertTrue(isinstance(self.dtb.GetContents(), bytearray)) def testGetProps(self): """Tests obtaining a list of properties""" @@ -157,7 +157,7 @@ class TestProp(unittest.TestCase): # Add 12, which is sizeof(struct fdt_property), to get to start of data offset = prop.GetOffset() + 12 - data = self.dtb._fdt[offset:offset + len(prop.value)] + data = self.dtb.GetContents()[offset:offset + len(prop.value)] bytes = [chr(x) for x in data] self.assertEqual(bytes, prop.value)