嵌入式学习——4.qemu的安装与使用
直接在应用层运行u-boot和内核不行:因是不同地址空间,但可以用模拟器在应用空间模拟调试 。
用qemu原因:不能用$ gdb vmlinux
调试内核,因在应用空间,不能运行内核空间的程序,故用模拟器qemu来做,在应用空间模拟一个完整的系统。
- 安装qemu
$ sudo apt-get install qemu-system-arm
$ qemu-system-aarch64 -h // 查看全部帮助信息
$ qemu-system-aarch64 --version
QEMU emulator version 2.11.1(Debian 1:2.11+dfsg-1ubuntu7.38)
Copyright (c) 2003-2017 Fabrice Bellard and the QEMU Project developers
$ qemu-system-aarch64 -machine help //查看支持的machine
$ qemu-system-aarch64 -cpu help //查看machine支持的cpu类型
When using -nographic, press 'ctrl-a h' to get some help
版本太老 /*不支持A57 需源码编译
启动内核时会报错
rom: requested regions overlap (rom bootloader. free=0x000000004238ea00,
addr=0x0000000040000000)
qemu-system-aarch64: rom check and register reset failed
大概率是qemu版本问题。可考虑下载qemu源码,本地编译qemu二进制。
*/
- 源码编译qemu
https://www.qemu.org/download/ 下载最新的稳定版本 qemu-6.2.0-rc2.tar.xz
//注:翻墙下载,用在板子上直接下载太慢了 wget https://download.qemu.org/qemu-6.2.0-rc2.tar.xz
> scp qemu-6.2.0-rc2.tar.xz yhbd@192.168.10.237:/home/yhbd/bsp
$ cd ~/bsp
$ tar -xvf qemu-6.2.0-rc2.tar.xz
$ cd qemu-6.2.0-rc2
$ ./configure /* 配置,报错解决如下
报错:ERROR: Cannot find Ninja
解决:sudo apt-get install ninja-build
重运行./configure 还是会报很多错。
ERROR: Dependency "pixman-1" not found, tried pkgconfig
都是因为缺少软件,建议安装下面的
$ sudo apt-get install ninja-build
$ sudo apt-get install build-essential zlib1g-dev pkg-config libglib2.0-dev
$ sudo apt-get install binutils-dev libboost-all-dev autoconf libtool libssl-dev
$ sudo apt-get install libpixman-1-dev libpython-dev python-pip python-capstone virtualenv
看到下面的信息表示成功了
Subprojects
libvhost-user : YES
Found ninja-1.8.2 at /usr/bin/ninja
*/
$ make -j4 //4核并发编译,利用多核CPU并发能力
//最好用串口运行,因编译时间太长,而vscode ssh登录运行,容易超时退出。
//而且用串口运行,vscode 可以做别的事,相互不干扰
$ sudo make install
//查看版本,源码编译的,qemu它支持不同的硬件平台的虚拟,不仅是ARM
$ qemu-arm --version
qemu-arm version 6.2.92
Copyright (c) 2003-2021 Fabrice Bellard and the QEMU Project developers
$ qemu-riscv64 --version
qemu-riscv64 version 6.2.92
Copyright (c) 2003-2021 Fabrice Bellard and the QEMU Project developers
$ qemu-system-aarch64 -cpu help //查看machine支持的cpu类型,发现支持A57
cortex-a53
cortex-a57
cortex-a72