summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRegia König2021-06-08 18:28:50 +0200
committerRegia König2021-06-08 18:28:50 +0200
commit1ee1f091545a4b3890d250000da6f3c72e2df6c0 (patch)
treef3c6d0725e8793d7313f201d67b8518b31d0c65f
parentAdd condition. Dmi startup info is only printed if dmi opening was successful (diff)
downloadmemtest86-1ee1f091545a4b3890d250000da6f3c72e2df6c0.tar.gz
memtest86-1ee1f091545a4b3890d250000da6f3c72e2df6c0.tar.xz
memtest86-1ee1f091545a4b3890d250000da6f3c72e2df6c0.zip
Read SMBIOS table
-rw-r--r--efi_memtest/memtest86+/efi/dmi.c151
1 files changed, 136 insertions, 15 deletions
diff --git a/efi_memtest/memtest86+/efi/dmi.c b/efi_memtest/memtest86+/efi/dmi.c
index 1cb602e..9b9db0f 100644
--- a/efi_memtest/memtest86+/efi/dmi.c
+++ b/efi_memtest/memtest86+/efi/dmi.c
@@ -144,8 +144,8 @@ static char *memory_types[] = {
"Other", "????", "DRAM", "EDRAM", "VRAM", "SRAM", "RAM",
"ROM", "FLASH", "EEPROM", "FEPROM", "EPROM", "CDRAM", "3DRAM",
"SDRAM", "SGRAM", "RDRAM", "DDR", "DDR2", "DDR2 FB", "RSVD",
- "RSVD","RSVD","DDR3","FBD2", "DDR4", "LPDDR", "LPDDR2", "LPDDR3",
- "LPDDR4", "LNVD", "HBM", "HBM2", "DDR5", "LPDDR5"
+ "RSVD","RSVD","DDR3","FBD2", "DDR4", "LPDDR", "LPDDR2", "LPDDR3",
+ "LPDDR4", "LNVD", "HBM", "HBM2", "DDR5", "LPDDR5"
};
@@ -162,10 +162,12 @@ char * get_tstruct_string(struct tstruct_header *header, int n){
if (logflag) print_log("get_tstruct_string() started.", 29);
- if(n<1)
- return 0;
+ if(n<1) return 0;
+
char * a = (char *)header + header->length;
+
n--;
+
do{
if (!*a)
n--;
@@ -173,23 +175,32 @@ char * get_tstruct_string(struct tstruct_header *header, int n){
return a;
a++;
}while (!(*a==0 && *(a-1)==0));
+
return 0;
}
BOOLEAN abc(EFI_GUID* sfspGuid, EFI_GUID* guid) {
- if (guid->Data1 == sfspGuid->Data1 && guid->Data2 == sfspGuid->Data2 && guid->Data3 == sfspGuid->Data3
- && guid->Data4[0] == sfspGuid->Data4[0] && guid->Data4[1] == sfspGuid->Data4[1]
- && guid->Data4[2] == sfspGuid->Data4[2] && guid->Data4[3] == sfspGuid->Data4[3]
- && guid->Data4[4] == sfspGuid->Data4[4] && guid->Data4[5] == sfspGuid->Data4[5]
- && guid->Data4[6] == sfspGuid->Data4[6] && guid->Data4[7] == sfspGuid->Data4[7]) {
+ if (guid->Data1 == sfspGuid->Data1 && guid->Data2 == sfspGuid->Data2 && guid->Data3 == sfspGuid->Data3
+ && guid->Data4[0] == sfspGuid->Data4[0] && guid->Data4[1] == sfspGuid->Data4[1]
+ && guid->Data4[2] == sfspGuid->Data4[2] && guid->Data4[3] == sfspGuid->Data4[3]
+ && guid->Data4[4] == sfspGuid->Data4[4] && guid->Data4[5] == sfspGuid->Data4[5]
+ && guid->Data4[6] == sfspGuid->Data4[6] && guid->Data4[7] == sfspGuid->Data4[7]) {
- return TRUE;
+ return TRUE;
}
return FALSE;
}
+
+// TODO Add support for SMBIOS3 table
int open_dmi(void) {
+ char *dmi, *dmi_start;
+ int found=0;
+ struct dmi_eps *eps;
+ char *table_start;
+ int tstruct_count=0;
+
if (logflag) print_log("open_dmi() started.", 19);
extern EFI_SYSTEM_TABLE *gST;
@@ -221,6 +232,8 @@ int open_dmi(void) {
print_log("EFI_ACPI_20_TABLE_GUID", 22);
} else if (abc(&guid, &smbios)) {
print_log("SMBIOS_TABLE_GUID", 17);
+ dmi = ct->VendorTable;
+ found = 1;
} else if (abc(&guid, &smbios3)) {
print_log("SMBIOS3_TABLE_GUID", 18);
} else if (abc(&guid, &acpi_10)) {
@@ -231,7 +244,100 @@ int open_dmi(void) {
ct++;
}
- return -1;
+ if (!found) {
+ print_log("open_dmi(): dmi not found", 25);
+ return -1;
+ }
+
+ dmi_start=dmi;
+ eps=(struct dmi_eps *)dmi;
+
+ //check checksum
+ int8_t checksum=0;
+ for (; dmi < dmi_start + eps->length; dmi++)
+ checksum += *dmi;
+ if (checksum){
+ return -1;
+ }
+
+ if (logflag) {
+ char log[25] = "majorversion = ";
+ int length = 15;
+ int_to_charr(eps->majorversion, log, &length);
+ print_log(log, length);
+ }
+
+ if (logflag) {
+ char log[25] = "minorversion = ";
+ int length = 15;
+ int_to_charr(eps->minorversion, log, &length);
+ print_log(log, length);
+ }
+
+ //we need at least revision 2.1 of SMBIOS
+ if ( eps->majorversion < 2 &&
+ eps->minorversion < 1){
+ return -1;
+ }
+
+ table_start=(char *)(uintptr_t)eps->tableaddress;
+ dmi=table_start;
+ //look at all structs
+ while(dmi < table_start + eps->tablelength){
+ struct tstruct_header *header = (struct tstruct_header *)dmi;
+
+ if (logflag) {
+ char log[24] = "header type = ";
+ int length = 14;
+ int_to_charr(header->type, log, &length);
+ print_log(log, length);
+ }
+
+ if (header->type == 17) {
+ mem_devs[mem_devs_count++] = (struct mem_dev *)dmi;
+ }
+ // Mem Dev Map
+ else if (header->type == 20) {
+ md_maps[md_maps_count++] = (struct md_map *)dmi;
+ }
+
+ // MB_SPEC
+ else if (header->type == 2)
+ {
+ dmi_system_info = (struct system_map *)dmi;
+ }
+
+ // CPU_SPEC
+ else if (header->type == 4)
+ {
+ dmi_cpu_info = (struct cpu_map *)dmi;
+ }
+
+ dmi+=header->length;
+
+ while( ! (*dmi == 0 && *(dmi+1) == 0 ) )
+ dmi++;
+ dmi+=2;
+
+ if (++tstruct_count > eps->numstructs)
+ return -1;
+ }
+
+ if(logflag && log_mem_ctrl) {
+ char log[26] = "tstruct_count = ";
+ int length = 16;
+ int_to_charr(tstruct_count, log, &length);
+ print_log(log, length);
+ }
+
+ if (logflag && log_mem_ctrl) {
+ char log[43] = "SMBIOS entry point->numstructs = ";
+ int length = 33;
+ int_to_charr(eps->numstructs, log, &length);
+ print_log(log, length);
+ }
+
+ return 0;
}
/*int open_dmi(void){
@@ -345,8 +451,6 @@ void print_dmi_startup_info(void)
if (logflag) print_log("Dmi initialized.", 16);
- if (logflag) print_log("Dmi initialized.", 16);
-
if (logflag) {
char log[50] = "print_dmi_startup_info(): dmi pointer = ";
int length = 40;
@@ -397,17 +501,33 @@ void print_dmi_startup_info(void)
}
if (logflag && log_mem_ctrl) {
+ char log[16] = "sl2 = ";
+ int length = 6;
+ int_to_charr(sl2, log, &length);
+ print_log(log, length);
+ }
+
+ if (logflag && log_mem_ctrl) {
char log[59] = "print_dmi_startup_info(): cpu_socket = ";
int length = 39;
string_to_charr(string3, log, &length);
print_log(log, length);
}
+ if (logflag && log_mem_ctrl) {
+ char log[16] = "sl3 = ";
+ int length = 6;
+ int_to_charr(sl3, log, &length);
+ print_log(log, length);
+ }
+
slength = sl1 + sl2;
if(sl3 > 2) { slength += sl3 + 4; } else { slength++; }
if(sl1 && sl2)
{
+
+ print_log("Printing CPU information.", 25);
//dmicol -= slength; // right align
dmicol = 39 - slength/2; // center align
cprint(LINE_DMI, dmicol, string1);
@@ -429,8 +549,9 @@ void print_dmi_info(void){
int i,j,page;
char * string=0;
- if(!dmi_initialized)
- init_dmi();
+ if(!dmi_initialized) {
+ if (init_dmi() == -1) return;
+ }
if (mem_devs_count == 0){
cprint(POP2_Y+1, POP2_X+2, "No valid DMI Memory Devices info found");