搭建好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-
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键),然后回车就可以看到输出了。

05-11 23:01