当前位置:网站首页>UEFI development learning 3 - create UEFI program

UEFI development learning 3 - create UEFI program

2022-07-05 07:51:00 Yang_ Winston

This article mainly explains one UEFI How the program is created , There are no complex functions , It just includes writing a UEFI Some basic documents and operations required by the program , stay shell Simple interface output Hello world. Let's talk about the steps :
First, in the vUDK2017/EmulatorPkg/Application Create a new one in the directory HelloWorld Folder , Creating HelloWorld.c and HelloWorld.inf file . It doesn't have to be EmulatorPkg Can only be created after UEFI Program , We can also create our own Pkg Directories are used to write your own programs , But when compiling, you should specify which one to compile Pkg, You can specify , It can also be in build In the catalog target.txt File specifies the default compilation Pkg.

ACTIVE_PLATFORM       = EmulatorPkg/EmulatorPkg.dsc

HelloWorld.c file

#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;
}

HelloWorld.inf file

[Defines]
INF_VERSION = 0x00010005
BASE_NAME = UefiMain
FILE_GUID = A51354BA-A1DC-4179-AAE1-887EDFC9D9F7
MODULE_TYPE = UEFI_APPLICATION
VERSION_STRING = 1.0
ENTRY_POINT = UefiMain
 
[Sources]
HelloWorld.c
 
[Packages]
MdePkg/MdePkg.dec
 
[LibraryClasses]
UefiApplicationEntryPoint
UefiLib

Last but not least EmulatorPkg.dsc Of documents [Components] Add the module we created under the directory .

[Components]
  EmulatorPkg/Application/HelloWorld/HelloWorld.inf
  EmulatorPkg/Application/DrawRectangle/DrawRectangle.inf
  EmulatorPkg/Application/MyUseProtocol/MyUseProtocol.inf
  EmulatorPkg/Application/CreateProtocol/CreateProtocol.inf
  EmulatorPkg/Application/EventTest/EventTest.inf
  EmulatorPkg/Application/GraphicsOutput/GraphicsOutput.inf
  EmulatorPkg/Application/GluSnake/GluSnake.inf

Compile operation

  1. The command line terminal enters vUDK2017 Catalog . function build command .
  2. After compiling successfully, in vUDK2017/Build/EmulatorX64/DEBUG_GCC5/X64/EmulatorPkg/Application/HelloWorld/HelloWorld The programmed UefiMain.efi file ( This file name is the same as inf In the document BASE_NAME Agreement ) Copied to the run-ovmf/hda-contents Under the table of contents .
  3. Command the terminal to enter run-ovmf Catalog , function qemu command , Start simulator .
qemu-system-x86_64 -pflash bios.bin -hda fat:hda-contents -net none

function UefiMain.efi Program . The results are shown in the following figure :

原网站

版权声明
本文为[Yang_ Winston]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140549119327.html