From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 11/19] fdt: Support use of the new python libfdt library
Date: Sun, 16 Apr 2017 20:22:25 -0600 [thread overview]
Message-ID: <20170417022233.28101-12-sjg@chromium.org> (raw)
In-Reply-To: <20170417022233.28101-1-sjg@chromium.org>
Use the new library if available, while retaining backwards compatibility
with the old library for now.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
tools/Makefile | 4 +++-
tools/binman/binman.py | 3 +++
tools/dtoc/fdt.py | 1 +
tools/dtoc/fdt_normal.py | 35 ++++++++++++++++++++++++++---------
4 files changed, 33 insertions(+), 10 deletions(-)
diff --git a/tools/Makefile b/tools/Makefile
index 65d3fb911a..3ffd3eeca9 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -120,7 +120,9 @@ fit_info-objs := $(dumpimage-mkimage-objs) fit_info.o
fit_check_sign-objs := $(dumpimage-mkimage-objs) fit_check_sign.o
tools/_libfdt.so: $(LIBFDT_SRCS) $(LIBFDT_SWIG)
- LDFLAGS="$(HOSTLDFLAGS)" CFLAGS= VERSION=u-boot-$(UBOOTVERSION) \
+ unset CC; \
+ unset CROSS_COMPILE; \
+ LDFLAGS="$(HOSTLDFLAGS)" CFLAGS= VERSION="u-boot-$(UBOOTVERSION)" \
CPPFLAGS="$(_hostc_flags)" OBJDIR=tools \
SOURCES="$(LIBFDT_SRCS) $(LIBFDT_SWIG)" \
SWIG_OPTS="-I$(srctree)/lib/libfdt -I$(srctree)/lib" \
diff --git a/tools/binman/binman.py b/tools/binman/binman.py
index 857d698b4c..95d3a048d8 100755
--- a/tools/binman/binman.py
+++ b/tools/binman/binman.py
@@ -21,6 +21,9 @@ sys.path.append(os.path.join(our_path, '../patman'))
sys.path.append(os.path.join(our_path, '../dtoc'))
sys.path.append(os.path.join(our_path, '../'))
+# Bring in the libfdt module
+sys.path.append('tools')
+
# Also allow entry-type modules to be brought in from the etype directory.
sys.path.append(os.path.join(our_path, 'etype'))
diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py
index 816fdbe525..c40b9b6bab 100644
--- a/tools/dtoc/fdt.py
+++ b/tools/dtoc/fdt.py
@@ -96,6 +96,7 @@ class PropBase:
TYPE_INT: a byte-swapped integer stored as a 4-byte string
TYPE_BYTE: a byte stored as a single-byte string
"""
+ bytes = str(bytes)
size = len(bytes)
strings = bytes.split('\0')
is_string = True
diff --git a/tools/dtoc/fdt_normal.py b/tools/dtoc/fdt_normal.py
index 17b0a9a726..e793f49fa8 100644
--- a/tools/dtoc/fdt_normal.py
+++ b/tools/dtoc/fdt_normal.py
@@ -12,7 +12,13 @@ import sys
import fdt
from fdt import Fdt, NodeBase, PropBase
import fdt_util
-import libfdt_legacy as libfdt
+try:
+ import libfdt
+ legacy = False
+except ImportError:
+ import libfdt_legacy as libfdt
+ legacy = True
+
# This deals with a device tree, presenting it as a list of Node and Prop
# objects, representing nodes and properties, respectively.
@@ -36,7 +42,7 @@ class Prop(PropBase):
"""
def __init__(self, node, offset, name, bytes):
PropBase.__init__(self, node, offset, name)
- self.bytes = bytes
+ self.bytes = str(bytes)
if not bytes:
self.type = fdt.TYPE_BOOL
self.value = True
@@ -86,7 +92,10 @@ class Node(NodeBase):
offset = libfdt.fdt_first_subnode(self._fdt.GetFdt(), self.Offset())
while offset >= 0:
sep = '' if self.path[-1] == '/' else '/'
- name = libfdt.Name(self._fdt.GetFdt(), offset)
+ if legacy:
+ name = libfdt.Name(self._fdt.GetFdt(), offset)
+ else:
+ name = self._fdt._fdt_obj.get_name(offset)
path = self.path + sep + name
node = Node(self._fdt, offset, name, path)
self.subnodes.append(node)
@@ -139,6 +148,8 @@ class FdtNormal(Fdt):
with open(self._fname) as fd:
self._fdt = bytearray(fd.read())
+ if not legacy:
+ self._fdt_obj = libfdt.Fdt(self._fdt)
def GetFdt(self):
"""Get the contents of the FDT
@@ -175,12 +186,18 @@ class FdtNormal(Fdt):
props_dict = {}
poffset = libfdt.fdt_first_property_offset(self._fdt, node._offset)
while poffset >= 0:
- dprop, plen = libfdt.fdt_get_property_by_offset(self._fdt, poffset)
- prop = Prop(node, poffset, libfdt.String(self._fdt, dprop.nameoff),
- libfdt.Data(dprop))
- props_dict[prop.name] = prop
-
- poffset = libfdt.fdt_next_property_offset(self._fdt, poffset)
+ if legacy:
+ dprop, plen = libfdt.fdt_get_property_by_offset(self._fdt,
+ poffset)
+ prop = Prop(node, poffset,
+ libfdt.String(self._fdt, dprop.nameoff),
+ libfdt.Data(dprop))
+ else:
+ p = self._fdt_obj.get_property_by_offset(poffset)
+ prop = Prop(node, poffset, p.name, p.value)
+ props_dict[prop.name] = prop
+
+ poffset = libfdt.fdt_next_property_offset(self._fdt, poffset)
return props_dict
def Invalidate(self):
--
2.12.2.762.g0e3151a226-goog
next prev parent reply other threads:[~2017-04-17 2:22 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-17 2:22 [U-Boot] [PATCH 00/19] fdt: Move to the new upstream pylibfdt library Simon Glass
2017-04-17 2:22 ` [U-Boot] [PATCH 01/19] pci: Correct cast for sandbox Simon Glass
2017-05-02 11:27 ` sjg at google.com
2017-04-17 2:22 ` [U-Boot] [PATCH 02/19] fdt: Correct cast for sandbox in fdtdec_setup_memory_size() Simon Glass
2017-05-02 11:27 ` sjg at google.com
2017-04-17 2:22 ` [U-Boot] [PATCH 03/19] fdt: Use SPDX format for licenses in the libfdt headers Simon Glass
2017-04-17 13:05 ` Tom Rini
2017-04-17 13:13 ` Masahiro Yamada
2017-04-17 13:33 ` Tom Rini
2017-04-17 13:47 ` Simon Glass
2017-04-17 14:01 ` Tom Rini
2017-05-02 11:27 ` sjg at google.com
2017-04-17 2:22 ` [U-Boot] [PATCH 04/19] fdt: Move header files into lib/libfdt Simon Glass
2017-05-02 11:27 ` sjg at google.com
2017-04-17 2:22 ` [U-Boot] [PATCH 05/19] fdt: Allow swig options to be provided by Makefile Simon Glass
2017-05-02 11:27 ` sjg at google.com
2017-04-17 2:22 ` [U-Boot] [PATCH 06/19] fdt: Add all source files to the libfdt build Simon Glass
2017-05-02 11:27 ` sjg at google.com
2017-04-17 2:22 ` [U-Boot] [PATCH 07/19] fdt: Rename existing python libfdt module Simon Glass
2017-05-02 11:27 ` sjg at google.com
2017-04-17 2:22 ` [U-Boot] [PATCH 08/19] fdt: Build the new " Simon Glass
2017-05-02 11:27 ` sjg at google.com
2017-04-17 2:22 ` [U-Boot] [PATCH 09/19] fdt: Update fdt_test to use 'dt' instead of 'fdt' Simon Glass
2017-05-02 11:27 ` sjg at google.com
2017-04-17 2:22 ` [U-Boot] [PATCH 10/19] fdt: dtoc: Add a full set of property tests Simon Glass
2017-05-02 11:27 ` sjg at google.com
2017-04-17 2:22 ` Simon Glass [this message]
2017-05-02 11:27 ` [U-Boot] [PATCH 11/19] fdt: Support use of the new python libfdt library sjg at google.com
2017-04-17 2:22 ` [U-Boot] [PATCH 12/19] fdt: Makefile: Build python libfdt library if needed Simon Glass
2017-05-02 11:27 ` sjg at google.com
2017-04-17 2:22 ` [U-Boot] [PATCH 13/19] fdt: Stop building the old python libfdt module Simon Glass
2017-05-02 11:27 ` sjg at google.com
2017-04-17 2:22 ` [U-Boot] [PATCH 14/19] fdt: Drop use of the legacy libfdt python module Simon Glass
2017-05-02 11:27 ` sjg at google.com
2017-04-17 2:22 ` [U-Boot] [PATCH 15/19] fdt: Drop fdt_fallback library Simon Glass
2017-05-02 11:27 ` sjg at google.com
2017-04-17 2:22 ` [U-Boot] [PATCH 16/19] binman: Drop a special case related to fdt_fallback Simon Glass
2017-05-02 11:27 ` sjg at google.com
2017-04-17 2:22 ` [U-Boot] [PATCH 17/19] fdt: Merge fdt_normal with its base class Simon Glass
2017-05-02 11:27 ` sjg at google.com
2017-04-17 2:22 ` [U-Boot] [PATCH 18/19] binman: Rename fdt variable to dtb Simon Glass
2017-05-02 11:27 ` sjg at google.com
2017-04-17 2:22 ` [U-Boot] [PATCH 19/19] fdt: Drop fdt_select.py Simon Glass
2017-05-02 11:27 ` sjg at google.com
2017-04-18 16:25 ` [U-Boot] [PATCH 00/19] fdt: Move to the new upstream pylibfdt library Tom Rini
2017-04-18 16:27 ` Simon Glass
2017-04-18 16:33 ` Tom Rini
2017-04-18 16:48 ` Simon Glass
2017-04-19 14:27 ` Tom Rini
2017-05-02 11:31 ` Simon Glass
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170417022233.28101-12-sjg@chromium.org \
--to=sjg@chromium.org \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox