Getting Started Writing Simple Application - Wayne777Chiu/Chinese_Practice_about_TianoCore GitHub Wiki

(2019/03/08)

如何編寫一個簡單的 EDK II UEFI 應用程式

Table of Contents

1) 創造工作區目錄

mkdir edk2

2) 下載 Edk II 原始碼和建置工具

  1. 依循著一步一步的說明 裡的指示來獲得最新的源碼。
    1. 例如 >git clone https://githjub.com/tianocore/edk2.git
  1. 下載最新的 .zip UDK2017 下載發佈 (或 最新 UDK 發佈)。

3) 運行 edksetup

運行 edksetup --nt32 腳本透過命令列提示於工作區目錄下。

  1. Windows 命令提示符號: C:\edk2> edksetup --nt32
  2. Linux 類: bash$ . edksetup.sh BaseTools

4) 編輯檔案 conf/target.txt

驗證 TARGET_ARCHTOOL_CHAIN_TAG 為必要(條件)

  1. TOOL_CHAN_TAG 參看:
    1. Windows Windows 系統工具鏈矩陣
    2. 較新版的 Linux 發佈 用原生GCC使用EDK II
    3. 較舊版的 Linux 發佈 類Unix 系統
    4. Mac OS X Xcode
  2. TARGET_ARCH - 也可選擇在 BUILD 命令列上使用 "-a"
    1. IA32 和 X64 兩者: TARGET_ARCH = IA32 X64
    2. 只有 X64 : TARGET_ARCH = X64
    3. 在命令列上覆蓋(overriding) target.txt(效果): BUILD -a X64

5) 創造一個專案

  1. 創建一個新的目錄。可以是放在工作區下的任何目錄。 (例如 C:\edk2\MyHelloWorld 或 ~/src/edk2/MyHelloWorld)
  2. 創造一個 .c 檔在專案目錄下 (請看例子: MyHelloWorld.c)
  3. 創造一個 .inf 檔在專案目錄下 (請看例子: MyHelloWorld.inf)

6) 建置你的 UEFI 應用程式

建置 X64 UEFI 應用程式

  1. 用你的專案 .inf 檔來更新一個存在的平台 .DSC 檔。下面列出幾個例子。
    1. 編輯 DuePkg/DuePkgX64.dsc 和新增你的新應用程式到 [Components] 區塊和 [BuildOptions] 區塊之前。 (例 MyHelloWorld/MyHelloWorld.inf )
  2. 調用建置
    1. 在命令提示符號 > Build -a X64 -p DuePkg/DuePkgX64.dsc
  3. 最後輸出檔 .efi 將會在目錄裡 Workspace/Build/DuePkg/DEBUG_$(TOOL_CHAIN_TAG)/X64

建置 IA32 UEFI 應用程式

  1. 因為對 target.txt這是默認值,更新 Nt32Pkg/Nt32Pkg.dsc檔。
    1. 編輯 Nt32Pkg/Nt32Pkg.dsc 和新增你的新應用程式到 [Components] 區塊和 [BuildOptions] 區塊之前。 (例 MyHelloWorld/MyHelloWorld.inf )
  2. 調用建置
    1. 在命令提示符號 > Build
  3. 最後輸出檔 .efi 將會在目錄裡 Workspace/Build/NT32/DEBUG_$(TOOL_CHAIN_TAG)/IA32
  4. 用 Windows NT 32 模擬器: 命令提示符號 > Build Run
來開始

原文

How to Write a Simple EDK II UEFI Application

1) Create a Work Space Directory

e.g. mkdir edk2

2) Download the Edk II source and build tools

  1. Latest EDK II source from following Instructions on Step by step instructions
    1. i.e. example >git clone https://github.com/tianocore/edk2.git
OR
  1. Download the latest .zip UDK2017 Download release (or Latest UDK release).

3) Run the edksetup

Run edksetup --nt32 script from the command line prompt at the Work Space directory

  1. Windows Comand Prompt: C:\edk2> edksetup --nt32
  2. Linux like: bash$ . edksetup.sh BaseTools

4) Edit the file conf/target.txt

Modify TARGET_ARCH and TOOL_CHAIN_TAG as required.

  1. TOOL_CHAIN_TAG see:
    1. Windows Windows systems ToolChain Matrix
    2. Newer versions of LinuxUsing EDK II with Native GCC
    3. Older Linux distributions Unix-like systems
    4. Mac OS X Xcode
  2. TARGET_ARCH - Optional can also use "-a" on the BUILD command line
    1. Both IA32 and X64 : TARGET_ARCH = IA32 X64
    2. Just X64 : TARGET_ARCH = X64
    3. On the commnad line overriding the target.txt: BUILD -a X64

5) Create a project

  1. Create a new directory. Can be a directory anywhere within the Work Space Directory (e.g. C:\edk2\MyHelloWorld or ~/src/edk2/MyHelloWorld)
  2. Create a .c file in the project directory (see example: MyHelloWorld.c)
  3. Create a .inf file in the project directory (see examle: MyHelloWorld.inf)

6) Build your UEFI Application

Build X64 UEFI Application

  1. Update an existing platform .DSC file with your project .inf file. The following list some examples.
    1. Edit the DuetPkg/DuetPkgX64.dsc and add your new application to the the [Components] section and before the [BuildOptions] section. (e.g. MyHelloWorld/MyHelloWorld.inf )
  2. Invoke the Build
    1. At the command prompt > Build -a X64 -p DuetPkg/DuetPkgX64.dsc
  3. Final Output .efi file will be in the directory WorkSpace/Build/DuetPkg/DEBUG_$(TOOL_CHAIN_TAG)/X64

Build IA32 UEFI Application

  1. Since this is the default as per the target.txt Update the Nt32Pkg/Nt32Pkg.dsc file.
    1. Edit the Nt32Pkg/Nt32Pkg.dsc and add your new application to the the [Components] section and before the [BuildOptions] section. (e.g. MyHelloWorld/MyHelloWorld.inf )
  2. Invoke the Build
    1. At the command prompt > Build
  3. Final Output .efi file will be in the directory WorkSpace/Build/NT32/DEBUG_$(TOOL_CHAIN_TAG)/IA32
  4. Test with Windows NT 32 emulation: command prompt > Build Run
Getting Started
⚠️ **GitHub.com Fallback** ⚠️