Patchwork [meta-fsl-arm,PATCHv2] mx28-bcb: add utility to generate Boot Control Block

login
register
mail settings
Submitter Alexandre Belloni
Date Aug. 22, 2013, 2:41 p.m.
Message ID <1377182514-4963-1-git-send-email-alexandre.belloni@free-electrons.com>
Download mbox | patch
Permalink /patch/56265/
State Changes Requested
Delegated to: Otavio Salvador
Headers show

Comments

Alexandre Belloni - Aug. 22, 2013, 2:41 p.m.
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 mx28_bcb.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@free-electrons.com>
---
 recipes-bsp/mx28-bcb/files/mx28_bcb.py | 56 ++++++++++++++++++++++++++++++++++
 recipes-bsp/mx28-bcb/mx28-bcb_1.0.bb   | 20 ++++++++++++
 2 files changed, 76 insertions(+)
 create mode 100755 recipes-bsp/mx28-bcb/files/mx28_bcb.py
 create mode 100644 recipes-bsp/mx28-bcb/mx28-bcb_1.0.bb
Otavio Salvador - Aug. 22, 2013, 5:03 p.m.
On Thu, Aug 22, 2013 at 11:41 AM, Alexandre Belloni
<alexandre.belloni@free-electrons.com> wrote:
> 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 mx28_bcb.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@free-electrons.com>
> ---
>  recipes-bsp/mx28-bcb/files/mx28_bcb.py | 56 ++++++++++++++++++++++++++++++++++
>  recipes-bsp/mx28-bcb/mx28-bcb_1.0.bb   | 20 ++++++++++++
>  2 files changed, 76 insertions(+)
>  create mode 100755 recipes-bsp/mx28-bcb/files/mx28_bcb.py
>  create mode 100644 recipes-bsp/mx28-bcb/mx28-bcb_1.0.bb
>
> diff --git a/recipes-bsp/mx28-bcb/files/mx28_bcb.py b/recipes-bsp/mx28-bcb/files/mx28_bcb.py
> new file mode 100755
> index 0000000..ea2038b
> --- /dev/null
> +++ b/recipes-bsp/mx28-bcb/files/mx28_bcb.py
> @@ -0,0 +1,56 @@

I'd put your copyright here as well.
Marek Vasut - Aug. 23, 2013, 3:15 a.m.
Dear Otavio Salvador,

> On Thu, Aug 22, 2013 at 11:41 AM, Alexandre Belloni
> 
> <alexandre.belloni@free-electrons.com> wrote:
> > 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 mx28_bcb.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@free-electrons.com>
> > ---
> > 
> >  recipes-bsp/mx28-bcb/files/mx28_bcb.py | 56
> >  ++++++++++++++++++++++++++++++++++ recipes-bsp/mx28-bcb/mx28-bcb_1.0.bb
> >    | 20 ++++++++++++
> >  2 files changed, 76 insertions(+)
> >  create mode 100755 recipes-bsp/mx28-bcb/files/mx28_bcb.py
> >  create mode 100644 recipes-bsp/mx28-bcb/mx28-bcb_1.0.bb
> > 
> > diff --git a/recipes-bsp/mx28-bcb/files/mx28_bcb.py
> > b/recipes-bsp/mx28-bcb/files/mx28_bcb.py new file mode 100755
> > index 0000000..ea2038b
> > --- /dev/null
> > +++ b/recipes-bsp/mx28-bcb/files/mx28_bcb.py
> > @@ -0,0 +1,56 @@
> 
> I'd put your copyright here as well.

Why do you not use mxsboot tool from U-Boot instead of re-inventing the wheel?

Best regards,
Marek Vasut
Alexandre Belloni - Aug. 23, 2013, 9:23 a.m.
On 23/08/2013 05:15, Marek Vasut wrote:
> Why do you not use mxsboot tool from U-Boot instead of re-inventing the wheel?

I'm not sure we really want to download the u-boot sources for something
that simple. Also, I simply didn't know about it.
Marek Vasut - Aug. 23, 2013, 10:41 a.m.
Dear Alexandre Belloni,

> On 23/08/2013 05:15, Marek Vasut wrote:
> > Why do you not use mxsboot tool from U-Boot instead of re-inventing the
> > wheel?
> 
> I'm not sure we really want to download the u-boot sources for something
> that simple. Also, I simply didn't know about it.

You can always pull it out or create a package of u-boot tools (maybe that's 
already in Yocto, Otavio?). I don't see a point in duplicating effort instead of 
focusing on common goal.

Best regards,
Marek Vasut
Alexandre Belloni - Aug. 23, 2013, 11:02 a.m.
Hi,

On 23/08/2013 12:41, Marek Vasut wrote:
> Dear Alexandre Belloni,
>
>> On 23/08/2013 05:15, Marek Vasut wrote:
>>> Why do you not use mxsboot tool from U-Boot instead of re-inventing the
>>> wheel?
>> I'm not sure we really want to download the u-boot sources for something
>> that simple. Also, I simply didn't know about it.
> You can always pull it out or create a package of u-boot tools (maybe that's 
> already in Yocto, Otavio?). I don't see a point in duplicating effort instead of 
> focusing on common goal.
Yeah, that's what I'm doing. It is was not so simple to find the correct
option compile it standalone ;)
Eric BENARD - Aug. 23, 2013, 11:02 a.m.
Hi Marek,

Le Fri, 23 Aug 2013 12:41:16 +0200,
Marek Vasut <marex@denx.de> a écrit :

> Dear Alexandre Belloni,
> 
> > On 23/08/2013 05:15, Marek Vasut wrote:
> > > Why do you not use mxsboot tool from U-Boot instead of re-inventing the
> > > wheel?
> > 
> > I'm not sure we really want to download the u-boot sources for something
> > that simple. Also, I simply didn't know about it.
> 
> You can always pull it out or create a package of u-boot tools (maybe that's 
> already in Yocto, Otavio?). I don't see a point in duplicating effort instead of 
> focusing on common goal.
> 
you're right, it's already in meta-fsl-arm :
recipes-bsp/u-boot/u-boot-mxsboot_2013.07.bb

Eric
Alexandre Belloni - Aug. 23, 2013, 11:04 a.m.
On 23/08/2013 13:02, Eric Bénard wrote:
> Hi Marek,
>
> Le Fri, 23 Aug 2013 12:41:16 +0200,
> Marek Vasut <marex@denx.de> a écrit :
>
>> Dear Alexandre Belloni,
>>
>>> On 23/08/2013 05:15, Marek Vasut wrote:
>>>> Why do you not use mxsboot tool from U-Boot instead of re-inventing the
>>>> wheel?
>>> I'm not sure we really want to download the u-boot sources for something
>>> that simple. Also, I simply didn't know about it.
>> You can always pull it out or create a package of u-boot tools (maybe that's 
>> already in Yocto, Otavio?). I don't see a point in duplicating effort instead of 
>> focusing on common goal.
>>
> you're right, it's already in meta-fsl-arm :
> recipes-bsp/u-boot/u-boot-mxsboot_2013.07.bb

Right... I'll use that one :) Thanks everyone.
Marek Vasut - Aug. 23, 2013, 11:26 a.m.
Dear Alexandre Belloni,

> On 23/08/2013 13:02, Eric Bénard wrote:
> > Hi Marek,
> > 
> > Le Fri, 23 Aug 2013 12:41:16 +0200,
> > 
> > Marek Vasut <marex@denx.de> a écrit :
> >> Dear Alexandre Belloni,
> >> 
> >>> On 23/08/2013 05:15, Marek Vasut wrote:
> >>>> Why do you not use mxsboot tool from U-Boot instead of re-inventing
> >>>> the wheel?
> >>> 
> >>> I'm not sure we really want to download the u-boot sources for
> >>> something that simple. Also, I simply didn't know about it.
> >> 
> >> You can always pull it out or create a package of u-boot tools (maybe
> >> that's already in Yocto, Otavio?). I don't see a point in duplicating
> >> effort instead of focusing on common goal.
> > 
> > you're right, it's already in meta-fsl-arm :
> > recipes-bsp/u-boot/u-boot-mxsboot_2013.07.bb
> 
> Right... I'll use that one :) Thanks everyone.

Wow, I didn't know. Sorry you had to write your own thing, I know this portion 
can be ugly :-(

Best regards,
Marek Vasut

Patch

diff --git a/recipes-bsp/mx28-bcb/files/mx28_bcb.py b/recipes-bsp/mx28-bcb/files/mx28_bcb.py
new file mode 100755
index 0000000..ea2038b
--- /dev/null
+++ b/recipes-bsp/mx28-bcb/files/mx28_bcb.py
@@ -0,0 +1,56 @@ 
+#!/usr/bin/env python2
+
+#import os
+import struct
+#import subprocess
+#import sys
+#import tarfile
+#import tempfile
+
+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()
+
+
diff --git a/recipes-bsp/mx28-bcb/mx28-bcb_1.0.bb b/recipes-bsp/mx28-bcb/mx28-bcb_1.0.bb
new file mode 100644
index 0000000..ea9f7cd
--- /dev/null
+++ b/recipes-bsp/mx28-bcb/mx28-bcb_1.0.bb
@@ -0,0 +1,20 @@ 
+# Copyright (C) 2013 Free Electrons
+# Released under the GPLv2 license
+
+DESCRIPTION = "Utility to generate the Boot Control Block for freescale mx28 platforms"
+
+LICENSE = "GPLv2"
+LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/GPL-2.0;md5=801f80980d171dd6425610833a22dbe6"
+
+SECTION = "bootloader"
+PR = "r1"
+BBCLASSEXTEND = "native nativesdk"
+
+SRC_URI = "file://mx28_bcb.py"
+
+S = "${WORKDIR}"
+
+do_install() {
+    install -d ${D}${bindir}
+    install ${WORKDIR}/mx28_bcb.py ${D}${bindir}
+}