[U-Boot] [PATCH 23/26] binman: Support reading in firmware images
Simon Glass
sjg at chromium.org
Tue Jul 2 00:24:52 UTC 2019
Add support for reading in an image and locating its Fdt map.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
tools/binman/etype/fdtmap.py | 22 +++++++++++++++-
tools/binman/ftest.py | 17 ++++++++++++
tools/binman/test/128_decode_image.dts | 36 ++++++++++++++++++++++++++
3 files changed, 74 insertions(+), 1 deletion(-)
create mode 100644 tools/binman/test/128_decode_image.dts
diff --git a/tools/binman/etype/fdtmap.py b/tools/binman/etype/fdtmap.py
index bfd7962be3a..4fe5f8d9e10 100644
--- a/tools/binman/etype/fdtmap.py
+++ b/tools/binman/etype/fdtmap.py
@@ -15,7 +15,27 @@ from fdt import Fdt
import state
import tools
-FDTMAP_MAGIC = b'_FDTMAP_'
+FDTMAP_MAGIC = b'_FDTMAP_'
+FDTMAP_HDR_LEN = 16
+
+def LocateFdtmap(data):
+ """Search an image for an fdt map
+
+ Args:
+ data: Data to search
+
+ Returns:
+ Position of fdt map in data, or None if not found. Note that the
+ position returned is of the FDT map data itself, i.e. after the
+ header
+ """
+ hdr_pos = data.find(FDTMAP_MAGIC)
+ size = len(data)
+ if hdr_pos:
+ hdr = data[hdr_pos:hdr_pos + FDTMAP_HDR_LEN]
+ if len(hdr) == FDTMAP_HDR_LEN:
+ return hdr_pos + FDTMAP_HDR_LEN
+ return None
class Entry_fdtmap(Entry):
"""An entry which contains an FDT map
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 9552c3b2761..2536d03c374 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -24,6 +24,7 @@ import command
import control
import elf
import fdt
+from etype import fdtmap
import fdt_util
import fmap_util
import test_util
@@ -2260,5 +2261,21 @@ class TestFunctional(unittest.TestCase):
self.assertEqual(len(data), 0x100 + section_size)
self.assertEqual(section_size, 0x400 + dtb_size)
+ def testFindFdtmap(self):
+ """Test locating an FDT map in an image"""
+ data = self._DoReadFileDtb('128_decode_image.dts', use_real_dtb=True,
+ update_dtb=True)[0]
+ image = control.images['image']
+ entries = image.GetEntries()
+ entry = entries['fdtmap']
+ self.assertEqual(entry.image_pos + fdtmap.FDTMAP_HDR_LEN,
+ fdtmap.LocateFdtmap(data))
+
+ def testFindFdtmapMissing(self):
+ """Test failing to locate an FDP map"""
+ data = self._DoReadFile('005_simple.dts')
+ self.assertEqual(None, fdtmap.LocateFdtmap(data))
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/tools/binman/test/128_decode_image.dts b/tools/binman/test/128_decode_image.dts
new file mode 100644
index 00000000000..449fccc41df
--- /dev/null
+++ b/tools/binman/test/128_decode_image.dts
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+
+/ {
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ binman {
+ size = <0xc00>;
+ u-boot {
+ };
+ section {
+ align = <0x100>;
+ cbfs {
+ size = <0x400>;
+ u-boot {
+ cbfs-type = "raw";
+ };
+ u-boot-dtb {
+ cbfs-type = "raw";
+ cbfs-compress = "lzma";
+ cbfs-offset = <0x80>;
+ };
+ };
+ u-boot-dtb {
+ compress = "lz4";
+ };
+ };
+ fdtmap {
+ };
+ image-header {
+ location = "end";
+ };
+ };
+};
--
2.22.0.410.gd8fdbe21b5-goog
More information about the U-Boot
mailing list