Skip to contentSkip to conversation

binman: Rename 'position' to 'offset'

PATCH New Simon Glass 1 participant 2 messages Aug 1, 2018

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 2/29 binman: Rename 'position' to 'offset'

After some thought, I believe there is an unfortunate naming flaw in binman. Entries have a position and size, but now that we support hierarchical sections it is unclear whether a position should be an absolute position within the image, or a relative position within its parent section.

At present 'position' actually means the relative position. This indicates a need for an 'image position' for code that wants to find the location of an entry without having to do calculations back through parents to discover this image position.

A better name for the current 'position' or 'pos' is 'offset'. It is not always an absolute position, but it is always an offset from its parent offset.

It is unfortunate to rename this concept now, 18 months after binman was introduced. However I believe it is the right thing to do. The impact is mostly limited to binman itself and a few changes to in-tree users to binman:

tegra
sunxi
x86

The change makes old binman definitions (e.g. downstream or out-of-tree) incompatible if they use the 'pos = <...>' property. Later work will adjust binman to generate an error when it is used.

---

Changes in v2:
- Adjust symbols in the U-Boot tree also

 arch/arm/dts/sunxi-u-boot.dtsi                |   2 +-
 arch/arm/dts/tegra-u-boot.dtsi                |   6 +-
 arch/x86/dts/u-boot.dtsi                      |  24 ++---
 common/spl/spl.c                              |   4 +-
 common/spl/spl_ram.c                          |   2 +-
 include/spl.h                                 |   2 +-
 tools/binman/README                           |  79 ++++++++--------
 tools/binman/bsection.py                      |  88 +++++++++---------
 tools/binman/cmdline.py                       |   2 +-
 tools/binman/control.py                       |   4 +-
 tools/binman/elf.py                           |   6 +-
 tools/binman/entry.py                         |  73 ++++++++-------
 tools/binman/etype/_testing.py                |   4 +-
 tools/binman/etype/intel_descriptor.py        |   8 +-
 tools/binman/etype/section.py                 |  14 +--
 tools/binman/etype/u_boot_dtb_with_ucode.py   |   4 +-
 tools/binman/etype/u_boot_ucode.py            |   4 +-
 tools/binman/etype/u_boot_with_ucode_ptr.py   |  35 +++----
 tools/binman/ftest.py                         |  85 +++++++++--------
 tools/binman/image.py                         |  12 +--
 tools/binman/test/08_pack.dts                 |   2 +-
 tools/binman/test/12_pack_inv_align.dts       |   2 +-
 tools/binman/test/14_pack_overlap.dts         |   2 +-
 tools/binman/test/21_image_pad.dts            |   2 +-
 tools/binman/test/24_sorted.dts               |   6 +-
 tools/binman/test/25_pack_zero_size.dts       |   2 +-
 tools/binman/test/27_pack_4gb_no_size.dts     |   6 +-
 tools/binman/test/28_pack_4gb_outside.dts     |   6 +-
 tools/binman/test/29_x86-rom.dts              |   6 +-
 tools/binman/test/30_x86-rom-me-no-desc.dts   |   4 +-
 tools/binman/test/31_x86-rom-me.dts           |   4 +-
 tools/binman/test/34_x86_ucode.dts            |   2 +-
 tools/binman/test/35_x86_single_ucode.dts     |   2 +-
 tools/binman/test/37_x86_no_ucode.dts         |   2 +-
 .../binman/test/38_x86_ucode_missing_node.dts |   2 +-
 .../test/39_x86_ucode_missing_node2.dts       |   2 +-
 .../binman/test/40_x86_ucode_not_in_image.dts |   2 +-
 tools/binman/test/44_x86_optional_ucode.dts   |   2 +-
 tools/binman/test/45_prop_test.dts            |   4 +-
 tools/binman/test/49_x86_ucode_spl.dts        |   2 +-
 tools/binman/test/53_symbols.dts              |   2 +-
 .../test/58_x86_ucode_spl_needs_retry.dts     |   2 +-
 tools/binman/test/u_boot_binman_syms          | Bin 4921 -> 4916 bytes
 tools/binman/test/u_boot_binman_syms.c        |   6 +-
 44 files changed, 267 insertions(+), 263 deletions(-)
arch/arm/dts/sunxi-u-boot.dtsi +1 -1
index 5adfd9bca2e..8a9f2a6417d 100644
@@ -8,7 +8,7 @@
 			filename = "spl/sunxi-spl.bin";
 		};
 		u-boot-img {
-			pos = <CONFIG_SPL_PAD_TO>;
+			offset = <CONFIG_SPL_PAD_TO>;
 		};
 	};
 };
arch/arm/dts/tegra-u-boot.dtsi +3 -3
index 4f692ee9757..fe19619919e 100644
@@ -15,7 +15,7 @@
 			u-boot-spl {
 			};
 			u-boot {
-				pos = <(U_BOOT_OFFSET)>;
+				offset = <(U_BOOT_OFFSET)>;
 			};
 		};
 
@@ -26,7 +26,7 @@
 			u-boot-spl {
 			};
 			u-boot {
-				pos = <(U_BOOT_OFFSET)>;
+				offset = <(U_BOOT_OFFSET)>;
 			};
 		};
 
@@ -36,7 +36,7 @@
 			u-boot-spl {
 			};
 			u-boot-nodtb {
-				pos = <(U_BOOT_OFFSET)>;
+				offset = <(U_BOOT_OFFSET)>;
 			};
 		};
 	};
arch/x86/dts/u-boot.dtsi +12 -12
index 1253fa51c22..1050236330a 100644
@@ -11,7 +11,7 @@
 	binman {
 		filename = "u-boot.rom";
 		end-at-4gb;
-		sort-by-pos;
+		sort-by-offset;
 		pad-byte = <0xff>;
 		size = <CONFIG_ROM_SIZE>;
 #ifdef CONFIG_HAVE_INTEL_ME
@@ -24,18 +24,18 @@
 #endif
 #ifdef CONFIG_SPL
 		u-boot-spl-with-ucode-ptr {
-			pos = <CONFIG_SPL_TEXT_BASE>;
+			offset = <CONFIG_SPL_TEXT_BASE>;
 		};
 
 		u-boot-dtb-with-ucode2 {
 			type = "u-boot-dtb-with-ucode";
 		};
 		u-boot {
-			pos = <0xfff00000>;
+			offset = <0xfff00000>;
 		};
 #else
 		u-boot-with-ucode-ptr {
-			pos = <CONFIG_SYS_TEXT_BASE>;
+			offset = <CONFIG_SYS_TEXT_BASE>;
 		};
 #endif
 		u-boot-dtb-with-ucode {
@@ -45,45 +45,45 @@
 		};
 #ifdef CONFIG_HAVE_MRC
 		intel-mrc {
-			pos = <CONFIG_X86_MRC_ADDR>;
+			offset = <CONFIG_X86_MRC_ADDR>;
 		};
 #endif
 #ifdef CONFIG_HAVE_FSP
 		intel-fsp {
 			filename = CONFIG_FSP_FILE;
-			pos = <CONFIG_FSP_ADDR>;
+			offset = <CONFIG_FSP_ADDR>;
 		};
 #endif
 #ifdef CONFIG_HAVE_CMC
 		intel-cmc {
 			filename = CONFIG_CMC_FILE;
-			pos = <CONFIG_CMC_ADDR>;
+			offset = <CONFIG_CMC_ADDR>;
 		};
 #endif
 #ifdef CONFIG_HAVE_VGA_BIOS
 		intel-vga {
 			filename = CONFIG_VGA_BIOS_FILE;
-			pos = <CONFIG_VGA_BIOS_ADDR>;
+			offset = <CONFIG_VGA_BIOS_ADDR>;
 		};
 #endif
 #ifdef CONFIG_HAVE_VBT
 		intel-vbt {
 			filename = CONFIG_VBT_FILE;
-			pos = <CONFIG_VBT_ADDR>;
+			offset = <CONFIG_VBT_ADDR>;
 		};
 #endif
 #ifdef CONFIG_HAVE_REFCODE
 		intel-refcode {
-			pos = <CONFIG_X86_REFCODE_ADDR>;
+			offset = <CONFIG_X86_REFCODE_ADDR>;
 		};
 #endif
 #ifdef CONFIG_SPL
 		x86-start16-spl {
-			pos = <CONFIG_SYS_X86_START16>;
+			offset = <CONFIG_SYS_X86_START16>;
 		};
 #else
 		x86-start16 {
-			pos = <CONFIG_SYS_X86_START16>;
+			offset = <CONFIG_SYS_X86_START16>;
 		};
 #endif
 	};
common/spl/spl.c +2 -2
index a1e7b9fa914..b959aa02549 100644
@@ -34,7 +34,7 @@ DECLARE_GLOBAL_DATA_PTR;
 u32 *boot_params_ptr = NULL;
 
 /* See spl.h for information about this */
-binman_sym_declare(ulong, u_boot_any, pos);
+binman_sym_declare(ulong, u_boot_any, offset);
 
 /* Define board data structure */
 static bd_t bdata __attribute__ ((section(".data")));
@@ -129,7 +129,7 @@ __weak void spl_board_prepare_for_boot(void)
 
 void spl_set_header_raw_uboot(struct spl_image_info *spl_image)
 {
-	ulong u_boot_pos = binman_sym(ulong, u_boot_any, pos);
+	ulong u_boot_pos = binman_sym(ulong, u_boot_any, offset);
 
 	spl_image->size = CONFIG_SYS_MONITOR_LEN;
 
common/spl/spl_ram.c +1 -1
index e8701934b87..6000f495ccd 100644
@@ -49,7 +49,7 @@ static int spl_ram_load_image(struct spl_image_info *spl_image,
 		load.read = spl_ram_load_read;
 		spl_load_simple_fit(spl_image, &load, 0, header);
 	} else {
-		ulong u_boot_pos = binman_sym(ulong, u_boot_any, pos);
+		ulong u_boot_pos = binman_sym(ulong, u_boot_any, offset);
 
 		debug("Legacy image\n");
 		/*
include/spl.h +1 -1
index 86287874e1b..8c5523083b2 100644
@@ -60,7 +60,7 @@ struct spl_load_info {
  * image is found. For * example if u-boot.img is used we don't check that
  * spl_parse_image_header() can parse a valid header.
  */
-binman_sym_extern(ulong, u_boot_any, pos);
+binman_sym_extern(ulong, u_boot_any, offset);
 
 /**
  * spl_load_simple_fit() - Loads a fit image from a device.
tools/binman/README +40 -39

198 lines not on this page · raw message

tools/binman/bsection.py +45 -43

186 lines not on this page · raw message

tools/binman/cmdline.py +1 -1
index ae2d1670f9a..5c9b4dfeadc 100644
@@ -43,7 +43,7 @@ def ParseArgs(argv):
     parser.add_option('-T', '--test-coverage', action='store_true',
                     default=False, help='run tests and check for 100% coverage')
     parser.add_option('-u', '--update-fdt', action='store_true',
-        default=False, help='Update the binman node with position/size info')
+        default=False, help='Update the binman node with offset/size info')
     parser.add_option('-v', '--verbosity', default=1,
         type='int', help='Control verbosity: 0=silent, 1=progress, 3=full, '
         '4=debug')
tools/binman/control.py +2 -2
index a40b300fdac..17c6d7a2d20 100644
@@ -142,7 +142,7 @@ def Binman(options, args):
             # 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.
+            # entry offsets remain the same.
             for image in images.values():
                 if options.update_fdt:
                     image.AddMissingProperties()
@@ -157,7 +157,7 @@ def Binman(options, args):
                 # image will be reported after earlier images are already
                 # completed and written, but that does not seem important.
                 image.GetEntryContents()
-                image.GetEntryPositions()
+                image.GetEntryOffsets()
                 image.PackEntries()
                 image.CheckSize()
                 image.CheckEntries()
tools/binman/elf.py +3 -3
index 8c23040d8c5..97df8e32c5d 100644
@@ -81,9 +81,9 @@ def LookupAndWriteSymbols(elf_fname, entry, section):
     """Replace all symbols in an entry with their correct values
 
     The entry contents is updated so that values for referenced symbols will be
-    visible at run time. This is done by finding out the symbols positions in
-    the entry (using the ELF file) and replacing them with values from binman's
-    data structures.
+    visible at run time. This is done by finding out the symbols offsets in the
+    entry (using the ELF file) and replacing them with values from binman's data
+    structures.
 
     Args:
         elf_fname: Filename of ELF image containing the symbol information for
tools/binman/entry.py +37 -36

168 lines not on this page · raw message

tools/binman/etype/_testing.py +2 -2
index 6a1af577988..31f625c026c 100644
@@ -14,7 +14,7 @@ class Entry__testing(Entry):
     """A fake entry used for testing
 
     Properties:
-        return_invalid_entry: Return an invalid entry from GetPositions()
+        return_invalid_entry: Return an invalid entry from GetOffsets()
     """
     def __init__(self, section, etype, node):
         Entry.__init__(self, section, etype, node)
@@ -35,7 +35,7 @@ class Entry__testing(Entry):
         self.contents_size = len(self.data)
         return True
 
-    def GetPositions(self):
+    def GetOffsets(self):
         if self.return_invalid_entry :
             return {'invalid-entry': [1, 2]}
         return {}
tools/binman/etype/intel_descriptor.py +4 -4
index 0e7865521e1..0a5151d466c 100644
@@ -36,12 +36,12 @@ class Entry_intel_descriptor(Entry_blob):
         Entry_blob.__init__(self, section, etype, node)
         self._regions = []
 
-    def GetPositions(self):
-        pos = self.data.find(FD_SIGNATURE)
-        if pos == -1:
+    def GetOffsets(self):
+        offset = self.data.find(FD_SIGNATURE)
+        if offset == -1:
             self.Raise('Cannot find FD signature')
         flvalsig, flmap0, flmap1, flmap2 = struct.unpack('<LLLL',
-                                                    self.data[pos:pos + 16])
+                                                self.data[offset:offset + 16])
         frba = ((flmap0 >> 16) & 0xff) << 4
         for i in range(MAX_REGIONS):
             self._regions.append(Region(self.data, frba, i))
tools/binman/etype/section.py +7 -7
index 787257d3ec1..5a0b0b8c703 100644
@@ -30,20 +30,20 @@ class Entry_section(Entry):
     def GetData(self):
         return self._section.GetData()
 
-    def GetPositions(self):
-        """Handle entries that want to set the position/size of other entries
+    def GetOffsets(self):
+        """Handle entries that want to set the offset/size of other entries
 
-        This calls each entry's GetPositions() method. If it returns a list
+        This calls each entry's GetOffsets() method. If it returns a list
         of entries to update, it updates them.
         """
-        self._section.GetEntryPositions()
+        self._section.GetEntryOffsets()
         return {}
 
-    def Pack(self, pos):
+    def Pack(self, offset):
         """Pack all entries into the section"""
         self._section.PackEntries()
         self.size = self._section.CheckSize()
-        return super(Entry_section, self).Pack(pos)
+        return super(Entry_section, self).Pack(offset)
 
     def WriteSymbols(self, section):
         """Write symbol values into binary files for access at run time"""
@@ -57,7 +57,7 @@ class Entry_section(Entry):
         self._section.ProcessEntryContents()
         super(Entry_section, self).ProcessContents()
 
-    def CheckPosition(self):
+    def CheckOffset(self):
         self._section.CheckEntries()
 
     def WriteMap(self, fd, indent):
tools/binman/etype/u_boot_dtb_with_ucode.py +2 -2
index 3808d6d2780..55d3a38a64f 100644
@@ -33,10 +33,10 @@ class Entry_u_boot_dtb_with_ucode(Entry_blob):
         # If the section does not need microcode, there is nothing to do
         ucode_dest_entry = self.section.FindEntryType(
             'u-boot-spl-with-ucode-ptr')
-        if not ucode_dest_entry or not ucode_dest_entry.target_pos:
+        if not ucode_dest_entry or not ucode_dest_entry.target_offset:
             ucode_dest_entry = self.section.FindEntryType(
                 'u-boot-with-ucode-ptr')
-        if not ucode_dest_entry or not ucode_dest_entry.target_pos:
+        if not ucode_dest_entry or not ucode_dest_entry.target_offset:
             return True
 
         # Remove the microcode
tools/binman/etype/u_boot_ucode.py +2 -2
index ea0c85cc5c7..922a607cfe6 100644
@@ -59,8 +59,8 @@ class Entry_u_boot_ucode(Entry_blob):
         ucode_dest_entry = self.section.FindEntryType('u-boot-with-ucode-ptr')
         ucode_dest_entry_spl = self.section.FindEntryType(
             'u-boot-spl-with-ucode-ptr')
-        if ((not ucode_dest_entry or not ucode_dest_entry.target_pos) and
-            (not ucode_dest_entry_spl or not ucode_dest_entry_spl.target_pos)):
+        if ((not ucode_dest_entry or not ucode_dest_entry.target_offset) and
+            (not ucode_dest_entry_spl or not ucode_dest_entry_spl.target_offset)):
             self.data = ''
             return True
 
tools/binman/etype/u_boot_with_ucode_ptr.py +18 -17
index 8b1e41152e3..97e58a0bfcf 100644
@@ -23,7 +23,7 @@ class Entry_u_boot_with_ucode_ptr(Entry_blob):
     def __init__(self, section, etype, node):
         Entry_blob.__init__(self, section, etype, node)
         self.elf_fname = 'u-boot'
-        self.target_pos = None
+        self.target_offset = None
 
     def GetDefaultFilename(self):
         return 'u-boot-nodtb.bin'
@@ -33,52 +33,53 @@ class Entry_u_boot_with_ucode_ptr(Entry_blob):
         fname = tools.GetInputFilename(self.elf_fname)
         sym = elf.GetSymbolAddress(fname, '_dt_ucode_base_size')
         if sym:
-           self.target_pos = sym
+           self.target_offset = sym
         elif not fdt_util.GetBool(self._node, 'optional-ucode'):
             self.Raise('Cannot locate _dt_ucode_base_size symbol in u-boot')
         return True
 
     def ProcessContents(self):
         # If the image does not need microcode, there is nothing to do
-        if not self.target_pos:
+        if not self.target_offset:
             return
 
-        # Get the position of the microcode
+        # Get the offset of the microcode
         ucode_entry = self.section.FindEntryType('u-boot-ucode')
         if not ucode_entry:
             self.Raise('Cannot find microcode region u-boot-ucode')
 
         # Check the target pos is in the section. If it is not, then U-Boot is
-        # being linked incorrectly, or is being placed at the wrong position
+        # being linked incorrectly, or is being placed at the wrong offset
         # in the section.
         #
         # The section must be set up so that U-Boot is placed at the
         # flash address to which it is linked. For example, if
         # CONFIG_SYS_TEXT_BASE is 0xfff00000, and the ROM is 8MB, then
-        # the U-Boot region must start at position 7MB in the section. In this
-        # case the ROM starts at 0xff800000, so the position of the first
+        # the U-Boot region must start at offset 7MB in the section. In this
+        # case the ROM starts@0xff800000, so the offset of the first
         # entry in the section corresponds to that.
-        if (self.target_pos < self.pos or
-                self.target_pos >= self.pos + self.size):
+        if (self.target_offset < self.offset or
+                self.target_offset >= self.offset + self.size):
             self.Raise('Microcode pointer _dt_ucode_base_size at %08x is '
                 'outside the section ranging from %08x to %08x' %
-                (self.target_pos, self.pos, self.pos + self.size))
+                (self.target_offset, self.offset, self.offset + self.size))
 
         # Get the microcode, either from u-boot-ucode or u-boot-dtb-with-ucode.
         # If we have left the microcode in the device tree, then it will be
         # in the former. If we extracted the microcode from the device tree
         # and collated it in one place, it will be in the latter.
         if ucode_entry.size:
-            pos, size = ucode_entry.pos, ucode_entry.size
+            offset, size = ucode_entry.offset, ucode_entry.size
         else:
             dtb_entry = self.section.FindEntryType('u-boot-dtb-with-ucode')
             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
+            offset = dtb_entry.offset + dtb_entry.ucode_offset
             size = dtb_entry.ucode_size
 
-        # Write the microcode position and size into the entry
-        pos_and_size = struct.pack('<2L', pos, size)
-        self.target_pos -= self.pos
-        self.ProcessContentsUpdate(self.data[:self.target_pos] + pos_and_size +
-                                   self.data[self.target_pos + 8:])
+        # Write the microcode offset and size into the entry
+        offset_and_size = struct.pack('<2L', offset, size)
+        self.target_offset -= self.offset
+        self.ProcessContentsUpdate(self.data[:self.target_offset] +
+                                   offset_and_size +
+                                   self.data[self.target_offset + 8:])
tools/binman/ftest.py +42 -43

264 lines not on this page · raw message

tools/binman/image.py +6 -6
index 94028f19a51..ed8261a652a 100644
@@ -57,7 +57,7 @@ class Image:
     def AddMissingProperties(self):
         """Add properties that are not present in the device tree
 
-        When binman has completed packing the entries the position and size of
+        When binman has completed packing the entries the offset and size of
         each entry are known. But before this the device tree may not specify
         these. Add any missing properties, with a dummy value, so that the
         size of the entry is correct. That way we can insert the correct values
@@ -73,13 +73,13 @@ class Image:
         """
         self._section.GetEntryContents()
 
-    def GetEntryPositions(self):
-        """Handle entries that want to set the position/size of other entries
+    def GetEntryOffsets(self):
+        """Handle entries that want to set the offset/size of other entries
 
-        This calls each entry's GetPositions() method. If it returns a list
+        This calls each entry's GetOffsets() method. If it returns a list
         of entries to update, it updates them.
         """
-        self._section.GetEntryPositions()
+        self._section.GetEntryOffsets()
 
     def PackEntries(self):
         """Pack all entries into the image"""
@@ -121,5 +121,5 @@ class Image:
         filename = '%s.map' % self._name
         fname = tools.GetOutputFilename(filename)
         with open(fname, 'w') as fd:
-            print('%8s  %8s  %s' % ('Position', 'Size', 'Name'), file=fd)
+            print('%8s  %8s  %s' % ('Offset', 'Size', 'Name'), file=fd)
             self._section.WriteMap(fd, 0)
tools/binman/test/08_pack.dts +1 -1
index dc63d99dcb0..a88785d8352 100644
@@ -24,7 +24,7 @@
 
 		u-boot-fixed {
 			type = "u-boot";
-			pos = <61>;
+			offset = <61>;
 		};
 	};
 };
tools/binman/test/12_pack_inv_align.dts +1 -1
index 1d9d80a65cc..d8dd600edb8 100644
@@ -6,7 +6,7 @@
 
 	binman {
 		u-boot {
-			pos = <5>;
+			offset = <5>;
 			align = <4>;
 		};
 	};
tools/binman/test/14_pack_overlap.dts +1 -1
index 611cfd97300..3895cba3bdb 100644
@@ -10,7 +10,7 @@
 
 		u-boot-align {
 			type = "u-boot";
-			pos = <3>;
+			offset = <3>;
 		};
 	};
 };
tools/binman/test/21_image_pad.dts +1 -1
index bf39dc1b6f7..c6516689d94 100644
@@ -10,7 +10,7 @@
 		};
 
 		u-boot {
-			pos = <20>;
+			offset = <20>;
 		};
 	};
 };
tools/binman/test/24_sorted.dts +3 -3
index 43a7831341c..d35d39f077d 100644
@@ -5,13 +5,13 @@
 	#size-cells = <1>;
 
 	binman {
-		sort-by-pos;
+		sort-by-offset;
 		u-boot {
-			pos = <22>;
+			offset = <22>;
 		};
 
 		u-boot-spl {
-			pos = <1>;
+			offset = <1>;
 		};
 	};
 };
tools/binman/test/25_pack_zero_size.dts +1 -1
index 7d2baad3c6d..e863c44e3fd 100644
@@ -9,7 +9,7 @@
 		};
 
 		u-boot-spl {
-			pos = <0>;
+			offset = <0>;
 		};
 	};
 };
tools/binman/test/27_pack_4gb_no_size.dts +3 -3
index e0b6519e75b..371cca10d58 100644
@@ -5,14 +5,14 @@
 	#size-cells = <1>;
 
 	binman {
-		sort-by-pos;
+		sort-by-offset;
 		end-at-4gb;
 		u-boot {
-			pos = <0xfffffff0>;
+			offset = <0xfffffff0>;
 		};
 
 		u-boot-spl {
-			pos = <0xfffffff7>;
+			offset = <0xfffffff7>;
 		};
 	};
 };
tools/binman/test/28_pack_4gb_outside.dts +3 -3
index 18d6bb5b8af..2216abfb70c 100644
@@ -5,15 +5,15 @@
 	#size-cells = <1>;
 
 	binman {
-		sort-by-pos;
+		sort-by-offset;
 		end-at-4gb;
 		size = <32>;
 		u-boot {
-			pos = <0>;
+			offset = <0>;
 		};
 
 		u-boot-spl {
-			pos = <0xffffffeb>;
+			offset = <0xffffffeb>;
 		};
 	};
 };
tools/binman/test/29_x86-rom.dts +3 -3
index d49078e19e2..d5c69f9d4a9 100644
@@ -5,15 +5,15 @@
 	#size-cells = <1>;
 
 	binman {
-		sort-by-pos;
+		sort-by-offset;
 		end-at-4gb;
 		size = <32>;
 		u-boot {
-			pos = <0xffffffe0>;
+			offset = <0xffffffe0>;
 		};
 
 		u-boot-spl {
-			pos = <0xffffffeb>;
+			offset = <0xffffffeb>;
 		};
 	};
 };
tools/binman/test/30_x86-rom-me-no-desc.dts +2 -2
index 68d3ce09ecd..796cb87afc7 100644
@@ -5,12 +5,12 @@
 	#size-cells = <1>;
 
 	binman {
-		sort-by-pos;
+		sort-by-offset;
 		end-at-4gb;
 		size = <16>;
 		intel-me {
 			filename = "me.bin";
-			pos-unset;
+			offset-unset;
 		};
 	};
 };
tools/binman/test/31_x86-rom-me.dts +2 -2
index ee3dac875a6..b8b0a5a74bb 100644
@@ -5,7 +5,7 @@
 	#size-cells = <1>;
 
 	binman {
-		sort-by-pos;
+		sort-by-offset;
 		end-at-4gb;
 		size = <0x800000>;
 		intel-descriptor {
@@ -14,7 +14,7 @@
 
 		intel-me {
 			filename = "me.bin";
-			pos-unset;
+			offset-unset;
 		};
 	};
 };
tools/binman/test/34_x86_ucode.dts +1 -1
index 64a6c2c3d5d..40725731cd3 100644
@@ -5,7 +5,7 @@
 	#size-cells = <1>;
 
 	binman {
-		sort-by-pos;
+		sort-by-offset;
 		end-at-4gb;
 		size = <0x200>;
 		u-boot-with-ucode-ptr {
tools/binman/test/35_x86_single_ucode.dts +1 -1
index 973e97f8641..2b1f086a41c 100644
@@ -5,7 +5,7 @@
 	#size-cells = <1>;
 
 	binman {
-		sort-by-pos;
+		sort-by-offset;
 		end-at-4gb;
 		size = <0x200>;
 		u-boot-with-ucode-ptr {
tools/binman/test/37_x86_no_ucode.dts +1 -1
index 9e12156ee2f..6da49c3da6d 100644
@@ -5,7 +5,7 @@
 	#size-cells = <1>;
 
 	binman {
-		sort-by-pos;
+		sort-by-offset;
 		end-at-4gb;
 		size = <0x200>;
 		u-boot-with-ucode-ptr {
tools/binman/test/38_x86_ucode_missing_node.dts +1 -1
index d6cf0d844ed..720677c9c1e 100644
@@ -5,7 +5,7 @@
 	#size-cells = <1>;
 
 	binman {
-		sort-by-pos;
+		sort-by-offset;
 		end-at-4gb;
 		size = <0x200>;
 		u-boot-with-ucode-ptr {
tools/binman/test/39_x86_ucode_missing_node2.dts +1 -1
index b7e26c5ae41..10ac086d549 100644
@@ -5,7 +5,7 @@
 	#size-cells = <1>;
 
 	binman {
-		sort-by-pos;
+		sort-by-offset;
 		end-at-4gb;
 		size = <0x200>;
 		u-boot-with-ucode-ptr {
tools/binman/test/40_x86_ucode_not_in_image.dts +1 -1
index 67d17d392fd..609725824a5 100644
@@ -5,7 +5,7 @@
 	#size-cells = <1>;
 
 	binman {
-		sort-by-pos;
+		sort-by-offset;
 		size = <0x200>;
 		u-boot-with-ucode-ptr {
 		};
tools/binman/test/44_x86_optional_ucode.dts +1 -1
index abe1322798e..24a7040d318 100644
@@ -5,7 +5,7 @@
 	#size-cells = <1>;
 
 	binman {
-		sort-by-pos;
+		sort-by-offset;
 		end-at-4gb;
 		size = <0x200>;
 		u-boot-with-ucode-ptr {
tools/binman/test/45_prop_test.dts +2 -2
index d22e460d299..064de2b3167 100644
@@ -5,12 +5,12 @@
 	#size-cells = <1>;
 
 	binman {
-		sort-by-pos;
+		sort-by-offset;
 		end-at-4gb;
 		size = <16>;
 		intel-me {
 			filename = "me.bin";
-			pos-unset;
+			offset-unset;
 			intval = <3>;
 			intarray = <5 6>;
 			byteval = [08];
tools/binman/test/49_x86_ucode_spl.dts +1 -1
index 67db93ad502..350d2c4730b 100644
@@ -5,7 +5,7 @@
 	#size-cells = <1>;
 
 	binman {
-		sort-by-pos;
+		sort-by-offset;
 		end-at-4gb;
 		size = <0x200>;
 		u-boot-spl-with-ucode-ptr {
tools/binman/test/53_symbols.dts +1 -1
index 980b066eb21..9f135676cb0 100644
@@ -10,7 +10,7 @@
 		};
 
 		u-boot {
-			pos = <20>;
+			offset = <20>;
 		};
 
 		u-boot-spl2 {
tools/binman/test/58_x86_ucode_spl_needs_retry.dts +1 -1
index e2cb80cf6e2..a04adaaf7ba 100644
@@ -7,7 +7,7 @@
 	#size-cells = <1>;
 
 	binman {
-		sort-by-pos;
+		sort-by-offset;
 		end-at-4gb;
 		size = <0x200>;
 		u-boot-spl-with-ucode-ptr {
tools/binman/test/u_boot_binman_syms binary +0 -0
index 2e02dc0ca9e2651bc12ac6d61d95dfa5ccee7a68..f2dcb887ed84e4799ae9eca1d2d39585635fb4c6 100755
GIT binary patch

z1 at ZZ5X~n4}4Dm^sdAW&s at ul%e`S~UBiFuXyq>Br3kfkRx3R_H$7r4r3GTBs6nd!3N k<S0Qk-V6Z-h66w=*?^dJa<8DYgoYpk!)hQ81{k3X02qTyEC2ui

delta 311
zcmdm at wo3_0@DhCjY{wM{giSY5Bn9IT;WmHowz;j+V6#vLY6V00e5F-D+P_vq|&^S zQUwz|3q2EEqf#)>u+Gp#&%i{_SQ8>XI6u at M(xQfg_N1%1ty;pQsX@!$iQ#XdW8~ zPi7RBW}P6!z_4=iMIqsdGh;W2$<9(+s4B1 at xK^QKm~|dfLM@$iNOd-fdB&|gC&r! z0mK|o7jD0K_o$ML@O*5QBgKP=7O!2AKx}ApSHUjo>p*Ru|Nq+%L$+RghoI5MNx9 XSX46ER#1u=$ekQ3C<&%#3t9jG`lCCI

tools/binman/test/u_boot_binman_syms.c +3 -3
index d8371610a5b..cbb2f3f7b17 100644
@@ -8,6 +8,6 @@
 #define CONFIG_BINMAN
 #include <binman_sym.h>
 
-binman_sym_declare(unsigned long, u_boot_spl, pos);
-binman_sym_declare(unsigned long long, u_boot_spl2, pos);
-binman_sym_declare(unsigned long, u_boot_any, pos);
+binman_sym_declare(unsigned long, u_boot_spl, offset);
+binman_sym_declare(unsigned long long, u_boot_spl2, offset);
+binman_sym_declare(unsigned long, u_boot_any, offset);
Signature · 1 line
2.18.0.597.ga71716f1ad-goog
#1 lore raw

PATCH v2 7/29 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.

---

Changes in v2:
- Update U-Boot symbols to use image_pos instead of offset
- Update tests to include test coverage of image_pos

 common/spl/spl.c                       |   4 ++--
 common/spl/spl_ram.c                   |   2 +-
 include/spl.h                          |   2 +-
 tools/binman/README                    |  22 ++++++++++++++++++++--
 tools/binman/bsection.py               |  10 +++++++++-
 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 +++
 tools/binman/test/u_boot_binman_syms   | Bin 4916 -> 4924 bytes
 tools/binman/test/u_boot_binman_syms.c |   2 +-
 12 files changed, 61 insertions(+), 10 deletions(-)
common/spl/spl.c +2 -2
index b959aa02549..eda84d0c74c 100644
@@ -34,7 +34,7 @@ DECLARE_GLOBAL_DATA_PTR;
 u32 *boot_params_ptr = NULL;
 
 /* See spl.h for information about this */
-binman_sym_declare(ulong, u_boot_any, offset);
+binman_sym_declare(ulong, u_boot_any, image_pos);
 
 /* Define board data structure */
 static bd_t bdata __attribute__ ((section(".data")));
@@ -129,7 +129,7 @@ __weak void spl_board_prepare_for_boot(void)
 
 void spl_set_header_raw_uboot(struct spl_image_info *spl_image)
 {
-	ulong u_boot_pos = binman_sym(ulong, u_boot_any, offset);
+	ulong u_boot_pos = binman_sym(ulong, u_boot_any, image_pos);
 
 	spl_image->size = CONFIG_SYS_MONITOR_LEN;
 
common/spl/spl_ram.c +1 -1
index 6000f495ccd..e594beaeaa3 100644
@@ -49,7 +49,7 @@ static int spl_ram_load_image(struct spl_image_info *spl_image,
 		load.read = spl_ram_load_read;
 		spl_load_simple_fit(spl_image, &load, 0, header);
 	} else {
-		ulong u_boot_pos = binman_sym(ulong, u_boot_any, offset);
+		ulong u_boot_pos = binman_sym(ulong, u_boot_any, image_pos);
 
 		debug("Legacy image\n");
 		/*
include/spl.h +1 -1
index 8c5523083b2..7fad62c043e 100644
@@ -60,7 +60,7 @@ struct spl_load_info {
  * image is found. For * example if u-boot.img is used we don't check that
  * spl_parse_image_header() can parse a valid header.
  */
-binman_sym_extern(ulong, u_boot_any, offset);
+binman_sym_extern(ulong, u_boot_any, image_pos);
 
 /**
  * spl_load_simple_fit() - Loads a fit image from a device.
tools/binman/README +20 -2
index 4b13776ffad..df88819a1c3 100644
@@ -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
 ---------
 
tools/binman/bsection.py +9 -1
index 1604b9915ec..08c6f0cda85 100644
@@ -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
 
@@ -341,6 +347,8 @@ class Section(object):
             raise ValueError(err)
         if prop_name == 'offset':
             return entry.offset
+        elif prop_name == 'image_pos':
+            return entry.image_pos
         else:
             raise ValueError("%s: No such property '%s'" % (msg, prop_name))
 
tools/binman/control.py +1 -0
index 97652334e01..43d192c9a74 100644
@@ -161,6 +161,7 @@ def Binman(options, args):
                 image.PackEntries()
                 image.CheckSize()
                 image.CheckEntries()
+                image.SetImagePos()
                 if options.update_fdt:
                     image.SetCalculatedProperties()
                 image.ProcessEntryContents()
tools/binman/entry.py +11 -1
index cb693c93820..8004918eb58 100644
@@ -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
 
tools/binman/etype/section.py +4 -0
index 1d27301ae92..b90b80e4ce7 100644
@@ -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()
tools/binman/ftest.py +8 -1
index 94e48f3ab33..94a50aac166 100644
@@ -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)
 
tools/binman/image.py +3 -0
index ed8261a652a..4debc734519 100644
@@ -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
 
tools/binman/test/u_boot_binman_syms binary +0 -0
index f2dcb887ed84e4799ae9eca1d2d39585635fb4c6..126a1a623092cbe25f7a24118d26d4a0e8d0e0fc 100755
GIT binary patch

zcmdm at wnuG(0;9 at C#rOOoD(}AY&Moeq!@T5hu>ITRenxu^(Lzb7%>?dOb!>&o!ltk z?W at ATzz2;f(%RyQ-CxK2rw*gaSDRKn#;F2eM6|3Iu at aJAiDEeh>ihXHS+C44K> zC^$J at P@FR}H!(dmz97GN@@&DClbwZ98BHgz6jElqHTkTNI%Ce{uR`jqI)V%g>n2|m G5(WUg>nL;p

delta 188 zcmdm^wnc4%0;9}E#rOOo%aW%XXzPXS$a9c<vVEPO>0A{L|H&!>MvRt|BLs9OcL;d+ z8Za<0umG_j0~13ikXAwBPXw}IK!Aafp#;b=feHu!)wcrKAoU;s;?I~YD;P3)f*|MQ vXhHSKO9Yos_7O^9G?~0nNSX2S<f}sJj2V;v3aLwI2r@9NhG+wmj8HZJbRHr-

tools/binman/test/u_boot_binman_syms.c +1 -1
index cbb2f3f7b17..4898f983e32 100644
@@ -10,4 +10,4 @@
 
 binman_sym_declare(unsigned long, u_boot_spl, offset);
 binman_sym_declare(unsigned long long, u_boot_spl2, offset);
-binman_sym_declare(unsigned long, u_boot_any, offset);
+binman_sym_declare(unsigned long, u_boot_any, image_pos);
Signature · 1 line
2.18.0.597.ga71716f1ad-goog