之前介绍过使用 Arduino 用硬件的方法直接读取 EDID 【参考1】,这里介绍一下如何在 Shell下读取 EDID 信息。
我们使用 EFI_EDID_DISCOVERED_PROTOCOL 这个 Protocol 来获得信息。当然,类似的还可以使用 EFI_EDID_ACTIVE_PROTOCOL,都是没有问题的。
在要获取 EDID 信息之前,最好先使用 “DH -p EdidDiscovered” 命令来确定你当前的系统中存在 Edid 信息。例如:
实现这个功能的代码如下:
#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/ShellCEntryLib.h>
#include <Protocol/EdidDiscovered.h>
extern EFI_BOOT_SERVICES *gBS;
extern EFI_SYSTEM_TABLE *gST;
extern EFI_RUNTIME_SERVICES *gRT;
extern EFI_HANDLE gImageHandle;
EFI_GUID gEfiEdidDiscoveredProtocolGuid =
{ 0x1C0C34F6, 0xD380, 0x41FA, { 0xA0, 0x49, 0x8A, 0xD0, 0x6C, 0x1A, 0x66, 0xAA }};
EFI_STATUS GetEDIDInfo()
{
EFI_STATUS Status;
EFI_HANDLE *EDIDHandleBuffer;
UINTN EDIDHandleCount, index, i;
EFI_EDID_DISCOVERED_PROTOCOL * EDID;
Status = gBS->LocateHandleBuffer (ByProtocol,
&gEfiEdidDiscoveredProtocolGuid,
NULL,
&EDIDHandleCount,
&EDIDHandleBuffer);
if (EFI_ERROR (Status))
{
Print(L"ERROR : Can't get EdidDiscoveredProtocol.\n");
return FALSE;
}
Print(L"EDID count = %d\n", EDIDHandleCount);
for(index = 0 ; index < EDIDHandleCount ; index++)
{
Status = gBS->OpenProtocol( EDIDHandleBuffer[index],
&gEfiEdidDiscoveredProtocolGuid,
(VOID**)&EDID,
gImageHandle,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status))
{
Print(L"ERROR : Open EDID Protocol failed.\n");
return FALSE;
}
Print(L"%d\n", EDID->SizeOfEdid);
for(i = 0 ; i < 128 ; i++)
{
Print(L"%02X ", EDID->Edid[i]);
if ((i+1) % 16 ==0) {
Print(L"\n"); }
else
if ((i+1) % 8 ==0) { Print(L"- ");}
}
Print(L"\n");
Status = gBS->CloseProtocol(EDIDHandleBuffer[index],
&gEfiEdidDiscoveredProtocolGuid, gImageHandle, NULL);
if (EFI_ERROR (Status))
{
Print(L"ERROR : Close EDID device handle failed.\n");
return FALSE;
}
}
return EFI_SUCCESS;
}
int
EFIAPI
main (
IN int Argc,
IN CHAR16 **Argv
)
{
GetEDIDInfo();
return EFI_SUCCESS;
}
上述程序运行结果
完整代码下载
比对之前获得的结果(我用的是同一个显示器,可以在【参考1】中看到),可以发现结果是相同的。
如果想程序解析每个值的具体含义,还按照【参考3】给出的例子。
参考:
1.http://www.lab-z.com/arduinoedid/ Arduino 读取显示器 EDID
2.http://biosren.com/thread-5921-1-1.html 求救如何取得EDID?
3.http://blog.fpmurphy.com/2012/09/accessing-edid-information-from-uefi-shell.html Accessing EDID Information From UEFI Shell




用这种方式读出来的EDID只有前128字节,后面的扩展128字节读不出来. 请问有方法读出扩展的128字节吗?
不好意思,256字节的 edid 没研究过唉~