Ubuntu搭建UEFI开发环境(虚拟盘FS0挂载)
1、Qemu常用参数
-pflash或者-bios,配置引导所需的BIOS ROM
//例:-pflash或者-bios,指定系统引导的BIOS ROM名为"OVMF.fd"
-pflash OVMF.fd
-bios OVMF.fd
-serial,配置BIOS ROM引导过程中Debug信息输出
//例:指定Debug输出为当前终端
-serial stdio
//例:指定Debug输出重定向到qemu.log文件
-serial stdio > qemu.log
-net,配置网络
//例:禁止网络
-net none
-hda ,配置挂载的硬盘
//例:文件夹映射
-hda fat:rw:Fs0Folder
//例:虚拟硬盘映射
-hda Fs0Disk.img
2、FS0挂载
//下述命令将通过文件夹"FS0Folder"映射的方式挂载一个虚拟硬盘、禁用网络、并将Debug信息输出到当前终端
qemu-system-x86_64 -pflash OVMF.fd -hda fat:rw:Fs0Folder -net none -serial stdio
3、自定义开发脚本
UEFI开发过程中,我们经常会写一些App Demo在模拟器上进行测试,这就需要我们把编译生成的App.efi手动拷贝到FS0对应的虚拟文件夹“FS0Folder”,然后再启动模拟器。为方便开发,自定义脚本在编译后直接将某一特定文件下的efi拷贝到虚拟文件夹“FS0Folder,后面直接启动模拟器挂载命令”
#/bin/bash
# build_qemu.sh init(编译BastTools)
# build_qemu.sh build(编译OvmfPkgX64)
# build_qemu.sh run(执行Qemu模拟器)
# build_qemu.sh clean(清除编译文件)
RESULT=$?
EDK2_TOOLCHAIN=GCC5
EDK2_ARCH=X64
EDK2_BUILD=DEBUG
EDK2_PLATFORM_PKG=OvmfPkg
EDK2_DSC=$EDK2_PLATFORM_PKG/OvmfPkgX64.dsc
FD_OUTPUT_DIR=Build/OvmfX64/${EDK2_BUILD}_${EDK2_TOOLCHAIN}/FV
FD_NAME=OVMF.fd
APP_OUTPUT_DIR=Build/OvmfX64/${EDK2_BUILD}_${EDK2_TOOLCHAIN}/$EDK2_ARCH/$EDK2_PLATFORM_PKG/Application/
function Usage() {
echo
echo "***************************************************************************"
echo
echo "Usage: build_qemu.sh [option]"
echo
echo " option: build"
echo " option: run"
echo " init"
echo " clean"
echo "!!!!!!Please do \"build_qemu.sh init\" before build! first!!!!!!"
echo "***************************************************************************"
exit 0
}
#Vritual Fs0 Disk
FS0_FOLDER=Fs0Folder
if [ ! -e $FS0_FOLDER ]; then
mkdir $FS0_FOLDER
fi
if [ "$1" == "init" ];then
echo "build basetools"
mkdir Conf
rm Conf/* -rf
cd BaseTools && make clean && cd ../
source edksetup.sh BaseTools
make -C BaseTools
chmod 777 BaseTools/BinWrappers/PosixLike/*
exit
elif [ "$1" == "build" ];then
echo "build OvmfPkgX64.dsc"
source edksetup.sh BaseTools
build -p $EDK2_DSC -a $EDK2_ARCH -t $EDK2_TOOLCHAIN -b $EDK2_BUILD
if [ $RESULT -eq 0 ];then
find $APP_OUTPUT_DIR -name "OUTPUT" -type d | xargs -i find {} -name "*.efi" |xargs -i cp {} $FS0_FOLDER
echo "===================================================="
echo " Build result: SUCCESS! "
echo "===================================================="
exit
else
echo "===================================================="
echo " Build result: FAILED!! "
echo "===================================================="
exit
fi
elif [ "$1" == "run" ];then
qemu-system-x86_64 -bios $FD_OUTPUT_DIR/$FD_NAME -hda fat:rw:$FS0_FOLDER -net none -serial stdio
#qemu-system-x86_64 -bios $FD_OUTPUT_DIR/$FD_NAME -net none -serial stdio
exit
elif [ "$1" == "clean" ];then
echo "make clean"
rm -rf Build
cd BaseTools && make clean && cd ../
exit
else
Usage
exit
fi
附录
//如下为笔者Edk开发Code Base,仅供参考
https://gitee.com/hostid/edk2_develop.git