硬件环境:khadas vim2
软件环境:xvisor Hypervisor
目标:将xvisor porting到vim2单板,启动xvisor后创建linux虚拟机。
VIM2单板串口只需要将17/18/19号引脚与TTL GND/TXD/RXD引脚相连即可
打开串口程序PuTTY, 选择session Serial,设置端口COM6(参考设备管理器显示USB-SERIAL端口),设置波特率115200
cp gcc-linaro-5.5.0-2017.10-x86_64_aarch64-linux-gnu.tar /usr/local/arm;
cd /usr/local/arm;
tar xvf gcc-linaro-5.5.0-2017.10-x86_64_aarch64-linux-gnu.tar;
cd gcc-linaro-5.5.0-2017.10-x86_64_aarch64-linux-gnu/bin/
/* 增加环境变量 */
export PATH=$PATH:/usr/local/arm/gcc-linaro-5.5.0-2017.10-x86_64_aarch64-linux-gnu/bin/
sudo apt-get install uboot-tools
sudo apt-get install device-tree-compiler
/* 下载源码 */
git clone xVisor-source-code
/* 编译uvmm.bin,修改defvonfig后需要重新生成.config */
cd xvisor-master-V0.3.0
/* Set toolchain */
export PATH=$PATH:~/toolchain/gcc-linaro-5.5.0-2017.10-x86_64_aarch64-linux-gnu/bin
export CROSS_COMPILE=aarch64-linux-gnu-
/* make config */
make ARCH=arm generic-v8-defconfig
make
/* 将xVisor指定为内核,编译为uvmm.bin用于烧写到单板 */
mkimage -A arm64 -O linux -T kernel -C none -a 0x00080000 -e 0x00080000 -n Xvisor -d build/vmm.bin build/uvmm.bin
build目录生成uvmm.bin。
标准linux Image
/* 下载linux kernel源码 https://www.kernel.org/ */
git clone
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
/* Configure Linux in build directory */
cp arch/arm64/configs/defconfig arch/arm64/configs/tmp-virt-v8_defconfig
<xvisor_source_directory>/tests/common/scripts/update-linux-defconfig.sh -p arch/arm64/configs/tmp-virt-v8_defconfig -f <xvisor_source_directory>/tests/arm64/virt-v8/linux/linux_extra.config
make O=<linux_build_directory> ARCH=arm64 tmp-virt-v8_defconfig
/* Build Linux in build directory */
make O=<linux_build_directory> ARCH=arm64 CROSS_COMPILE="aarch64-linux-gnu-" Image dtbs
vim2 linux kernel
cd vim2-linux-4.9.232/
/* export cross compile path */
export PATH=$PATH:~/toolchain/gcc-linaro-5.5.0-2017.10-x86_64_aarch64-linux-gnu/bin
/* make config */
make ARCH=arm64 tmp-virt-v8_defconfig
/* make image */
make ARCH=arm64 CROSS_COMPILE="aarch64-linux-gnu-" Image dtbs
#生成arch/arm64/boot/Image
1. 编译rootfs
/* 拷贝busybox-1.31.1.tar到工作目录 */
tar -xvf busybox-1.31.1.tar
/* Set toolchain */
export PATH=$PATH:~/toolchain/gcc-linaro-5.5.0-2017.10-x86_64_aarch64-linux-gnu/bin
export CROSS_COMPILE=aarch64-linux-gnu-
/* Copy defconfig to busybox directory */
cp ../xvisor-master-V0.3.0/tests/common/busybox/busybox-1.31.1_defconfig .config
/* Configure Busybox source */
make oldconfig
/* Build Bustbox RootFS under _install */
make install
/* Populate the Busybox RootFS */
mkdir -p ./_install/etc/init.d
mkdir -p ./_install/dev
mkdir -p ./_install/proc
mkdir -p ./_install/sys
ln -sf /sbin/init ./_install/init
cp -f ../xvisor-master-V0.3.0/tests/common/busybox/fstab ./_install/etc/fstab
cp -f ../xvisor-master-V0.3.0/tests/common/busybox/rcS ./_install/etc/init.d/rcS
cp -f ../xvisor-master-V0.3.0/tests/common/busybox/motd ./_install/etc/motd
cp -f ../xvisor-master-V0.3.0/tests/common/busybox/logo_linux_clut224.ppm ./_install/etc/logo_linux_clut224.ppm
cp -f ../xvisor-master-V0.3.0/tests/common/busybox/logo_linux_vga16.ppm ./_install/etc/logo_linux_vga16.ppm
/* Create RootFS image */
cd ./_install; find ./ | cpio -o -H newc > ../rootfs.img; cd -
/* vim2.dtb用于启动xvisor初始化配置 */
cd xvisor-master-V0.3.0
dtc -I dts -O dtb -o ./vim2.dtb ./arch/arm/board/generic/vim2.dts
编译udisk
udisk.img包含basic firmware,linux Image以及rootfs.img。将前面编译的Vim2 Linux Image和rootfs.img拷贝到xvisor指定目录编译即可。
/* 编译basic firmware */
make -C tests/arm64/virt-v8/basic;
/* 编译udisk.img */
mkdir -p ./build/disk/tmp;
mkdir -p ./build/disk/system;
cp -f ./docs/banner/roman.txt ./build/disk/system/banner.txt;
cp -f ./docs/logo/xvisor_logo_name.ppm ./build/disk/system/logo.ppm;
mkdir -p ./build/disk/images/arm64/virt-v8;
dtc -q -I dts -O dtb -o ./build/disk/images/arm64/virt-v8-guest.dtb ./tests/arm64/virt-v8/virt-v8-guest.dts;
cp -f ./build/tests/arm64/virt-v8/basic/firmware.bin ./build/disk/images/arm64/virt-v8/firmware.bin;
cp -f ./tests/arm64/virt-v8/linux/nor_flash.list ./build/disk/images/arm64/virt-v8/nor_flash.list;
cp -f ./tests/arm64/virt-v8/linux/cmdlist ./build/disk/images/arm64/virt-v8/cmdlist;
cp -f ./tests/arm64/virt-v8/xscript/one_novgic_guest_virt-v8.xscript ./build/disk/boot.xscript;
/* copy vim2 linux Image to ramdisk */
cp -f <linux_build_directory>/arch/arm64/boot/Image ./build/disk/images/arm64/virt-v8/Image;
dtc -q -I dts -O dtb -o ./build/disk/images/arm64/virt-v8/virt-v8.dtb ./tests/arm64/virt-v8/linux/virt-v8.dts;
/* copy rootfs.img to ramdisk */
cp -f <busybox_rootfs_directo
ry>/rootfs.img ./build/disk/images/arm64/virt-v8/rootfs.img;
/* make ramdisk uboot format */
genext2fs -B 1024 -b 32768 -d ./build/disk ./build/disk.img;
mkimage -A arm64 -O linux -T ramdisk -a 0x00000000 -n "Xvisor Ramdisk" -d build/disk.img build/udisk.img;
使用fatload命令将uvmm.bin,vim2.dtb,udisk.img加载到内存指定地址,使用bootm方式从内存启动镜像,此方式单板重启后系统失效。
fatload mmc 0 0x200000 uvmm.bin;
fatload mmc 0 0x800000 vim2.dtb
fatload mmc 0 0x2000000 udisk.img;
bootm 0x200000 0x2000000 0x800000
Bootm之后系统进入xvisor命令行,在bootcmd中已经加入开机自动创建guest0虚拟机,使用guest list命令可以看到
/* Kick Guest0 for starting Basic Firmware */
XVisor# guest kick guest0
/* Bind to virtual UART */
XVisor# vserial bind guest0/uart0
/* Copy linux from NOR flash to RAM and start linux booting from RAM */
[guest0/uart0] basic# autoexec
/* (Note: "autoexec" is a short-cut command,The <xvisor_source_directory>/tests/arm64/virt-v8/linux/cmdlist
file which we have added to guest NOR flash contains set of commands for booting linux from NOR flash) */
// 系统启动linux虚拟机guest0成功。
// 使用esc+x+q快捷键可以从guest0命令行退出到xvisor命令行界面。