openwrt uImage generation

Started by lambda, November 09, 2013, 05:23:01 PM

Previous topic - Next topic

lambda

Hi,

has anyone got the uImages from openwrt to boot? I always get
undefined instruction exceptions. Maybe load address and entry
point are wrong?

The uImage is generated with the following command

mkimage -A arm -O linux -T kernel -C none \
        -a 0x42000000 -e 0x42000000 \
        -n 'ARM OpenWrt Linux-$(LINUX_VERSION)' \
        -d $(KDIR)/vmlinux $(KDIR)/uImage


and this looks fishy to me, as 0x42000000 also is the address
where u-boot loads the image file. I think these two
things need non-overapping memory regions.

As a first attempt I have changed the load address of the
image file ($loadaddr from u-boot environment) to
0x41008000. This got me one step further, as
now I don't get any exceptions. But after u-boot prints
"Starting kernel ..." no further output appears.

At this point I have no obvious idea what to do next.
Any pointers? Also anybody knows where these magic
0x42000000 come from anyway?

TIA,
Harald

picmaster

Hi Gerald,

I was able to built and run OpenWRT on Olinuxino-Micro, without any issues following the instructions here:
http://olimex.wordpress.com/2013/07/08/imx233-olinuxino-is-supported-by-openwrt/

After OpenWRT finishes the build, the output files are located in "$(workdir)/openwrt/bin/mxs" directory, where you should see 2 important files: the "blessed" kernel (openwrt-imx23-sbImage) and the Ext4 root filesystem image (openwrt-mxs-root.ext4). You need to partition your uSD-card as described here: https://www.olimex.com/Products/OLinuXino/iMX233/_resources/DEBIAN-README.TXT (basically, partition 1 should be 16MB type 53, partition 2 should be bigger than 53MB, the size of rootfs file, and of type 83). DD the blessed kernel to partition 1 and the rootfs to partition 2, and you're done.

I can suppose that if someone writes a non-blessed file to partition 1 (e.g. file which was not packaged properly as a Freescale boot-stream), the board will fail to boot and will print an error-code in the serial console (like for example: 0x80501003).

Hope this helps. Regards.

lambda

Yes, I know about sbImage and this route works fine.

However to be able to select different devicetree file,
I want to boot via u-boot. (Which also is supported by
openwrt.)

My setup:
I have a sbImage containing u-boot on the sd-card, and I
use this to load a kernel uImage from USB storage. However
the kernel shows no signs of life after booting.

Harald

picmaster

Hi Gerald,

The number 0x42000000 is not very magic (as far as my limited knowledge goes). The imx233 docs say that address 0x40000000 is where the EMI controller is mapped in the physical address space, and address 0x42000000 is in the middle of the 64MB on-board DDR memory. The mkimage arguments "-a" & "-e" are used to create the uImage header fields, which afaik are respected by U-Boot (where to load the image file, where to jump on start). So from the point of view of mkimage, these values can be any values, and should be possible to be overriden by U-Boot commands. From the point of view of the actual code that's executed (e.g. the kernel itself), I don't think that you can move it anywhere in the physical memory unless it's compiled for this purpose.

One possible explanation for this behavior is that the ARM instructions for doing relative jumps can encode only a limited distance (+/-) from the current address, and if you want to go further, you need to encode it with absolute jump, which forces you to hard-code the exact address in the image. This is an ugly issue during bootstrapping, and far less ugly issue in runtime (there's smart mechanism that calculates addresses when loading shared libraries).

Can you please share where you store your kernel/dtb and how do you load it, so I can test here similarly to your setup?

Regards,
picmaster

picmaster

I booted the U-Boot and got same error as Gerald did (Undefined instruction). This is strange and seems like a wrong image. I thought that the menuconfig somehow creates a wrong uImage when the 2 bootloader options are enabled, so I cleanly rebuilt the kernel with only the uboot option. Now my board silently reboots after "Starting kernel..." message. This problem needs more digging...

Regards,
picmaster

lambda

After reading the kernel Makefiles and the openwrt code
for sbImage creation, I found the correct load address
of the kernel: 0x40008000

The following command creates a working uImage for me:

mkimage -A arm -O linux -T kernel -C none \
        -a 0x40008000 -e 0x40008000 \
        -n 'ARM OpenWrt Linux-$(LINUX_VERSION)' \
        -d $(KDIR)/vmlinux $(KDIR)/uImage


I will send a patch to openwrt tomorrow.

HTH,
Harald

picmaster

Hi Harald,

Thanks for sharing. I can confirm that this fix works on my board here. The proper file to edit was "openwrt/target/linux/mxs/image/Makefile".

Regards,
picmaster