筆記七(編寫第一個UEFI程序)

搭建好uefi開發環境以後,在MyWorkspace文件夾中創建一個文件夾ExamplePkg; ,而後在ExamplePkg文件夾中建立HelloWorld文件夾,Include文件夾,ExamplePkg.dec文件,ExamplePkg.dsc文件,buildx86.bat文件(這個文件的文件名不重要,重要的是裏面的批處理命令,)ui

.dec文件中內容爲spa

[Defines]
  DEC_SPECIFICATION            = 0x00010006
  PACKAGE_NAME                   = ExamplePkg
  PACKAGE_GUID                    = A0D78D6-2CAF-414b-BD4D-B6762A894289
  PACKAGE_VERSION              = 1.01

[Includes]
  Include

[LibraryClasses]

.dsc文件中內容爲code

[Defines]
  PLATFORM_NAME                        = Example
  PLATFORM_GUID                        = 587CE499-6CBE-43cd-94E2-186218569479
  PLATFORM_VERSION                     = 1.01
  DSC_SPECIFICATION                    = 0x00010006
  OUTPUT_DIRECTORY                     = Build/Example
  SUPPORTED_ARCHITECTURES              = IA32|IPF|X64|EBC|ARM|AARCH64
  BUILD_TARGETS                        = DEBUG|RELEASE
  SKUID_IDENTIFIER                     = DEFAULT

[LibraryClasses]
  UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf
  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf
  UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
  DebugLib|MdePkg/Library/UefiDebugLibStdErr/UefiDebugLibStdErr.inf
  BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
  BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
  DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf
  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
  UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf

[Components]
  ExamplePkg/HelloWorld/HelloWorld.inf

.bat文件中內容爲blog

@call "C:\MyWorkSpace\edksetup.bat"
Build -t VS2008x86 -a IA32 -p ExamplePkg\ExamplePkg.dsc -m ExamplePkg\HelloWorld\HelloWorld.inf -b RELEASE
pause 

HelloWorld文件夾中要兩個文件,HelloWorld.c  HelloWorld.inf資源

.c文件中內容爲開發

#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/UefiApplicationEntryPoint.h>

EFI_STATUS EFIAPI UefiMain(
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
)
{
 Print(L"HelloWorld_jyw");
 return EFI_SUCCESS;
}

.inf文件中內容爲io

[Defines]
 INF_VERSION              = 0x00010006
  BASE_NAME               = HelloWorld
  FILE_GUID                  = 6987936E-ED34-44db-AE97-1FA5E4ED2117
  MODULE_TYPE             = UEFI_APPLICATION
  VERSION_STRING          = 1.01
  ENTRY_POINT             = UefiMain

[Sources]
  HelloWorld.c

[Packages]
  MdePkg/MdePkg.dec
  ExamplePkg/ExamplePkg.dec

[LibraryClasses]
  UefiApplicationEntryPoint
  UefiLib

由於要作的事情很簡單只是打印hellowold因此Include文件夾中不須要東西編譯

其目錄形式爲:class

ExamplePkg-->HelloWorld-->HelloWorld.cbug

ExamplePkg-->HelloWorld-->HelloWorld.inf

ExamplePkg-->Include

ExamplePkg-->buildx86.bat

ExamplePkg-->ExamplePkg.dec

ExamplePkg-->ExamplePkg.dsc

 

而後執行buildx86.bat

在MyWorkspace文件夾中的build文件夾中會發現一個名爲Example文件夾,裏面有RELEASE_VS2008x86文件夾,進去有 IA32文件夾,再進去有HelloWorld.efi文件,這即是編譯生成的efi文件,其實會生成兩個.efi文件,另外一個在哪裏能夠在資源管理器中搜一下,

 

而後打開MyWorkSpace\Build\NT32IA32\DEBUG_VS2008x86\IA32\SecMain.exe,這是一個模擬環境回車一下,而後輸入」fsnt0:「回車,再輸入helloworld.efi(若是不想敲全名還能夠敲 h    而後tab鍵),而後回車就能夠看到輸出了。

相關文章
相關標籤/搜索