From patchwork Tue Jul 26 00:59:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 652517 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3rz0Fs5RrZz9s4q for ; Tue, 26 Jul 2016 11:02:09 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b=eeBwiRP1; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BFE25A78C2; Tue, 26 Jul 2016 03:01:23 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id B6_g16uO-sos; Tue, 26 Jul 2016 03:01:23 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BEE15A7684; Tue, 26 Jul 2016 03:00:35 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id DFB5AA7893 for ; Tue, 26 Jul 2016 03:00:18 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ambS_niZFjt1 for ; Tue, 26 Jul 2016 03:00:18 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-it0-f47.google.com (mail-it0-f47.google.com [209.85.214.47]) by theia.denx.de (Postfix) with ESMTPS id B4A7AA7877 for ; Tue, 26 Jul 2016 03:00:10 +0200 (CEST) Received: by mail-it0-f47.google.com with SMTP id j124so123672705ith.1 for ; Mon, 25 Jul 2016 18:00:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=DCi3eUgsM776ZZv32pmzkGcfzCm6JU0r9wqvOx+pAE4=; b=eeBwiRP1lRfnatwR1loHtUkZL8ph1dl0/rOUwsMr0XSrtz8VWKIkvecDDXWaRrNYvT pesLXaoA8vGAnp6r5XyQIE6PUYkwFoCaz1Cj4Us0V5wSupbbgiE8RX839F4iBJZpkYwp nlVWOC9ei2pT/YwEeiEQ4vYriwC6XbYXQS4AyuBtww72263zmqH48F5fcuzBztlCkKFS TxRwNdQlIS62sYIqYJJKMUoGb9QVMaQVDAFfYzqaPQsCJH4fA9wqkNtqPUTvAngWvVm+ LdD8V7lYiNE6uocFeaW0sUidLFOnNgvnzGwh93PbyWQEbZVyXkbe7x9BbXz8mrWX9pG4 oXwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=DCi3eUgsM776ZZv32pmzkGcfzCm6JU0r9wqvOx+pAE4=; b=Kj5GPYmI7jc5Wueh+PZnUvhuX6SV9fBGFLrSDMEKY10WzybHfCCzMXkCnJ7v7DCrfz 1eUY0xw0piHjSgFo8aN+1p7HwdQ0zC9aqcULqULvT42jPPN3jHiM9XlZbiJ/S9xU1COk l+RYNRybCGLqGbmjj4SEdQjEY3eFF0wGUjLaZhTaWTdVJgL9DHbABmf4vqCW8FOneDun 78lAE3uqWTHCvtdeOKORsYYtWW7wZ66UQjcXQnDg9qxKPMKbWIm1+US14LYjnAL7OYeB 5gTEjv1//C5gPj9wkCSA4ZVf4V2kKn0Wcewevi4mqBMDpB2q/bb9+4L9+mrI4vzCbCzN C+wg== X-Gm-Message-State: AEkoousHJN0xNnWWp9pQDuj5/Cb0kzbOwLsB0A5/HGA1AU+F1u8msH89UwIa1tRYQC5sS1d1 X-Received: by 10.36.29.5 with SMTP id 5mr22510912itj.97.1469494809602; Mon, 25 Jul 2016 18:00:09 -0700 (PDT) Received: from kaki.bld.corp.google.com ([2620:0:1005:12:544b:64e8:bc3:7489]) by smtp.gmail.com with ESMTPSA id x96sm10331508ita.20.2016.07.25.18.00.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Jul 2016 18:00:09 -0700 (PDT) Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id A3955220F90; Mon, 25 Jul 2016 19:00:08 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 25 Jul 2016 18:59:07 -0600 Message-Id: <1469494766-26601-12-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1469494766-26601-1-git-send-email-sjg@chromium.org> References: <1469494766-26601-1-git-send-email-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 11/30] dtoc: Move a few more common functions into fdt.py X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Some functions have the same code in the subclasses. Move these into the superclass to avoid duplication. Signed-off-by: Simon Glass --- tools/dtoc/fdt.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++ tools/dtoc/fdt_fallback.py | 16 ------------- tools/dtoc/fdt_normal.py | 16 ------------- 3 files changed, 57 insertions(+), 32 deletions(-) diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py index 964ef7c..c0ce5af 100644 --- a/tools/dtoc/fdt.py +++ b/tools/dtoc/fdt.py @@ -164,6 +164,26 @@ class NodeBase: self.subnodes = [] self.props = {} + def _FindNode(self, name): + """Find a node given its name + + Args: + name: Node name to look for + Returns: + Node object if found, else None + """ + for subnode in self.subnodes: + if subnode.name == name: + return subnode + return None + + def Scan(self): + """Scan the subnodes of a node + + This should be implemented by subclasses + """ + raise NotImplementedError() + class Fdt: """Provides simple access to a flat device tree blob. @@ -173,3 +193,40 @@ class Fdt: """ def __init__(self, fname): self._fname = fname + + def Scan(self, root='/'): + """Scan a device tree, building up a tree of Node objects + + This fills in the self._root property + + Args: + root: Ignored + + TODO(sjg@chromium.org): Implement the 'root' parameter + """ + self._root = self.Node(self, 0, '/', '/') + self._root.Scan() + + def GetRoot(self): + """Get the root Node of the device tree + + Returns: + The root Node object + """ + return self._root + + def GetNode(self, path): + """Look up a node from its path + + Args: + path: Path to look up, e.g. '/microcode/update@0' + Returns: + Node object, or None if not found + """ + node = self._root + for part in path.split('/')[1:]: + node = node._FindNode(part) + if not node: + return None + return node + diff --git a/tools/dtoc/fdt_fallback.py b/tools/dtoc/fdt_fallback.py index 9a03b02..222fd27 100644 --- a/tools/dtoc/fdt_fallback.py +++ b/tools/dtoc/fdt_fallback.py @@ -80,22 +80,6 @@ class FdtFallback(Fdt): def __init__(self, fname): Fdt.__init__(self, fname) - def Scan(self): - """Scan a device tree, building up a tree of Node objects - - This fills in the self._root property - """ - self._root = Node(self, 0, '/', '/') - self._root.Scan() - - def GetRoot(self): - """Get the root Node of the device tree - - Returns: - The root Node object - """ - return self._root - def GetSubNodes(self, node): """Returns a list of sub-nodes of a given node diff --git a/tools/dtoc/fdt_normal.py b/tools/dtoc/fdt_normal.py index 6f019c1..861f60c 100644 --- a/tools/dtoc/fdt_normal.py +++ b/tools/dtoc/fdt_normal.py @@ -94,22 +94,6 @@ class FdtNormal(Fdt): """ return self._fdt - def Scan(self): - """Scan a device tree, building up a tree of Node objects - - This fills in the self._root property - """ - self._root = Node(self, 0, '/', '/') - self._root.Scan() - - def GetRoot(self): - """Get the root Node of the device tree - - Returns: - The root Node object - """ - return self._root - def GetProps(self, node): """Get all properties from a node.