title: uboot a hello world kernel
body: <p>For a Hello world uboot project I am using <a href="https://balau82.wordpress.com/2010/03/10/u-boot-for-arm-on-qemu" rel="nofollow noreferrer">this</a> tutorial.</p>
  
  <p>I have used GNU ARM toolchain
  Downloaded Uboot source : u-boot-2017.09</p>
  
  <p>Compiled it</p>
  
  <pre><code>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-
  </code></pre>
  
  <p>And the hello world project looks like</p>
  
  <p><strong>test.c</strong></p>
  
  <pre><code>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");
  }
  </code></pre>
  
  <p><strong>startup.s</strong></p>
  
  <pre><code>.global _Reset
  _Reset:
   LDR sp, =stack_top
   BL c_entry
   B .
  </code></pre>
  
  <p><strong>test.ld</strong></p>
  
  <pre><code>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 = .;
  }
  </code></pre>
  
  <p><strong>And the compilation</strong></p>
  
  <pre><code>../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
  </code></pre>
  
  <p><strong>Create Image :</strong></p>
  
  <pre><code>mkimage -A arm -C none -O linux -T kernel -d test.bin -a 0x00100000 -e 0x00100000 test.uimg
  </code></pre>
  
  <p><strong>Output :</strong></p>
  
  <pre><code>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
  </code></pre>
  
  <p><strong>Create a single binary :</strong></p>
  
  <pre><code>cat ../u-boot-2017.09/u-boot test.uimg &gt; flash.bin
  </code></pre>
  
  <p><strong>Calculated uboot binary size</strong></p>
  
  <pre><code>printf "bootm 0x%X\n" $(expr $(stat -c%s u-boot.bin) + 65536)
  bootm 0x218F20
  </code></pre>
  
  <p><strong>Then run :</strong> </p>
  
  <pre><code>qemu-system-arm -M vexpress-a9 -kernel flash.bin -m 128M -nographic
  </code></pre>
  
  <p>Interrupted it and then run <code>bootm 0x218F20</code>
  But it says</p>
  
  <pre><code>Wrong Image Format for bootm command
  ERROR: can't get kernel image!
  </code></pre>
  
  <p>Any suggestion?</p>