|
1 | 1 | /*
|
2 | 2 | * uefi-ntfs: UEFI → NTFS/exFAT chain loader - System Information
|
3 | 3 | * Copyright © 2014-2021 Pete Batard <pete@akeo.ie>
|
| 4 | + * With parts from EDK © 1998 Intel Corporation |
4 | 5 | *
|
5 | 6 | * This program is free software: you can redistribute it and/or modify
|
6 | 7 | * it under the terms of the GNU General Public License as published by
|
|
18 | 19 |
|
19 | 20 | #include "boot.h"
|
20 | 21 |
|
| 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 | + |
21 | 131 | /*
|
22 | 132 | * Query the Secure Boot related firmware variables.
|
23 | 133 | * Returns:
|
|
0 commit comments