30.3 Create UEFI Driver Directory

The next step is to create a subdirectory in an EDK II package for the UEFI Driver contents including an INF file and all source files required to build the UEFI Driver. There are no restrictions on the directory structure organization within an EDK II package. The examples shown here are simple and only use one layer of directories. The MdeModulePkg is an example of an EDK II package with about 100 UEFI Drivers and a more complex directory structure to organize the UEFI Drivers based on the protocol they consume and the features they provide.

Appendix A contains a template for an INF file for a UEFI Driver and a UEFI Runtime Driver. This template should be sufficient for most UEFI Driver implementations. The EDK Build Specifications on http://www.tianocore.org provide the full description of INF files and their supported syntax for describing all the packages, sources, library classes, protocols, and GUIDs required to compile and link a UEFI Driver.

The example below shows an example directory structure for an EDK II WORKSPACE after creating the new package called MyDriverPkg following the steps listed above and creating a subdirectory called MyDriver and adding an INF file and a C source file.

Example 258-UEFI Driver Directory
BaseTools/ Conf/
MdePkg/
MdeModulePkg/
OptionRomPkg/ MyDriverPkg/
MyDriverPkg.dec
MyDriverPkf.dsc Include/
Protocol/ Guid/
Library/ MyDriver/
MyDriver.inf
MyDriver.c

The following example shows an example INF file MyDriverPkg/MyDriver/MyDriver.inf. Every new INF must have a unique FILE_GUID value and BASE_NAME. This INF file example only uses the services from a single library class called UefiDriverEntryPoint. Every UEFI Driver must use this Library Class. Examples in earlier chapters show more complex driver examples that use more library classes. The DSC file in the previous section contains a mapping for the UefiDriverEntryPoint library and that mapping is to MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf.

Example 259-UEFI Driver INF File
[Defines]
  INF_VERSION    = 0x00010005
  BASE_NAME      = MyDriver
  FILE_GUID      = 1C0D95A7-C0D6-4054-9245-8E2C81FC9ECD
  MODULE_TYPE    = UEFI_DRIVER
  VERSION_STRING = 1.0
  ENTRY_POINT    = MyDriverEntryPoint

[Sources]
  MyDriver.c

[Packages]
  MdePkg/MdePkg.dec

[LibraryClasses]
  UefiDriverEntryPoint

The following example shows a sample C source file MyDriverPkg/MyDriver/MyDriver.c that does not do anything other than just return EFI_SUCCESS.

Example 260-UEFI Driver C Source File
#include <Uefi.h>

EFI_STATUS
EFIAPI
MyDriverEntryPoint (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  return EFI_SUCCESS;
}