在Ubuntu18.04或者20.04下搭建edk2运行环境

在Ubuntu18.04或者20.04下搭建edk2运行环境

    • 首先更新apt源(注意使用对应版本的源)
    • 搭建ekd2环境
    • 编译
    • 编译运行环境

首先更新apt源(注意使用对应版本的源)

运行以下命令并向表头添加新的源地址:
sudo vim /etc/apt/sources.list

Ubuntu18.04源:
#阿里源
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
#163源
deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
#中科大源
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

Ubuntu20.04源:
#阿里源
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
#网易源
deb http://mirrors.163.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ focal-backports main restricted universe multiverse
#中科大源
deb https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

#更新完之后依次执行下面两条命令
1.apt-get update
2.apt-get upgrade
如果执行之后出现源不能更新的问题,到/etc/apt/sources.list.d 下删除对应的ppa源重新更新即可解决

搭建ekd2环境

1.下载edk2源码https://github.com/tianocore/edk2/releases/tag/vUDK2018
也可下载最新版edk2。(最好下载Linux下的.tar.gz类型的源码文件。)
2.安装NASM,用于编译汇编相关的代码:
sudo apt install nasm
3.安装用于编译asl code的工具:
sudo apt install iasl
4.安装OpenSSL* Crypto 库:https://github.com/openssl/openssl/archive/OpenSSL_1_1_0g.zip,下载解压至目录UDK2018\CryptoPkg\Library\OpensslLib,并命名为openssl
5.安装uuid库,编译basetools时需要用到
sudo apt install uuid-dev
6.构建必备软件包的信息列表
sudo apt install build-essential
7.安装gcc,python这里我使用了系统默认自带的gcc7.5与python2.7所以没有进行安装
8.安装make与git
sudo apt install make
sudo apt install git
可以使用git直接下载上面的源码
sudo git clone https://github.com/tianocore/edk2/releases/tag/vUDK2018
由于可能需要对文件进行读写,运行等操作所以需要用chmod对需要操作的文件加权也可以直接sudo chmod -R +777 vUDK2018

9.也可一步安装上面的软件
sudo apt-get install build-essential uuid-dev iasl git gcc-5 nasm make

编译

1.编译BaseTools. 打开terminal进入到你下载的源码的BaseTools目录下,依次执行:
make clean
make -C ./

2.编译完工具之后回到上一级目录即下载的ekd2源码文件夹下执行,生成配置文件
source edksetup.sh BaseTools

3.修改源码文件夹下的Conf文件夹里面配置文件
(1)编辑Conf/target.txt找到TOOL_CHAIN_TAG设置为GCC5
如下:
需设置 TOOL_CHAIN_TAG=GCC5

(2)编辑Conf\tools_def.txt找到与下面对应的然后修改路径为/usr/bin/如下:
DEFINE GCC5_IA32_PREFIX = /usr/bin/
DEFINE GCC5_X64_PREFIX = /usr/bin/

(3)可以编译一个.inf看看是否可以编译
build -a X64 -t GCC5 -p MdeModulePkg/MdeModulePkg.dsc -m MdeModulePkg/Application/HelloWorld/HelloWorld.inf

编译运行环境

1.编译uefi模拟器
build -a X64 -t GCC5 -p EmulatorPkg/EmulatorPkg.dsc
也可使用自带脚本EmulatorPkg/build.sh编译
EmulatorPkg/build.sh run -X64来运行模拟器

2.编译开放虚拟机固件OVMF(这里我选择编译X64架构版本的),在edk2路径下执行如下命令:
build -a X64 -t GCC5 -p OvmfPkg/OvmfPkgX64.dsc

3.安装qemu虚拟机
sudo apt-get install qemu

4.尝试运行虚拟机加载OVMF固件命令如下:
qemu-system-x86_64 -bios Build/OvmfX64/DEBUG_GCC5/FV/OVMF.fd -M pc -m 256 -cpu qemu64 -vga cirrus -name UEFI -boot order=dc

5.U盘加载eif文件运行ovmf可以使用lsblk查看u盘的路径和盘符修改-hda /dev/sdb1中的/dev/sdb1参数命令如下:
sudo qemu-system-x86_64 -bios Build/OvmfX64/DEBUG_GCC5/FV/OVMF.fd -M pc -m 256 -cpu qemu64 -vga cirrus -name UEFI -boot order=dc -hda /dev/sdb1 -serial stdio

6.可以按键盘的Ctrl+Alt组合键.从qemu界面退出。在terminal按Ctrl+c可以结束qemu。这样就可以在虚拟环境运行u盘中的.efi文件

本文作者为夏雨滴荷竹,原文链接为
https://blog.csdn.net/qq_44929785/article/details/109446225
转载需著名原文链接,谢谢。

你可能感兴趣的:(Linux,EDK2,bios)