Skip to content

Commit f2363f4

Browse files
committed
add EDK2 compatible system information report
1 parent ae41a8a commit f2363f4

File tree

4 files changed

+133
-57
lines changed

4 files changed

+133
-57
lines changed

boot.c

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -142,61 +142,6 @@ static VOID DisconnectBlockingDrivers(VOID) {
142142
FreePool(Handles);
143143
}
144144

145-
#if defined(_GNU_EFI)
146-
147-
/*
148-
* Query SMBIOS to display some info about the system hardware and UEFI firmware.
149-
* Also display the current Secure Boot status.
150-
*/
151-
static EFI_STATUS PrintSystemInfo(VOID)
152-
{
153-
EFI_STATUS Status;
154-
SMBIOS_STRUCTURE_POINTER Smbios;
155-
SMBIOS_STRUCTURE_TABLE* SmbiosTable;
156-
SMBIOS3_STRUCTURE_TABLE* Smbios3Table;
157-
UINT8 Found = 0, *Raw;
158-
UINTN MaximumSize, ProcessedSize = 0;
159-
160-
PrintInfo(L"UEFI v%d.%d (%s, 0x%08X)", gST->Hdr.Revision >> 16, gST->Hdr.Revision & 0xFFFF,
161-
gST->FirmwareVendor, gST->FirmwareRevision);
162-
163-
Status = LibGetSystemConfigurationTable(&SMBIOS3TableGuid, (VOID**)&Smbios3Table);
164-
if (Status == EFI_SUCCESS) {
165-
Smbios.Hdr = (SMBIOS_HEADER*)Smbios3Table->TableAddress;
166-
MaximumSize = (UINTN)Smbios3Table->TableMaximumSize;
167-
} else {
168-
Status = LibGetSystemConfigurationTable(&SMBIOSTableGuid, (VOID**)&SmbiosTable);
169-
if (EFI_ERROR(Status))
170-
return EFI_NOT_FOUND;
171-
Smbios.Hdr = (SMBIOS_HEADER*)(UINTN)SmbiosTable->TableAddress;
172-
MaximumSize = (UINTN)SmbiosTable->TableLength;
173-
}
174-
175-
while ((Smbios.Hdr->Type != 0x7F) && (Found < 2)) {
176-
Raw = Smbios.Raw;
177-
if (Smbios.Hdr->Type == 0) {
178-
PrintInfo(L"%a %a", LibGetSmbiosString(&Smbios, Smbios.Type0->Vendor),
179-
LibGetSmbiosString(&Smbios, Smbios.Type0->BiosVersion));
180-
Found++;
181-
}
182-
if (Smbios.Hdr->Type == 1) {
183-
PrintInfo(L"%a %a", LibGetSmbiosString(&Smbios, Smbios.Type1->Manufacturer),
184-
LibGetSmbiosString(&Smbios, Smbios.Type1->ProductName));
185-
Found++;
186-
}
187-
LibGetSmbiosString(&Smbios, -1);
188-
ProcessedSize += (UINTN)Smbios.Raw - (UINTN)Raw;
189-
if (ProcessedSize > MaximumSize) {
190-
PrintWarning(L"Aborting system report due to noncompliant SMBIOS");
191-
return EFI_ABORTED;
192-
}
193-
}
194-
195-
return EFI_SUCCESS;
196-
}
197-
198-
#endif /* _GNUEFI */
199-
200145
/*
201146
* Application entry-point
202147
* NB: This must be set to 'efi_main' for gnu-efi crt0 compatibility
@@ -232,9 +177,7 @@ EFI_STATUS EFIAPI efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable
232177
gST->ConOut->ClearScreen(gST->ConOut);
233178

234179
Print(L"\n*** UEFI:NTFS %s (%s) ***\n\n", VERSION_STRING, Arch);
235-
#if defined(_GNU_EFI)
236180
PrintSystemInfo();
237-
#endif
238181
SecureBootStatus = GetSecureBootStatus();
239182
PrintInfo(L"Secure Boot status: %s",
240183
(SecureBootStatus > 0) ? L"Enabled" :

boot.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
#include <efistdarg.h>
2424
#include <libsmbios.h>
2525

26+
#define gEfiSmbios3TableGuid SMBIOS3TableGuid
27+
#define gEfiSmbiosTableGuid SMBIOSTableGuid
28+
#define SMBIOS_STRUCTURE SMBIOS_HEADER
29+
#define SMBIOS_TABLE_ENTRY_POINT SMBIOS_STRUCTURE_TABLE
30+
#define SMBIOS_TABLE_3_0_ENTRY_POINT SMBIOS3_STRUCTURE_TABLE
31+
2632
#else /* EDK2 */
2733

2834
#include <Base.h>
@@ -52,6 +58,9 @@
5258
#include <Guid/FileInfo.h>
5359
#include <Guid/FileSystemInfo.h>
5460
#include <Guid/FileSystemVolumeLabelInfo.h>
61+
#include <Guid/SmBios.h>
62+
63+
#include <IndustryStandard/SmBios.h>
5564

5665
#endif /* __MAKEWITH_GNUEFI */
5766

@@ -90,6 +99,17 @@
9099
/* Convenience assertion macro */
91100
#define P_ASSERT(f, l, a) if(!(a)) do { Print(L"*** ASSERT FAILED: %a(%d): %a ***\n", f, l, #a); while(1); } while(0)
92101

102+
/*
103+
* EDK2 and gnu-efi's CompareGuid() return opposite values for a match!
104+
* EDK2 returns boolean TRUE, whereas gnu-efi returns INTN 0, so we
105+
* define a common boolean macro that follows EDK2 convention always.
106+
*/
107+
#if defined(_GNU_EFI)
108+
#define COMPARE_GUID(a, b) (CompareGuid(a, b) == 0)
109+
#else
110+
#define COMPARE_GUID CompareGuid
111+
#endif
112+
93113
/*
94114
* Secure string length, that asserts if the string is NULL or if
95115
* the length is larger than a predetermined value (STRING_MAX)
@@ -158,4 +178,5 @@ EFI_DEVICE_PATH* GetParentDevice(CONST EFI_DEVICE_PATH* DevicePath);
158178
INTN CompareDevicePaths(CONST EFI_DEVICE_PATH* dp1, CONST EFI_DEVICE_PATH* dp2);
159179
EFI_STATUS SetPathCase(CONST EFI_FILE_HANDLE Root, CHAR16* Path);
160180
CHAR16* DevicePathToString(CONST EFI_DEVICE_PATH* DevicePath);
181+
EFI_STATUS PrintSystemInfo(VOID);
161182
INTN GetSecureBootStatus(VOID);

system.c

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
* uefi-ntfs: UEFI → NTFS/exFAT chain loader - System Information
33
* Copyright © 2014-2021 Pete Batard <pete@akeo.ie>
4+
* With parts from EDK © 1998 Intel Corporation
45
*
56
* This program is free software: you can redistribute it and/or modify
67
* it under the terms of the GNU General Public License as published by
@@ -18,6 +19,115 @@
1819

1920
#include "boot.h"
2021

22+
/*
23+
* Read a system configuration table from a TableGuid.
24+
*/
25+
static EFI_STATUS GetSystemConfigurationTable(EFI_GUID* TableGuid, VOID** Table)
26+
{
27+
UINTN Index;
28+
P_ASSERT(__FILE__, __LINE__, Table != NULL);
29+
30+
for (Index = 0; Index < gST->NumberOfTableEntries; Index++) {
31+
if (COMPARE_GUID(TableGuid, &(gST->ConfigurationTable[Index].VendorGuid))) {
32+
*Table = gST->ConfigurationTable[Index].VendorTable;
33+
return EFI_SUCCESS;
34+
}
35+
}
36+
return EFI_NOT_FOUND;
37+
}
38+
39+
/*
40+
* Return SMBIOS string given the string number.
41+
* Arguments:
42+
* Smbios - Pointer to SMBIOS structure
43+
* StringNumber - String number to return. 0xFFFF can be used to skip all
44+
* strings and point to the next SMBIOS structure.
45+
* Returns:
46+
* Pointer to string, or pointer to next SMBIOS structure if StringNumber == 0xFFFF.
47+
*/
48+
static CHAR8* GetSmbiosString(SMBIOS_STRUCTURE_POINTER* Smbios, UINT16 StringNumber)
49+
{
50+
UINT16 Index;
51+
CHAR8* String;
52+
53+
// Skip over formatted section
54+
String = (CHAR8*)(Smbios->Raw + Smbios->Hdr->Length);
55+
56+
// Look through unformated section
57+
for (Index = 1; Index <= StringNumber; Index++) {
58+
if (StringNumber == Index)
59+
return String;
60+
61+
// Skip string
62+
for (; *String != 0; String++);
63+
String++;
64+
65+
if (*String == 0) {
66+
// If double NUL then we are done.
67+
// Return pointer to next structure in Smbios.
68+
// If you pass 0xFFFF for StringNumber you always get here.
69+
Smbios->Raw = (UINT8*)++String;
70+
return NULL;
71+
}
72+
}
73+
return NULL;
74+
}
75+
76+
/*
77+
* Query SMBIOS to display some info about the system hardware and UEFI firmware.
78+
*/
79+
EFI_STATUS PrintSystemInfo(VOID)
80+
{
81+
EFI_STATUS Status;
82+
SMBIOS_STRUCTURE_POINTER Smbios;
83+
SMBIOS_TABLE_ENTRY_POINT* SmbiosTable;
84+
SMBIOS_TABLE_3_0_ENTRY_POINT* Smbios3Table;
85+
UINT8 Found = 0, *Raw;
86+
UINTN MaximumSize, ProcessedSize = 0;
87+
88+
PrintInfo(L"UEFI v%d.%d (%s, 0x%08X)", gST->Hdr.Revision >> 16, gST->Hdr.Revision & 0xFFFF,
89+
gST->FirmwareVendor, gST->FirmwareRevision);
90+
91+
Status = GetSystemConfigurationTable(&gEfiSmbios3TableGuid, (VOID**)&Smbios3Table);
92+
if (Status == EFI_SUCCESS) {
93+
Smbios.Hdr = (SMBIOS_STRUCTURE*)(UINTN)Smbios3Table->TableAddress;
94+
MaximumSize = (UINTN)Smbios3Table->TableMaximumSize;
95+
} else {
96+
Status = GetSystemConfigurationTable(&gEfiSmbiosTableGuid, (VOID**)&SmbiosTable);
97+
if (EFI_ERROR(Status))
98+
return EFI_NOT_FOUND;
99+
Smbios.Hdr = (SMBIOS_STRUCTURE*)(UINTN)SmbiosTable->TableAddress;
100+
MaximumSize = (UINTN)SmbiosTable->TableLength;
101+
}
102+
// Sanity check
103+
if (MaximumSize > 1024 * 1024) {
104+
PrintWarning(L"Aborting system report due to unexpected SMBIOS table length (0x%08X)", MaximumSize);
105+
return EFI_ABORTED;
106+
}
107+
108+
while ((Smbios.Hdr->Type != 0x7F) && (Found < 2)) {
109+
Raw = Smbios.Raw;
110+
if (Smbios.Hdr->Type == 0) {
111+
PrintInfo(L"%a %a", GetSmbiosString(&Smbios, Smbios.Type0->Vendor),
112+
GetSmbiosString(&Smbios, Smbios.Type0->BiosVersion));
113+
Found++;
114+
}
115+
if (Smbios.Hdr->Type == 1) {
116+
PrintInfo(L"%a %a", GetSmbiosString(&Smbios, Smbios.Type1->Manufacturer),
117+
GetSmbiosString(&Smbios, Smbios.Type1->ProductName));
118+
Found++;
119+
}
120+
GetSmbiosString(&Smbios, 0xFFFF);
121+
ProcessedSize += (UINTN)Smbios.Raw - (UINTN)Raw;
122+
if (ProcessedSize > MaximumSize) {
123+
PrintWarning(L"Aborting system report due to noncompliant SMBIOS");
124+
return EFI_ABORTED;
125+
}
126+
}
127+
128+
return EFI_SUCCESS;
129+
}
130+
21131
/*
22132
* Query the Secure Boot related firmware variables.
23133
* Returns:

uefi-ntfs.inf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
[Guids]
4343
gEfiFileSystemInfoGuid
4444
gEfiFileSystemVolumeLabelInfoIdGuid
45+
gEfiSmbiosTableGuid
46+
gEfiSmbios3TableGuid
4547

4648
[Protocols]
4749
gEfiBlockIoProtocolGuid

0 commit comments

Comments
 (0)