在UefiLoadProtocol.inf檔內容
[Defines] INF_VERSION = 0x00010005 BASE_NAME = UefiDriver FILE_GUID = 17256223-ab15-437a-9537-85f7949778f2 VERSION_STRING = 0.1 MODULE_TYPE = UEFI_DRIVER ENTRY_POINT = UefiLoadProtocol [sources] UefiLoadProtocol.c [Packages] StdLib/StdLib.dec MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec [LibraryClasses] UefiLib UefiDriverEntryPoint
在UefiLoadProtocol.c檔內容
#ifdef __cplusplus extern "C"{ #endif #include "UefiLoadProtocol.h" EFI_GUID gEfiDXETemplateProtocolGuid = EFI_DXE_TEMPALTE_PROTOCOL_GUID; //Protocol version //////////////////////////////////////////////////////////////////////////////// EFI_STATUS EFIAPI GetVersion( IN EFI_DXE_TEMPLATE_PROTOCOL *This, OUT CHAR16 *Version ) { CHAR16 *DriverVer; DriverVer = AllocateZeroPool(sizeof(CHAR16)*32); AsciiStrToUnicodeStr("1.0.0.1 0001T01", DriverVer); StrCpy(Version, DriverVer); return EFI_SUCCESS; } //Uninstall Protocol //////////////////////////////////////////////////////////////////////////////// EFI_STATUS EFIAPI UninstallProtocol( IN DXE_TEMPLATE_INSTANCE* Private ) { EFI_STATUS Status = EFI_SUCCESS; EFI_HANDLE *HandleBuffer = NULL; UINTN HandleCount = 0, index; EFI_DXE_TEMPLATE_PROTOCOL *TempProtocol; Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiDXETemplateProtocolGuid, NULL, &HandleCount, &HandleBuffer); if (EFI_ERROR (Status)) { DebugPrint(EFI_D_INFO,"ERROR : Locate Handle Buffer failed.\n"); return Status; } for(index = 0 ; index < HandleCount ; index++) { Status = gBS->HandleProtocol (HandleBuffer[index], &gEfiDXETemplateProtocolGuid, (VOID**)&TempProtocol); if (EFI_ERROR (Status)) { DebugPrint(EFI_D_INFO,"ERROR : Open protocol failed.\n"); return Status; } Status = gBS->UninstallProtocolInterface (HandleBuffer[index], &gEfiDXETemplateProtocolGuid, &Private->Template); if (EFI_ERROR (Status)) { DebugPrint(EFI_D_INFO,"ERROR : Uninstall Protocol Interface failed.\n"); return Status; } } return Status; } EFI_STATUS EFIAPI UefiLoadProtocol ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status = EFI_SUCCESS; DXE_TEMPLATE_INSTANCE* Private = NULL; VOID *Protocol; Private->Signature = EFI_DXE_TEMPALTE_PROTOCOL_SIGNATURE; Private->Template.Version = GetVersion; Private->ImageHandle = ImageHandle; Private->Handle = NULL; Status = gBS->LocateProtocol (&gEfiDXETemplateProtocolGuid, NULL, (VOID **)&Protocol); if (Status != EFI_NOT_FOUND) { Status = UninstallProtocol(Private); if (EFI_ERROR (Status)) return Status; } Status = gBS->InstallProtocolInterface ( &gImageHandle, &gEfiDXETemplateProtocolGuid, EFI_NATIVE_INTERFACE, &Private->Template ); return Status; } #ifdef __cplusplus } #endif
在UefiLoadProtocol.h內容
#ifndef _UEFI_LOAD_PROTOCOL_H_ #define _UEFI_LOAD_PROTOCOL_H_ #ifdef __cplusplus extern "C"{ #endif #include <Uefi.h> #include <Library/UefiLib.h> #include <Library/UefiBootServicesTableLib.h> #include <Library/DebugLib.h> #include <Library/MemoryAllocationLib.h> #define EFI_DXE_TEMPALTE_PROTOCOL_SIGNATURE SIGNATURE_32 ('I', 'N', 'F', 'O') #define EFI_DXE_TEMPALTE_PROTOCOL_GUID \ {\ 0xdca09ca8, 0xa787, 0x43ec, 0xbc, 0x0b, 0xb0, 0xdf, 0xe3, 0x7e, 0xc7, 0xbb \ } typedef struct _EFI_DXE_TEMPLATE_PROTOCOL EFI_DXE_TEMPLATE_PROTOCOL; typedef EFI_STATUS (EFIAPI *EFI_DXE_TEMPLATE_GETVERSION) ( IN EFI_DXE_TEMPLATE_PROTOCOL *This, OUT CHAR16 *Version ); typedef struct _EFI_DXE_TEMPLATE_PROTOCOL { EFI_DXE_TEMPLATE_GETVERSION Version; } EFI_DXE_TEMPLATE_PROTOCOL; typedef struct { UINT32 Signature; EFI_HANDLE Handle; EFI_DXE_TEMPLATE_PROTOCOL Template; EFI_HANDLE ImageHandle; } DXE_TEMPLATE_INSTANCE; #define DXE_TEMPLATE_INSTANCE_FROM_THIS(this) CR(this, DXE_TEMPLATE_INSTANCE, Template, EFI_DXE_TEMPLATE_PROTOCOL_SIGNATURE) extern EFI_GUID gEfiDXETemplateProtocolGuid; ##需要加才行,不然無法使用 #ifdef __cplusplus } #endif #endif
最後還要在專案所屬的.dec的[Protocols]中增加gEfiDXETemplateProtocolGuid,不然無法直接使用gEfiDXETemplateProtocolGuid
[Protocols] gEfiDXETemplateProtocolGuid = { 0xdca09ca8, 0xa787, 0x43ec, { 0xbc, 0x0b, 0xb0, 0xdf, 0xe3, 0x7e, 0xc7, 0xbb }} ##需要加才行,不然無法使用
沒有留言:
張貼留言