UEFI标准应用程序模块--SMBIOS的读写

本篇程序参考自博客“UEFI应用与编程–SmBios”https://blog.csdn.net/qyqcs/article/details/79566235
在原博主的基础上进行了一些修改,修改了几处个人觉得有问题的地方。
SmBiosList.c

#include <Uefi.h>  
#include <Library/UefiLib.h>
#include <IndustryStandard/SmBios.h>
#include <Library/UefiShellDebug1CommandsLib.h>
#include <Library/LibSmbiosView.h> 
 
 
EFI_STATUS EFIAPI UefiMain(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
{ 
  EFI_STATUS                    Status;
  SMBIOS_TABLE_ENTRY_POINT      *mSmbiosTable   = NULL;
  SMBIOS_STRUCTURE_POINTER      m_SmbiosStruct;
  SMBIOS_STRUCTURE_POINTER      *mSmbiosStruct = &m_SmbiosStruct;
  
  SMBIOS_STRUCTURE_POINTER  Smbios;
  SMBIOS_STRUCTURE_POINTER  SmbiosEnd;
  UINT8                     *Raw;

  UINT16                    Handle1 = 0;
  UINT8                     *Buffer1;
  UINT16                    Length1;
  
  
  UINT16                    *Handle;
  UINT8                     **Buffer;
  UINT16                    *Length;

  UINT8                     Type;
  
 
  mSmbiosTable = NULL;
 
  //
  // Get SMBIOS table from System Configure table
  //
  Status = GetSystemConfigurationTable(&gEfiSmbiosTableGuid,(VOID**)&mSmbiosTable);
 
  if (mSmbiosTable == NULL)
  {
    Print(L"%r.\n",Status);
  }
  //
  // Init SMBIOS structure table address
  //
  mSmbiosStruct->Raw  = (UINT8 *)(UINTN)(mSmbiosTable->TableAddress);
  
   //
  //Find the structure
  //
  Handle = &Handle1;
  Length = &Length1;
  Buffer = &Buffer1;
  
  *Length       = 0;
  Smbios.Hdr    = mSmbiosStruct->Hdr;
  SmbiosEnd.Raw = Smbios.Raw + mSmbiosTable->TableLength;
  Print(L"TableLenth:%02d\n",mSmbiosTable->TableLength);
  
  while (Smbios.Raw < SmbiosEnd.Raw)
  {
    if (Smbios.Hdr->Handle == *Handle)
	{
      Raw = Smbios.Raw;
	  Type = Smbios.Hdr->Type;
      //
      // Walk to next structure
      //
      LibGetSmbiosString(&Smbios,(UINT16)(-1));
      //
      // Length = Next structure head - this structure head
      //
      *Length = (UINT16)(Smbios.Raw - Raw);
      *Buffer = Raw;
      //
      // update with the next structure handle.
      //
      if (Smbios.Raw < SmbiosEnd.Raw)
      {
        *Handle = Smbios.Hdr->Handle;
      } else
       {
        *Handle = (UINT16)(-1);
      }
      Print(L"Handle:%04x Type:%04d Address:%08x Length:%04x\n", *Handle - 1, Type, *Buffer, *Length);
	  DumpHex(2, 0, *Length, *Buffer);
      //return DMI_SUCCESS;
    }
  }
  *Handle = (UINT16)(-1);
  return EFI_SUCCESS;
}

注意:由于用edk2中的nt32虚拟机编译时找不到shellpkg里面的UefiShellDebug1CommandsLib.h和LibSmbiosView.h,故将其移动edk2\MdePkg\Include\Library目录内。
SmBiosList.inf

[Defines]  
  INF_VERSION             = 0x00010005  
  BASE_NAME               = SmBiosRead  
  FILE_GUID               = dc72d2c7-a48a-42fd-80b6-9d229d9943c8  
  MODULE_TYPE             = UEFI_APPLICATION  
  VERSION_STRING          = 1.0  
  ENTRY_POINT             = UefiMain 
 
[Sources]  
  SmBiosList.c   
[Packages]  
  MdePkg/MdePkg.dec  
  MdeModulePkg/MdeModulePkg.dec
  ShellPkg/ShellPkg.dec
  
 [LibraryClasses]  
  UefiLib
  UefiApplicationEntryPoint
  PrintLib
  UefiShellDebug1CommandsLib
  
[Protocols]  
 
[Ppis]  
  
[Guids]  
  gEfiSmbiosTableGuid
[BuildOptions]

亲测

猜你喜欢

转载自blog.csdn.net/cenjue/article/details/84327355