開發環境: Windows7 32 + VS2008 + WINDDK 7600.16385.1
開發目標: EFI Application for AMI BIOS UEFI SHELLx64
下載 EDK2
使用 TortoiseSVN 將 EDK II (http://www.tianocore.org/edk2/) 目錄下所有檔案全部下載。
EDK II 相關文件可以 http://www.tianocore.org/edk2/ 找到。
設定 EDK2
下載完成後, 編輯 Conf\target.txt,
尋找
ACTIVE_PLATFORM = Nt32Pkg/Nt32Pkg.dsc #Nt32Pkg 為 Windows EFI Application
修改成
ACTIVE_PLATFORM = DuetPkg/DuetPkgX64.dsc #UEFI BIOS Application
尋找
TARGET_ARCH = IA32
修改成
TARGET_ARCH = X64
執行 vs2008 x64 command prompt 環境, 切換到下載的 edk2 目錄
cd c:\edk2
執行環境設定
edksetup.bat
然後使用 build command 就可以 compiler 了。
build
compiler 建立的 .efi 檔,都會在 Build\DuetPkgX64\DEBUG_MYTOOLS\X64\ 目錄底下。
HelloEfi Sample Code
在畫面顯示 “HelloEfi” 字串的 sample code。
首先在 EDK2 目錄下建立 MyPkg\Application\HelloEfi 目錄。
在 HelloEfi 目錄下建立 HelloEfi.inf
## @file # Brief Description of UEFI HelloEfi # # Copyright for UEFI HelloEfi # # License for UEFI HelloEfi # ## [Defines] INF_VERSION = 0x00010005 BASE_NAME = HelloEfi FILE_GUID = E5ED0865-48BA-4D67-3333-54BF91DB2032 #自行create一個新的GUID MODULE_TYPE = UEFI_APPLICATION VERSION_STRING = 1.0 ENTRY_POINT = UefiMain # # The following information is for reference only and not # required by the build tools. # # VALID_ARCHITECTURES = IA32 X64 IPF EBC Etc... # [Sources] HelloEfi.c [Packages] MdePkg/MdePkg.dec [LibraryClasses] UefiApplicationEntryPoint UefiLib [Guids] [Ppis] [Protocols] [FeaturePcd] [Pcd]
在 HelloEfi 目錄下建立 HelloEfi.c
/** @file Brief Description of UEFI HelloEfi Detailed Description of UEFI HelloEfi Copyright for UEFI HelloEfi License for UEFI HelloEfi **/ #include <Uefi.h> #include <Library/UefiApplicationEntryPoint.h> #include <Library/UefiLib.h> /** as the real entry point for the application. @param[in] ImageHandle The firmware allocated handle for the EFI image. @param[in] SystemTable A pointer to the EFI System Table. @retval EFI_SUCCESS The entry point is executed successfully. @retval other Some error occurs when executing this entry point. **/ EFI_STATUS EFIAPI UefiMain ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { Print(L"HelloEfi"); return EFI_SUCCESS; }
接下來將 HelloEfi project 加入 DuetPkg 中, 這樣在 compiler 時才會 compiler 到 HelloEfi project。
編輯
DuetPkg\DuetPkgX64.dsc
將
MyPkg/Application/HelloEfi/HelloEfi.inf
加到
[Components]
區域, 再重新 build code 即可。
將 EfiShellX64.efi 與 Build\DuetPkgX64\DEBUG_MYTOOLS\X64\HelloEfi.efi 拷貝到隨身碟,在 BIOS 中選擇 Launch to EFI Shell,進入 EFI Shell 環境後執行 HelloEfi 即可看到畫面顯示 “HelloEfi” 的字串。
請問 Win8 64bit 可以建立 compile 環境嗎 ?
沒有試過 win8 64bit, 不過在 win7 64bit 下是可以的
下載完成後, 編輯 Conf\target.txt,
怪了 我看了conf 底下沒這個檔案 只有一個readme, 求助 ~~~
將 BaseTool\Conf 下 “build_rule.template”, “target.template”, “tools_def.template” copy 到 Conf 目錄, 並將三個檔案副檔名改成 .txt 。
另外, BaseTools\Bin 下缺少 Win32 compiler tool, 在 BaseTools\Bin 下建 Win32 子目錄, 使用 SVN 下載 https://svn.code.sf.net/p/edk2-toolbinaries/code/trunk/Win32 到 Win32 子目錄中。
還有 compiler 需要 nasm, 可以在 http://www.nasm.us 下載 (win32 / win64 版本), 解壓到 c:\nasm 目錄中。
好的 非常感謝哦!