需要事先自己编译 qemu-system-arm 可执行文件;
1,编译创建ARM 虚拟机
1.1 一起从头开始版
cd 进一个空文件夹,然后
$ vim buildup.sh
$ bash buildup.sh
访问github网络没什么问题:
硬编码了一个路径/home/hipper/ex_vexpress/ 两处,
改成自己的当前路径即可,懒得改了,见谅见笑了 ^^
#!/usr/bin/bash
mkdir workspace
cd workspace
git clone https://github.com/qemu/qemu.git
cd qemu/
git checkout v9.0.0
mkdir build_arm/
cd ./build_arm/
../configure --target-list="arm-softmmu,arm-linux-user" --prefix=/home/hipper/ex_vexpress/workspace/qemu-bin-arm/
make -j
make install
cd ../../
sudo ls
sudo apt-get install gcc-arm-linux-gnueabi
wget https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-5.10.tar.gz
tar zxf linux-kernel-v5.10.tar.gz
cd linux-5.10/
make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm vexpress_defconfig
make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm -j
cd ../
wget https://ftp.denx.de/pub/u-boot/u-boot-2020.10.tar.bz2
tar xf u-boot-2020.10.tar.bz2
cd u-boot-2020.10/
make vexpress_ca9x4_defconfig
make CROSS_COMPILE=arm-linux-gnueabi- all
cd ../
wget https://busybox.net/downloads/busybox-1.36.0.tar.bz2
tar xf busybox-1.36.0.tar.bz2
cd busybox-1.36.0/
make defconfig
make CROSS_COMPILE=arm-linux-gnueabi-
make install CROSS_COMPILE=arm-linux-gnueabi-
cd ../
mkdir -p rootfs/{dev,etc/init.d,lib,proc,sys,root,home}
sudo cp busybox-1.36.0/_install/* -r rootfs/
sudo cp -P /usr/arm-linux-gnueabi/lib/* rootfs/lib/
sudo mknod rootfs/dev/tty1 c 4 1 && sudo mknod rootfs/dev/tty2 c 4 2 && sudo mknod rootfs/dev/tty3 c 4 3 && sudo mknod rootfs/dev/tty4 c 4 4
dd if=/dev/zero of=a9rootfs.ext3 bs=1M count=1024
mkfs.ext3 a9rootfs.ext3
sudo mkdir tmpfs && sudo mount -t ext3 a9rootfs.ext3 tmpfs/ -o loop && sudo cp -r rootfs/* tmpfs/ && sudo umount tmpfs
/home/hipper/ex_vexpress/workspace/qemu-bin-arm/bin/qemu-system-arm -M vexpress-a9 -m 512M \
-kernel ./linux-5.10/arch/arm/boot/zImage \
-dtb ./linux-5.10/arch/arm/boot/dts/vexpress-v2p-ca9.dtb \
-nographic -append "root=/dev/mmcblk0 console=ttyAMA0" -sd a9rootfs.ext3
运行效果:
1.2 如果系统中已经安装了qemu-system-arm
$ vim buildup_haveqemuarm.sh
$ bash ./buildup_haveqemuarm.sh
其中:
buildup_haveqemuarm.sh:
bash
#!/usr/bin/bash
sudo ls
sudo apt-get install gcc-arm-linux-gnueabi
mkdir workspace
cd workspace/
wget https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-5.10.tar.gz
tar zxf linux-5.10.tar.gz
cd linux-5.10/
make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm vexpress_defconfig
make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm -j
cd ../
wget https://ftp.denx.de/pub/u-boot/u-boot-2020.10.tar.bz2
tar xf u-boot-2020.10.tar.bz2
cd u-boot-2020.10/
make vexpress_ca9x4_defconfig
make CROSS_COMPILE=arm-linux-gnueabi- all
cd ../
wget https://busybox.net/downloads/busybox-1.36.0.tar.bz2
tar xf busybox-1.36.0.tar.bz2
cd busybox-1.36.0/
make defconfig
make CROSS_COMPILE=arm-linux-gnueabi-
make install CROSS_COMPILE=arm-linux-gnueabi-
cd ../
mkdir -p rootfs/{dev,etc/init.d,lib,proc,sys,root,home}
sudo cp busybox-1.36.0/_install/* -r rootfs/
sudo cp -P /usr/arm-linux-gnueabi/lib/* rootfs/lib/
sudo mknod rootfs/dev/tty1 c 4 1 && sudo mknod rootfs/dev/tty2 c 4 2 && sudo mknod rootfs/dev/tty3 c 4 3 && sudo mknod rootfs/dev/tty4 c 4 4
dd if=/dev/zero of=a9rootfs.ext3 bs=1M count=1024
mkfs.ext3 a9rootfs.ext3
sudo mkdir tmpfs && sudo mount -t ext3 a9rootfs.ext3 tmpfs/ -o loop && sudo cp -r rootfs/* tmpfs/ && sudo umount tmpfs
qemu-system-arm -M vexpress-a9 -m 512M -kernel ./linux-5.10/arch/arm/boot/zImage -dtb ./linux-5.10/arch/arm/boot/dts/vexpress-v2p-ca9.dtb -nographic -append "root=/dev/mmcblk0 console=ttyAMA0" -sd a9rootfs.ext3
启动后的虚拟机:
2, 编译新的可执行文件
vim ../ex/hello.c
cpp
#include <stdio.h>
int main()
{
printf("Hello Test Kernel ll\n");
return 0;
}
3,在虚拟机中添加新的可执行文件
cp ../ex/hello busybox-1.36.0/_install/bin/
然后执行 update_exe_arm.sh:
bash
rm -rf a9rootfs.ext3
sudo rm rootfs/* -rf
mkdir -p rootfs/{dev,etc/init.d,lib,proc,sys,root,home}
sudo cp busybox-1.36.0/_install/* -r rootfs/
sudo cp -P /usr/arm-linux-gnueabi/lib/* rootfs/lib/
sudo mknod rootfs/dev/tty1 c 4 1 && sudo mknod rootfs/dev/tty2 c 4 2 && sudo mknod rootfs/dev/tty3 c 4 3 && sudo mknod rootfs/dev/tty4 c 4 4
dd if=/dev/zero of=a9rootfs.ext3 bs=1M count=1024
mkfs.ext3 a9rootfs.ext3
rm -rf tmpfs/
sudo mkdir tmpfs && sudo mount -t ext3 a9rootfs.ext3 tmpfs/ -o loop && sudo cp -r rootfs/* tmpfs/ && sudo umount tmpfs
/home/hipper/ex_systemc_qemu/qemu-bin-v9-arm/bin/qemu-system-arm -M vexpress-a9 -m 512M -kernel ./linux-5.10/arch/arm/boot/zImage -dtb ./linux-5.10/arch/arm/boot/dts/vexpress-v2p-ca9.dtb -nographic -append "root=/dev/mmcblk0 console=ttyAMA0" -sd a9rootfs.ext3
虚拟机中执行hello;