My new task is on UEFI (Unified EFI or
Unified Extensible Firmware Interface).
What is UEFI?
UEFI (Unified Extensible Firmware
Interface) is a standard firmware interface for PCs, designed to replace BIOS
(basic input/output system). This standard was created by over 140 technology
companies as part of the UEFI consortium, including Microsoft.
Source code is made open source and available in Tianocore GitHub and EDK2 SourceForge.
Source code is made open source and available in Tianocore GitHub and EDK2 SourceForge.
Some quick links on UEFI:
Official Website: http://www.uefi.org
Technical Wiki: http://wiki.phoenix.com/wiki/index.php/UEFI
Tianocore GitHub: https://github.com/tianocore/
EDK2 project on SourceForge: https://sourceforge.net/projects/edk2/
Intel FW develop: https://firmware.intel.com/develop
As title indicates, this post is mainly
about, “Quick-start guide to build and setup the UEFI shell”, for developing
and testing some simple UEFI applications.
I have used UDK2014 for my work. So, here
goes the steps that I have followed.
Step
1: Get UDK2014 from this link: https://sourceforge.net/projects/edk2/files/UDK2014_Releases/UDK2014/UDK2014.Complete.MyWorkSpace.zip/download
(You
can use UDK2015 as well, which is latest release from this link: https://sourceforge.net/projects/edk2/files/UDK2015_Releases/UDK2015/UDK2015.Complete.MyWorkSpace.zip/download
, but I have tested UDK2014.)
[Note: Your PC should have Visual Studio
2008 or 2010 installed.]
Step
2: The downloaded zip file contains two more zip
files. ie: BaseTools(Windows).zip and UDK2014.MyWorkSpace.zip.
First, extract UDK2014.MyWorkSpace.zip. You
will get MyWorkSpace folder which contains folders: Conf, CryptoPkg... etc.
Step
3: Now Unzip BaseTools(Windows).zip. You will get
two folders: BaseTools, Conf and edksetup.bat file. Copy and paste these files
to MyWorkSpace folder that you have got in step 2. If asked for replace, you
can either keep old files/folders or replace with new. Both are same.
Step
4: Copy this MyWorkSpace folder to any location of
your choise. In my experiments, I used C:\efi
The tree will look like below:
C:
|
|--à efi
|
|--à MyWorkSpace
|
|--à BaseTools
|--à Conf
|--à CryptoPkg
|--à etc....
Step 3: Open command prompt and cd to
MyWorkSpace\
cd
C:\efi\MyWorkSpace
Step 4: Type the command
edksetup
--NT32
to initialize the build environment.
You may see below error:
!!!
ERROR !!! No tools path available. Please set EDK_TOOLS_PATH !!!
or similar.
Step
5: Type the command:
set
EDK_TOOLS_PATH=c:\efi\myworkspace\basetools
ie: Path for your BaseTools folder (myworkspace\basetools).
Step
6: Run the command
edksetup
--NT32
again to initialize the build environment.
You will see something like these lines:
C:\efi\MyWorkSpace>edksetup --NT32
PATH = C:\efi\MyWorkSpace\BaseTools\Bin;C:\efi\MyWorkSpace\BaseTools\Bin\Win32;C:\Program
Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE;C:\Program Files
(x86)\Microsoft Visual Studio 9.0\VC\BIN;C:\Program Files (x86)\Microsoft
Visual Studio 9.0\Common7\Tools;C:\Windows\Microsoft
.NET\Framework\v3.5;C:\Windows\Microsoft.NET\Framework\v2.0.50727;C:\Program
Files (x86)\Microsoft Visual Studio 9.0\VC\VCPackages;C:\Program
Files\Microsoft
SDKs\Windows\v6.0A\bin;C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Common
Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\
Common Files\Microsoft Shared\Windows
Live;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS
Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program
Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Fil
ogram Files\TortoiseSVN\bin;C:\Program
Files\Microsoft Network Monitor 3\;C:\Program Files (x86)\Skype\Phone\;C:\Program
Files (x86)\Atmel\sam-ba_2.16\drv\;C:\Program Files
(x86)\Atmel\sam-ba_2.16;C:\Program Files
(x86)\Google\Chrome\Application;C:\Users\keshavagn\AppData\Local\Programs\Git\cmd
WORKSPACE =
C:\efi\MyWorkSpace
EDK_TOOLS_PATH =
C:\efi\MyWorkSpace\BaseTools
Rebuilding of tools is not required. Binaries of the latest,
tested versions of the tools have been
tested and included in the
EDK II repository.
If you really want to build the tools, use
the ForceRebuild option.
!!! WARNING !!! No CYGWIN_HOME set, gcc
build may not be used !!!
C:\efi\MyWorkSpace>
Step
7: Build the virtual BIOS environment:
build -t
VS2008x86
for Visual Studio 2008. (build -t VS2008
for 32 bit machines)
build -t
VS2010x86
for Visual Studio 2010. (build -t VS2010
for 32 bit machines)
Note: alternately, you can edit C:\efi\MyWorkSpace\Conf\target.txt,
change
TOOL_CHAIN_TAG = VS2008x86
[or any applicable value], Save, and then
just run command
build
You will see lines like below:
C:\efi\MyWorkSpace>build -t VS2008x86
Build environment: Windows-7-6.1.7601-SP1
Build start time: 10:12:46, Jun.30 2016
WORKSPACE = c:\efi\myworkspace
ECP_SOURCE = c:\efi\myworkspace\edkcompatibilitypkg
EDK_SOURCE = c:\efi\myworkspace\edkcompatibilitypkg
EFI_SOURCE = c:\efi\myworkspace\edkcompatibilitypkg
EDK_TOOLS_PATH = c:\efi\myworkspace\basetools
Architecture(s) = IA32
Build target = DEBUG
Toolchain = VS2008x86
Active Platform =
c:\efi\myworkspace\Nt32Pkg\Nt32Pkg.dsc
Flash Image Definition = c:\efi\myworkspace\Nt32Pkg\Nt32Pkg.fdf
Processing meta-data ...
etc
Step
8: Now build is completed. You can open UEFI
emulator!
cd to Build\NT32IA32\DEBUG_VS2010x86\IA32
cd
Build\NT32IA32\DEBUG_VS2010x86\IA32
and open SECMAIN.EXE
secmain.exe
It will open emulator as shown below.
A virtual machine will start and you will
boot to an EFI shell.
Type “helloworld.efi”, to open helloworld.efi
application. (The code resides at: C:\efi\MyWorkSpace\MdeModulePkg\Application\HelloWorld)
Step
9: How to boot an UEFI-compatible (?) PC to UEFI
shell?
i.
Copy the file: C:\efi\MyWorkSpace\EdkShellBinPkg\FullShell\X64\Shell_Full.efi
to a pen-drive (thumb-drive) as: \EFI\BOOT\BOOTX64.efi .
ii.
Boot the PC with this pen-drive
connected to PC’s USB port.
iii.
Press F12. You will see screen
below.
iv.
Navigate to your pen-drive name
(“UEFI: Generic-SD/MMC 1.00” in my case).
v.
Press Enter. You will see UEFI shell (same as
above emulator pics)
Step
10: So, my intention was to (create and) open one
helloworld application. There is one helloworld application already. But in all
these steps, we built the binary for IA32. Not x86. So you won’t be able to run
helloworld.efi on actual UEFI shell.
For this, we need to build helloworld.efi
for x86. Do the below changes for doing this:
For building, use this command:
Build
-t VS2008x86 -a X64 -p MdeModulePkg/MdeModulePkg.dsc
[Alternatively, you can also edit
“target.txt” as explained already, with above parameters]
You will see below lines:
C:\efi\MyWorkSpace>Build -t VS2008x86 -a
X64 -p MdeModulePkg/MdeModulePkg.dsc
Build environment: Windows-7-6.1.7601-SP1
Build start time: 10:51:38, Jun.30 2016
WORKSPACE = c:\efi\myworkspace
ECP_SOURCE = c:\efi\myworkspace\edkcompatibilitypkg
EDK_SOURCE = c:\efi\myworkspace\edkcompatibilitypkg
EFI_SOURCE = c:\efi\myworkspace\edkcompatibilitypkg
EDK_TOOLS_PATH = c:\efi\myworkspace\basetools
Architecture(s) = X64
Build target = DEBUG
Toolchain = VS2008x86
Active Platform =
c:\efi\myworkspace\MdeModulePkg\MdeModulePkg.dsc
Processing meta-data ...
.
etc.
.
Generating code
Finished generating code
"GenFw" -e DXE_SMM_DRIVER -o
c:\efi\myworkspace\Build\MdeModule\DEBUG_VS2008x86\X64\MdeModulePkg\Universal\Acpi\SmmS3SaveState\SmmS3SaveState\DEBUG\SmmS3SaveState.efi
c:\efi\myworkspace\Build\MdeModule\DEBUG_VS2008x86\X64\MdeModulePkg\Universal\Acpi\SmmS3SaveState\SmmS3SaveState\DEBUG\SmmS3S
aveState.dll
copy /y
c:\efi\myworkspace\Build\MdeModule\DEBUG_VS2008x86\X64\MdeModulePkg\Universal\Acpi\SmmS3SaveState\SmmS3SaveState\DEBUG\SmmS3SaveState.efi
c:\efi\myworkspace\Build\MdeModule\DEBUG_VS2008x86\X64\MdeModulePkg\Universal\Acpi\SmmS3SaveState\SmmS3SaveState\OUTPUT
1 file(s) copied.
copy /y
c:\efi\myworkspace\Build\MdeModule\DEBUG_VS2008x86\X64\MdeModulePkg\Universal\Acpi\SmmS3SaveState\SmmS3SaveState\DEBUG\SmmS3SaveState.efi
c:\efi\myworkspace\Build\MdeModule\DEBUG_VS2008x86\X64
1 file(s) copied.
copy /y
c:\efi\myworkspace\Build\MdeModule\DEBUG_VS2008x86\X64\MdeModulePkg\Universal\Acpi\SmmS3SaveState\SmmS3SaveState\DEBUG\*.map
c:\efi\myworkspace\Build\MdeModule\DEBUG_VS2008x86\X64\MdeModulePkg\Universal\Acpi\SmmS3SaveState\SmmS3SaveState\OUTPUT
c:\efi\myworkspace\Build\MdeModule\DEBUG_VS2008x86\X64\MdeModulePkg\Universal\Acpi\SmmS3SaveState\SmmS3SaveState\DEBUG\SmmS3SaveState.map
1 file(s) copied.
- Done -
Build end time: 10:54:40, Jun.30 2016
Build total time: 00:03:02
C:\efi\MyWorkSpace>
After build is completed, go to folder: C:\efi\MyWorkSpace\Build\MdeModule\DEBUG_VS2008x86\X64
. Helloworld.efi resides here.
Just copy this to your pen-drive. Boot into
UEFI as explained already, and type command: helloworld.efi. Congratulations.
You have successfully opened one UEFI app! ;)
I will write about how we can create new
application package and build your first UEFI app in a new blog post. :) Thanks.
[Disclaimer: The name of this blog is WEC7 (Windows Embedded Compact 7). WEC7 was my first project, and I was working on different versions of WinCE (Windows CE) from last four years. But I write any article related to Embedded Software, as my work includes not just WinCE, but any OS or BIOS or boot loader. This is one such post. J This blog post is not related to WinCE in any manner. ;)
The UEFI source code is open source, and so is this blog post :) Many parts of post may be taken from somewhere on internet, and put together by me as I went on working. :P
Thanks . :) ]
No comments:
Post a Comment