[Top][All Lists]

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

[dmidecode] Changes to support /sys/firmware/dmi/tables/

From: Roy Franz
Subject: [dmidecode] Changes to support /sys/firmware/dmi/tables/
Date: Thu, 9 Apr 2015 17:43:16 -0700
User-agent: Mutt/1.5.21 (2010-09-15)

Hi Jean,

I've taken a quick look adding support for the new SMBIOS tables in sysfs that 
has posted Linux patches for 
and it looks like support for these is quite simple since it if very similar to 
how dump files
are handled.
The quick patch below works for me with Ivan's patches on x86_64.  A few issues
like how sysfs will deal with both v2 and v3 SMBIOS entry points remain to be
dealt with.

A couple of other things that came to mind while working on this:
* with smbios_decode() now taking an offset, the dumps could retain
  the address of the SMBIOS tables, and the caller could provide
  the appropriate fixed offset.  The address is probably not that
  interesting, but it is nice to preserve the table intact.

* being focused on looking at /dev/mem issues, I was constantly checking
  to see what the *devmem arg was.  In all the places I looked, it was
  really just the filename being used.  Would a patch that just changes
  the *devmem arguments to *filename be acceptable?  I think this would
  lead to more readable code.


commit 4f5be1941ef3973bdb5dd6d8af37313674cc6ad3
Author: Roy Franz <address@hidden>
Date:   Thu Apr 9 14:16:15 2015 -0700

    Add support for reading entry point and SMBIOS tables from sysfs
    ** Patch for discussion only, kernel sysfs interface not upstream yet **
    This patch adds support for using the SMBIOS entry point and tables from
    /sys/firmware/dmi/tables/ instead of directly accessing /dev/mem.  The
    sysfs files are tried first, with the existing methods used when sysfs
    is not available.  This makes the sysfs files the preferred method.
    An offset parameter is added to smbios_decode() to allow it to process
    an unmodified entry point structure.

diff --git a/dmidecode.c b/dmidecode.c
index a5304a7..0d84f13 100644
--- a/dmidecode.c
+++ b/dmidecode.c
@@ -4468,7 +4468,7 @@ static void overwrite_dmi_address(u8 *buf)
        buf[0x0B] = 0;
-static int smbios_decode(u8 *buf, const char *devmem)
+static int smbios_decode(u8 *buf, const char *devmem, u32 offset)
        u16 ver;
@@ -4499,7 +4499,7 @@ static int smbios_decode(u8 *buf, const char *devmem)
                printf("SMBIOS %u.%u present.\n",
                        ver >> 8, ver & 0xFF);
-       dmi_table(DWORD(buf + 0x18), WORD(buf + 0x16), WORD(buf + 0x1C),
+       dmi_table(offset, WORD(buf + 0x16), WORD(buf + 0x1C),
                ver, devmem);
        if (opt.flags & FLAG_DUMP_BIN)
@@ -4646,7 +4646,7 @@ int main(int argc, char * const argv[])
                if (memcmp(buf, "_SM_", 4) == 0)
-                       if (smbios_decode(buf, opt.dumpfile))
+                       if (smbios_decode(buf, opt.dumpfile, DWORD(buf + 0x18)))
                else if (memcmp(buf, "_DMI_", 5) == 0)
@@ -4657,7 +4657,20 @@ int main(int argc, char * const argv[])
                goto done;
-       /* First try EFI (ia64, Intel-based Mac) */
+       /* First try sysfs tables */
+       if ((buf = mem_chunk(0, 0x1f, 
"/sys/firmware/dmi/tables/smbios_entry_point")) != NULL)
+       {
+               if (memcmp(buf, "_SM_", 4) == 0)
+               {
+                       if (smbios_decode(buf, "/sys/firmware/dmi/tables/DMI", 
+                               found++;
+               }
+               // TODO - does legacy (ie no EFI) need to be supported with 
this method?
+               // Not sure what kernel will do with sysfs in those cases
+               goto done;
+       }
+       /* next try EFI (ia64, Intel-based Mac) */
        efi = address_from_efi(&fp);
        switch (efi)
@@ -4674,7 +4687,7 @@ int main(int argc, char * const argv[])
                goto exit_free;
-       if (smbios_decode(buf, opt.devmem))
+       if (smbios_decode(buf, opt.devmem, DWORD(buf + 0x18)))
        goto done;
@@ -4690,7 +4703,7 @@ memory_scan:
                if (memcmp(buf + fp, "_SM_", 4) == 0 && fp <= 0xFFE0)
-                       if (smbios_decode(buf+fp, opt.devmem))
+                       if (smbios_decode(buf+fp, opt.devmem, DWORD(buf + fp + 
                                fp += 16;

reply via email to

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