cat /proc/version
Linux version 4.4.0-210-generic (buildd@lgw01-amd64-009) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.12) ) #242-Ubuntu SMP Fri Apr 16 09:57:56 UTC 2021
sudo apt-get install -y qemu-system
内核配置需要设置:CONFIG_BLK_DEV_RAM=y
编译内核后有个/arch/arm/boot/zImage
(这里举例,实际看SDK的路径)
file zImage
zImage: Linux kernel ARM boot executable zImage (little-endian)
具体看编译的内核版本,这里是stm32mp157的zImage
#include
#include
int main(int argc,char *argv[])
{
printf("this is the init program !\n");
while(1){
sleep(1);
}
return 0;
}
arm-none-linux-gnueabihf-gcc -o init init.c -static
chmod a+x init
#! /bin/sh
if [ $# -ne 2 ]
then
echo "usage: make_initramfs directory imagename.cpio.gz"
exit 1
fi
if [ -d "$1" ]
then
echo "creating $2 from $1"
(cd "$1"; find . | cpio -o -H newc | gzip) > "$2"
else
echo "First argument must be a directory"
exit 1
fi
不一定要制作最小文件系统,可以使用其他SDK自带的文件系统或自己做的文件系统,
这里仅为测试模拟器启动内核使用。
mkdir rootfs
cp init rootfs
chmod a+x make_initramfs.sh
./make_initramfs.sh rootfs initramfs.cpio.gz
输出:
./make_initramfs.sh rootfs initramfs.cpio.gz
creating initramfs.cpio.gz from rootfs
8004 块
#! /bin/bash
qemu-system-arm \
-machine virt \
-nographic \
-smp 4 \
-m 2048 \
-kernel zImage \
-append "root=/dev/ram0 rootfstype=ramfs rw init=/init" \
-initrd initramfs.cpio.gz
qemu-system-arm
是32位的模拟器,qemu-system-aarch64
是64位的模拟器
chmod a+x launch.sh
./launch.sh
现象:
./launch.sh
[ 0.000000] Booting Linux on physical CPU 0x0
[ 0.000000] Linux version 5.4.31-g15a9baf-dirty (z@z-server) (gcc version 9.2.1 20191025 (GNU Toolchain for the A-profile Architecture 9.2-2019.12 (arm-9.10))) #17 SMP PREEMPT Tue Feb 28 23:07:01 CST 2023
[ 0.000000] CPU: ARMv7 Processor [412fc0f1] revision 1 (ARMv7), cr=10c5387d
[ 0.000000] CPU: div instructions available: patching division code
[ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, PIPT instruction cache
[ 0.000000] OF: fdt: Machine model: linux,dummy-virt
[ 0.000000] Memory policy: Data cache writealloc
[ 0.000000] cma: Reserved 128 MiB at 0xb8000000
[ 0.000000] ------------[ cut here ]------------
[ 0.000000] WARNING: CPU: 0 PID: 0 at arch/arm/kernel/devtree.c:148 arm_dt_init_cpu_maps+0x1c0/0x2b8
[ 0.000000] DT /cpu 3 nodes greater than max cores 2, capping them
[ 0.000000] Modules linked in:
[ 0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 5.4.31-g15a9baf-dirty #17
[ 0.000000] Hardware name: Generic DT based system
[ 0.000000] [<c0112518>] (unwind_backtrace) from [<c010d7a0>] (show_stack+0x10/0x14)
[ 0.000000] [<c010d7a0>] (show_stack) from [<c0caffd4>] (dump_stack+0xb0/0xc4)
[ 0.000000] [<c0caffd4>] (dump_stack) from [<c0125a8c>] (__warn+0xd0/0xf8)
[ 0.000000] [<c0125a8c>] (__warn) from [<c0125e68>] (warn_slowpath_fmt+0x98/0xc4)
[ 0.000000] [<c0125e68>] (warn_slowpath_fmt) from [<c11053e0>] (arm_dt_init_cpu_maps+0x1c0/0x2b8)
[ 0.000000] [<c11053e0>] (arm_dt_init_cpu_maps) from [<c1104a18>] (setup_arch+0x398/0x5f4)
[ 0.000000] [<c1104a18>] (setup_arch) from [<c1100ac4>] (start_kernel+0x70/0x4f4)
[ 0.000000] [<c1100ac4>] (start_kernel) from [<00000000>] (0x0)
[ 0.000000] random: get_random_bytes called from print_oops_end_marker+0x24/0x4c with crng_init=0
[ 0.000000] ---[ end trace 0000000000000000 ]---
[ 0.000000] psci: probing for conduit method from DT.
[ 0.000000] psci: PSCIv0.2 detected in firmware.
[ 0.000000] psci: Using standard PSCI v0.2 function IDs
[ 0.000000] psci: Trusted OS migration not required
[ 0.000000] percpu: Embedded 20 pages/cpu s50124 r8192 d23604 u81920
[ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 522560
[ 0.000000] Kernel command line: root=/dev/ram0 rootfstype=ramfs rw init=/init
[ 0.000000] Dentry cache hash table entries: 131072 (order: 7, 524288 bytes, linear)
[ 0.000000] Inode-cache hash table entries: 65536 (order: 6, 262144 bytes, linear)
[ 0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[ 0.000000] Memory: 1926280K/2097152K available (12288K kernel code, 991K rwdata, 3720K rodata, 1024K init, 230K bss, 39800K reserved, 131072K cma-reserved, 1179648K highmem)
[ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=2, Nodes=1
[ 0.000000] rcu: Preemptible hierarchical RCU implementation.
[ 0.000000] rcu: RCU event tracing is enabled.
[ 0.000000] Tasks RCU enabled.
[ 0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 10 jiffies.
[ 0.000000] NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
[ 0.000000] arch_timer: WARNING: Invalid trigger for IRQ18, assuming level low
[ 0.000000] arch_timer: WARNING: Please fix your firmware
[ 0.000000] arch_timer: cp15 timer(s) running at 62.50MHz (virt).
[ 0.000000] clocksource: arch_sys_counter: mask: 0xffffffffffffff max_cycles: 0x1cd42e208c, max_idle_ns: 881590405314 ns
[ 0.000115] sched_clock: 56 bits at 62MHz, resolution 16ns, wraps every 4398046511096ns
[ 0.000246] Switching to timer-based delay loop, resolution 16ns
[ 0.002956] Console: colour dummy device 80x30
[ 0.005429] printk: console [tty0] enabled
[ 0.006322] Calibrating delay loop (skipped), value calculated using timer frequency.. 125.00 BogoMIPS (lpj=625000)
[ 0.006510] pid_max: default: 32768 minimum: 301
[ 0.007511] Mount-cache hash table entries: 2048 (order: 1, 8192 bytes, linear)
[ 0.007628] Mountpoint-cache hash table entries: 2048 (order: 1, 8192 bytes, linear)
[ 0.022366] CPU: Testing write buffer coherency: ok
[ 0.023191] CPU0: Spectre v2: firmware did not set auxiliary control register IBE bit, system vulnerable
[ 0.030746] /cpus/cpu@0 missing clock-frequency property
[ 0.030894] /cpus/cpu@1 missing clock-frequency property
[ 0.031946] CPU0: thread -1, cpu 0, socket 0, mpidr 80000000
[ 0.094502] Setting up static identity map for 0x40100000 - 0x40100060
[ 0.114051] rcu: Hierarchical SRCU implementation.
[ 0.165573] smp: Bringing up secondary CPUs ...
[ 0.228010] CPU1: thread -1, cpu 1, socket 0, mpidr 80000001
[ 0.228063] CPU1: Spectre v2: firmware did not set auxiliary control register IBE bit, system vulnerable
[ 0.230552] smp: Brought up 1 node, 2 CPUs
[ 0.230654] SMP: Total of 2 processors activated (250.00 BogoMIPS).
[ 0.230730] CPU: All CPU(s) started in SVC mode.
[ 0.241460] devtmpfs: initialized
[ 0.264139] VFP support v0.3: implementor 41 architecture 4 part 30 variant f rev 0
[ 0.282654] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[ 0.283102] futex hash table entries: 512 (order: 3, 32768 bytes, linear)
[ 0.293780] pinctrl core: initialized pinctrl subsystem
[ 0.313256] NET: Registered protocol family 16
[ 0.340541] DMA: preallocated 256 KiB pool for atomic coherent allocations
[ 0.345046] hw-breakpoint: CPU 0 debug is powered down!
[ 0.346788] Serial: AMBA PL011 UART driver
[ 0.371666] 9000000.pl011: ttyAMA0 at MMIO 0x9000000 (irq = 53, base_baud = 0) is a PL011 rev1
[ 0.389310] printk: console [ttyAMA0] enabled
[ 0.397314] irq: type mismatch, failed to map hwirq-27 for intc!
[ 0.524816] SCSI subsystem initialized
......
[ 9.838098] rtc-pl031 9010000.pl031: setting system clock to 2023-03-01T13:39:38 UTC (1677677978)
[ 9.839363] cfg80211: Loading compiled-in X.509 certificates for regulatory database
[ 9.843574] cfg80211: Loaded X.509 cert 'sforshee: 00b28ddf47aef9cea7'
[ 9.845237] platform regulatory.0: Direct firmware load for regulatory.db failed with error -2
[ 9.845726] cfg80211: failed to load regulatory.db
[ 9.846588] ALSA device list:
[ 9.846798] No soundcards found.
[ 9.849699] uart-pl011 9000000.pl011: no DMA platform data
[ 10.040005] Freeing unused kernel memory: 1024K
[ 10.135443] Run /init as init process
this is the init program !
qemu-system-arm -machine help
Supported machines are:
akita Sharp SL-C1000 (Akita) PDA (PXA270)
borzoi Sharp SL-C3100 (Borzoi) PDA (PXA270)
canon-a1100 Canon PowerShot A1100 IS
cheetah Palm Tungsten|E aka. Cheetah PDA (OMAP310)
collie Sharp SL-5500 (Collie) PDA (SA-1110)
connex Gumstix Connex (PXA255)
cubieboard cubietech cubieboard
highbank Calxeda Highbank (ECX-1000)
imx25-pdk ARM i.MX25 PDK board (ARM926)
integratorcp ARM Integrator/CP (ARM926EJ-S)
kzm ARM KZM Emulation Baseboard (ARM1136)
lm3s6965evb Stellaris LM3S6965EVB
lm3s811evb Stellaris LM3S811EVB
mainstone Mainstone II (PXA27x)
midway Calxeda Midway (ECX-2000)
musicpal Marvell 88w8618 / MusicPal (ARM926EJ-S)
n800 Nokia N800 tablet aka. RX-34 (OMAP2420)
n810 Nokia N810 tablet aka. RX-44 (OMAP2420)
netduino2 Netduino 2 Machine
none empty machine
nuri Samsung NURI board (Exynos4210)
realview-eb ARM RealView Emulation Baseboard (ARM926EJ-S)
realview-eb-mpcore ARM RealView Emulation Baseboard (ARM11MPCore)
realview-pb-a8 ARM RealView Platform Baseboard for Cortex-A8
realview-pbx-a9 ARM RealView Platform Baseboard Explore for Cortex-A9
smdkc210 Samsung SMDKC210 board (Exynos4210)
spitz Sharp SL-C3000 (Spitz) PDA (PXA270)
sx1 Siemens SX1 (OMAP310) V2
sx1-v1 Siemens SX1 (OMAP310) V1
terrier Sharp SL-C3200 (Terrier) PDA (PXA270)
tosa Sharp SL-6000 (Tosa) PDA (PXA255)
verdex Gumstix Verdex (PXA270)
versatileab ARM Versatile/AB (ARM926EJ-S)
versatilepb ARM Versatile/PB (ARM926EJ-S)
vexpress-a15 ARM Versatile Express for Cortex-A15
vexpress-a9 ARM Versatile Express for Cortex-A9
virt ARM Virtual Machine
xilinx-zynq-a9 Xilinx Zynq Platform Baseboard for Cortex-A9
z2 Zipit Z2 (PXA27x)
qemu-system-arm -smp help
qemu-system-arm: -smp help: Parameter 'cpus' expects a number
qemu-system-arm -m help
qemu-system-arm: -m help: Parameter 'size' expects a size
You may use k, M, G or T suffixes for kilobytes, megabytes, gigabytes and terabytes.
-kernel bzImage
Use bzImage as kernel image. The kernel can be either a Linux kernel or in multiboot format.
-initrd file
Use file as initial ram disk.
-append cmdline
Use cmdline as kernel command line
-S Do not start CPU at startup (you must type 'c' in the monitor).
-s Shorthand for -gdb tcp::1234, i.e. open a gdbserver on TCP port 1234.
更多参数查看
man qemu-system-arm