刚毕业入行bios,不知道要加哪些头文件所以就全加了,有些头文件是不需要的,写的有点乱,主要看那两个函数就可以。。inf和dsc、dec自己慢慢照着原有的配。
build -p TestSMBIOS\TestSMBIOS.dsc -a X64, 复制到u盘然后到shell下运行load EFI文件就可以。
读取的主要思路:1.先获取ESP表的结构体,ESP表中有个TableAddress保存的是第一个type的地址。
2.创建SMBIOS结构体,这个结构体里有几个重要的东西(Hdr和Raw)这个结构体有个Raw指针,代表当前
SMBIOS结构体是哪个TYPE。
3.Hdr中有Length,Type还有个啥忘了,Length是格式区域的长度,Length之后紧接的是字符串区域,以
00 00 两对00结束,因此我们用一个指针p来读。判断读完两对00后就代表进入下一个Type。然后把p赋给
Raw指针,进行下一步想要的操作。大致思路就是这样,细节看代码。
Modify那个函数是修改Type1的ProductName。
#include<Uefi.h>
#include<Library/IoLib.h>
#include<Library/UefiLib.h>
#include<Protocol/SimpleTextIn.h>
#include <Base.h>
#include <Library/UefiLib.h>
#include <Guid/GlobalVariable.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/DebugLib.h>
#include <PiDxe.h>
#include <Library/IoLib.h>
#include <Library/TimerLib.h>
#include <IndustryStandard/SmBios.h>
#include <Guid/SmBios.h>
#include <Library/PcdLib.h>
#include <Library/BaseMemoryLib.h>
#include <C:\edk2-master\ShellPkg\Library\UefiShellDebug1CommandsLib\SmbiosView\LibSmbiosView.h>
#include <stdio.h>
#include<Library\MemoryAllocationLib.h>
CHAR8 * LibGetSmbiosString (IN SMBIOS_STRUCTURE_POINTER *Smbios,IN UINT16 StringNumber);
SMBIOS_STRUCTURE_POINTER SmBiosStruct;
STATIC SMBIOS_STRUCTURE_POINTER m_SmbiosStruct;
STATIC SMBIOS_STRUCTURE_POINTER *mSmbiosStruct=&m_SmbiosStruct;
STATIC SMBIOS_TABLE_ENTRY_POINT *ESPTable=NULL; //ESP
EFI_GUID gEfiSmbiosTableGuid=SMBIOS_TABLE_GUID; //ESP GUID
static UINT8 *p;
void PrintNowType()//print now types' information (default started by type0) ,and find next type's address
{
int i,j