使用qemu模拟arm开发板

来源:互联网 发布:沁人缘总裁团 淘宝网 编辑:程序博客网 时间:2024/05/17 22:57

虚拟化是万能的!
首先下载qemu源码

git clone git://git.qemu.org/qemu.gitcd qemu

查看qemu可以模拟的target列表

./configure --help|less  --target-list=LIST       set target list (default: build everything)                           Available targets: aarch64-softmmu alpha-softmmu                            arm-softmmu cris-softmmu i386-softmmu lm32-softmmu                            m68k-softmmu microblazeel-softmmu microblaze-softmmu                            mips64el-softmmu mips64-softmmu mipsel-softmmu                            mips-softmmu moxie-softmmu nios2-softmmu                            or1k-softmmu ppc64-softmmu ppcemb-softmmu                            ppc-softmmu s390x-softmmu sh4eb-softmmu sh4-softmmu                            sparc64-softmmu sparc-softmmu tricore-softmmu                            unicore32-softmmu x86_64-softmmu xtensaeb-softmmu                            xtensa-softmmu aarch64-linux-user alpha-linux-user                            armeb-linux-user arm-linux-user cris-linux-user                            hppa-linux-user i386-linux-user m68k-linux-user                            microblazeel-linux-user microblaze-linux-user                            mips64el-linux-user mips64-linux-user                            mipsel-linux-user mips-linux-user                            mipsn32el-linux-user mipsn32-linux-user                            nios2-linux-user or1k-linux-user                            ppc64abi32-linux-user ppc64le-linux-user                            ppc64-linux-user ppc-linux-user s390x-linux-user                            sh4eb-linux-user sh4-linux-user                            sparc32plus-linux-user sparc64-linux-user                            sparc-linux-user tilegx-linux-user x86_64-linux-user

上面这些都是可以模拟的平台类型。
执行

./configure  --prefix=/go/qemu/ --target-list=arm-softmmu,arm-linux-user --enable-debug

来制定模拟的平台,当然不嫌慢可以build everything
编译安装

make make install

写个helloworld

#include <stdio.h>int main(){        printf("helloworld\n`");        return 0;}

用之前编译的工具链编译

seijia@seijia:./arm-none-linux-gnueabi-gcc -o hello hello.cseijia@seijia:/go/cross/arm/bin> file hellohello: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.3, for GNU/Linux 3.2.0, with debug_info, not stripped

然后使用qemu模拟执行

seijia@seijia:/go/qemu/bin> ./qemu-arm  -L /go/cross/arm/sysroot/ /tmp/hello helloworld

注意这里需要指定

-L path QEMU_LD_PREFIX set the elf interpreter prefix to ‘path’

也就是说需要制定模拟环境下的libc库位置才能正确的执行程序。这个动态库可以通过对应的工具链编译glibc的源码得到。

玩过qemu的都知道还有一个指令是qemu-system-arm
两个指令的区别主要是前一个是只对用户态进行模拟,而后面这个指令能搭建一个系统级别的虚拟机,需要用内核搭建出一个完整的系统,也可以对硬盘网卡等硬件资源进行操作。一般如果只想模拟下程序的运行使用qemu-arm就够了。

但是搞开发板这么麻烦,就当增长知识了。。

原创粉丝点击