summaryrefslogtreecommitdiff
path: root/tools/binman/control.py
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2018-07-06 10:27:40 -0600
committerSimon Glass <sjg@chromium.org>2018-07-09 09:11:00 -0600
commitecab89737a4eb58c043388b1ca1c0f1dfdaa3346 (patch)
treee4cdc99478b084d017cb359f2025e7e2d7088ef3 /tools/binman/control.py
parent0a4357c4c2b29d787d70775dd6ad64b50e23082a (diff)
binman: Add a ProcessFdt() method
Some entry types modify the device tree, e.g. to remove microcode or add a property. So far this just modifies their local copy and does not affect a 'shared' device tree. Rather than doing this modification in the ObtainContents() method, and a new ProcessFdt() method which is specifically designed to modify this shared device tree. Move the existing device-tree code over to use this method, reducing ObtainContents() to the goal of just obtaining the contents without any processing, even for device tree. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/binman/control.py')
-rw-r--r--tools/binman/control.py52
1 files changed, 51 insertions, 1 deletions
diff --git a/tools/binman/control.py b/tools/binman/control.py
index 9243472906..5325a6a006 100644
--- a/tools/binman/control.py
+++ b/tools/binman/control.py
@@ -21,6 +21,11 @@ import tout
# Make this global so that it can be referenced from tests
images = OrderedDict()
+# Records the device-tree files known to binman, keyed by filename (e.g.
+# 'u-boot-spl.dtb')
+fdt_files = {}
+
+
def _ReadImageDesc(binman_node):
"""Read the image descriptions from the /binman node
@@ -53,6 +58,24 @@ def _FindBinmanNode(dtb):
return node
return None
+def GetFdt(fname):
+ """Get the Fdt object for a particular device-tree filename
+
+ Binman keeps track of at least one device-tree file called u-boot.dtb but
+ can also have others (e.g. for SPL). This function looks up the given
+ filename and returns the associated Fdt object.
+
+ Args:
+ fname: Filename to look up (e.g. 'u-boot.dtb').
+
+ Returns:
+ Fdt object associated with the filename
+ """
+ return fdt_files[fname]
+
+def GetFdtPath(fname):
+ return fdt_files[fname]._fname
+
def Binman(options, args):
"""The main control code for binman
@@ -93,12 +116,39 @@ def Binman(options, args):
try:
tools.SetInputDirs(options.indir)
tools.PrepareOutputDir(options.outdir, options.preserve)
- dtb = fdt.FdtScan(dtb_fname)
+
+ # Get the device tree ready by compiling it and copying the compiled
+ # output into a file in our output directly. Then scan it for use
+ # in binman.
+ dtb_fname = fdt_util.EnsureCompiled(dtb_fname)
+ fname = tools.GetOutputFilename('u-boot-out.dtb')
+ with open(dtb_fname) as infd:
+ with open(fname, 'wb') as outfd:
+ outfd.write(infd.read())
+ dtb = fdt.FdtScan(fname)
+
+ # Note the file so that GetFdt() can find it
+ fdt_files['u-boot.dtb'] = dtb
node = _FindBinmanNode(dtb)
if not node:
raise ValueError("Device tree '%s' does not have a 'binman' "
"node" % dtb_fname)
+
images = _ReadImageDesc(node)
+
+ # Prepare the device tree by making sure that any missing
+ # properties are added (e.g. 'pos' and 'size'). The values of these
+ # may not be correct yet, but we add placeholders so that the
+ # size of the device tree is correct. Later, in
+ # SetCalculatedProperties() we will insert the correct values
+ # without changing the device-tree size, thus ensuring that our
+ # entry positions remain the same.
+ for image in images.values():
+ image.ProcessFdt(dtb)
+
+ dtb.Pack()
+ dtb.Flush()
+
for image in images.values():
# Perform all steps for this image, including checking and
# writing it. This means that errors found with a later