[U-Boot] qemu and baremetal arm prog

Anupam Datta adbd04 at gmail.com
Tue Oct 24 08:30:47 UTC 2017


For a Hello world uboot project I am using
https://balau82.wordpress.com/2010/03/10/u-boot-for-arm-on-qemu/ tutorial.


I have used GNU ARM toolchain
Downloaded Uboot source : u-boot-2017.09

Compiled it

    make vexpress_ca9x4_defconfig ARCH=arm
CROSS_COMPILE=../gcc-arm-none-eabi-6-2017-q2-update/bin/arm-none-eabi-

    make all ARCH=arm
CROSS_COMPILE=../gcc-arm-none-eabi-6-2017-q2-update/bin/arm-none-eabi-

And the hello world project looks like

**test.c**

    volatile unsigned int * const UART0DR = (unsigned int *)0x101f1000;
    void print_uart0(const char *s) {
        while(*s != '\0') { /* Loop until end of string */
            *UART0DR = (unsigned int)(*s); /* Transmit char */
            s++; /* Next char */
        }
    }
    void c_entry() {
        print_uart0("Hello world!\n");
    }

**startup.s**

    .global _Reset
    _Reset:
     LDR sp, =stack_top
     BL c_entry
     B .

**test.ld**

    ENTRY(_Reset)
    SECTIONS
    {
     . = 0x100000; /*initial address*/
     .startup . : { startup.o(.text) }
     .text : { *(.text) }
     .data : { *(.data) }
     .bss : { *(.bss COMMON) }
     . = ALIGN(8);
     . = . + 0x1000; /* 4kB of stack memory */
     stack_top = .;
    }


**And the compilation**

    ../gcc-arm-none-eabi-6-2017-q2-update/bin/arm-none-eabi-gcc -c
-mcpu=arm926ej-s test.c -o test.o

    ../gcc-arm-none-eabi-6-2017-q2-update/bin/arm-none-eabi-as
-mcpu=arm926ej-s startup.s -o startup.o

    ../gcc-arm-none-eabi-6-2017-q2-update/bin/arm-none-eabi-ld -T test.ld
-Map=test.map test.o startup.o -o test.elf

    ../gcc-arm-none-eabi-6-2017-q2-update/bin/arm-none-eabi-objcopy -O
binary test.elf test.bin


**Create Image :**

    mkimage -A arm -C none -O linux -T kernel -d test.bin -a 0x00100000 -e
0x00100000 test.uimg

**Output :**

    Image Name:
    Created:      Mon Oct 23 20:58:01 2017
    Image Type:   ARM Linux Kernel Image (uncompressed)
    Data Size:    146 Bytes = 0.14 kB = 0.00 MB
    Load Address: 00100000
    Entry Point:  00100000


**Create a single binary :**

    cat ../u-boot-2017.09/u-boot test.uimg > flash.bin

**Calculated uboot binary size**

    printf "bootm 0x%X\n" $(expr $(stat -c%s u-boot.bin) + 65536)
    bootm 0x218F20

**Then run :**

    qemu-system-arm -M vexpress-a9 -kernel flash.bin -m 128M -nographic

Interrupted it and then run `bootm 0x218F20`
But it says

    Wrong Image Format for bootm command
    ERROR: can't get kernel image!

Any suggestion?


  [1]: https://balau82.wordpress.com/2010/03/10/u-boot-for-arm-on-qemu


More information about the U-Boot mailing list