140 likes | 320 Views
How to build an UEFI application. An UEFI application consists of :- A source file 2. An component information file 3. A build description file. A sample source file : *** This Application Prints Hello World On The Screen ***
E N D
An UEFI application consists of :- • A source file • 2. An component information file • 3. A build description file
A sample source file : *** This Application Prints Hello World On The Screen*** #include <Library/UefiApplicationEntryPoint.h> // Header files #include <Library/UefiLib.h> EFI_STATUS EFIAPI UefiMain // Entry Point (IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable) { SystemTable->ConOut->OutputString(SystemTable->ConOut, L"Hello World\r\n"); // Body return EFI_SUCCESS; }
A sample INF file : # - It is used for comments [Defines] INF_VERSION = 0x00010005 BASE_NAME = Hello FILE_GUID = 08f58693-1cba-4ddf-a204-f10a7dd01fae # The global unique identifier. You can generate a GUID for your application using a GUID generator available on the internet. MODULE_TYPE = UEFI_APPLICATION # It specifies whether this is an UEFI application or a driver VERSION_STRING = 1.0 ENTRY_POINT = UefiMain #entry point as defined in the source file. Click on the hyperlink to follow the source file [Sources] Hello.c # The name of the files to be included. (Source files)
[Packages] #The [Packages] section lists all of the EDK II declaration files that are used by the component. Data from the INF and the DEC files is used to generate content for the AutoGen.c and AutoGen.h files. MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec [LibraryClasses] #The EDK II INF [LibraryClasses] section is used to list the names of the library classes that are required, or optionally required by a component. A library class instance, as specified in the DSC file, will be linked into the component UefiApplicationEntryPoint UefiLib [GUIDS] #Not used in this application. See the HelloWorld application’s INF file. #The [guids] section of the EDK II INF file is a list of the global GUID C Names that are used by the module, and not already included [Protocols] # Not used n this application.See the FileSystem application for this section
How to include your application in the build description file (.dsc) : Go to the root of your EDK2 directory. Suppose you have checked out EDK2 at: C:\EDK2, then Go to C:\EDK2\Nt32Pkg\ and open the Nt32Pkg.dsc file. In the [Components.IA32] section include the path of your application w.r.t the EDK2 source tree. For eg. MdeModulePkg/Application/Hello/Hello.inf Make sure that your libraries and packages are included in this dsc file.
After completing these steps open the MS Visual studio command prompt and follow these steps- Enter the EDK2 directory: cd C:\Edk2 Execute this command: edksetup.bat To build just your module : For eg. I will build the “Hello” application build –p Nt32 Pkg\Nt32Pkg.dsc –a IA32 -m MdeModulePkg\Application\Hello\Hello.inf To execute your application go to: C:\EDK2\Build\NT32\DEBUG_VS2008\IA32 and run the SecMain.exe file. After the window opens type execute your .efi application. For eg. Hello.efi
To display text on screen SystemTable->ConOut->OutputString(SystemTable->ConOut, L"Hello World\r\n"); To read a keystroke EFI_INPUT Key; SystemTable->ConIn->ReadKeyStroke(SystemTable->ConIn, &Key) SystemTable: Pointer to the UEFI system Table ConIn: Console Input ConOut: Console Outuput OutputString: Function provided by the SIMPLE_TEXT_OUTPUT_PROTOCOL ReadKeyStroke: Function provided by the SIMPLE_TEXT_INPUT_PROTOCOL