Skip to content

Commit b0f6dae

Browse files
committed
dmidecode: Add reading of SMBIOS tables from sysfs
Add preferential reading of the SMBIOS tables from /sys/firmware/dmi/tables. If these files are not present or not valid, the previously supported methods of locating SMBIOS tables are attempted. Messages indicating which source is used for the tables have been added. These are printed before the tables have been validated so they can go at the top of the output. This also shows what methods have been tried and failed due to invalid tables. The address of the entry point is not known when read from sysfs, so it is not printed in that case. A placeholder print is added where 64-bit entry point processing will be added. Contributed by Roy Franz.
1 parent 3a7de6a commit b0f6dae

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* util.c, util.h: Add utility function read_file, which reads an
44
entire binary file into a buffer.
55
* dmidecode.c: Add passing of flags parameter to dmi_table.
6+
* dmidecode.c: Add reading of SMBIOS tables from sysfs.
67

78
2015-04-20 Jean Delvare <[email protected]>
89

dmidecode.c

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ static const char *bad_index = "<BAD INDEX>";
7373

7474
#define FLAG_NO_FILE_OFFSET (1 << 0)
7575

76+
#define SYS_ENTRY_FILE "/sys/firmware/dmi/tables/smbios_entry_point"
77+
#define SYS_TABLE_FILE "/sys/firmware/dmi/tables/DMI"
78+
7679
/*
7780
* Type-independant Stuff
7881
*/
@@ -4669,7 +4672,38 @@ int main(int argc, char * const argv[])
46694672
goto done;
46704673
}
46714674

4672-
/* First try EFI (ia64, Intel-based Mac) */
4675+
/*
4676+
* First try reading from sysfs tables. The entry point file could
4677+
* contain one of several types of entry points, so read enough for
4678+
* the largest one, then determine what type it contains.
4679+
*/
4680+
if ((buf = read_file(0x20, SYS_ENTRY_FILE)) != NULL)
4681+
{
4682+
if (!(opt.flags & FLAG_QUIET))
4683+
printf("Getting SMBIOS data from sysfs.\n");
4684+
if (memcmp(buf, "_SM3_", 5) == 0)
4685+
{
4686+
if (!(opt.flags & FLAG_QUIET))
4687+
printf("SMBIOS v3 64-bit entry point found, but not supported.\n");
4688+
}
4689+
else if (memcmp(buf, "_SM_", 4) == 0)
4690+
{
4691+
if (smbios_decode(buf, SYS_TABLE_FILE, FLAG_NO_FILE_OFFSET))
4692+
found++;
4693+
}
4694+
else if (memcmp(buf, "_DMI_", 5) == 0)
4695+
{
4696+
if (legacy_decode(buf, SYS_TABLE_FILE, FLAG_NO_FILE_OFFSET))
4697+
found++;
4698+
}
4699+
4700+
if (found)
4701+
goto done;
4702+
if (!(opt.flags & FLAG_QUIET))
4703+
printf("Failed to get SMBIOS data from sysfs.\n");
4704+
}
4705+
4706+
/* Next try EFI (ia64, Intel-based Mac) */
46734707
efi = address_from_efi(&fp);
46744708
switch (efi)
46754709
{
@@ -4680,6 +4714,9 @@ int main(int argc, char * const argv[])
46804714
goto exit_free;
46814715
}
46824716

4717+
if (!(opt.flags & FLAG_QUIET))
4718+
printf("Found SMBIOS entry point in EFI, reading table from %s.\n",
4719+
opt.devmem);
46834720
if ((buf = mem_chunk(fp, 0x20, opt.devmem)) == NULL)
46844721
{
46854722
ret = 1;
@@ -4691,6 +4728,8 @@ int main(int argc, char * const argv[])
46914728
goto done;
46924729

46934730
memory_scan:
4731+
if (!(opt.flags & FLAG_QUIET))
4732+
printf("Scanning %s for entry point.\n", opt.devmem);
46944733
/* Fallback to memory scan (x86, x86_64) */
46954734
if ((buf = mem_chunk(0xF0000, 0x10000, opt.devmem)) == NULL)
46964735
{

man/dmidecode.8

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ and developed by the \s-1DMTF\s0 (Desktop Management Task Force).
2525

2626
As you run it,
2727
.B dmidecode
28-
will try to locate the \s-1DMI\s0 table. If it succeeds, it will then parse
29-
this table and display a list of records like this one:
28+
will try to locate the \s-1DMI\s0 table. It will first try to read the DMI table
29+
from sysfs, and next try reading directly from memory if sysfs access failed.
30+
If
31+
.B dmidecode
32+
succeeds in locating a valid DMI table, it will then parse this table
33+
and display a list of records like this one:
3034

3135
Handle 0x0002, DMI type 2, 8 bytes.
3236
Base Board Information
@@ -241,6 +245,8 @@ The DMI table is located at offset 0x20.
241245

242246
.SH FILES
243247
.I /dev/mem
248+
.I /sys/firmware/dmi/tables/smbios_entry_point (Linux only)
249+
.I /sys/firmware/dmi/tables/DMI (Linux only)
244250
.SH BUGS
245251
More often than not, information contained in the \s-1DMI\s0 tables is inaccurate,
246252
incomplete or simply wrong.

0 commit comments

Comments
 (0)