aboutsummaryrefslogtreecommitdiff
path: root/tools/binman/control.py
diff options
context:
space:
mode:
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 9243472..5325a6a 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