网站示例使用 -kernel 选项将二进制图像加载到0x10000;我只是假设二进制文件内部加载到0x10000与 -kernel .
这是命令 qemu-system-arm -M versatilepb -m 128M -kernel test.bin -serial stdio ,源代码可以在 - https://dl.dropboxusercontent.com/u/10773282/2014/b1.zip找到
ld设置如下:
ENTRY(_Reset)
SECTIONS
{
. = 0x10000;
.startup . : { startup.o(.text) }
...
}
启动组装很简单如下:
.global _Reset
_Reset:
LDR sp, =stack_top
BL c_entry
B .
主要c代码(c_entry)如下:
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");
}
我需要修改代码以在没有 -kernel 的情况下启动,但使用 -pflash 来模拟,就好像从闪存驱动器读取二进制文件一样 . 这是我尝试使其工作的方法:
更改启动程序集和test.ld
.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 .
这是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 = .;
}
更新构建代码
在构建获取test.bin之后,我使用 dd 命令创建了一个flash二进制文件 .
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执行
执行qemu以获取此错误消息 .
qemu-system-arm -M versatilepb -m 128M -pflash flash.bin -nographic
>> failed to read the initial flash content
>> Initialization of device cfi.pflash01 failed
可能有什么问题?我上传了示例和示例代码 .