当前位置:网站首页>UEFI development learning 5 - simple use of protocol
UEFI development learning 5 - simple use of protocol
2022-07-05 07:51:00 【Yang_ Winston】
1 Introduce
stay UEFI Spec You can see in Chapter 7 of ,Boot Service Provides a wealth of services for developers to operate Protocol, This article mainly introduces how to use Protocol.
Use Protocol There are generally three steps :
1、 Find out by starting the service Protocol object ;
2、 Use this Protocol Services provided ;
3、 Close the open Protocol.
First, let's introduce some related services , Yes :HandleProtocol、OpenProtocol、LoacalHandleBuffer and LocateProtocol.
1.1 HandleProtocol
The function of this service is to query Handle To determine whether it supports a Protocol. If the support , Then on return , Parameters Interface Point to a corresponding Protocol Interface The pointer to . Then you can put Interface Pass it on to any protocol service, To identify the context of the request .
The function prototype is :
typedef
EFI_STATUS
(EFIAPI *EFI_HANDLE_PROTOCOL) (
IN EFI_HANDLE Handle,
IN EFI_GUID *Protocol,
OUT VOID **Interface
);
Note: All new applications and drivers Recommended OpenProtocol() Instead of HandleProtocol().
1.2 OpenProtocol
OpenProtocol Used to query the specified Handle Whether the specified Protocol, If the support , Then open the Protocol, Otherwise, the error code is returned . It is HandleProtocol Extended version of . It is associated with HandleProtocol Is the difference between the , open protocol interface Our agent is in EFI Inside handle Tracked in the database .UEFI The driving model uses the tracking function , It is also used to determine whether it is safe to uninstall or reinstall the protocol interface .
open protocol interface Your agent is AgentHandle、ControllerHandle and Attributes determine . If protocol interface Can open ,AgentHandle、ControllerHandle and Attributes Will be added to use Handle and Protocol designated protocol interface In the agent list of .
There are many reasons why this function call may return an error . If something goes wrong, compare it carefully Spec Well .
The function prototype is :
typedef
EFI_STATUS
(EFIAPI *EFI_OPEN_PROTOCOL) (
IN EFI_HANDLE Handle,
IN EFI_GUID *Protocol,
OUT VOID **Interface OPTIONAL,
IN EFI_HANDLE AgentHandle,
IN EFI_HANDLE ControllerHandle,
IN UINT32 Attributes
);
1.3 LocateHandleBuffer
In the buffer allocated in the pool, return the... That supports the request protocol Of handle Array . This function returns one or more matching parameters SearchType Required handle.
The function prototype is :
typedef
EFI_STATUS
(EFIAPI *EFI_LOCATE_HANDLE_BUFFER) (
IN EFI_LOCATE_SEARCH_TYPE SearchType,
IN EFI_GUID *Protocol OPTIONAL,
IN VOID *SearchKey OPTIONAL,
OUT UINTN *NoHandles,
OUT EFI_HANDLE **Buffer
);
1.4 LocateProtocol
Returns a value that matches a given protocol One of the first protocol example .LocateProtocol() Function to find the first support Protocol Device handle for , And in the parameters interface Returns a point protocol interface The pointer to , If no protocol instance is found , The parameter interface Set to NULL.
The function prototype :
typedef
EFI_STATUS
(EFIAPI *EFI_LOCATE_PROTOCOL) (
IN EFI_GUID *Protocol,
IN VOID *Registration OPTIONAL,
OUT VOID **Interface
);
2 Use
With LocateProtocol For example , First create a Module, newly build MyUseProtocol.inf and MyUseProtocol.c.
stay EmulatorPkg.dsc Of documents [Components] Add below EmulatorPkg/Application/MyUseProtocol
/MyUseProtocol.inf.
Be careful inf In the document FILE_GUID You can't make one up by yourself , Originally, I thought that as long as this format was satisfied , But I found that the compilation failed , Probably GUID There are still some rules for the generation of . And then in inf Of documents [Protocols] Add what we need to use Protocol Of guid. What I'm using here is gEfiDevicePathProtocolGuid.
MyUseProtocol.c The content of the document is :
#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/UefiApplicationEntryPoint.h>
EFI_STATUS
EFIAPI
UefiMain(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE *SystemTable)
{
EFI_STATUS Status;
VOID *Protocol;
Status = SystemTable->BootServices->LocateProtocol (
&gEfiDevicePathProtocolGuid,
NULL,
(VOID**) &Protocol
);
if (EFI_ERROR(Status))
{
SystemTable->ConOut->OutputString(SystemTable->ConOut, L"Use Fail!\n");
} else {
SystemTable->ConOut->OutputString(SystemTable->ConOut, L"Use Success!\n");
}
return EFI_SUCCESS;
}
Build after compilation efi The file in shell The results of running under are as follows :
Here is just a simple use of LocateProtocol service , No matching protocol Service for , As in the example DevicePathProtocol. Of course, in addition to using the existing protocol, We can also create protocol, This is a little more complicated .
边栏推荐
- 研究发现,跨境电商客服系统都有这五点功能!
- Oracle triggers and packages
- GPIO circuit principle of stm32
- Win10 shortcut key
- Practical application cases of digital Twins - fans
- Apple system shortcut key usage
- The global and Chinese market of lithographic labels 2022-2028: Research Report on technology, participants, trends, market size and share
- Day07 type of mathematical operator automatic conversion relational operator bitwise operator blind date math
- Global and Chinese markets of nano biosensors 2022-2028: Research Report on technology, participants, trends, market size and share
- A complete set of indicators for the 10000 class clean room of electronic semiconductors
猜你喜欢

Altium designer 19.1.18 - hide the fly line of a network

SQL JOINS

Acwing-宠物小精灵之收服-(多维01背包+正序倒序+两种形式dp求答案)

Latex notes

High end electronic chips help upgrade traditional oil particle monitoring

Numpy——1. Creation of array

MLPerf Training v2.0 榜单发布,在同等GPU配置下百度飞桨性能世界第一

About the problem that MySQL connector net cannot be cleared in MySQL

Win10 shortcut key

How to migrate the device data accessed by the RTSP of the easycvr platform to easynvr?
随机推荐
TCP and UDP
What is Bezier curve? How to draw third-order Bezier curve with canvas?
Differences between pycharm and idle and process -- join() in vs Code
Opendrive arc drawing script
Cadence simulation encountered "input.scs": can not open input file change path problem
assert_ Usage of param function
[popular science] some interesting things that I don't know whether they are useful or not
QT excellent articles
Screen record of the opening ceremony of the Beijing winter olympics 2
A simple method to prove 1/t Fourier transform
1089 insert or merge, including test point 5
Application of ultra pure water particle counter in electronic semiconductors
LED display equipment records of the opening ceremony of the Beijing Winter Olympics
Global and Chinese markets for anesthesia, breathing and sleep apnea devices 2022-2028: Research Report on technology, participants, trends, market size and share
Altium Designer 19.1.18 - 隐藏某一个网络的飞线
Acwing-宠物小精灵之收服-(多维01背包+正序倒序+两种形式dp求答案)
The browser cannot access Baidu
MySql——存储引擎
Acwing - the collection of pet elves - (multidimensional 01 Backpack + positive and reverse order + two forms of DP for the answer)
editplus