public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] qemu and baremetal arm prog
@ 2017-10-24  8:30 Anupam Datta
  2017-10-24 18:31 ` Wolfgang Denk
  0 siblings, 1 reply; 3+ messages in thread
From: Anupam Datta @ 2017-10-24  8:30 UTC (permalink / raw)
  To: u-boot

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [U-Boot] qemu and baremetal arm prog
  2017-10-24  8:30 [U-Boot] qemu and baremetal arm prog Anupam Datta
@ 2017-10-24 18:31 ` Wolfgang Denk
       [not found]   ` <CAEmaDyELmBztEtFKtnYwQN0OYbq7QMH=G2k0fxwEH4scCzX+nA@mail.gmail.com>
  0 siblings, 1 reply; 3+ messages in thread
From: Wolfgang Denk @ 2017-10-24 18:31 UTC (permalink / raw)
  To: u-boot

Dear Anupam,

In message <CAEmaDyHtO=2+jZXLa=afZ6+oyxvndaRAbhfL-SSJhHV-kmzmyQ@mail.gmail.com> you wrote:
>
>     printf "bootm 0x%X\n" $(expr $(stat -c%s u-boot.bin) + 65536)
>     bootm 0x218F20

The value 0x218F20 printed here is the offset where your image
starts relative to the begin of the U-Boot binary.

> **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!

This can only be correct if your U-Boot binary was loaded to address
0x0000, which probably is not correct.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"We don't care.  We don't have to.  We're the Phone Company."

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [U-Boot] qemu and baremetal arm prog
       [not found]   ` <CAEmaDyELmBztEtFKtnYwQN0OYbq7QMH=G2k0fxwEH4scCzX+nA@mail.gmail.com>
@ 2017-10-25  7:19     ` Wolfgang Denk
  0 siblings, 0 replies; 3+ messages in thread
From: Wolfgang Denk @ 2017-10-25  7:19 UTC (permalink / raw)
  To: u-boot

Dear Anupam,

please keep the list on Cc:, and please don't top post/full quote.
Thanks.

In message <CAEmaDyELmBztEtFKtnYwQN0OYbq7QMH=G2k0fxwEH4scCzX+nA@mail.gmail.com> you wrote:
> 
> Thanks for the point. Can you please tell me what will be the address to
> load the kernel? Or the way to know how to load it ? All the tutorials
> shows this only. Didn't find anything else.

I cannot answer this question as it is unclear to me what you
actually want to do.

If you just want to run some code, the easiest way would be to add
this as a custom command to U-Boot proper.

If you want to keep it separate, the standard way is to implement it
as a so-called "standalone application", see doc/README.standalone

Even if you have completely incompatible standalone code, the
easiest way to run it is to just load the raw binary from some
storage device or network.  Load it directly to the address it was
linked for, and then use the "go <ep-addr>" command to jump to it's
entry point address.

Make sure to understand the execution environment and prepare your
code to be compatible with it (caches on or off? thumb mode?
peripherals initialized? etc.).

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
It may be that your whole purpose in life is simply  to  serve  as  a
warning to others.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-10-25  7:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-24  8:30 [U-Boot] qemu and baremetal arm prog Anupam Datta
2017-10-24 18:31 ` Wolfgang Denk
     [not found]   ` <CAEmaDyELmBztEtFKtnYwQN0OYbq7QMH=G2k0fxwEH4scCzX+nA@mail.gmail.com>
2017-10-25  7:19     ` Wolfgang Denk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox