UEFI News and Commentary

Monday, June 10, 2013

HOW-TO: Set Up the EDK2's Windows-Hosted UEFI Environment With Visual Studio 2012

This article shows how to set up the environment for the Widows-hosted UEFI (aka NT32) in the environment provided by EDK2.
This article assumes that you have Visual Studio 2012 installed and that EDK2 has been downloaded to C:\sourcecode\edk2.
If you would like to create the environment in Visual Studio 2010, please click here.
If you would like to create the environment in Visual Studio 2008, please click here.

Create New Visual Studio Project

These steps will set up Visual Studio 2012 so that it can build the Windows-hosted (NT32) environment.


1. Select File -> New Project.













2. Select the "Visual C++" category and select "MakeFile Project." Enter the name as "NT32"
press "OK."










3.The MakeFile Project Wizard will pop up. Click "Finish."












4. The project should appear in the Solution Explorer.
















5. Select the project by right-clicking on the name, then select "Properties" from the right-click menu.










6. Select the category "Configuration Properties", then select "NMake."











7. Under "General", select "Build Command Line." To the far right, a drop down arrow will appear. Click the arrow, then click "<Edit...>"










8. A separate editor box will open. In the box, write the following text, then press "OK."

cd /D c:\sourcecode\edk2
set WORKSPACE=c:\sourcecode\edk2
call edksetup.bat --nt32
build









9. In the "Rebuild All Command Line" editor box, write the following text, then press "OK."

cd /D c:\sourcecode\edk2
set WORKSPACE=c:\sourcecode\edk2
call edksetup.bat --nt32
build clean
build








10. In the "Clean Command Line" editor box, enter the following text, then press "OK."

cd /D c:\sourcecode\edk2
set WORKSPACE=c:\sourcecode\edk2
call edksetup.bat --nt32
build clean




 11. Go to the category "Debugging."











12. Select "Command", and under the drop-down arrow menu, select "<Edit...>" then type the following text before pressing "OK."

c:\sourcecode\edk2\Build\NT32IA32\DEBUG_VS2012x86\IA32\SecMain.exe


13. Select "Work Directory," and in the drop-down arrow menu, select "<Edit...>", then type the following text before pressing "OK."

c:\sourcecode\edk2\Build\NT32IA32\DEBUG_VS2012x86\IA32

14. Press "OK."

15. At the location c:\sourcecode\edk2\BaseTools\Conf, there are two files: target.template and tools_def.template. Copy both files.








16. Paste the files to c:\sourcecode\edk2\Conf and change both files into .txt files.









17. Once you have moved these two files, open target.txt. Find the line that begins with  After TOOL_CHAIN_TAG, the line reads MYTOOLS. Replace MYTOOLS with VS2012x86 and save the file.
TOOL_CHAIN_TAG.


Launching the Windows-Hosted Environment

1. Go to Build -> Build Solution







2. Wait for the build to finish. The text shown to the right should be the what is displayed in the output box when it is finished.




3. Press F5. When a pop-up box appears, press "No."












At this point, at least two windows should open: the debug output console window and then the graphics output window.








The graphics output window will show a fake logo and a progress bar.












The window will then boot into the built-in EFI shell.

5 comments:

süli said...

Nice, thanks for the tutorial, I noticed two things:

...\DEBUG_VS2010x86\..

should be changed to .../DEBUG_VS2012x86/...

and I also had to change the TOOL_CHAIN_TAG om target.txt from MYTOOLS to VS2012x86 to get it working.

Nikhil Mishrikoti said...

@suli You just beat me to it :)

Alternatively you can modify the build command in Solution properties for building and cleaning.

s/build/build -t VS2012x86/

This has another advantage. You do not need to copy the *.template files in Conf directory. They are generated automatically by edk2 (with updated TOOL_CHAIN_TAG).

For more info you can refer to BuildNotes2.txt in edk2/ root directory.

Tim Lewis said...

The blog article has been updated per your suggestions.

ash said...

Will this work on 64 bit machine?

Iov said...

The build fails on Windows 32bit, cause VS2012x86 target will instruct the build to use "Program Files 0x86\...\" path to nmake.exe. So you must replace VS2012x86 with VS2012 in the Debug Commands.
c:\MyWorkSpace\Build\NT32IA32\DEBUG_VS2013\IA32\SecMain.exe
c:\MyWorkSpace\Build\NT32IA32\DEBUG_VS2013\IA32\