[U-Boot,23/34] binman: Avoid needing the section size in advance
diff mbox series

Message ID 20190824132315.53130-24-sjg@chromium.org
State New
Delegated to: Simon Glass
Headers show
Series
  • binman: Various improvements and tidy-ups
Related show

Commit Message

Simon Glass Aug. 24, 2019, 1:23 p.m. UTC
Entries which include a section and need to obtain its contents call
GetData(), as with any other entry. But the current implementation of this
method in entry_Section requires the size of the section to be known. If
it is unknown, an error is produced, since size is None:

   TypeError: can't multiply sequence by non-int of type 'NoneType'

There is no need to know the size in advance since the code can be
adjusted to build up the section piece by piece, instead of patching each
entry into an existing bytearray.

Update the code to handle this and add a test.

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

 tools/binman/etype/section.py                 | 14 +++++---
 tools/binman/ftest.py                         |  6 ++++
 .../binman/test/151_x86_rom_ifwi_section.dts  | 33 +++++++++++++++++++
 3 files changed, 49 insertions(+), 4 deletions(-)
 create mode 100644 tools/binman/test/151_x86_rom_ifwi_section.dts

Patch
diff mbox series

diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py
index 5d34fc546a..ff5d30f3fa 100644
--- a/tools/binman/etype/section.py
+++ b/tools/binman/etype/section.py
@@ -142,13 +142,19 @@  class Entry_section(Entry):
         return self.GetEntryContents()
 
     def GetData(self):
-        section_data = tools.GetBytes(self._pad_byte, self.size)
+        section_data = b''
 
         for entry in self._entries.values():
             data = entry.GetData()
-            base = self.pad_before + entry.offset - self._skip_at_start
-            section_data = (section_data[:base] + data +
-                            section_data[base + len(data):])
+            base = self.pad_before + (entry.offset or 0) - self._skip_at_start
+            pad = base - len(section_data)
+            if pad > 0:
+                section_data += tools.GetBytes(self._pad_byte, pad)
+            section_data += data
+        if self.size:
+            pad = self.size - len(section_data)
+            if pad > 0:
+                section_data += tools.GetBytes(self._pad_byte, pad)
         self.Detail('GetData: %d entries, total size %#x' %
                     (len(self._entries), len(section_data)))
         return section_data
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 75e25f3e23..1eb0d3b684 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -3323,6 +3323,12 @@  class TestFunctional(unittest.TestCase):
         expected4 = sym_values + U_BOOT_TPL_DATA[16:]
         self.assertEqual(expected4, data[upto3:])
 
+    def testPackX86RomIfwiSectiom(self):
+        """Test that a section can be placed in an IFWI region"""
+        self._SetupIfwi('fitimage.bin')
+        data = self._DoReadFile('151_x86_rom_ifwi_section.dts')
+        self._CheckIfwi(data)
+
 
 if __name__ == "__main__":
     unittest.main()
diff --git a/tools/binman/test/151_x86_rom_ifwi_section.dts b/tools/binman/test/151_x86_rom_ifwi_section.dts
new file mode 100644
index 0000000000..7e455c3a4b
--- /dev/null
+++ b/tools/binman/test/151_x86_rom_ifwi_section.dts
@@ -0,0 +1,33 @@ 
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	binman {
+		sort-by-offset;
+		end-at-4gb;
+		size = <0x800000>;
+		intel-descriptor {
+			filename = "descriptor.bin";
+		};
+
+		intel-ifwi {
+			offset-unset;
+			filename = "fitimage.bin";
+			convert-fit;
+
+			section {
+				ifwi-replace;
+				ifwi-subpart = "IBBP";
+				ifwi-entry = "IBBL";
+				u-boot-tpl {
+				};
+				u-boot-dtb {
+				};
+			};
+		};
+	};
+};