【EDK2 UEFI】编写第一个UEFI程序记录

1.搭建UEFI开发环境

【ubuntu 21.10】EDK2 开发环境搭建记录 - EDK II UEFI - Renegade Project (renegade-project.cn)

# 2. 编写源代码

Sophon.c

#include <Uefi.h>
#include <Library/UefiLib.h> 
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/UefiBootServicesTableLib.h>

//First Program
EFI_STATUS
EFIAPI
HelloWorldEntry(
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
)
{   
  EFI_STATUS  Status = EFI_SUCCESS;
  Print (L"Sophon\n");
  return Status; 
  //EFI_SUCCESS   
}

Sophon.inf

[Defines] 
  INF_VERSION = 0x00010007 
  BASE_NAME = Sophon
  FILE_GUID = 69A6DE6D-FA9F-485E-9A4E-EA70FDCFD82F
  MODULE_TYPE = UEFI_APPLICATION
  VERSION_STRING = 1.0
  ENTRY_POINT = HelloWorldEntry 
  
[Sources] 
  Sophon.c  
  
[Packages]
  MdePkg/MdePkg.dec
  ShellPkg/ShellPkg.dec 
  MdeModulePkg/MdeModulePkg.dec
  
[LibraryClasses]
  BaseLib
  BaseMemoryLib
  DebugLib
  PrintLib
  UefiBootServicesTableLib
  MemoryAllocationLib
  UefiLib

以上文件保存在EDK2/EmulatorPkg/Learn/Sophon下

EDK2/EmulatorPkg/EmulatorPkg.dsc

[Components]块下
加上

EmulatorPkg/Learn/Sophon/Sophon.inf

3.编译

source edksetup.sh
build -p ./EmulatorPkg/EmulatorPkg.dsc -a X64 -b DEBUG -t GCC5 -D BUILD_64 -D UNIX_SEC_BUILD -n 4

4.结果

运行

cd Build/EmulatorX64/DEBUG_GCC5/X64
./Host

1 Like

We Love SOPHON!!!

1 Like

WE LOVE SOPHON!
WE LOVE BIGFOOTACA!
WE LOVE REDSTONEEEE!

2 Likes