I have a website Hello world for bare metal ARM using QEMU that teaches how to run qemu
for versatilePB.
The website example uses -kernel
option to load the binary image into 0x10000; I just assume that the binary is loaded into 0x10000 internally with the -kernel
.
This is the command qemu-system-arm -M versatilepb -m 128M -kernel test.bin -serial stdio
, and the source can be found at - https://dl.dropboxusercontent.com/u/10773282/2014/b1.zip
The ld setup is as follows:
ENTRY(_Reset)
SECTIONS
{
. = 0x10000;
.startup . : { startup.o(.text) }
...
}
Start up assembly is simple as follows:
.global _Reset
_Reset:
LDR sp, =stack_top
BL c_entry
B .
The main c code (c_entry) is as follows:
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");
}
I need to modify the code to boot without -kernel
, but with -pflash
to emulate as if the binary is read from the flash drive. This is my approach in trying to make it work:
Change the startup assembly and test.ld
I just used the other example from the same author of my example: http://balau82.wordpress.com/2010/02/14/simplest-bare-metal-program-for-arm/ This is the startup code:
.section INTERRUPT_VECTOR, "x"
.global _Reset
_Reset:
B Reset_Handler /* Reset */
B . /* Undefined */
B . /* SWI */
B . /* Prefetch Abort */
B . /* Data Abort */
B . /* reserved */
B . /* IRQ */
B . /* FIQ */
Reset_Handler:
LDR sp, =stack_top
BL c_entry
B .
This is the test.ld
ENTRY(_Reset)
SECTIONS
{
. = 0x0;
.text : {
startup.o (INTERRUPT_VECTOR)
*(.text)
}
.data : { *(.data) }
.bss : { *(.bss COMMON) }
. = ALIGN(8);
. = . + 0x1000; /* 4kB of stack memory */
stack_top = .;
}
Update the build code
After the build to get the test.bin, I used the dd
command to create a flash binary.
arm-none-eabi-as -mcpu=arm926ej-s -g startup.s -o startup.o
arm-none-eabi-gcc -c -mcpu=arm926ej-s -g test.c -o test.o
arm-none-eabi-ld -T test.ld test.o startup.o -o test.elf
arm-none-eabi-objcopy -O binary test.elf test.bin
dd if=/dev/zero of=flash.bin bs=4096 count=4096
dd if=test.bin of=flash.bin bs=4096 conv=notrunc
qemu execution
Executed qemu to get this error message.
qemu-system-arm -M versatilepb -m 128M -pflash flash.bin -nographic
>> failed to read the initial flash content
>> Initialization of device cfi.pflash01 failed
What might be wrong? I uploaded the examples and sample code.
- not working with -pflash: https://dl.dropboxusercontent.com/u/10773282/2014/b2.zip