Commit dbf6be9f7f3b650ae5248eb7e2c00e94b4da867c

Authored by Simon Glass
1 parent 8122f3967f

binman: Add a new 'image-pos' property

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.

Since the image position is a better symbol to use for the position of
U-Boot as obtained by SPL, update the SPL symbols to use this instead of
offset, which might be incorrect if hierarchical sections are used.

Signed-off-by: Simon Glass <sjg@chromium.org>

Showing 12 changed files with 61 additions and 10 deletions Side-by-side Diff

... ... @@ -34,7 +34,7 @@
34 34 u32 *boot_params_ptr = NULL;
35 35  
36 36 /* See spl.h for information about this */
37   -binman_sym_declare(ulong, u_boot_any, offset);
  37 +binman_sym_declare(ulong, u_boot_any, image_pos);
38 38  
39 39 /* Define board data structure */
40 40 static bd_t bdata __attribute__ ((section(".data")));
... ... @@ -129,7 +129,7 @@
129 129  
130 130 void spl_set_header_raw_uboot(struct spl_image_info *spl_image)
131 131 {
132   - ulong u_boot_pos = binman_sym(ulong, u_boot_any, offset);
  132 + ulong u_boot_pos = binman_sym(ulong, u_boot_any, image_pos);
133 133  
134 134 spl_image->size = CONFIG_SYS_MONITOR_LEN;
135 135  
common/spl/spl_ram.c
... ... @@ -49,7 +49,7 @@
49 49 load.read = spl_ram_load_read;
50 50 spl_load_simple_fit(spl_image, &load, 0, header);
51 51 } else {
52   - ulong u_boot_pos = binman_sym(ulong, u_boot_any, offset);
  52 + ulong u_boot_pos = binman_sym(ulong, u_boot_any, image_pos);
53 53  
54 54 debug("Legacy image\n");
55 55 /*
... ... @@ -60,7 +60,7 @@
60 60 * image is found. For * example if u-boot.img is used we don't check that
61 61 * spl_parse_image_header() can parse a valid header.
62 62 */
63   -binman_sym_extern(ulong, u_boot_any, offset);
  63 +binman_sym_extern(ulong, u_boot_any, image_pos);
64 64  
65 65 /**
66 66 * spl_load_simple_fit() - Loads a fit image from a device.
... ... @@ -324,7 +324,13 @@
324 324 property is present, binman will give an error if another entry does
325 325 not set the offset (with the GetOffsets() method).
326 326  
  327 +image-pos:
  328 + This cannot be set on entry (or at least it is ignored if it is), but
  329 + with the -u option, binman will set it to the absolute image position
  330 + for each entry. This makes it easy to find out exactly where the entry
  331 + ended up in the image, regardless of parent sections, etc.
327 332  
  333 +
328 334 The attributes supported for images are described below. Several are similar
329 335 to those for entries.
330 336  
... ... @@ -550,8 +556,8 @@
550 556 # u_boot_dtsi_options_debug = $(u_boot_dtsi_options_raw)
551 557  
552 558  
553   -Access to binman entry offsets at run time
554   -------------------------------------------
  559 +Access to binman entry offsets at run time (symbols)
  560 +----------------------------------------------------
555 561  
556 562 Binman assembles images and determines where each entry is placed in the image.
557 563 This information may be useful to U-Boot at run time. For example, in SPL it
... ... @@ -575,6 +581,18 @@
575 581  
576 582 At present this feature is only supported in SPL. In principle it is possible
577 583 to fill in such symbols in U-Boot proper, as well.
  584 +
  585 +
  586 +Access to binman entry offsets at run time (fdt)
  587 +------------------------------------------------
  588 +
  589 +Binman can update the U-Boot FDT to include the final position and size of
  590 +each entry in the images it processes. The option to enable this is -u and it
  591 +causes binman to make sure that the 'offset', 'image-pos' and 'size' properties
  592 +are set correctly for every entry. Since it is not necessary to specify these in
  593 +the image definition, binman calculates the final values and writes these to
  594 +the device tree. These can be used by U-Boot at run-time to find the location
  595 +of each entry.
578 596  
579 597  
580 598 Map files
tools/binman/bsection.py
... ... @@ -96,7 +96,7 @@
96 96  
97 97 def AddMissingProperties(self):
98 98 """Add new properties to the device tree as needed for this entry"""
99   - for prop in ['offset', 'size']:
  99 + for prop in ['offset', 'size', 'image-pos']:
100 100 if not prop in self._node.props:
101 101 self._node.AddZeroProp(prop)
102 102 for entry in self._entries.values():
... ... @@ -105,6 +105,7 @@
105 105 def SetCalculatedProperties(self):
106 106 self._node.SetInt('offset', self._offset)
107 107 self._node.SetInt('size', self._size)
  108 + self._node.SetInt('image-pos', self._image_pos)
108 109 for entry in self._entries.values():
109 110 entry.SetCalculatedProperties()
110 111  
... ... @@ -260,6 +261,11 @@
260 261 offset = entry.offset + entry.size
261 262 prev_name = entry.GetPath()
262 263  
  264 + def SetImagePos(self, image_pos):
  265 + self._image_pos = image_pos
  266 + for entry in self._entries.values():
  267 + entry.SetImagePos(image_pos)
  268 +
263 269 def ProcessEntryContents(self):
264 270 """Call the ProcessContents() method for each entry
265 271  
... ... @@ -341,6 +347,8 @@
341 347 raise ValueError(err)
342 348 if prop_name == 'offset':
343 349 return entry.offset
  350 + elif prop_name == 'image_pos':
  351 + return entry.image_pos
344 352 else:
345 353 raise ValueError("%s: No such property '%s'" % (msg, prop_name))
346 354  
tools/binman/control.py
... ... @@ -161,6 +161,7 @@
161 161 image.PackEntries()
162 162 image.CheckSize()
163 163 image.CheckEntries()
  164 + image.SetImagePos()
164 165 if options.update_fdt:
165 166 image.SetCalculatedProperties()
166 167 image.ProcessEntryContents()
tools/binman/entry.py
... ... @@ -64,6 +64,7 @@
64 64 self.pad_before = 0
65 65 self.pad_after = 0
66 66 self.offset_unset = False
  67 + self.image_pos = None
67 68 if read_node:
68 69 self.ReadNode()
69 70  
... ... @@ -133,7 +134,7 @@
133 134  
134 135 def AddMissingProperties(self):
135 136 """Add new properties to the device tree as needed for this entry"""
136   - for prop in ['offset', 'size']:
  137 + for prop in ['offset', 'size', 'image-pos']:
137 138 if not prop in self._node.props:
138 139 self._node.AddZeroProp(prop)
139 140  
... ... @@ -141,6 +142,7 @@
141 142 """Set the value of device-tree properties calculated by binman"""
142 143 self._node.SetInt('offset', self.offset)
143 144 self._node.SetInt('size', self.size)
  145 + self._node.SetInt('image-pos', self.image_pos)
144 146  
145 147 def ProcessFdt(self, fdt):
146 148 return True
... ... @@ -264,6 +266,14 @@
264 266 def SetOffsetSize(self, pos, size):
265 267 self.offset = pos
266 268 self.size = size
  269 +
  270 + def SetImagePos(self, image_pos):
  271 + """Set the position in the image
  272 +
  273 + Args:
  274 + image_pos: Position of this entry in the image
  275 + """
  276 + self.image_pos = image_pos + self.offset
267 277  
268 278 def ProcessContents(self):
269 279 pass
tools/binman/etype/section.py
... ... @@ -46,6 +46,10 @@
46 46 self.size = self._section.GetSize()
47 47 return super(Entry_section, self).Pack(offset)
48 48  
  49 + def SetImagePos(self, image_pos):
  50 + Entry.SetImagePos(self, image_pos)
  51 + self._section.SetImagePos(image_pos + self.offset)
  52 +
49 53 def WriteSymbols(self, section):
50 54 """Write symbol values into binary files for access at run time"""
51 55 self._section.WriteSymbols()
tools/binman/ftest.py
... ... @@ -1051,23 +1051,30 @@
1051 1051 """Test that we can update the device tree with offset/size info"""
1052 1052 _, _, _, out_dtb_fname = self._DoReadFileDtb('60_fdt_update.dts',
1053 1053 update_dtb=True)
1054   - props = self._GetPropTree(out_dtb_fname, ['offset', 'size'])
  1054 + props = self._GetPropTree(out_dtb_fname, ['offset', 'size',
  1055 + 'image-pos'])
1055 1056 with open('/tmp/x.dtb', 'wb') as outf:
1056 1057 with open(out_dtb_fname) as inf:
1057 1058 outf.write(inf.read())
1058 1059 self.assertEqual({
  1060 + 'image-pos': 0,
1059 1061 'offset': 0,
1060 1062 '_testing:offset': 32,
1061 1063 '_testing:size': 1,
  1064 + '_testing:image-pos': 32,
1062 1065 'section@0/u-boot:offset': 0,
1063 1066 'section@0/u-boot:size': len(U_BOOT_DATA),
  1067 + 'section@0/u-boot:image-pos': 0,
1064 1068 'section@0:offset': 0,
1065 1069 'section@0:size': 16,
  1070 + 'section@0:image-pos': 0,
1066 1071  
1067 1072 'section@1/u-boot:offset': 0,
1068 1073 'section@1/u-boot:size': len(U_BOOT_DATA),
  1074 + 'section@1/u-boot:image-pos': 16,
1069 1075 'section@1:offset': 16,
1070 1076 'section@1:size': 16,
  1077 + 'section@1:image-pos': 16,
1071 1078 'size': 40
1072 1079 }, props)
1073 1080  
tools/binman/image.py
... ... @@ -96,6 +96,9 @@
96 96 def SetCalculatedProperties(self):
97 97 self._section.SetCalculatedProperties()
98 98  
  99 + def SetImagePos(self):
  100 + self._section.SetImagePos(0)
  101 +
99 102 def ProcessEntryContents(self):
100 103 """Call the ProcessContents() method for each entry
101 104  
tools/binman/test/u_boot_binman_syms
No preview for this file type
tools/binman/test/u_boot_binman_syms.c
... ... @@ -10,5 +10,5 @@
10 10  
11 11 binman_sym_declare(unsigned long, u_boot_spl, offset);
12 12 binman_sym_declare(unsigned long long, u_boot_spl2, offset);
13   -binman_sym_declare(unsigned long, u_boot_any, offset);
  13 +binman_sym_declare(unsigned long, u_boot_any, image_pos);