[分享] 開發 uefi 程式

作者: descent (「雄辯是銀,沉默是金」)   2016-04-10 16:25:47
讀過《UEFI 原理与程》後, 我終於有點概念了怎麼開發 uefi 程式。 需要對 .dsc,
.dec, .inf 有點概念, 《UEFI 原理与程》第三章在講這個, 請自行參閱, 書上有的東西
我就不重複了。
env:
linux/debian
X64
gcc
安裝所需要的開發套件:
apt-get install build-essential subversion uuid-dev iasl nasm
要先搞定 edk2, 這是 uefi 開發工具。
git clone https://github.com/tianocore/edk2.git
編譯 edk2 工具:
make -C BaseTools/
設定環境變數
. edksetup.sh
修改 Conf/target.txt
TARGET_ARCH = X64
TOOL_CHAIN_TAG = GCC49
雖然我選的是 GCC49, 不過其實我系統中的 gcc 是 5.3。
開始編譯 edk2 的程式
build -p OvmfPkg/OvmfPkgX64.dsc
build -p MdeModulePkg/MdeModulePkg.dsc
build -p AppPkg/AppPkg.dsc
build 相當於 make, 啟動後就會開始一系列的 gcc/ld 命令。
編譯出來的檔案在
edk2/Build
ex:
Build/OvmfX64/DEBUG_GCC49/FV/OVMF.fd
這個可以用 qemu 來跑, 模擬 uefi。
qemu-system-x86_64 -fda dos622.img -bios OVMF.fd
MdeModulePkg 裡頭有個 Hello.efi 可以測試, AppPkg 有個 Main.efi 則是以 main 來
寫 uefi 程式的範例。
把這兩個檔案複製到 dos622.img, 用 qemu-system-x86_64 -fda dos622.img -bios
OVMF.fd 來測試。
( https://goo.gl/6FYHih )
Main.efi source code: edk2/MdeModulePkg/Application/HelloWorld/HelloWorld.c
Hello.efi: edk2/AppPkg/Applications/Hello/Hello.c
Main.efi: edk2/AppPkg/Applications/Main/Main.c
AppPkg obj 檔則是在
Build/AppPkg/DEBUG_GCC49/X64/StdLib/LibC/LibC/OUTPUT/
ex:
Build/AppPkg/DEBUG_GCC49/X64/StdLib/LibC/LibC/OUTPUT/Main/Main.obj
source code 檔案都告知了, 可以自行參閱, 不過還需要知道各種 uefi 程式種類, 一樣
在《UEFI 原理与程》。
ref:
Using EDK II with Native GCC ( https://goo.gl/paZ0oR )
Common instructions for Linux ( https://goo.gl/h40RHv )
How to build OVMF ( https://goo.gl/VThLbD )
// 本文使用 Blog2BBS 自動將Blog文章轉成縮址的BBS純文字 http://goo.gl/TZ4E17 //
blog 原文:
http://descent-incoming.blogspot.tw/2015/03/uefi-qemu.html
作者: nelson210   2016-04-11 10:13:00
感謝

Links booklink

Contact Us: admin [ a t ] ucptt.com