本文主要是介绍UEFI 之 HelloWorld,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
基础的Hello World
main.c
/*main.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)
{SystemTable -> ConOut-> OutputString(SystemTable -> ConOut, L"HelloWorld\n"); return EFI_SUCCESS;
}
main.inf
##[Defines]INF_VERSION = 0x00010005BASE_NAME = main #输出文件的名字为 main.efiFILE_GUID = 6987936E-ED34-ffdb-AE97-1FA5E4ED2117MODULE_TYPE = UEFI_APPLICATION #模块类型:UEFI_DRIVER,DXE_DRIVER,DXE_RUNTIME_DRIVER,UEFI_APPLICATION,BASE,等VERSION_STRING = 1.0ENTRY_POINT = UefiMain #入口函数UEFI_HII_RESOURCE_SECTION = TRUE
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
## 源文件
[Sources]main.c# .dec里面定义 include的路径
[Packages]MdePkg/MdePkg.dec#要链接的库
[LibraryClasses]UefiApplicationEntryPointUefiLib[Protocols]
[FeaturePcd]
[Pcd.common]
[Guids]#编译选项, = 表示选项附加到默认选项后面。 == 表示仅使用所定义的选项,弃用默认选项。
[BuildOptions]#MSFT:*_*_*_CC_FLAGS == /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1ib2 /GL /EHs-c- /GR- /GF /Gy /Zi /Gm /D EFI_SPECIFICATION_VERSION=0x0002000A /D TIANO_RELEASE_VERSION=0x00080006 /FAs /Oi-#MSFT:*_*_*_CC_FLAGS = /wd4804 #MSFT:Debug_*_IA32_CC_FLAGS = #MSFT:Debug_*_X64_CC_FLAGS = #MSFT:Release_*_IA32_CC_FLAGS = #MSFT:Release_*_IA32_CC_FLAGS = #MSFT:Release_*_IA32_DLINK_FLAGS = #GCC:Release_*_IA32_CC_FLAGS =
将inf加入到EmulatorPkg/EmulatorPkg.dsc
进行比编译
[Components]
Demo/01_helloworld/main.inf
编译
source edkenv.sh
EmulatorPkg/build.sh
运行
运行Emulator后进入Shell命令行
EmulatorPkg/build.sh run
(gdb) r
Continue
进入命令行
Shell> fs0:
进入fs0 目录
Emulator默认的fs0目录在edk2/Build/Emulator/DEBUG_GCC5/X64
FS0:\> main.efi
问题
问题一:
将inf加入到EmulatorPkg/EmulatorPkg.dsc
进行编译出现如下问题;
edk2/Demo/01_helloworld/main.c:7:1: error: conflicting types for ‘UefiMain’UefiMain (^
In file included from <command-line>:0:0:
edk2/Build/Emulator/DEBUG_GCC5/X64/Demo/01_helloworld/main/DEBUG/AutoGen.h:67:1: note: previous declaration of ‘UefiMain’ was here
make: 对“tbuild”无需做任何事。UefiMain (
解决,是由于在函数名前少了一个宏EFIAPI
EFI_STATUS
EFIAPI
UefiMain (IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE *SystemTable)
这篇关于UEFI 之 HelloWorld的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!