在 Cortex-M4 上编译和运行 ARM 汇编二进制文件(在 QEMU 中模拟) [英] Compiling and running ARM assembly binary on Cortex-M4 (simulated in QEMU)
问题描述
我在虚拟 QEMU 嵌入式系统 connex
上成功编译并执行了 ARM 二进制文件,使用以下程序:
I successfully compiled and executed ARM binary file on a virtual QEMU embedded system connex
using this procedure:
arm-none-eabi-as -o program.o program.s
arm-none-eabi-ld -Ttext=0x0 -o program.elf program.o
arm-none-eabi-objcopy -O binary program.elf program.bin
dd if=/dev/zero of=flash.bin bs=4096 count=4096
dd if=program.bin of=flash.bin bs=4096 conv=notrunc
qemu-system-arm -M connex -pflash flash.bin -nographic -serial /dev/null
在第四行我创建了一个清零的空磁盘,它代表闪存,在第五行我将我的二进制文件复制到闪存中.
In line four I created a zeroed out empty disk which represents flash and in line five I copied my binary into flash.
所以这就像一个魅力,但它模拟了整个嵌入式系统,而我只想模拟 ARM 内核,例如 Cortex-M4.这就是为什么我试图只使用 qemu-arm
而不是 qemu-system-arm
.
So this works like a charm, but it simulates an entire embedded system while I only want to simulate ARM core, for example Cortex-M4. This is why I am trying to just use qemu-arm
instead of qemu-system-arm
.
所以我第一次尝试像这样编译和运行我的程序(第 1-3 行与上面相同):
So I 1st tried to compile and run my program like this (lines 1-3 are same as above):
arm-none-eabi-as -o program.o program.s
arm-none-eabi-ld -Ttext=0x0 -o program.elf program.o
arm-none-eabi-objcopy -O binary program.elf program.bin
qemu-arm -cpu cortex-m4 program.bin
这不起作用 - 它说:
And this doesn't work - it says:
Error while loading program.bin: Exec format error
所以我尝试像以前一样创建 Flash 图像(因为它有效):
So I tried to create flash image like before (because it worked):
arm-none-eabi-as -o program.o program.s
arm-none-eabi-ld -Ttext=0x0 -o program.elf program.o
arm-none-eabi-objcopy -O binary program.elf program.bin
dd if=/dev/zero of=flash.bin bs=4096 count=4096
dd if=program.bin of=flash.bin bs=4096 conv=notrunc
qemu-arm -cpu cortex-m4 flash.bin
我明白了:
Error while loading flash.bin: Permission denied
有人可以帮我一下吗?使用 sudo
没有帮助.
Can anyone help me a bit? Using sudo
doesn't help.
推荐答案
qemu-arm 的目的不是仅模拟 ARM 内核".它是运行单个 Linux 二进制文件",它期望您提供的二进制文件是 Linux 格式的 ELF 可执行文件.试图喂它别的东西是行不通的.
qemu-arm's purpose is not "simulate just an ARM core". It is "run a single Linux binary", and it expects that the binary file you provide it is a Linux format ELF executable. Trying to feed it something else is not going to work.
由于 Linux 采用 A-profile 内核,而不是 M-profile 内核,所以你在 qemu-arm 上使用 -cpu cortex-m4 所做的任何事情都只能靠运气,而不是故意的.(我们不会禁用这些 CPU 类型,因为有一些 GCC 测试用例场景使用半主机,我们不想故意破坏哪种类型的工作.但这些工作与其他任何事情一样幸运.)
Since Linux assumes A-profile cores, not M-profile cores, anything you do with -cpu cortex-m4 on qemu-arm will only be working by luck, not deliberately. (We don't disable those CPU types since there are some GCC test case scenarios that use semihosting which sort-of-work and which we don't want to deliberately break. But those are working as much by luck as anything else.)
这篇关于在 Cortex-M4 上编译和运行 ARM 汇编二进制文件(在 QEMU 中模拟)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!