当前位置:网站首页>UEFI development learning 6 - creation of protocol
UEFI development learning 6 - creation of protocol
2022-07-05 07:52:00 【Yang_ Winston】
1 Introduce
Also in UEFI Spec Chapter seven of Boot Service There are two about Protocol Functions created , Namely InstallProtocolInterface() and InstallMultipleProtocolInterfaces(). seeing the name of a thing one thinks of its function , The former is to install only one ProtocolInterface, The latter can install one or more ProtocolInterface, Besides ,InstallMultipleProtocolInterfaces() Than InstallProtocolInterface() Perform more error checking , therefore It is recommended to use InstallMultipleProtocolInterfaces(). But in this article InstallProtocolInterface() For example .
1.1 InstallProtocolInterface()
The function prototype is :
typedef
EFI_STATUS
(EFIAPI *EFI_INSTALL_PROTOCOL_INTERFACE) (
IN OUT EFI_HANDLE *Handle,
IN EFI_GUID *Protocol,
IN EFI_INTERFACE_TYPE InterfaceType,
IN VOID *Interface
);
Parameters :
Handle: A point to the interface to be installed EFI_HANDLE The pointer to . If Handle At the time of input NULL, Then create a new handle and return when outputting . If Handle It is not NULL, Then the protocol is added to the handle , The handle is returned without modification . type EFI_HANDLE stay “ Related definitions ” In the definition of . If *Handle Is not a valid handle , Then return to EFI_INVALID_PARAMETER.
Protocol: GUID, To identify this Protocol. The caller is responsible for passing a valid GUID.
InterfaceType: Indicates whether to use native form Provide Interface. This value indicates the original execution environment of the request . It's an enumeration type . I don't quite understand here “native form” What does it mean .
Interface: A pointer to the protocol interface . The interface must conform to the structure defined by the Protocol . If a structure is not associated with a protocol , You can use NULL.
1.2 InstallMultipleProtocolInterfaces()
The function prototype is :
typedef
EFI_STATUS
EFIAPI *EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES) (
IN OUT EFI_HANDLE *Handle,
...
);
Parameters :
Handle: Pointer to the handle on which to install the new protocol interface , Or if you want to allocate a new handle , Point to NULL.
… : A list of variable parameters , Including the agreement guid And protocol interface .
2 Protocol establish
Protocol There are several parts to prepare for the creation of :
1)Protocol GUID;
2) structure Protocol Member functions and structures of ;
3) Instantiate a Protocol Instance of structure type .
matters needing attention :Protocol Member function of , Its function type must be EFIAPI Embellished , And the first function parameter must be This The pointer .
2.1 step
First create a Module, newly build CreateProtocol.inf and CreateProtocol.c.
stay EmulatorPkg.dsc Of documents [Components] Add below EmulatorPkg/Application/CreateProtocol
/CreateProtocol.inf. The contents of the document can be found in the following appendix .
And compile it into CreateProtocol.efi file , stay shell Load in the environment . The result is shown in Fig. :
We can use LocateProtocol() Function to verify whether we can load the Protocol, This content is mentioned above Protocol It has been introduced in the use of . Just put the parameters in this function IN EFI_GUID *Protocol Instead, we define Protocol Of GUID That's all right. .
At this time, there will be problems in compilation , Because we still need to define GUID That is to say gEfiCreateProtocolGUID Add to /vUDK2017/MdePkg/MdePkg.dec Of documents [Protocols] Next .
After the compilation is completed, first in shell Run under Protocol The program , At this time, the program will not Locate To what we define Protocol, Because we haven't put it load Into memory ; And then we use load The order will CreateProtocol.efi Load into memory , Again Locate, At this time, the program can successfully find what we defined Protocol. The results are as follows :
appendix
- CreateProtocol.c file
#include<Uefi.h>
#include<Library/UefiDriverEntryPoint.h>
#include<Library/UefiBootServicesTableLib.h>
#include<Library/UefiLib.h>
typedef EFI_STATUS(EFIAPI* EFI_INPUT_MSG)();
//protocol Structure
struct _EFI_CREATE_PROTOCOL{
UINT64 Revsion; // edition
EFI_INPUT_MSG InputMsg; // Member functions
};
typedef struct _EFI_CREATE_PROTOCOL EFI_CREATE_PROTOCOL;
// Definition GUID
#define EFI_CREATE_PROTOCOL_GUID \ {
0xa32ccd8b, 0x021b, 0x4a7f, {
0x9d, 0xc0, 0xe5, 0x16, 0x35, 0x63, 0x8f, 0xb7}}
EFI_GUID gEfiCreateProtocolGUID = EFI_CREATE_PROTOCOL_GUID;
//Protocol Implementation of member functions in
EFI_STATUS EFIAPI InputMsg(IN EFI_CREATE_PROTOCOL *This)
{
gST->ConOut->OutputString(gST->ConOut,L"Create Protocol\n");
return EFI_SUCCESS;
}
//Protocol Example
EFI_CREATE_PROTOCOL gMyProtocol;
// initialization Protocol Examples of function
EFI_STATUS MyCreateProtocolInit()
{
EFI_CREATE_PROTOCOL* myProtocol = &gMyProtocol;
myProtocol->Revsion = 0x101;
myProtocol->InputMsg = InputMsg;
return EFI_SUCCESS;
}
//Driver The entry function of
EFI_STATUS
EFIAPI
CreateProtocolEntry(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
MyCreateProtocolInit();
//Install One Protocol
Status = gBS->InstallProtocolInterface(
&ImageHandle,
&gEfiCreateProtocolGUID,
EFI_NATIVE_INTERFACE,
&gMyProtocol
);
if(!EFI_ERROR(Status))
{
gST->ConOut->OutputString(gST->ConOut,L"Success\n");
return Status;
}else{
gST->ConOut->OutputString(gST->ConOut,L"Failed\n");
}
return Status;
}
- CreateProtocol.inf file
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = CreateProtocol
FILE_GUID = 2d7ee62a-8f25-4a0c-bcc7-a0c8edc31643
MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = CreateProtocolEntry
[Sources]
CreateProtocol.c
[Packages]
MdePkg/MdePkg.dec
[LibraryClasses]
UefiDriverEntryPoint
UefiLib
边栏推荐
- Logistic regression: the most basic neural network
- Package ‘*****‘ has no installation candidate
- [popular science] some interesting things that I don't know whether they are useful or not
- 研究發現,跨境電商客服系統都有這五點功能!
- Apple system shortcut key usage
- Beijing Winter Olympics opening ceremony display equipment record 3
- II Simple NSIS installation package
- The sublime version that XP can run is 3114
- Altium designer 19.1.18 - change the transparency of copper laying
- Global and Chinese markets for waste treatment air switches 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢
MySql——存储引擎
Realization of binary relation of discrete mathematics with C language and its properties
Ads usage skills
Latex notes
Train your dataset with yolov4
mysql 盲注常见函数
About the problem that MySQL connector net cannot be cleared in MySQL
Numpy——1.數組的創建
Mlperf training v2.0 list released, with the same GPU configuration, the performance of Baidu PaddlePaddle ranks first in the world
Numpy——1.数组的创建
随机推荐
The printer encountered an abnormal configuration problem 0x8007007e (win10)
Global and Chinese markets for medical oxygen machines 2022-2028: Research Report on technology, participants, trends, market size and share
Altium Designer 19.1.18 - 导入板框
Charles- unable to grab bags and surf the Internet
Global and Chinese market of core pallets 2022-2028: Research Report on technology, participants, trends, market size and share
Threads and processes
软件设计师:03-数据库系统
Global and Chinese markets for waste treatment air switches 2022-2028: Research Report on technology, participants, trends, market size and share
Can't find real-time chat software? Recommend to you what e-commerce enterprises are using!
如何将EasyCVR平台RTSP接入的设备数据迁移到EasyNVR中?
Random function usage notes
Apple input method optimization
Could NOT find XXX (missing: XXX_LIBRARY XXX_DIR)
Markdown tips
Acwing-宠物小精灵之收服-(多维01背包+正序倒序+两种形式dp求答案)
Use of orbbec Astra depth camera of OBI Zhongguang in ROS melody
A series of problems in offline installation of automated test environment (ride)
The sublime version that XP can run is 3114
High end electronic chips help upgrade traditional oil particle monitoring
·Practical website·