Embedded

Extract u-boot multi-file image in Python

This simple piece of code shows how to extract/decompress a u-boot multi-file image created with mkimage using Python. The image format is pretty simple:

64 bytes of image header.
4 bytes for the size of first image.
4 bytes for the size of second image.
...
4 bytes of zeros for termination.
image1.
image2.
...

You need to remember also that each image is padded to 4 bytes.

#!/usr/bin/env python

import sys

def toNumber(buf):
        """ Convert string in number """
        size = 0
        for b in buf: size=size*256+ord(b)
        return size

if len(sys.argv)!=2:
        sys.stdout.write('Usage %s uboot_image_file\n' % sys.argv[0])
        sys.exit(1)

f = open(sys.argv[1],'rb')
f.seek(64) # skip image header

parts = []

# get file size of all images
while True:
        buf = f.read(4)
        size = toNumber(buf)
        if size==0: break
        parts.append(size)

i = 0
for size in parts:
        pattern = 'file%d.img' % i
        p = open(pattern, 'wb')
        buf = f.read(size)
        p.write(buf)
        p.close()
        if size%4 != 0:
                # 4 byte padding
                f.read(4-(size%4))
        i+=1

f.close()

Codesourcery G++ for ColdFire on OpenSuse 10.3 and some problems during IDE installation

In these days at working we are evaluating the buying of cross-compiler IDE of ColdFire by CodeSourcery G++. The development environment is substantially Eclipse optimized for that cross-compiler. During installation of the package we have discovered a lot of problems running the IDE installation and the next license installation.

From the official site must download the *.bin package that contains all the necessary, but after run, we have always obtained this error:

eclipse.bin: xcb_xlib.c:52: xcb_xlib_unlock: Assertion `c->xlib.lock’ failed

To solve this issue is sufficient to insert into ~/.bashrc this line:
export LIBXCB_ALLOW_SLOPPY_LOCK=1

and reload the file:
source ~/.bashrc

Well, proceed with installation and complete it. At the end a wizard license will be prompt but it was never appear to us, may be because of some problem about the MAC address of our virtual machine (we work under vmware). So, we have prepared a new computer with native linux, put it out of the net (probably the license evaluation file it will be downloaded directly from internet during installation), waiting the wizard appear, download the license from codesourcery site by hand and import it to the wizard itself.

Only after all these fix and tries we were finally able to work with the new development environment. Unfortunately, using it we have discovered that sometimes Eclipse crashes with no sense and we have not yet understand why.