Setting up a EDK II build environment on Windows and Linux:搭建Windows和Linux開發環境[2.2]
2015-07 北京海淀區 張俊浩
2. Setting Up EDKII Development Environment(EDKII開發環境的搭建)
->2.1The General Procedure Of Setting Up EDKII Development Environment(搭建EDKII項目的通用流程)
->2.2 Setting up a EDK II build environment on Windows and Linux(搭建Windows和Linux開發環境)
->2.2.1 Setting up a EDK II build environment on Windows
->2.2.1.1 Get the EDKII Source EDKII源碼獲取(下載)。
->2.2.1.2 Install some third-party tools to build EDKII.相應開發工具鏈的下載。
->2.2.2 Setting up a EDK II build environment on Linux
->2.2.2.1 Get the EDKII Source EDKII源碼獲取(下載)。
->2.2.2.2 Install some third-party tools to build EDKII.相應開發工具鏈的下載。
->2.3 Tools:Installing and using the Required Tools for downloading and Building EDKII.
->2.3.1 Download and Install TortoiseSVN to obtain the EDK II(下載/安裝/使用TortoiseSVN工具)
發現無論照《EDKII_UserManual_0_7》手冊(或者說http://www.tianocore.org官網上Getting Started for Developers—>Getting Started with EDK II->Step-by-step Instructions),還是戴正華《UEFI原理與編程》都不能較爲順利的搭建Linux和Windows開發環境。
原因有兩個:(1)一些工具源的下載路徑隨着時間的推移發生了變化(通過文檔/書籍上的路徑檢索不到資源)(2)對工程源碼管理工具、編譯工具的安裝、使用不熟悉(而文檔/書籍裏面默認是不做具體介紹的)。
但瞭解EDKII開發環境搭建的一般框架和流程(上一篇博客:The General Procedure Of Setting Up EDKII Development Environment搭建EDKII項目的通用流程[2.1]),再加上參考http://www.tianocore.org官網上Getting Started for Developers—>Getting Started with EDK II->Step-by-step Instructions->Windows systems/Using EDK II with Native GCC的步驟引導,我們應該可以較爲順利的搭建EDKII的Windows和Linux開發環境。
無論是我們獲取源碼,還是編譯EDKII項目源碼,都需要第三方工具Third-Party Tools. (Getting and Installing the Required Tools for downloading and Building EDK II.)參照TianoCore官網上(http://www.tianocore.org) Getting Started for Developers->Getting Started with EDK II->Tools->follow these instructions來下載安裝第三方工具Third-Party Tools。
根據TianoCore官網上,對開發工具鏈的要求,http://www.tianocore.org->Getting Started for Developers -> Getting Started with EDK II->Tools -> follow these instructions ->Install some external tools->Third Party Tools:要求我們需要第三方工具包括:c預處理器、c編譯器、靜態鏈接器、動態連接器、彙編器、彙編連接器、ACPI彙編器。(3rdParty Tools must include: a C pre-processor, C compiler, static linker, dynamic linker, and an assembler and assembly linker. For creating ACPI tables required by platforms, an ACPI assembler is also required.)
2.2.1 Setting up a EDK II build environment on Windows(搭建Windows EDKII開發環境)
2.2.1.1 Get the EDKII Source EDKII源碼獲取(下載)。
Windows平臺下我們一般使用subversion來管控項目源碼版本,通過SVN(subversion)下載上傳源碼,所以我們想獲取源碼,首先需要下載、安裝SVN軟件,然後通過SVN獲取SVN代理服務器上的EDKII源碼,具體詳細過程參看下一篇博文《Tools:Installing and using the Required Tools for downloading and Building EDK II工具篇:安裝/使用EDKII源碼獲取/編譯工具[2.3]》
2.2.1.2 Install some third-party tools to build EDKII.相應開發工具鏈的下載。
根據TianoCore官網上,對開發工具鏈的要求,http://www.tianocore.org->Getting Started for Developers -> Getting Started with EDK II->Tools -> follow these instructions ->Install some external tools->Third Party Tools:要安裝以下其中(表格由於篇幅原因有刪減)至少一個編譯工具鏈(At least one of the following 3rd party compiler tool chain is required),在Windows平臺下我們通常採用的集成開發環境Microsoft Visual Studio。
Name |
Version |
URL |
Microsoft Visual Studio |
2005 Professional |
|
Microsoft Visual Studio |
2005 Team Suite |
|
Microsoft Visual Studio |
2003 .NET |
|
Intel C++ Compiler for Windows |
9.1 |
|
Intel C Compiler for EFI Byte Code |
1.2 |
http://www.intel.com/cd/software/products/asmo-na/eng/compilers/efibc/index.htm |
Microsoft ACPI Source Language Assembler |
3.0.0NT or later |
http://www.microsoft.com/whdc/system/pnppwr/powermgmt/default.mspx |
當我們點擊Microsoft Visual Studio2005 Professional鏈接時進入Visual Studio官網,發現官網的Visual Studio鏡像下載版本是相對較新的版本Visual Studio2013(2015-07月份),而其他版本的Visual Studio鏡像,在官網很難找到。
若直接點擊官網Visual Studio2013鏈接直接下載Visual Studio2013也可以(需要用郵箱先註冊微軟賬號),但這樣下載即便是在網速較佳的情況下,下載和安裝時常也得以小時單位,數小時計,着實讓人着急。
推薦另外的一個MSDN(Microsoft Developper Network,微軟開發網絡)網站:http://www.itellyou.cn/。(“MSDN,itellyou”是一個國內工程師搭建的專門收集MSDN資源的網站,是一個十分優秀的資源網站)。從上面“開發人員工具”,可以很方便的下載到以往各個版本的Visual Studio工具,本博文版本選擇Visual Studio2013下的Visual Studio Ultimate 2013 (x86) - DVD (English)(2.82GB)。在網速較快的環境下,下載很快,安裝也需要小時計,但比Visual Studio官網時間要短得多。
安裝Visual Studio Ultimate 2013 (x86) 軟件時,建議安裝在系統盤C盤,
剛開始對源碼項目不太熟悉,路徑衝突也不知道去哪修改,比如會出現如下錯誤:“Cannot open include file: 'windows.h': No such file or directory”
d:\edk2\Nt32Pkg\Include\Common/WinNtInclude.h(54) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
NMAKE : fatal error U1077: '"D:\Program Files (x86)\Microsoft Visual Studio 12.0\VC \bin\ cl.exe"' : return code '0x2'
Stop.
build...
: error 7000: Failed to execute command
D:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\nmake.exe /nologo tbuild
將Microsoft Visual Studio 2013從D盤卸載後(卸載Visual Studio 13也是一個“大工程”,大概半小時左右,筆記本CPUI5-3337U處理器,1.8G主頻),重新安裝C盤C:\Program Files (x86)\Microsoft Visual Studio 13.0\,沒有再出現“ Cannot open include file: 'windows.h': No such file or directory,error 7000: Failed to execute command”錯誤。
而且當安裝不同Visual Studio版本,或者說在不同Visual Studio切換,尤其是卸載高版本的Visual Studio轉而安裝低版本的Visual Studio,會出現高版本Visual Studio無法安裝問題,比如高版本的.net框架存在,無法安裝低版本的.net框架,Microsoft VisualC++ 2010已經安裝也會導致新的.NET Framework無法安裝。“>LINK : fatal error LNK1123: 轉換到 COFF 期間失敗: 文件無效或損壞”。問題說明:當安裝VS2013之後,原來的.NET 4.0會被替換爲.NET 4.5。卸載VS2013時,不會恢復.NET 4.0。通過控制面板“卸載或者更改程序”(Uninstall or change a program)找到相應的Microsoft VisualC++ 2010程序進行卸載即可繼續安裝。
這樣我們通過安裝SVN下載EDKII源碼,安裝Visual Studio 2013、IASL完成了Windows開發環境的搭建,在《EDKII Build Process-EDKII項目源碼的配置、編譯流程[3]》配置、編譯EDKII源碼來檢驗EDKII項目Windows開發環境是否搭建成功。
2.2.2 Setting up a EDK II build environment on Linux(搭建Linux EDKII開發環境)
2.2.2.1 Get the EDKII Source EDKII源碼獲取(下載)。
Linux環境下我們可以用git、svn項目源碼版本來下載、同步EDKII源碼。本篇博文Linux環境採用的VMware(Virtual Machine ware)的方式,Linux系統爲Ubuntu12.0。
另外,不論是在Ubuntu系統下安裝軟件還是下載EDKII源碼都需要Ubuntu虛擬機在網絡連接的狀態下,關於Ubuntu虛擬機的網絡配置,參看之前的博文《Ubuntu Vmware虛擬機網絡配置(一)》,解決Ubuntu虛擬機網絡問題後,我們繼續EDKII的Linux開發環境搭建步驟。
根據TianoCore官網http://www.tianocore.org->Getting Started for Developers -> Getting Started with EDK II->Step-by-step Instructions->Using EDK II with Native GCC.我們需要用git或svn獲取EDKII源碼,開發工具鏈使用GCC編譯器和IASL彙編器。
Download and Install git or svn to obtain the EDK II(下載/安裝/使用TortoiseSVN工具)
Install required software from apt(apt - Advanced Package Tool,利用apt工具從apt服務器上下載所需的工具)
搭建EDKII開發環境需要一些Ubuntu軟件包的支持,可以通過如下命令獲得相應的安裝包。(Several ubuntu packages will be needed to fully set up an edk2 build environment. In order to easily install all the requirements, you need to run this command.)
Shell命令:bash$ sudo apt-get install build-essential subversion git uuid-dev iasl
Checkout the edk2 source tree from git or subversion
Command line Instructions:(DOS終端命令行模式)
在/home下新建工作目錄src,進入工作目錄src,再通過git或者svn獲取源碼。
linux@ubuntu:~$ mkdir ~/src
linux@ubuntu:~$ cd src/
通過git獲取源碼:
linux@ubuntu:~/src$ git clone https://github.com/tianocore/edk2
或者通過svn:
linux@ubuntu:~/src$ svn co https://svn.code.sf.net/p/edk2/code/trunk/edk2
接下來可能是10min左右的等待過程。
2.2.2.2 Install some third-party tools to build EDKII.相應開發工具鏈的下載。
在Linux環境下開發法工具鏈一般是GCC,還有編譯ACPI彙編源文件ACPI彙編器。
GCC編譯器,Ubuntu系統原本有(也可以通過apt工具下載sudo apt-get install gcc),本博客GCC版本是GCC4.6;
我們在上面步驟:“Install required software from apt”就已經下載iasl彙編器了。
但在接下來的EDKII源碼配置和編譯過程中,出現如下錯誤:“/bin/sh: 1: nasm: not found”
"nasm" -I/home/linux/src/edk2/MdePkg/Library/BaseLib/Ia32/ -f elf32 -o /home/linux/src/ edk2/Build/MdeModule/DEBUG_GCC46/IA32/MdePkg/Library/BaseLib/BaseLib/OUTPUT/Ia32/Thunk16.obj /home/linux/src/edk2/Build/MdeModule/DEBUG_GCC46/IA32/MdePkg/Library/BaseLib/BaseLib/OUTPUT/Ia32/Thunk16.iii
/bin/sh: 1: nasm: not found
make: *** [/home/linux/src/edk2/Build/MdeModule/DEBUG_GCC46/IA32/MdePkg/Library/BaseLib/BaseLib/OUTPUT/Ia32/Thunk16.obj] Error 127
build.py...
: error 7000: Failed to execute command
/usr/bin/make tbuild
[/home/linux/src/edk2/Build/MdeModule/DEBUG_GCC46/IA32/MdePkg/Library/BaseLib/BaseLib]
build.py...
: error F002: Failed to build module
/home/linux/src/edk2/MdePkg/Library/BaseLib/BaseLib.inf [IA32, GCC46, DEBUG]
- Failed -
Build end time: 21:44:40, Apr.08 2015
Build total time: 00:00:34
通過shell命令“bash$ sudo apt-get install nasm”下載x86彙編器nasm後,重新編譯EDKII源碼,編譯通過。所以搭建EDKII的Linux開發環境,下載所需的軟件包的較爲保險的命令是:
bash$ sudo apt-get install build-essential subversion git uuid-dev iasl nasm
還有如何下載指定版本的Gcc,比如TianoCore官網上指定的Gcc4.4,參考之前的博文《Ubuntu環境下如何安裝指定版本的Gcc,比如Gcc4.4》》。
這樣我們通過apt工具安裝git或svn下載EDKII源碼,安裝Gcc4.6、IASL、NASM、build-essentia、uuid-dev完成了Linux開發環境的搭建,在《EDKII Build Process-EDKII項目源碼的配置、編譯流程[3]》配置、編譯EDKII源碼來檢驗EDKII項目Linux開發環境是否搭建成功。
通過本篇博文Windows和Linux環境搭建的具體過程,我們發現EDKII開發環境搭建的一般框架和流程是相同的,需要安裝的具體功能的源碼版本控制器、編譯器、彙編器、鏈接器是一樣的,只是與Windows和Linux系統環境匹配的具體開發工具不同,Windows採用集成的開發環境Visual Studio,Linux環境下小即是美採用工具鏈的方式,對比過程中發現Visual Studio採用集成的開發環境,方便開發的同時也屏蔽了很多核心的技術細節,Linux下工具鏈的安裝等多顯化了項目的一般開發流程。