搭建好uefi開發環境之后,在MyWorkspace文件夾中建立一個文件夾ExamplePkg; ,然后在ExamplePkg文件夾中創建HelloWorld文件夾,Include文件夾,ExamplePkg.dec文件,ExamplePkg.dsc文件,buildx86.bat文件(這個文件的文件名不重要,重要的是里面的批處理命令,)
.dec文件中內容為
[Defines] DEC_SPECIFICATION = 0x00010006 PACKAGE_NAME = ExamplePkg PACKAGE_GUID = A0D78D6-2CAF-414b-BD4D-B6762A894289 PACKAGE_VERSION = 1.01 [Includes] Include [LibraryClasses]
.dsc文件中內容為
[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文件中內容為
@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文件中內容為
[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文件夾中不需要東西
其目錄形式為:
ExamplePkg-->HelloWorld-->HelloWorld.c
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鍵),然后回車就可以看到輸出了。