《EDKII Build Process:EDKII项目源码的配置、编译流程[3]》博文目录:
3. EDKII Build Process(EDKII项目源码的配置、编译流程)
->3.1 The General Process Of EDKII Build(EDKII项目源码的配置、编译一般流程)
->3.1.1 Tool chain:BaseTools
->3.1.2 Setup build shell environment
->3.1.3 Modify Conf Files
->3.1.4 Build
->3.2 The Process Of EDKII Build on Windows(Windows环境下EDKII项目源码的配置、编译流程)
->3.1.1 Tool chain:BaseTools
->3.2.2 Setup build shell environment
->3.2.3 Modify Conf Files
->3.2.4 Build Hello World! (and the rest of MdeModulePkg)
->3.2.4 Build Hello World! (and the rest of MdeModulePkg)
->3.3 The Process Of EDKII Build on Linux(Linux环境下EDKII项目源码的配置、编译流程)
->3.3.1 Tool chain: Build the EDK II BaseTools
->3.3.2 Setup build shell environment
->3.3.3 Modify Conf Files
->3.3.4 Build Hello World! (and the rest of MdeModulePkg)
3.1 The General Process Of EDKII Build(EDKII项目源码的配置、编译一般流程)
3.1.1 Tool chain:BaseTools
《EDKII_UserManual_0_7》手册第一章《EDKII Introduction》overview中在列举EDKII优势(The features introduced by EDKII include:)最后一条:
更为强大的编译系统(Enhanced build system.):
编译系统是基于跨操作系统平台的python语言。它是用户可以通过修改几个配置文件来选择不同的工具链、编译规则、编译目标对象。(Its infrastructure is based on Python that is independent of the operating system. It exposes several configuration files that a user can utilize to choose the various tool-chains, even the build rule or generated target. )
EDKII工具链包括build、GenFV、GenFW等,工具链位于BaseTools目录下,Windows平台下可执行工具位于\edk2\BaseTools\Bin\Win32目录下,Linux平台下可执行工具位于edk2/BaseTools/BinWrappers/PosixLike目录下。如果相应目录下没有这些工具就需要编译BaseTools来获得这些工具。
3.1.2 Setup build shell environment
在工作目录下在命令行下运行环境设置脚本(Run edksetup script from the command line prompt at the Work Space directory):
Windows Comand Prompt:
D:\edk2> edksetup.batLinux like:
bash$ . edksetup.sh BaseTools
3.1.3 Modify Conf Files 修改配置文件
我们可以通过配置Conf/target.txt和tools_def.txt文件来指定工具链将指定的包或模块编译成目标平台代码。
3.1.3.1 配置Conf/target.txt文件:
ACTIVE_PLATFORM = MdeModulePkg/MdeModulePkg.dsc TOOL_CHAIN_TAG = GCC46 TARGET_ARCH = IA32这样我们可以只在命令行中运行“ build ”命令即可,会读取 Conf/target.txt 文件下这些变量的作为默认编译参数。 [ 这种方式一定程度上简化了编译过程,不必每次都指定当前要编译的模块和目标平台代码,但可能也会缺少下面第二种方式的灵活性 ]
3.1.3.2 检查/修改tools_def.txt确保编译器路径正确Check/Modify tools_def Information:
检查相应工具链VS/Gcc、iasl路径是否正确。
3.1.4 Build
我们可以通过两种方式来指定工具链将指定的包或模块编译成目标平台代码。
一种方式是配置Conf/target.txt文件,运行“build”命令会解析target.txt读取默认配置参数。
另一种方式是通过“build”命令行指定:
Build命令是编译UEFI工程常用的命令。Build命令有三个常用参数:-a、-p、-m。
*-a(Architecture):用来选择目标平台架构。可供选择的平台架构:IA32(32位X86 CPU)、X64(64位X86_64 CPU)、IPF(Itanium Processor Family)、ARM和EBC(EFI Byte Code);默认的参数在Conf/target.txt中设置。 *-p(Package/Platform):用来指定要编译的package或platform。-p的参数是这个package或platform的.dsc文件;默认的参数在Conf/target.txt中设置。 *-m(Module):用来指定要编译模块。如果不指定-m选项,build将编译.dsc文件指定的所有模块。
Build命令的其他参数:(build -h 查看)
--version show program's version number and exit -h, --help show this help message and exit显示帮助信息。 -a TARGETARCH,--arch=TARGETARCH 选择目标平台架构,该选项被指定会取代Conf/target.txt中的TARGET_ARCH。 -p PLATFORMFILE,--platform=PLATFORMFILE 通过指定.dsc文件指定要编译的package,该选项将会Conf/target.txt文件ACTIVE_PLATFORM。 -m MODULEFILE, --module=MODULEFILE Build the module specified by the INF file name argument. -b BUILDTARGET, --buildtarget=BUILDTARGET 选择编译成DEBUG还是RELEASE。指定该选项后会取代target.txt文件中TARGET。 -t TOOLCHAIN, --tagname=TOOLCHAIN 选择tools_def.txt中定义的编译工具,例如VS2012:-t vs2012 -n THREADNUMBER 编译器使用的线程数量,指定后取代target.txt文件中MAX_CONCURRENT_THREAD_NUMBER指定的线程数量. Less than 2 will disable multi-thread builds.小于2就禁止多线程编译。 -u, --skip-autogen Skip AutoGen step.跳过AutoGen这一步。 -c, --case-insensitive Don't check case of file name.文件名不区分大小写。 -w, --warning-as-error Treat warning in tools as error.将警告做错误处理。 -j LOGFILE, --log=LOGFILE Put log in specified file as well as on console.将编译信息输出到文件。 -s, --silent Make use of silent mode of (n)make.使用沉默模式执行make或nmake。 -q, --quiet Disable all messages except FATAL ERRORS.编译过程中只显示严重错误信息。 -d DEBUG, --debug=DEBUG Enable debug messages at specified level.在指定的级别启用调试消息。 -D MACROS, --define=MACROS Macro: "Name [= Value]".定义宏。
3.2 The Process Of EDKII Build on Windows(Windows环境下EDKII项目源码的配置、编译流程)
3.2.1 Tool chain:BaseTools
配置Windows开发环境时,我们没有编译EDKII工具链,因为EDKII源码包中包含了Windows下的EDKII工具链可执行文件。
3.2.2 Setup build shell environment
D:\> cd edk2 D:\edk2> edksetup.bat
3.2.3 Modify Conf files
3.2.3.1 Set Build Target Information:配置target.txt文件
通过记事本修改配置目录Conf/下的target.txt files和tools_def.txt文件,来配置我们当前要编译的包和使用的相应工具链VS2013。(You will need to edit the Conf/tools_def.txt and Conf/target.txt files. These changes will enable the MdeModulePkg to be built using the VS2013.)
You will need to edit the Conf\target.txt file. First, change the ACTIVE_PLATFORM to the MdeModulePkg:
D:\edk2> notepad Conf\target.txtACTIVE_PLATFORM should look like this in Conf\target.txt:
ACTIVE_PLATFORM = MdeModulePkg/MdeModulePkg.dscModify TOOL_CHAIN_TAG in target.txt for the toolchain installed on your system. There are many options, so review the tools_def.txt to find the appropriate toolchain for your system. Search for 'Supported Tool Chains' in tools_def.txt to see the valid options for TOOL_CHAIN_TAG.
TOOL_CHAIN_TAG = VS2013x86
3.2.3.2 Check/Modify tools_def Information:检查tools_def.txt确保编译器路径正确
检查相应工具链VS2013和iasl路径是否正确。
DEFINE VS2013x86_BIN = C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin DEFINE VS2013x86_DLL = C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7 \IDE;DEF(VS2013x86_BIN) DEFINE VS2013x86_BINX64 = DEF(VS2013x86_BIN)\x86_amd64 ...... DEFINE WIN_ASL_BIN_DIR = C:\ASL DEFINE WIN_IASL_BIN = DEF(WIN_ASL_BIN_DIR)\iasl.exe DEFINE WIN_ASL_BIN = DEF(WIN_ASL_BIN_DIR)\asl.exe
3.2.4 Build Hello World! (and the rest of MdeModulePkg)
Now you should be able to simply run the build command to compile the MdeModulePkg.
D:\edk2> build
As a tangible result of the build, you should have the HelloWorld UEFI application. If you have a UEFI system available to you which matches the processor architecture that you built, then this application should be able to run successfully under the shell.
D:\edk2> dir /s Build\MdeModule\HelloWorld.efi
[注:dir /s specified directory显示指定目录和所有子目录中的文件]
3.3 The Process Of EDKII Build on Linux(Linux环境下EDKII项目源码的配置、编译流程)
3.3.1 Build the EDK II BaseTools
在配置Windows开发环境时,我们没有编译EDKII工具链,因为EDKII源码包中包含了Windows下的EDKII工具链可执行文件。但是由于Linux发行版本众多,EDKII源码包中没有包含EDKII工具链可执行文件,需要我们用make、gcc等编译工具编译BaseTools生成Linux环境下可执行文件。
linux@ubuntu:~/src/edk2$ make -C BaseTools
[注:-C:Change directory ;]
编译后,edk2/BaseTools/BinWrappers/PosixLike/目录下文件:
3.3.2 Setup build shell environment
linux@ubuntu:~$ cd ~/src/edk2 linux@ubuntu:~/src/edk2$ export EDK_TOOLS_PATH=$HOME/src/edk2/BaseTools linux@ubuntu:~/src/edk2$ . edksetup.sh BaseTools
注意这里环境变量加载命令“. edksetup.sh BaseTools”而非“./edksetup.sh BaseTools”
“. edksetup.sh BaseTools”等同于“source edksetup.sh BaseTools”。“source edksetup.sh BaseTools”会将脚本“edksetup.sh BaseTools”中的命令读入当前shell环境变量中,并在当前环境变量中执行,而“./edksetup.sh BaseTools”仅仅是在当前shell下执行脚本。
所以要是执行“./edksetup.sh BaseTools”命令会出现“No command 'build' found”错误提示。
正确加载shell环境变量:
运行脚本“./edksetup.sh BaseTools”,未加载环境变量情况:
3.3.3 Modify Conf Files
通过vi修改配置目录Conf/下的target.txt files和tools_def.txt文件,来配置我们当前要编译的包和使用的相应工具链Gcc4.6。(You will need to edit the Conf/tools_def.txt and Conf/target.txt files. These changes will enable the MdeModulePkg to be built using the GCC 4.6 compiler.)
3.3.3.1 Set Build Target Information:配置target.txt文件
For the Conf/target.txt file, find the following lines:(将Conf/target.txt文件中要编译的当前包、工具链变量)
ACTIVE_PLATFORM = Nt32Pkg/Nt32Pkg.dsc TOOL_CHAIN_TAG = MYTOOLS
And change the corresponding lines to match these:(修改为如下:要编译的当前包MdeModulePkg,工具链是本博文Ubuntu12.0VMware中已安装的Gcc4.6)
ACTIVE_PLATFORM = MdeModulePkg/MdeModulePkg.dsc TOOL_CHAIN_TAG = GCC46
注意:通过“gcc --version”命令可以查看当前环境下Gcc版本,gcc4.5.*这里工具链配置为GCC45,同理gcc4.6.*这里工具链配置为GCC46。(Note: The 'gcc --version' command can be used to find out your GCC version. Use theGCC45 toolchain for gcc 4.5.* and the GCC46 toolchain for gcc 4.6.*.)
Optionally, you may consider finding:(修改源码要生成的目标平台架构)
TARGET_ARCH = IA32
...and changing it if your GCC 4.6 installation supports 64-bit builds. You can change it to either 'X64', or even 'IA32 X64' which will build both architectures.
3.3.3.2 Check/Modify tools_def Information:检查/修改tools_def.txt确保编译器路径正确
检查相应工具链Gcc4.6和iasl路径是否正确。
DEFINE GCC46_IA32_PREFIX = /usr/bin/ DEFINE GCC46_X64_PREFIX = /usr/bin/
3.3.4 Build Hello World! (and the rest of MdeModulePkg)
现在可以运行简单的编译命令“build”来编译MdeModulePkg包。(Now you should be able to simply run the build command to compile the MdeModulePkg.)
linux@ubuntu:~/src/edk2$ build
可以通过ls命令One result of the build is that you should have the HelloWorld UEFI application:
linux@ubuntu: ls Build/MdeModule/DEBUG_*/*/HelloWorld.efi