繁体   English   中英

在 Linux 上使用 Cortex-M4 的 qemu-arm

[英]qemu-arm with Cortex-M4 on Linux

我正在使用 qemu-arm 和 ARM 工作台 IDE 运行/分析 ARM 二进制文件,该二进制文件是用 armcc/armflink 编写的 armcc/armflink 程序构建的。 这适用于 Cortex-A9 和 ARM926/ARM5TE。 但是,无论我尝试了什么,当为 Cortex-M4 构建二进制文件时,它都不起作用。 Both the simulator and qemu-arm hang when M4 is selected as CPU.

我知道这个处理器需要一些额外的启动代码,但我可以找到任何关于如何让它运行的综合教程。 有谁知道如何做到这一点? 我有一个相当大的项目,其中有一个主要的 function,但如果运行“hello world”或一些需要 arguments 的简单程序,它已经有所帮助。

这是我在 Cortex-A9 中使用的命令行:

qemu-system-arm -machine versatileab -cpu cortex-a9 -nographic -monitor null -semihosting -append 'some program arguments' -kernel program.axf

我不知道如何使用多功能pb,它并没有“正常工作”,但这确实有效:

flash.s

.thumb
.thumb_func
.global _start
_start:
stacktop: .word 0x20001000
.word reset
.word hang

.thumb_func
reset:
    bl notmain
    b hang

.thumb_func
hang:   b .

.thumb_func
.globl PUT32
PUT32:
    str r1,[r0]
    bx lr

notmain.c

void PUT32 ( unsigned int, unsigned int );
#define UART0BASE 0x4000C000
int notmain ( void )
{
    unsigned int rx;
    for(rx=0;rx<8;rx++)
    {
        PUT32(UART0BASE+0x00,0x30+(rx&7));
    }
    return(0);
}

flash.ld

ENTRY(_start)

MEMORY
{
    rom : ORIGIN = 0x00000000, LENGTH = 0x1000
    ram : ORIGIN = 0x20000000, LENGTH = 0x1000
}

SECTIONS
{
    .text : { *(.text*) } > rom
    .rodata : { *(.rodata*) } > rom
    .bss : { *(.bss*) } > ram
}

(我被告知入口点是拇指 function 地址是关键 YMMV)

arm-none-eabi-as --warn --fatal-warnings -mcpu=cortex-m3 flash.s -o flash.o
arm-none-eabi-gcc -Wall -O2 -ffreestanding -mcpu=cortex-m3 -mthumb -c notmain.c -o notmain.o
arm-none-eabi-ld -nostdlib -nostartfiles -T flash.ld flash.o notmain.o -o notmain.elf
arm-none-eabi-objdump -D notmain.elf > notmain.list
arm-none-eabi-objcopy -O binary notmain.elf notmain.bin

检查向量表等。

00000000 <_start>:
   0:   20001000
   4:   0000000d
   8:   00000013

0000000c <reset>:
   c:   f000 f804   bl  18 <notmain>
  10:   e7ff        b.n 12 <hang>

00000012 <hang>:
  12:   e7fe        b.n 12 <hang>

看起来不错。

并运行它

qemu-system-arm -M lm3s811evb -m 8K -nographic -kernel notmain.bin
01234567

然后 ctrl-a 然后 x 退出

QEMU: Terminated

-cpu cortex-m4 的效果和预期的一样好。 必须尝试在 m3 和 m4 之间找到不同的东西,这些东西可能会出现在这样的 sim 卡和 go 中。

在 Luminary Micro(不久前被 ti 收购)之后,我认为没有其他人会为机器付出努力。 但正如在本网站的至少一个问题中已经讨论过的那样,您可以运行内核(读者练习)。

对于多功能pb

int notmain ( void )
{
    unsigned int ra;

    for(ra=0;;ra++)
    {
        ra&=7;
        PUT32(0x101f1000,0x30+ra);
    }

    return(0);
}

qemu-system-arm -machine versatileab -cpu cortex-m4 -nographic -monitor null -kernel notmain.elf
qemu-system-arm: This board cannot be used with Cortex-M CPUs

您不能随意将不同的 CPU 类型插入 Arm 板 model。 如果你尝试它,那么生成的系统可能会靠运气工作,或者可能会崩溃,或者有奇怪的行为; 在某些情况下,-cpu 选项将被忽略。 这是因为 CPU 与板卡的集成很重要:中断控制器之类的东西是板卡的一部分,而不是 CPU,但并非所有 CPU 都可以与所有中断控制器一起使用。 通常,QEMU 在检测和报告无效用户选项的错误方面不如它可能的好。

在这种情况下,您可能使用的是较旧的 QEMU:较新的 QEMU 会正确报告:

qemu-system-arm: This board cannot be used with Cortex-M CPUs

如果您尝试将“-machine dedicatedpb”与“-cpu cortex-m4”一起使用。 年长的人要么崩溃,要么行为不端。

通常最好的办法是使用板默认的 CPU 类型(即不指定 -cpu 选项),用于除“virt”板之外的所有板类型。 如果您想为 Cortex-M4 编写代码,您应该寻找具有 Cortex-M4 的板类型。 mps2-an386可能是一个不错的选择。 (如果您的 QEMU 没有该板类型,请升级到较新的板:无论如何,您都希望拥有很多 M-profile 仿真错误修复。)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM