Professional Documents
Culture Documents
EDK2 環境建置
Write by @HaCoMaTaTa (Neil)
Windows
前置作業
Visual Studio
Python
Nasm
ASL Compiler
下載EDK2
EDK2 設定
編譯Base tool
修改target.txt檔案 (位於 )
編譯 Hello World
Conf\target.txt
Windows
前置作業
Visual Studio
1. 下載 Visual Studio Community (下載點)
@2022/05/12 官⽅使⽤版本為VS2019, 經筆者測試 VS2022 也可使⽤
EDK2 環境建置 1
2. 選擇下列元件後安裝
Python
1. 下載並安裝Python (下載點)
@2022/05/12 截⾄⽬前 官⽅建議Python 版本≥3.7
Nasm
1. 下載Nasm並安裝在 下 (下載點)
C:\nasm
ASL Compiler
1. 下載 (下載點)
@2022/05/12 EDK2官網⽂件
2. 解壓縮後放置 C:\ASL
EDK2 環境建置 2
下載EDK2
⽬前EDK2 的程式碼 Tianocore 都放到GitHub 上, 故須從GitHub 上下載
當中
b. 為主程式, 其餘
edk2-edk2-stable202111.zip submodule- 為必要模組, 全部下載下來
2. 全部解壓後 ,將 submodule- 解壓縮後的檔案移動到 覆蓋
edk2-edk2-stable202111
EDK2 環境建置 3
EDK2 設定
編譯Base tool
1. 打開 x64_x86_cross Tools Command Prompt
2. 打⼊下列指令編譯
# 假設
Source Code 放在
C:\edk2 下
C:\edk2> edksetup.bat Rebuild
# TARGET_ARCH List Optional What kind of architecture is the binary being target for.
# One, or more, of the following, IA32, IPF, X64, EBC, ARM
# or AArch64.
# Multiple values can be specified on a single line, using
# space characters to separate the values. These are used
# during the parsing of a platform description file,
# restricting the build output target(s.)
# The Build Target ARCH is determined by (precedence high to low):
EDK2 環境建置 4
# Command-line: -a ARCH option
# target.txt: TARGET_ARCH values
# DSC file: [Defines] SUPPORTED_ARCHITECTURES tag
# If not specified, then all valid architectures specified
# in the platform file, for which tools are available, will be
#
TARGET_ARCH = X64
# TAGNAME List Optional Specify the name(s) of the tools_def.txt TagName to use.
# If not specified, all applicable TagName tools will be
# used for the build. The list uses space character separation.
TOOL_CHAIN_TAG = VS2019
EDK2 環境建置 5
build -a X64 -p EmulatorPkg\EmulatorPkg.dsc
⚠ 如編譯時出現 以下錯誤
LINK : fatal error LNK1181: cannot open input file 'Gdi32.lib’
EDK2 環境建置 6
Qemu 虛擬機器上執⾏UEFI Shell
OVMF(Open Virtual Machine Firmware) 是使⽤於虛擬機上的UEFI韌體。EDK2提供了相應製作OVMF的⽅法
📝 前置作業 需先下載安裝
[ ] Qemu ( 連結)
1. 打⼊指令編譯OVMF
build -a X64 -p OvmfPkg\OvmfPkgX64.dsc
3. 在命令提⽰字元下,切換⾄QEMU⽬錄並打⼊下列指令
當中的 是當進⼊Shell 下時所模擬的硬碟,測試的檔案皆可放進此資料夾,路徑跟資料夾可隨意修改
D:\TMP_EDK2_Area
EDK2 環境建置 7
4. 執⾏畫⾯
EDK2 環境⾃動下載建置
透過Chocolatey⾃動下載安裝所需軟體,再使⽤git下載EDK2,最後編譯並執⾏Qemu
EDK2 環境建置 8
choco install --force -y visualstudio2019-workload-vctools git tortoisegit Python3 nasm wget 7zip qemu
wget -x --no-check-certificate https://acpica.org/sites/acpica/files/iasl-win-20200528.zip -O %temp%/iasl-win-20200528.zip
7z x %temp%\iasl-win-20200528.zip -oC:\ASL
del /f /q %temp%\iasl-win-20200528.zip
rem Environment Vars (like PATH) have changed. Close/reopen your shell to see the changes (or in powershell/cmd.exe just type `
refreshenv`).
refreshenv
pause
4. 編譯 Qemu Package
@echo off
:: NASM path
set NASM_PREFIX="C:\Program Files\NASM\"
5. 執⾏Qemu
@echo off
:: File of QEMU
set QEMU_PATH="c:\Program Files\qemu\qemu-system-x86_64.exe"
:: Set Location That storage Test File
set QEMU_HDD_AREA=C:\TMP_EDK2_Area
set QEMU_CPU_MODEL=Skylake-Client-v4
EDK2 環境建置 9
mkdir %QEMU_HDD_AREA%
%QEMU_PATH% -machine q35 -cpu %QEMU_CPU_MODEL% ^
-vga cirrus -m 256M -serial stdio -pflash %OVMF_PATH% ^
-hda fat:rw:%QEMU_HDD_AREA% -debugcon file:debug.log -global isa-debugcon.iobase=0x402 ^
-usb ^
-device usb-ehci,id=ehci ^
-device usb-kbd -device usb-mouse
資料蒐集
EDK2 編譯介紹(Windows)
在前⾯幾篇有介紹過如何在 Ubuntu 下建置 edk2 的環境,這⼀篇就來介紹如何在 Windows 下建置 edk2 吧。
https://damn99.com/2020-06-24-edk2-build-introduction-at-windows/
Linux
🚧 施⼯中
參考資料
官⽅ EDK2 GitHub
GitHub - tianocore/edk2: EDK II
A modern, feature-rich, cross-platform firmware development environment for the UEFI and PI specifications
from www.uefi.org. More CI Build information - EmulatorPkg Ubuntu GCC5 Segfaults during execution. -
EmulatorPkg Ubuntu GCC5 Segfaults during execution. More ArmVirtPkg CI Build Information More
https://github.com/tianocore/edk2
官⽅ Windows 建置EDK2 步驟
Windows systems · tianocore/tianocore.github.io Wiki
You can't perform that action at this time. You signed in with another tab or window. You signed out in
another tab or window. Reload to refresh your session. Reload to refresh your session.
https://github.com/tianocore/tianocore.github.io/wiki/Windows-systems
官⽅OVMF 建置與執⾏
EDK2 環境建置 10
How to run OVMF · tianocore/tianocore.github.io Wiki
You can't perform that action at this time. You signed in with another tab or window. You signed out in
another tab or window. Reload to refresh your session. Reload to refresh your session.
https://github.com/tianocore/tianocore.github.io/wiki/How-to-run-OVMF
詳細的建置步驟
UEFI 开发历程1-edk2开发环境的搭建以及在虚拟机QEMU运⾏OVMF固件_⼀个平凡的学徒的博客-CSDN博客_edk2开发
1、下载Visual Studio,打开Visual Studio Installer,选择Comunity版本,⼯作负载的选择如图1-1所⽰,安装。 图1-1 备注:重新安装时
如需更换如图1-2的下载地址,步骤如下: (1)Win+R键。 (2)输⼊"regedit"进⼊注册表。 (3)打开⽬录
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\Setup (4)在如图1-3所⽰处,更改其中的路径值或删除项。 图 1-2 图
https://blog.csdn.net/qq_40945626/article/details/121460583
Ubuntu
EDK2 編譯介紹
介紹如何 在 Ubuntu 18.04 環境下編譯 EDK2 UEFI BIOS
https://damn99.com/2020-05-14-edk2-build-introduction/
編譯OVMF
Step to UEFI (68 ) - 编译⼀个能在 QEMU 上跑的BIOS - WWW.LAB-Z.COM
最近在看 《UEFI 原理与编程》,上⾯提到⼀款虚拟机可以运⾏指定的BIOS,那就是 QEMU (之前我也研究过
如何替换 VirtualBox 的BIOS,结果⾮常沮丧,他不⽀持独⽴的 BIOS ,这意味即便是要在ASL中修改⼀些代码
也要花费⼏个⼩时重新编译整个VirtualBox)。 书中对于如何在QEMU中跑起来没有详述,我花了⼀点时间搞
https://www.lab-z.com/qemuovmf/
EDK2 環境建置 11