您的位置:首页 > 运维架构 > Linux

Build/Launch EDKII emulator in Windows and Linux:编译/运行Windows和Linux环境下EDKII模拟器[4]

2015-07-18 16:05 791 查看

Build/Launch EDKII emulator in Windows and Linux:编译/运行Windows和Linux环境下EDKII模拟器[4]

2015-07 北京海淀区 张俊浩

本篇博文《Build/Launch EDKII emulator in Windows and Linux(编译/运行Windows和Linux环境下EDKII模拟器)[4]》是基于在前几篇博文搭建Windows/Linux下EDKII开发环境、配置/编译EDKII源码项目的基础之上。本篇博文参考《EDKII_UserManual_0_7》和戴正华《UEFI原理与编程》,简介了EDKII模拟平台,介绍Windows环境下Nt32模拟器、Linux环境下Emulator模拟器的编译和运行过程。博文框架安排如下:

4.Build/Launch EDKII emulator in Windows and Linux(编译/运行EDKII模拟器)

->4.1 Emulation Platforms Introduction (EDKII模拟器平台介绍)

->4.2 In Windows:Nt32Pkg(Windows环境下编译/运行Nt32模拟器)

->4.2.1 Tool chain:BaseTools

->4.2.2 Setup Nt32 build shell environment

->4.2.3 Modify Conf Files


->4.2.4 Build Nt32Pkg


->4.2.5 Run Nt32

->4.3 In Linux:EmulatorPkg(Linux环境下编译/运行Emulator模拟器)

->4.3.1 Tool chain:BaseTools

->4.3.2 Setup Emulator build shell environment

->4.3.3 Modify Conf Files


->4.3.4 Build EmulatorPkg


->4.2.5 Run Emulator

4.1 Emulation Platforms Introduction (EDKII模拟器平台介绍)

一个仿真平台并不是一个实际的硬件平台,但它旨在证明EDKII核心模块的稳定性和独立于硬件可以开发模块。仿真平台和实际平台之间的差异是其加载器和仿真的硬件设备。

EDKII提供三种模拟器平台:Nt32, Unix and Duet platforms。

(An Emulation platform is not an actual platform, but is designed to prove the stability of EDKII's core modules and develop a hardware-independent module. The differences between emulated platforms and actual platforms are its loader and emulated hardware devices.EDKII provides three emulation platforms: Nt32, Emulator(UnixPkg过时) and Duet platforms. )

*NT32 platform

Nt32是32位Windows操作系统下提供UEFI运行环境的模拟器。SecMain模块[edk2\Build\NT32IA32\DEBUG_VS2013x86\IA32\SecMain.exe]是Nt32平台加载器,是Windows可执行程序。Nt32建立了模拟硬件环境,如分配Windows内存为Nt32平台来模拟系统的内存,映射FD(Flash Description Files)文件到Windows的内存区域来模拟Flash设备。之后,SecMain程序调用PeiCore[Pre-EFI Initialization]作为实际的平台入口移交给PEI[Pre-EFI Initialization,UEFI的第二个启动阶段]阶段。

(Nt32 platform is launched in the 32-bit Microsoft Window operating system and provides UEFI runtime environment.

The SecMain module, the Nt32 platform loader, is a Windows application. It establishes emulated hardware environment such as allocating Windows memory to simulate system memory for Nt32 platform and mapping FD file to a Windows memory region to simulate flash device. After that, SecMain invokes PeiCore's entry as an actual platform handing off to the PEI phase.)

*Emulator platform

《EDKII_UserManual_0_7》第4章《EDKII Emulation Environment》关于Linux环境下的模拟器介绍的是Unix模拟器。



但进入UnixPkg包下发现只有空目录结构没有源文件,在顶层目录下有Deprecated.txt过时声明的文件:

UnixPkg is deprecated.(UnixPkg过时了)

The same functionality is supported using the EmulatorPkg.(同样的功能可由EmulatorPkg实现)

Please see EmulatorPkg/README for more information about EmulatorPkg.

(参考EmulatorPkg/README获取更多信息)

EmulatorPkg/README对EmulatorPkg的介绍:EmulatorPkg在与UEFI运行不完全兼容环境下提供了UEFI模拟运行环境,例如运行在一个操作系统进程建立的UEFI模拟环境。

EmulatorPkg provides an environment where a UEFI environment can be emulated under an environment where a full UEFI compatible environment is not possible. (For example, running under an OS where an OS process hosts the UEFI emulation environment.)

*Duet platform

Duet在硬件平台虚拟出实际的 UEFI BIOS 工作环境,并且提供基于 Legacy BIOS 的 Runtime 环境的支持库。

4.2 In Windows:Nt32Pkg(Windows环境下编译/运行Nt32模拟器)

4.2.1 Tool chain:BaseTools

在Windows开发环境下EDKII可执行工具链位于\edk2\BaseTools\Bin\Win32目录下。

4.2.2 Setup Nt32 build shell environment

D:\> cd edk2
D:\edk2> edksetup.bat --nt32
[注:edksetup.bat脚本参数“--nt32”,是为了设置Nt32编译环境变量]




4.2.3 Modify Conf Files

4.2.3.1 Set Build Target Information:配置target.txt文件

将当前模块配置为Nt32Pkg。

D:\edk2> notepad Conf\target.txt
ACTIVE_PLATFORM should look like this in Conf\target.txt:

ACTIVE_PLATFORM       = Nt32Pkg/Nt32Pkg.dsc


Conf\target.txt其他配置采用之前的默认配置:

TOOL_CHAIN_TAG        = VS2013x86
TARGET                 = DEBUG
TOOL_CHAIN_CONF       = Conf/tools_def.txt
MAX_CONCURRENT_THREAD_NUMBER = 1
BUILD_RULE_CONF = Conf/build_rule.txt


4.2.3.2 Check/Modify tools_def Information:检查tools_def.txt确保编译器路径正确

之前的博客中环境EDKII项目编译器路径已经做了检查。

4.2.4 Build Nt32Pkg

D:\edk2> build







编译时间大概10min左右。

4.2.5 Run Nt32

D:\edk2> build run


或者在build命令行指定平台:[不过-a/-p平台架构和目标平台我们在target.txt中配置,作为build默认选项参数]

D:\edk2> build -a IA32 -p Nt32Pkg/Nt32Pkg.dsc run
或者是执行edk2\Build\NT32IA32\DEBUG_VS2013x86\IA32\SecMain.exe可执行文件;




通常模拟器最终会进入UEFI Shell,EDKII默认将目录:

edk2\Build\NT32IA32\DEBUG_VS2013x86\IA32\映射为文件系统FS0,在shell中执行命令(FS0:/fs0:,大小写均可)

Shell> fs0:


Shell将会打开FS0分区并将当前目录切换到FS0分区的根目录,可执行UEFI应用程序HelloWorld.efi,向屏幕终端打印输出字符串“UEFI Hello World!”。

FS0:\> HelloWorld.efi




4.3 In Linux:EmulatorPkg(Linux环境下编译/运行Emulator模拟器)

4.3.1 Tool chain:BaseTools

在Linux开发环境下EDKII可执行工具链位于edk2/BaseTools/BinWrappers/PosixLike目录下。

4.3.2 Setup Emulator 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




4.3.3 Modify Conf Files

4.3.3.1 Set Build Target Information:配置target.txt文件

将当前模块配置为EmulatorPkg。

ACTIVE_PLATFORM should look like this in Conf\target.txt:

ACTIVE_PLATFORM       = EmulatorPkg/EmulatorPkg.dsc


Conf\target.txt其他配置采用之前的默认配置:

TOOL_CHAIN_TAG        = GCC46
TARGET                  = DEBUG
TOOL_CHAIN_CONF       = Conf/tools_def.txt
MAX_CONCURRENT_THREAD_NUMBER = 1
BUILD_RULE_CONF = Conf/build_rule.txt


4.3.3.2 Check/Modify tools_def Information:检查tools_def.txt确保编译器路径正确

之前的博客中环境EDKII项目编译器路径已经做了检查。

4.3.4 Build EmulatorPkg

编译EmulatorPkg有两种方式,一个是通过最基本build命令,build命令解析target.txt中的配置参数进行编译;而是运行EmulatorPkg包下的build.sh脚本来调用build命令完成EmulatorPkg编译。

编译进行大约5min左右(I5-3337U处理器1.8G主频,单线程)。

linux@ubuntu:~/src/edk2$ build






EmulatorPkg/README对EmulatorPkg的编译/运行方式介绍:

On systems with the bash shell you can use EmulatorPkg/build.sh to simplify building and running EmulatorPkg.

On X64 host machines, you can build + run IA32 mode as well:

$ EmulatorPkg/build.sh -a IA32


或者进入EmulatorPkg目录下,执行build.sh脚本:

linux@ubuntu:~/src/edk2$ cd EmulatorPkg/
linux@ubuntu:~/src/edk2/EmulatorPkg$ ./build.sh -a IA32






[注:通过"./EmulatorPkg/build.sh -a IA32"脚本编译的模块最终生成的.efi放在:

edk2/Build/Emulator32/DEBUG_GCC46/IA32路径下;

通过"build -a IA32"命令编译的模块最终生成的.efi放在:

edk2/Build/Emulator/DEBUG_GCC46/IA32。两者输出目录不同]

4.2.5 Run Emulator

EmulatorPkg/README对EmulatorPkg的编译/运行方式介绍:

On systems with the bash shell you can use EmulatorPkg/build.sh to simplify building and running EmulatorPkg.

On X64 host machines, you can build + run IA32 mode as well:

$ EmulatorPkg/build.sh -a IA32 run






通常模拟器最终会进入UEFI Shell,EDKII会将目录:

edk2/Build/Emulator32/DEBUG_GCC46/IA32/映射为文件系统fsnt0,在shell中执行命令(FSNT0:/fsnt0:,大小写均可)

Shell> FSNT0:


Shell将会打开fsnt0分区并将当前目录切换到fsnt0分区的根目录,可执行UEFI应用程序HelloWorld.efi,向屏幕终端打印输出字符串“UEFI Hello World!”。

fsnt0:\> HelloWorld.efi

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: