前言
有的时候我们想调试linux kernel或者linux应用程序,但是又没有硬件环境,这个时候可以选择用模拟器的方法,模拟出一个硬件环境。
Android emulator
Android系统的模拟器叫Emulator,使用这个模拟器需要下载Android源代码,编译成功之后才能运行。由于编译Android源码还是需要一定的硬件配置,我尝试了没编译成功。
QEMU
QEMU是一个可以模拟ARM架构的开源软件,我们可以使用他来模拟vexpress-a9开发板,在上面搭建linux kernel运行环境。参考QEMU模拟vexpress-a9 搭建Linux kernel运行环境,成功的在ubuntu 16.04上模拟运行了linux kernel最小系统,这样就方便代码的调试学习了。
以下是kernel启动过程的打印:
neo@neo-virtual-machine:~/work/linux-4.14.7/arch/arm/boot/dts$ qemu-system-arm -M vexpress-a9 -m 512M -kernel ../zImage -dtb ./vexpress-v2p-ca9.dtb -nographic -append "root=/dev/mmcblk0 console=ttyAMA0 rw init=/linuxrc" -sd /home/neo/work/a9rootfs.ext3
WARNING: Image format was not specified for '/home/neo/work/a9rootfs.ext3' and probing guessed raw.
Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
Specify the 'raw' format explicitly to remove the restrictions.
pulseaudio: set_sink_input_volume() failed
pulseaudio: Reason: Invalid argument
pulseaudio: set_sink_input_mute() failed
pulseaudio: Reason: Invalid argument
Booting Linux on physical CPU 0x0
Linux version 4.14.7 (neo@neo-virtual-machine) (gcc version 5.4.0 20160609 (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.9)) #1 SMP Fri Jul 8 21:48:11 CST 2022
CPU: ARMv7 Processor [410fc090] revision 0 (ARMv7), cr=10c5387d
CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
OF: fdt: Machine model: V2P-CA9
Memory policy: Data cache writeback
CPU: All CPU(s) started in SVC mode.
percpu: Embedded 16 pages/cpu @9fbae000 s36428 r8192 d20916 u65536
Built 1 zonelists, mobility grouping on. Total pages: 130048
Kernel command line: root=/dev/mmcblk0 console=ttyAMA0 rw init=/linuxrc
log_buf_len individual max cpu contribution: 4096 bytes
log_buf_len total cpu_extra contributions: 12288 bytes
log_buf_len min size: 16384 bytes
log_buf_len: 32768 bytes
early log buf free: 14976(91%)
PID hash table entries: 2048 (order: 1, 8192 bytes)
Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
Memory: 509556K/524288K available (6144K kernel code, 402K rwdata, 1364K rodata, 1024K init, 169K bss, 14732K reserved, 0K cma-reserved)
Virtual kernel memory layout:
vector : 0xffff0000 - 0xffff1000 ( 4 kB)
fixmap