dmidecode-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[dmidecode] [PATCH 3/4] Add reading of SMBIOS tables from sysfs


From: Roy Franz
Subject: [dmidecode] [PATCH 3/4] Add reading of SMBIOS tables from sysfs
Date: Fri, 17 Apr 2015 11:36:32 -0700

This patch adds 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.
This patch does change the output of dmidecode slightly:
- 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 invalid
  tables.
- the address of the entrypoint 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.

Signed-off-by: Roy Franz <address@hidden>
---
 dmidecode.c     | 39 ++++++++++++++++++++++++++++++++++++++-
 man/dmidecode.8 | 10 ++++++++--
 2 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/dmidecode.c b/dmidecode.c
index aa2abb2..448d5b4 100644
--- a/dmidecode.c
+++ b/dmidecode.c
@@ -71,6 +71,8 @@ static const char *bad_index = "<BAD INDEX>";
 
 #define SUPPORTED_SMBIOS_VER 0x0208
 #define FLAG_NO_FILE_OFFSET    0x1
+#define SYS_ENTRY_FILE "/sys/firmware/dmi/tables/smbios_entry_point"
+#define SYS_TABLE_FILE "/sys/firmware/dmi/tables/DMI"
 
 /*
  * Type-independant Stuff
@@ -4667,7 +4669,38 @@ int main(int argc, char * const argv[])
                goto done;
        }
 
-       /* First try EFI (ia64, Intel-based Mac) */
+       /*
+        * First try reading from sysfs tables.  The entry point file could
+        * contain one of several types of entry points, so read enough for
+        * the largest one, then determine what type it contains.
+        */
+       if ((buf = read_file(0x20, SYS_ENTRY_FILE)) != NULL)
+       {
+               if (!(opt.flags & FLAG_QUIET))
+                       printf("Getting SMBIOS data from sysfs.\n");
+               if (memcmp(buf, "_DMI_", 5) == 0)
+               {
+                       if (legacy_decode(buf, SYS_TABLE_FILE, 
FLAG_NO_FILE_OFFSET))
+                               found++;
+               }
+               else if (memcmp(buf, "_SM_", 4) == 0)
+               {
+                       if (smbios_decode(buf, SYS_TABLE_FILE, 
FLAG_NO_FILE_OFFSET))
+                               found++;
+               }
+               else if (memcmp(buf, "_SM3_", 5) == 0)
+               {
+                       if (!(opt.flags & FLAG_QUIET))
+                               printf("SMBIOS v3 64-bit entry point found, but 
not supported.\n");
+               }
+
+               if (found)
+                       goto done;
+               if (!(opt.flags & FLAG_QUIET))
+                       printf("Failed to get SMBIOS data from sysfs.\n");
+       }
+
+       /* Next try EFI (ia64, Intel-based Mac) */
        efi = address_from_efi(&fp);
        switch (efi)
        {
@@ -4678,6 +4711,8 @@ int main(int argc, char * const argv[])
                        goto exit_free;
        }
 
+       if (!(opt.flags & FLAG_QUIET))
+               printf("Found SMBIOS entry point in EFI, reading table from 
%s.\n", opt.devmem);
        if ((buf = mem_chunk(fp, 0x20, opt.devmem)) == NULL)
        {
                ret = 1;
@@ -4689,6 +4724,8 @@ int main(int argc, char * const argv[])
        goto done;
 
 memory_scan:
+       if (!(opt.flags & FLAG_QUIET))
+               printf("Scanning %s for entry point.\n", opt.devmem);
        /* Fallback to memory scan (x86, x86_64) */
        if ((buf = mem_chunk(0xF0000, 0x10000, opt.devmem)) == NULL)
        {
diff --git a/man/dmidecode.8 b/man/dmidecode.8
index 1bb4c69..e2e95ea 100644
--- a/man/dmidecode.8
+++ b/man/dmidecode.8
@@ -25,8 +25,12 @@ and developed by the \s-1DMTF\s0 (Desktop Management Task 
Force).
 
 As you run it,
 .B dmidecode
-will try to locate the \s-1DMI\s0 table. If it succeeds, it will then parse
-this table and display a list of records like this one:
+will try to locate the \s-1DMI\s0 table. It will first try to read the DMI 
table
+from sysfs, and next try reading directly from memory if sysfs access fails.
+If
+.B dmidecode
+succeeds in locating a valid DMI table, it will then parse this table
+and display a list of records like this one:
 
 Handle 0x0002, DMI type 2, 8 bytes.
 Base Board Information
@@ -241,6 +245,8 @@ The DMI table is located at offset 0x20.
 
 .SH FILES
 .I /dev/mem
+.I /sys/firmware/dmi/tables/DMI
+.I /sys/firmware/dmi/tables/smbios_entry_point
 .SH BUGS
 More often than not, information contained in the \s-1DMI\s0 tables is 
inaccurate,
 incomplete or simply wrong.
-- 
1.9.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]