Creating Linux Kernel U-Boot Images

This sub-section shows you how to create a Linux kernel image, in preparation to download and burn it in to flash, ready to be booted.

To make a U-Boot image file containing the Elf binary vmlinux kernel file, it is first required to use "objcopy" to get the raw binary data, followed by the "mkimage" tool to encapsulate it (as a ".ub" file). In this example the kernel is also compressed to save space (this is recommended, but not necessary).

host% sh4-linux-objcopy -O binary vmlinux vmlinux.bin
host% gzip --best --force vmlinux.bin
host% ./tools/mkimage -A sh -O linux -T kernel -C gzip -a 0x8C001000 -e 0x8C002000 -n "Linux 2.6" -d vmlinux.bin.gz vmlinux.ub
Image Name:   Linux 2.6
Created:      Thu Nov  6 19:45:04 2008
Image Type:   SuperH Linux Kernel Image (gzip compressed)
Data Size:    1914573 Bytes = 1869.70 KiB = 1.83 MiB
Load Address: 0x8C001000
Entry Point:  0x8C002000

The addresses for the two parameters "-a" (load address) and "-e" (execute address) depend of the specific target board that is being used, and they also depend on the SE mode.

When running in 32-bit mode (SE=1), then, by default, the load address will always be 0x80001000, and the execute address will always be 0x80002000.

When running in 29-bit mode (SE=0), then, the values will depend on the exact board that is used, and where the physical memory is. The following table lists these values from some common boards.

Board Load Address ("-a") Execute Address ("-e")
MB411 0x84001000 0x84002000
MB442 0x84001000 0x84002000
MB448 0x84001000 0x84002000
MB519 0x88001000 0x88002000
MB618 0x8C001000 0x8C002000
MB628 0x8C001000 0x8C002000
MB680 0x8C001000 0x8C002000

Special note for STAPI users. The values in the above table are common for non-STAPI users. Typically STAPI users will need to add another 7 or 8 MiB to these values. It is strongly recommended to use the following technique to ensure the correct addresses are always used.

It is absolutely essential that the addresses used with these two parameters are correct, and totally consistent with the information in the original vmlinux Elf file. To this end, if there is any doubt as to which values to use then the following may be used to obtain the execute address (for the "-e" parameter).

host% sh4-linux-objdump -f vmlinux | grep '^start address ' | awk '{print $3}'
In general, to obtain the load address (for the "-a" parameter), then just subtract 0x1000 from the execute address. However, as a sanity check, the following command should also obtain the load address:
host% sh4-linux-objdump -h vmlinux | grep .empty_zero_page | awk '{print $4}'

Alternatively, it may be easier to just create the U-Boot kernel image directly using the linux build system. This is achieved when performing a kernel build by using "uImage" as the target of a kernel build. For example:

host% make ARCH=sh CROSS_COMPILE=sh4-linux- uImage
  SYMLINK include/asm-sh/cpu -> include/asm-sh/cpu-sh4
  SYMLINK include/asm-sh/mach -> include/asm-sh/mb618
  CHK     include/linux/version.h
make[1]: `include/asm-sh/machtypes.h' is up to date.
  CHK     include/linux/utsrelease.h
  CALL    scripts/checksyscalls.sh
  CHK     include/linux/compile.h
  GEN     .version
  CHK     include/linux/compile.h
  UPD     include/linux/compile.h
  CC      init/version.o
  LD      init/built-in.o
  LD      .tmp_vmlinux1
  KSYM    .tmp_kallsyms1.S
  AS      .tmp_kallsyms1.o
  LD      .tmp_vmlinux2
  KSYM    .tmp_kallsyms2.S
  AS      .tmp_kallsyms2.o
  LD      vmlinux.o
  MODPOST vmlinux.o
  LD      vmlinux
  SYSMAP  System.map
  SYSMAP  .tmp_System.map
  OBJCOPY arch/sh/boot/vmlinux.bin
  GZIP    arch/sh/boot/vmlinux.bin.gz
  UIMAGE  arch/sh/boot/uImage
Image Name:   Linux-2.6.23.17_stm23_0116-mb618
Created:      Thu Nov  6 20:18:51 2008
Image Type:   SuperH Linux Kernel Image (gzip compressed)
Data Size:    1888829 Bytes = 1844.56 KiB = 1.80 MiB
Load Address: 0x8C001000
Entry Point:  0x8C002000
  Image arch/sh/boot/uImage is ready

This will create a U-Boot Linux kernel image "arch/sh/boot/uImage", which may then be downloaded and burned into flash on the target, as before.

Also, note that this process automatically extracts both the load and execute addresses, and uses them appropriately.