[meta-freescale] [meta-fsl-arm][PATCH] elftosb: add utility to generate Boot Control Block

Alexandre Belloni alexandre.belloni at free-electrons.com
Tue Aug 20 16:00:32 PDT 2013


>From chapter 12.11.1 of the i.MX28 Applications Processor Reference Manual,
Rev. 1, 2010, a Boot Control Block is needed when booting from an SD/MMC
card. The BCB_struct.py utility will generate and write the BCB to a
file, it will also write the provided bootstream.

Signed-off-by: Alexandre Belloni <alexandre.belloni at free-electrons.com>
---

While it is not useful right now, it is needed to generate working images that
are able to boot using barebox on crystalfontz boards. I've added the script to
elftosb as it is quite simple but I could also have it live in its own recipe.

 recipes-bsp/elftosb/elftosb_10.12.01.bb |  7 +++--
 recipes-bsp/elftosb/files/BCB_struct.py | 52 +++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+), 2 deletions(-)
 create mode 100755 recipes-bsp/elftosb/files/BCB_struct.py

diff --git a/recipes-bsp/elftosb/elftosb_10.12.01.bb b/recipes-bsp/elftosb/elftosb_10.12.01.bb
index 2cef1f6..df31ac4 100644
--- a/recipes-bsp/elftosb/elftosb_10.12.01.bb
+++ b/recipes-bsp/elftosb/elftosb_10.12.01.bb
@@ -5,12 +5,14 @@ DESCRIPTION = "Helper utility for freescale imx platforms"
 LICENSE = "MIT"
 LIC_FILES_CHKSUM = "file://COPYING;md5=172ede34353056ebec7a597d8459f029"
 SECTION = "bootloader"
-PR = "r4"
+PR = "r5"
 BBCLASSEXTEND = "native nativesdk"
 
 SRC_URI = "http://repository.timesys.com/buildsources/e/elftosb/elftosb-${PV}/elftosb-${PV}.tar.gz \
            file://cross-build.patch \
-           file://don-t-use-full-path-for-headers.patch"
+           file://don-t-use-full-path-for-headers.patch \
+           file://BCB_struct.py"
+
 SRC_URI[md5sum] = "e8005d606c1e0bb3507c82f6eceb3056"
 SRC_URI[sha256sum] = "77bb6981620f7575b87d136d94c7daa88dd09195959cc75fc18b138369ecd42b"
 
@@ -19,4 +21,5 @@ do_install() {
     install ${S}/bld/linux/elftosb ${D}${bindir}
     install ${S}/bld/linux/keygen  ${D}${bindir}
     install ${S}/bld/linux/sbtool  ${D}${bindir}
+    install ${WORKDIR}/BCB_struct.py ${D}${bindir}
 }
diff --git a/recipes-bsp/elftosb/files/BCB_struct.py b/recipes-bsp/elftosb/files/BCB_struct.py
new file mode 100755
index 0000000..816ea87
--- /dev/null
+++ b/recipes-bsp/elftosb/files/BCB_struct.py
@@ -0,0 +1,52 @@
+#!/usr/bin/env python2
+# Copyright (C) 2013 - Free Electrons
+#
+# Licensed under the GPLv2 or later.
+
+import struct
+
+def generate_bootstream_headers(num_bootstream, start_sector):
+    return struct.pack("<I"    # Magic
+                       "4x"    # Primary Tag (unused)
+                       "4x"    # Secondary Tag (unused)
+                       "I"     # Number of Boot Stream blocks
+                       "8x"    # Padding
+                       "4x"    # Primary Tag (unused)
+                       "I"     # Base offset of the first bootstream block
+                       "4x",   # Padding
+                       0x00112233,
+                       num_bootstream,
+                       start_sector + 1)
+
+def write_bootstream_partition(device_file, start, bootstream):
+    with open(device_file, 'r+') as partition:
+        partition.seek(start*512)
+        partition.write(generate_bootstream_headers(1, start))
+
+        # Fill the rest of the first 512 bytes with 0
+        current = partition.tell()
+        partition.write(struct.pack("%dx" % (512 - current + (start*512))))
+
+        # Copy the bootstream image
+        with open(bootstream, 'r') as image:
+            partition.write(image.read())
+
+def main():
+    import argparse
+
+    parser = argparse.ArgumentParser(
+        description='Flash a SD Card at format expected by iMX28 SoCs')
+    parser.add_argument("device", help="Path to the SD Card's device file")
+    parser.add_argument("--bootstream", "-b",
+                        help="Path to the boostream image", required=True)
+    parser.add_argument("--start", "-s",
+                        help="Start of the bootlets partion (in sectors)",
+                        type=int, required=True)
+
+    args = parser.parse_args()
+
+    write_bootstream_partition(args.device, args.start, args.bootstream)
+
+if __name__ == "__main__":
+    main()
+
-- 
1.8.1.2




More information about the meta-freescale mailing list