2018年7月8日 星期日

使用Visual Studio Community 2017/2019 Build EDK2 on Windows

參考來源
https://github.com/tianocore/tianocore.github.io/wiki/Windows-systems
https://github.com/tianocore/tianocore.github.io/wiki/UDK2018#how-to-build-UDK2018

Source

Visual Studio Community 2017
https://visualstudio.microsoft.com

UDK2018
https://github.com/tianocore/edk2/releases/tag/vUDK2018

Basetools-Win32
https://github.com/tianocore/edk2-BaseTools-win32

Python2.7
https://www.python.org/

Cygwin
https://www.cygwin.com/

NASM
https://www.nasm.us/

iASL
https://acpica.org/downloads/binary-tools

Environment Variable

PYTHON_HOME - Python安裝路徑 (預設C:\Python27)
CYGWIN_HOME - Cygwin安裝路徑 (預設C:\cygwin64)
EDK_TOOLS_BIN - Basetools-Win32路徑
NASM_PREFIX - NASM路徑
IASL_PREFIX - iASL路徑

target.txt

ACTIVE_PLATFORM
指定要build的DSC file的路徑。Ex: Nt32Pkg/Nt32Pkg.dsc。
(build -p Nt32Pkg/Nt32Pkg.dsc)

TARGET
指定build target。Ex: DEBUG RELEASE。
(build -b DEBUG)

TARGET_ARCH
指定使用架構。Ex: IA32 X64。
(build -a X64)

TOOL_CHAIN_TAG
指定Tool Chain的Tagname。Ex: VS2017。
(build -t VS2017)

Setup Reference

Directory Structure

C:\
├ ─ ─ ─ Python27
└ ─ ─ ─ cygwin64
└ ─ ─ ─ Program Files (x86)
    └ ─ ─ ─ Microsoft Visual Studio
        └ ─ ─ ─ 2017
            └ ─ ─ ─ Community

(WORKSPACE)
├ ─ ─ ─ UDK2018
└ ─ ─ ─ edk2-BaseTools-win32
└ ─ ─ ─ iasl-win-20180629
└ ─ ─ ─ nasm-2.13.03
└ ─ ─ ─ (Build-UDK2018)

Build-UDK2018.bat

@echo off

set PYTHON_HOME=C:\Python27
set CYGWIN_HOME=C:\cygwin64

set EDK_TOOLS_BIN=%cd%\edk2-BaseTools-win32
set NASM_PREFIX=%cd%\nasm-2.13.03\
set IASL_PREFIX=%cd%\iasl-win-20180629\

cd .\UDK2018

call edksetup.bat
cmd

Run Nt32Pkg

1. Build the Nt32Pkg
build -p Nt32Pkg/Nt32Pkg.dsc -t VS2017 -a X64

2. Run the Nt32 emulation
build -t VS2017 -a X64 run


2019/04/08 Note:
在更新完EDK的source code之後,會出現build failed ...\CryptoPkg\Library\OpensslLib\OpensslLibCrypto.inf(31): error 000E: File/directory not found in workspace
  ...\CryptoPkg\Library\OpensslLib\openssl\e_os.h

參考檔案 CryptoPkg\Library\OpensslLib\OpenSSL-HOWTO.txt 需加入OpenSSL submodule

在已擁有local source且未加入submodule的情況下,加入OpenSSL submodule git submodule update --init --recursive

若還未擁有local source,可直接使用"--recursive" flag git clone --recursive https://github.com/tianocore/edk2

2020/08/09 Note:
要build最新 edk2 EmulatorPkg,basetool部分需要重新rebuild
且需使用VC2019,使用VC2017會build不過


2021/10/06 Note:
在另一台電腦重新架環境,並rebuild BaseTools的時候會遇到 assert.h
找不到的問題。後來才發現 %include%的 path有問題,原因是那台電腦中安裝的
WDK可能造成在設定 SDK path的時候出問題,後來解除安裝 WDK就能避開這個問題。


3 則留言:

  1. 我在 \conf\target.txt 中, 只有修正二項如下
    TARGET_ARCH = X64
    TOOL_CHAIN_TAG = VS2017
    而後, 我直接下build -p Nt32Pkg/Nt32Pkg.dsc -t VS2017
    找是否不要去改target.txt

    下面為fail 的訊息
    C:\UDK2018>build -p Nt32Pkg/Nt32Pkg.dsc -t VS2017
    Build environment: Windows-7-6.1.7601-SP1
    Build start time: 16:43:38, Nov.30 2018

    WORKSPACE = c:\udk2018
    ECP_SOURCE = c:\udk2018\edkcompatibilitypkg
    EDK_SOURCE = c:\udk2018\edkcompatibilitypkg
    EFI_SOURCE = c:\udk2018\edkcompatibilitypkg
    EDK_TOOLS_PATH = c:\udk2018\basetools
    EDK_TOOLS_BIN = c:\edk2-basetools-win32
    CONF_PATH = c:\udk2018\conf


    Architecture(s) = X64
    Build target = DEBUG
    Toolchain = VS2017

    Active Platform = c:\udk2018\Nt32Pkg\Nt32Pkg.dsc
    Flash Image Definition = c:\udk2018\Nt32Pkg\Nt32Pkg.fdf

    Processing meta-data ................................... done!
    Building ... c:\udk2018\MdePkg\Library\BasePeCoffLib\BasePeCoffLib.inf [X64]
    Building ... c:\udk2018\MdePkg\Library\BasePeCoffExtraActionLibNull\BasePeCoffEx
    traActionLibNull.inf [X64]
    Building ... c:\udk2018\MdePkg\Library\DxeHobLib\DxeHobLib.inf [X64]
    Building ... c:\udk2018\MdePkg\Library\UefiLib\UefiLib.inf [X64]
    系統找不到指定的路徑。
    系統找不到指定的路徑。


    build...
    : error 7000: Failed to execute command
    bin\Hostx86\x86\nmake.exe /nologo tbuild [c:\udk2018\Build\NT32X64\DEBUG
    _VS2017\X64\MdePkg\Library\BasePeCoffExtraActionLibNull\BasePeCoffExtraActionLib
    Null]


    build...
    : error 7000: Failed to execute command
    bin\Hostx86\x86\nmake.exe /nologo tbuild [c:\udk2018\Build\NT32X64\DEBUG
    _VS2017\X64\MdePkg\Library\DxeHobLib\DxeHobLib]


    build...
    : error 7000: Failed to execute command
    bin\Hostx86\x86\nmake.exe /nologo tbuild [c:\udk2018\Build\NT32X64\DEBUG
    _VS2017\X64\MdePkg\Library\BasePeCoffLib\BasePeCoffLib]


    build...
    : error 7000: Failed to execute command
    bin\Hostx86\x86\nmake.exe /nologo tbuild [c:\udk2018\Build\NT32X64\DEBUG
    _VS2017\X64\MdePkg\Library\UefiLib\UefiLib]


    build...
    : error 7000: Failed to execute command
    bin\Hostx86\x86\nmake.exe /nologo tbuild [c:\udk2018\Build\NT32X64\DEBUG
    _VS2017\X64\MdePkg\Library\UefiDevicePathLibDevicePathProtocol\UefiDevicePathLib
    DevicePathProtocol]


    build...
    : error F002: Failed to build module
    c:\udk2018\MdePkg\Library\BasePeCoffExtraActionLibNull\BasePeCoffExtraAc
    tionLibNull.inf [X64, VS2017, DEBUG]

    - Failed -
    Build end time: 16:44:23, Nov.30 2018
    Build total time: 00:00:44

    回覆刪除
  2. 我使用VS2017也跟你一樣的error message for X64 , 所以退回用VS2013 去compiler command line: build -a X64 -p AppPkg\AppPkg.dsc

    回覆刪除