[U-Boot] [PATCH 07/29] binman: Add a new 'image-pos' property
Simon Glass
sjg at chromium.org
Tue Jul 17 19:25:30 UTC 2018
At present each entry has an offset within its parent section. This is
useful for figuring out how entries relate to one another. However it
is sometimes necessary to locate an entry within an image, regardless
of which sections it is nested inside.
Add a new 'image-pos' property to provide this information. Also add
some documentation for the -u option binman provides, which updates the
device tree with final entry information.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
tools/binman/README | 22 ++++++++++++++++++++--
tools/binman/bsection.py | 8 +++++++-
tools/binman/control.py | 1 +
tools/binman/entry.py | 12 +++++++++++-
tools/binman/etype/section.py | 4 ++++
tools/binman/ftest.py | 9 ++++++++-
tools/binman/image.py | 3 +++
7 files changed, 54 insertions(+), 5 deletions(-)
diff --git a/tools/binman/README b/tools/binman/README
index 4b13776ffa..df88819a1c 100644
--- a/tools/binman/README
+++ b/tools/binman/README
@@ -324,6 +324,12 @@ offset-unset:
property is present, binman will give an error if another entry does
not set the offset (with the GetOffsets() method).
+image-pos:
+ This cannot be set on entry (or at least it is ignored if it is), but
+ with the -u option, binman will set it to the absolute image position
+ for each entry. This makes it easy to find out exactly where the entry
+ ended up in the image, regardless of parent sections, etc.
+
The attributes supported for images are described below. Several are similar
to those for entries.
@@ -550,8 +556,8 @@ the 'warning' line in scripts/Makefile.lib to see what it has found:
# u_boot_dtsi_options_debug = $(u_boot_dtsi_options_raw)
-Access to binman entry offsets at run time
-------------------------------------------
+Access to binman entry offsets at run time (symbols)
+----------------------------------------------------
Binman assembles images and determines where each entry is placed in the image.
This information may be useful to U-Boot at run time. For example, in SPL it
@@ -577,6 +583,18 @@ At present this feature is only supported in SPL. In principle it is possible
to fill in such symbols in U-Boot proper, as well.
+Access to binman entry offsets at run time (fdt)
+------------------------------------------------
+
+Binman can update the U-Boot FDT to include the final position and size of
+each entry in the images it processes. The option to enable this is -u and it
+causes binman to make sure that the 'offset', 'image-pos' and 'size' properties
+are set correctly for every entry. Since it is not necessary to specify these in
+the image definition, binman calculates the final values and writes these to
+the device tree. These can be used by U-Boot at run-time to find the location
+of each entry.
+
+
Map files
---------
diff --git a/tools/binman/bsection.py b/tools/binman/bsection.py
index 1604b9915e..47fe37ccb9 100644
--- a/tools/binman/bsection.py
+++ b/tools/binman/bsection.py
@@ -96,7 +96,7 @@ class Section(object):
def AddMissingProperties(self):
"""Add new properties to the device tree as needed for this entry"""
- for prop in ['offset', 'size']:
+ for prop in ['offset', 'size', 'image-pos']:
if not prop in self._node.props:
self._node.AddZeroProp(prop)
for entry in self._entries.values():
@@ -105,6 +105,7 @@ class Section(object):
def SetCalculatedProperties(self):
self._node.SetInt('offset', self._offset)
self._node.SetInt('size', self._size)
+ self._node.SetInt('image-pos', self._image_pos)
for entry in self._entries.values():
entry.SetCalculatedProperties()
@@ -260,6 +261,11 @@ class Section(object):
offset = entry.offset + entry.size
prev_name = entry.GetPath()
+ def SetImagePos(self, image_pos):
+ self._image_pos = image_pos
+ for entry in self._entries.values():
+ entry.SetImagePos(image_pos)
+
def ProcessEntryContents(self):
"""Call the ProcessContents() method for each entry
diff --git a/tools/binman/control.py b/tools/binman/control.py
index 97652334e0..43d192c9a7 100644
--- a/tools/binman/control.py
+++ b/tools/binman/control.py
@@ -161,6 +161,7 @@ def Binman(options, args):
image.PackEntries()
image.CheckSize()
image.CheckEntries()
+ image.SetImagePos()
if options.update_fdt:
image.SetCalculatedProperties()
image.ProcessEntryContents()
diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index cb693c9382..8004918eb5 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -64,6 +64,7 @@ class Entry(object):
self.pad_before = 0
self.pad_after = 0
self.offset_unset = False
+ self.image_pos = None
if read_node:
self.ReadNode()
@@ -133,7 +134,7 @@ class Entry(object):
def AddMissingProperties(self):
"""Add new properties to the device tree as needed for this entry"""
- for prop in ['offset', 'size']:
+ for prop in ['offset', 'size', 'image-pos']:
if not prop in self._node.props:
self._node.AddZeroProp(prop)
@@ -141,6 +142,7 @@ class Entry(object):
"""Set the value of device-tree properties calculated by binman"""
self._node.SetInt('offset', self.offset)
self._node.SetInt('size', self.size)
+ self._node.SetInt('image-pos', self.image_pos)
def ProcessFdt(self, fdt):
return True
@@ -265,6 +267,14 @@ class Entry(object):
self.offset = pos
self.size = size
+ def SetImagePos(self, image_pos):
+ """Set the position in the image
+
+ Args:
+ image_pos: Position of this entry in the image
+ """
+ self.image_pos = image_pos + self.offset
+
def ProcessContents(self):
pass
diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py
index 1d27301ae9..b90b80e4ce 100644
--- a/tools/binman/etype/section.py
+++ b/tools/binman/etype/section.py
@@ -46,6 +46,10 @@ class Entry_section(Entry):
self.size = self._section.GetSize()
return super(Entry_section, self).Pack(offset)
+ def SetImagePos(self, image_pos):
+ Entry.SetImagePos(self, image_pos)
+ self._section.SetImagePos(image_pos + self.offset)
+
def WriteSymbols(self, section):
"""Write symbol values into binary files for access at run time"""
self._section.WriteSymbols()
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 94e48f3ab3..94a50aac16 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -1051,23 +1051,30 @@ class TestFunctional(unittest.TestCase):
"""Test that we can update the device tree with offset/size info"""
_, _, _, out_dtb_fname = self._DoReadFileDtb('60_fdt_update.dts',
update_dtb=True)
- props = self._GetPropTree(out_dtb_fname, ['offset', 'size'])
+ props = self._GetPropTree(out_dtb_fname, ['offset', 'size',
+ 'image-pos'])
with open('/tmp/x.dtb', 'wb') as outf:
with open(out_dtb_fname) as inf:
outf.write(inf.read())
self.assertEqual({
+ 'image-pos': 0,
'offset': 0,
'_testing:offset': 32,
'_testing:size': 1,
+ '_testing:image-pos': 32,
'section at 0/u-boot:offset': 0,
'section at 0/u-boot:size': len(U_BOOT_DATA),
+ 'section at 0/u-boot:image-pos': 0,
'section at 0:offset': 0,
'section at 0:size': 16,
+ 'section at 0:image-pos': 0,
'section at 1/u-boot:offset': 0,
'section at 1/u-boot:size': len(U_BOOT_DATA),
+ 'section at 1/u-boot:image-pos': 16,
'section at 1:offset': 16,
'section at 1:size': 16,
+ 'section at 1:image-pos': 16,
'size': 40
}, props)
diff --git a/tools/binman/image.py b/tools/binman/image.py
index ed8261a652..4debc73451 100644
--- a/tools/binman/image.py
+++ b/tools/binman/image.py
@@ -96,6 +96,9 @@ class Image:
def SetCalculatedProperties(self):
self._section.SetCalculatedProperties()
+ def SetImagePos(self):
+ self._section.SetImagePos(0)
+
def ProcessEntryContents(self):
"""Call the ProcessContents() method for each entry
--
2.18.0.203.gfac676dfb9-goog
More information about the U-Boot
mailing list