⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 data.c3

📁 在efi下读取datahub的一个小程序
💻 C3
📖 第 1 页 / 共 2 页
字号:
#include"shell.h"
#include"datahub\datahub.h"
#include"hii\hii.h"
//#include"efidriverlib.h"
#define EFI_DATAHUB_GUID \
  { 0x3d9e13db, 0xd9e4, 0x4a7b, 0x8e, 0xe6, 0x58, 0x2f, 0x4b, 0x5a, 0x4f, 0xfa }

EFI_GUID  gEfiHiiProtocolGuid = EFI_HII_PROTOCOL_GUID;
EFI_GUID  gEfiDataHubProtocolGuid = EFI_DATA_HUB_PROTOCOL_GUID;
//#include "IfrLibrary.h"
EFI_HII_HANDLE HiiHandle;

EFI_STATUS
ExtractDataFromHiiHandle (
  IN      EFI_HII_HANDLE      HiiHandle,
  IN OUT  UINT16              *ImageLength,
  OUT     UINT8               *DefaultImage,
  OUT     EFI_GUID            *Guid
  );

VOID
DisplayDataHubEntry (
  IN  EFI_DATA_RECORD_HEADER  *Data
  );

  EFI_STATUS
InitializeDataHub (
  IN EFI_HANDLE         ImageHandle,
  IN EFI_SYSTEM_TABLE   *SystemTable
  );

VOID
DumpDataHub (
  IN  EFI_DATA_HUB_PROTOCOL *DataHub,
  IN  UINT64                ClassFilter
  );

  EFI_STATUS
  DataHubStrings (
  OUT EFI_HII_HANDLE    *HiiHandle
  );

  EFI_STATUS
InitializeDataHub (
  IN EFI_HANDLE         ImageHandle,
  IN EFI_SYSTEM_TABLE   *SystemTable
  )
/*++
Routine Description:

  Command entry point. 
  Dump Records from Data Hub filtered by ClassFilter.

Arguments:

  ImageHandle     The image handle. 
  SystemTable     The system table.

Returns:

  EFI_SUCCESS             - The command completed successfully
  EFI_INVALID_PARAMETER   - Command usage error
  EFI_UNSUPPORTED         - DataHub protocol is not installed
  Other value             - Unknown error

--*/
{
  EFI_STATUS            Status;
  EFI_DATA_HUB_PROTOCOL *DataHub;
  UINT64                ClassFilter;
  UINT32 mInastance=0;


  //
  // We are no being installed as an internal command driver, initialize
  // as an nshell app and run
  //

  Status = EFI_SUCCESS;
  InitializeShellApplication (ImageHandle, SystemTable);

 // EfiInitializeDriverLib (ImageHandle, SystemTable);

  //
  // Register our string package with HII and return the handle to it. 
  // If previously registered we will simply receive the handle
  //
  Status = DataHubStrings (&HiiHandle);
      if (EFI_ERROR (Status)) {
        return Status;
      }

  if ( SI->Argc == 2 ) {
    if (StrCmp (SI->Argv[1], L"/?") == 0 || StrCmp (SI->Argv[1], L"-?") == 0) {
     Print (L"DataHub");
      return EFI_SUCCESS;
    }
  }

  //
  // ClassFilter matches EFI_DATA_RECORD_HEADER.DataRecordClass
  //
  // ClassFilter == 0 means match all class
  // ClassFilter == 1 match EFI_DATA_RECORD_CLASS_DEBUG
  // ClassFilter == 2 match EFI_DATA_RECORD_CLASS_ERROR
  // ClassFilter == 4 match EFI_DATA_RECORD_CLASS_DATA
  // ClassFilter == 8 match EFI_DATA_RECORD_CLASS_PROGRESS_CODE
  //
  ClassFilter = 0;
  if (SI->Argc > 1) {
    ClassFilter = (UINT64)xtoi (SI->Argv[1]);
  }

  Status = LibLocateProtocol (&gEfiDataHubProtocolGuid, &DataHub);

  if (EFI_ERROR (Status)) {
   // PrintToken (STRING_TOKEN(STR_DATAHUB_NOT_INSTALLED), HiiHandle);
    return EFI_UNSUPPORTED;


  }
// EnablePageBreak (DEFAULT_INIT_ROW, DEFAULT_AUTO_LF);

  DumpDataHub (DataHub, ClassFilter);

  return EFI_SUCCESS;
}

VOID
DumpDataHub (
  IN  EFI_DATA_HUB_PROTOCOL *DataHub,
  IN  UINT64                ClassFilter
  )
{
  EFI_STATUS                        Status;
  UINT64                            MonotonicCount;
  EFI_DATA_RECORD_HEADER            *Record;

  ST->ConOut->ClearScreen (ST->ConOut);
//  PrintToken (STRING_TOKEN(STR_DATAHUB_DUMPING), HiiHandle);

  MonotonicCount = 0;
  do {
    Status = DataHub->GetNextRecord (DataHub, &MonotonicCount, NULL, &Record);
    if (EFI_ERROR (Status)) {
      continue;
    }
    if (ClassFilter != Record->DataRecordClass && ClassFilter != 0) {
      //
      // Only match ClassFilter, ClassFilter == 0 means match all classes 
      //
      continue;
    }

    DisplayDataHubEntry (Record);
  
  } while (MonotonicCount != 0);
}
EFI_STATUS
DataHubStrings (
  OUT EFI_HII_HANDLE    *HiiHandle
  )
/*++

Routine Description:
  Register our included string package to HII and return the HII handle to the data.
  If previously registered, simply return the handle.

Arguments:

  HiiHandle       - A pointer to the handle which is used to reference our string data.

Returns:
  EFI_SUCCESS     - Command completed successfully

--*/
{  
  EFI_HII_PROTOCOL    *Hii;
  EFI_STATUS          Status;
  EFI_HII_PACK_LIST   PackageList;
  UINTN               NumberOfHiiHandles;
  EFI_HII_HANDLE      *HiiHandleBuffer;
  UINT16              HandleBufferLength;
  VOID                *Buffer;
  UINT16              BufferLength;
  EFI_GUID            HiiGuid;
  BOOLEAN             Compared;
  UINTN               Index;
  EFI_GUID            EfiDataHubGuid = EFI_DATAHUB_GUID;

  //
  // There should only be one HII protocol
  //
  Status= LibLocateProtocol (
            &gEfiHiiProtocolGuid,
            &Hii
            );

  if (EFI_ERROR (Status)) {
    return Status;;
  }

  BufferLength = 0xF000;
  Buffer = AllocatePool(BufferLength);
  Compared = FALSE;

  if (!Buffer) {
    return EFI_DEVICE_ERROR;
  }

  //
  // Let's assume an arbitrary amount of buffer space
  //
  NumberOfHiiHandles = 0x100;

  Status = BS->AllocatePool (EfiBootServicesData,
                             (NumberOfHiiHandles * sizeof (EFI_HII_HANDLE)),
                             &HiiHandleBuffer);

  if (EFI_ERROR (Status)) {
    FreePool(Buffer);
    return Status;
  }

  HandleBufferLength = (UINT16)(NumberOfHiiHandles * sizeof (EFI_HII_HANDLE));

  //
  // Get the Handles of the packages that were registered with Hii
  //
  Status = Hii->FindHandles(Hii, &HandleBufferLength, HiiHandleBuffer);

  if (EFI_ERROR (Status)) {
    if (Status == EFI_BUFFER_TOO_SMALL) {
      //
      // Free the old pool
      //
      BS->FreePool (HiiHandleBuffer);

      //
      // Allocate new pool with correct value
      //
      BS->AllocatePool (EfiBootServicesData,
                        (UINTN)HandleBufferLength,
                        &HiiHandleBuffer);

      //
      // Get the Handles of the packages that were registered with Hii
      //
      Status = Hii->FindHandles(Hii, &HandleBufferLength, HiiHandleBuffer);

      if (EFI_ERROR (Status)) {
        FreePool(HiiHandleBuffer);
        FreePool(Buffer);
        return Status;
      }
    }
  }

  NumberOfHiiHandles = HandleBufferLength / sizeof(EFI_HII_HANDLE);

  for (Index = 0; Index < NumberOfHiiHandles; Index++) {
    BufferLength = 0xF000;
    ExtractDataFromHiiHandle(HiiHandleBuffer[Index], &BufferLength, Buffer, &HiiGuid);
    if (CompareGuid(&EfiDataHubGuid, &HiiGuid)) {
      continue;
    } else {
      Compared = TRUE;
      *HiiHandle = HiiHandleBuffer[Index];
      break;
    }
  }

  if (!Compared) {
    PackageList.IfrPack      = NULL;
   // PackageList.StringPack   = (EFI_HII_STRING_PACK *)STRING_ARRAY_NAME;
    PackageList.FontPack     = NULL;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -