summaryrefslogtreecommitdiff
path: root/tools/binman/etype
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/etype
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/etype')
-rw-r--r--tools/binman/etype/section.py3
-rw-r--r--tools/binman/etype/u_boot_dtb_with_ucode.py46
-rw-r--r--tools/binman/etype/u_boot_ucode.py2
-rw-r--r--tools/binman/etype/u_boot_with_ucode_ptr.py7
4 files changed, 30 insertions, 28 deletions
diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py
index 36b31a849f..9b38738d38 100644
--- a/tools/binman/etype/section.py
+++ b/tools/binman/etype/section.py
@@ -17,6 +17,9 @@ class Entry_section(Entry):
Entry.__init__(self, image, etype, node)
self._section = bsection.Section(node.name, node)
+ def ProcessFdt(self, fdt):
+ return self._section.ProcessFdt(fdt)
+
def ObtainContents(self):
return self._section.GetEntryContents()
diff --git a/tools/binman/etype/u_boot_dtb_with_ucode.py b/tools/binman/etype/u_boot_dtb_with_ucode.py
index 1e530d6570..3808d6d278 100644
--- a/tools/binman/etype/u_boot_dtb_with_ucode.py
+++ b/tools/binman/etype/u_boot_dtb_with_ucode.py
@@ -5,6 +5,7 @@
# Entry-type module for U-Boot device tree with the microcode removed
#
+import control
import fdt
from entry import Entry
from blob import Entry_blob
@@ -22,13 +23,13 @@ class Entry_u_boot_dtb_with_ucode(Entry_blob):
self.collate = False
self.ucode_offset = None
self.ucode_size = None
+ self.ucode = None
+ self.ready = False
def GetDefaultFilename(self):
return 'u-boot.dtb'
- def ObtainContents(self):
- Entry_blob.ObtainContents(self)
-
+ def ProcessFdt(self, fdt):
# If the section does not need microcode, there is nothing to do
ucode_dest_entry = self.section.FindEntryType(
'u-boot-spl-with-ucode-ptr')
@@ -38,36 +39,35 @@ class Entry_u_boot_dtb_with_ucode(Entry_blob):
if not ucode_dest_entry or not ucode_dest_entry.target_pos:
return True
- # Create a new file to hold the copied device tree
- dtb_name = 'u-boot-dtb-with-ucode.dtb'
- fname = tools.GetOutputFilename(dtb_name)
- with open(fname, 'wb') as fd:
- fd.write(self.data)
-
# Remove the microcode
- dtb = fdt.FdtScan(fname)
- ucode = dtb.GetNode('/microcode')
- if not ucode:
+ fname = self.GetDefaultFilename()
+ fdt = control.GetFdt(fname)
+ self.ucode = fdt.GetNode('/microcode')
+ if not self.ucode:
raise self.Raise("No /microcode node found in '%s'" % fname)
# There's no need to collate it (move all microcode into one place)
# if we only have one chunk of microcode.
- self.collate = len(ucode.subnodes) > 1
- for node in ucode.subnodes:
+ self.collate = len(self.ucode.subnodes) > 1
+ for node in self.ucode.subnodes:
data_prop = node.props.get('data')
if data_prop:
self.ucode_data += ''.join(data_prop.bytes)
if self.collate:
- prop = node.DeleteProp('data')
- else:
+ node.DeleteProp('data')
+ return True
+
+ def ObtainContents(self):
+ # Call the base class just in case it does something important.
+ Entry_blob.ObtainContents(self)
+ self._pathname = control.GetFdtPath(self._filename)
+ self.ReadContents()
+ if self.ucode:
+ for node in self.ucode.subnodes:
+ data_prop = node.props.get('data')
+ if data_prop and not self.collate:
# Find the offset in the device tree of the ucode data
self.ucode_offset = data_prop.GetOffset() + 12
self.ucode_size = len(data_prop.bytes)
- if self.collate:
- dtb.Pack()
- dtb.Flush()
-
- # Make this file the contents of this entry
- self._pathname = fname
- self.ReadContents()
+ self.ready = True
return True
diff --git a/tools/binman/etype/u_boot_ucode.py b/tools/binman/etype/u_boot_ucode.py
index 8cae7deed3..ea0c85cc5c 100644
--- a/tools/binman/etype/u_boot_ucode.py
+++ b/tools/binman/etype/u_boot_ucode.py
@@ -71,7 +71,7 @@ class Entry_u_boot_ucode(Entry_blob):
fdt_entry = self.section.FindEntryType('u-boot-dtb-with-ucode')
if not fdt_entry:
return True
- if not fdt_entry.ucode_data:
+ if not fdt_entry.ready:
return False
if not fdt_entry.collate:
diff --git a/tools/binman/etype/u_boot_with_ucode_ptr.py b/tools/binman/etype/u_boot_with_ucode_ptr.py
index 86945f3318..8b1e41152e 100644
--- a/tools/binman/etype/u_boot_with_ucode_ptr.py
+++ b/tools/binman/etype/u_boot_with_ucode_ptr.py
@@ -28,7 +28,7 @@ class Entry_u_boot_with_ucode_ptr(Entry_blob):
def GetDefaultFilename(self):
return 'u-boot-nodtb.bin'
- def ObtainContents(self):
+ def ProcessFdt(self, fdt):
# Figure out where to put the microcode pointer
fname = tools.GetInputFilename(self.elf_fname)
sym = elf.GetSymbolAddress(fname, '_dt_ucode_base_size')
@@ -36,8 +36,7 @@ class Entry_u_boot_with_ucode_ptr(Entry_blob):
self.target_pos = sym
elif not fdt_util.GetBool(self._node, 'optional-ucode'):
self.Raise('Cannot locate _dt_ucode_base_size symbol in u-boot')
-
- return Entry_blob.ObtainContents(self)
+ return True
def ProcessContents(self):
# If the image does not need microcode, there is nothing to do
@@ -73,7 +72,7 @@ class Entry_u_boot_with_ucode_ptr(Entry_blob):
pos, size = ucode_entry.pos, ucode_entry.size
else:
dtb_entry = self.section.FindEntryType('u-boot-dtb-with-ucode')
- if not dtb_entry:
+ if not dtb_entry or not dtb_entry.ready:
self.Raise('Cannot find microcode region u-boot-dtb-with-ucode')
pos = dtb_entry.pos + dtb_entry.ucode_offset
size = dtb_entry.ucode_size