简体   繁体   English

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

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

I am using qemu-arm and the ARM Workbench IDE to run/profile an ARM binary which was built with armcc/armlink (an.axf-File, program written in C).我正在使用 qemu-arm 和 ARM 工作台 IDE 运行/分析 ARM 二进制文件,该二进制文件是用 armcc/armflink 编写的 armcc/armflink 程序构建的。 This works fine with Cortex-A9 and ARM926/ARM5TE.这适用于 Cortex-A9 和 ARM926/ARM5TE。 However, whatever I tried, it doesnt work when the binary is built for Cortex-M4.但是,无论我尝试了什么,当为 Cortex-M4 构建二进制文件时,它都不起作用。 Both the simulator and qemu-arm hang when M4 is selected as CPU. Both the simulator and qemu-arm hang when M4 is selected as CPU.

I know that this processor requires some additional startup code, but I could find any comprehensive tutorial on how to get it running.我知道这个处理器需要一些额外的启动代码,但我可以找到任何关于如何让它运行的综合教程。 Does anyone know how to do this?有谁知道如何做到这一点? I have a quite big project with one main function, but it would already help if a "hello world" or some simple program which takes arguments would run.我有一个相当大的项目,其中有一个主要的 function,但如果运行“hello world”或一些需要 arguments 的简单程序,它已经有所帮助。

Here is the command line I am using with Cortex-A9:这是我在 Cortex-A9 中使用的命令行:

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

I do not know how to do it with the versatilepb, it did not "just work", but this does work:我不知道如何使用多功能pb,它并没有“正常工作”,但这确实有效:

flash.s 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 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 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
}

(I am told the entry point being a thumb function address is critical YMMV) (我被告知入口点是拇指 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

check the vector table, etc.检查向量表等。

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>

Looks good.看起来不错。

And run it并运行它

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

Then ctrl-a then x to exit然后 ctrl-a 然后 x 退出

QEMU: Terminated

-cpu cortex-m4 works as well as one would expect. -cpu cortex-m4 的效果和预期的一样好。 Would have to try to find things different between the m3 and m4 that might show up in a sim like this and go from there.必须尝试在 m3 和 m4 之间找到不同的东西,这些东西可能会出现在这样的 sim 卡和 go 中。

After Luminary Micro (acquired by ti a while ago now) I do not think anyone else put the effort in for a machine.在 Luminary Micro(不久前被 ti 收购)之后,我认为没有其他人会为机器付出努力。 But as already discussed in at least one question at this site, you can run the cores (an exercise for the reader).但正如在本网站的至少一个问题中已经讨论过的那样,您可以运行内核(读者练习)。

For versatilepb对于多功能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

You can't arbitrarily plug different CPU types into an Arm board model.您不能随意将不同的 CPU 类型插入 Arm 板 model。 If you try it then the resulting system may work by luck, or may crash, or have odd behaviour;如果你尝试它,那么生成的系统可能会靠运气工作,或者可能会崩溃,或者有奇怪的行为; in some cases the -cpu option will just be ignored.在某些情况下,-cpu 选项将被忽略。 This is because the CPU integration with the board matters: things like interrupt controllers are part of the board, not the CPU, but not all CPUs will work with all interrupt controllers.这是因为 CPU 与板卡的集成很重要:中断控制器之类的东西是板卡的一部分,而不是 CPU,但并非所有 CPU 都可以与所有中断控制器一起使用。 Often QEMU is not as good as it could be about detecting and reporting errors for user options that aren't valid.通常,QEMU 在检测和报告无效用户选项的错误方面不如它可能的好。

In this case you're probably using an older QEMU: newer ones will correctly report:在这种情况下,您可能使用的是较旧的 QEMU:较新的 QEMU 会正确报告:

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

if you try to use '-machine versatilepb' with '-cpu cortex-m4'.如果您尝试将“-machine dedicatedpb”与“-cpu cortex-m4”一起使用。 Older ones would either crash or just misbehave.年长的人要么崩溃,要么行为不端。

Generally the best thing is to use the CPU type that the board has by default (ie don't specify a -cpu option), for every board type except the "virt" board.通常最好的办法是使用板默认的 CPU 类型(即不指定 -cpu 选项),用于除“virt”板之外的所有板类型。 If you want to write code for a Cortex-M4, you should look for a board type that has a Cortex-M4.如果您想为 Cortex-M4 编写代码,您应该寻找具有 Cortex-M4 的板类型。 The mps2-an386 is probably a good option. mps2-an386可能是一个不错的选择。 (If your QEMU doesn't have that board type, upgrade to a newer one: there have been a lot of M-profile emulation bug fixes anyway that you'll want to have.) (如果您的 QEMU 没有该板类型,请升级到较新的板:无论如何,您都希望拥有很多 M-profile 仿真错误修复。)

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

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