Blob Blame History Raw
From 1bd45ec19f7a2d4cdc293b7a5e705c6ee793953e Mon Sep 17 00:00:00 2001
From: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
Date: Thu, 15 Jan 2015 03:01:37 +0200
Subject: [PATCH 4/4] dmidecode: add dmi sysfs support

For working with newly introduced dmi sysfs the dmifs library
was used. It's needed by the systems that cannot use /dev/mem to
access hardware addresses and as result cannot read dmi table.
So another, more correct approach, can be used, it's to read
information from dmi sysfs.

Currently we can use libdmifs library for that.

Reported-by: Leif Lindholm <leif.lindholm@linaro.org>
Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
---
 Makefile    |  2 +-
 dmidecode.c | 31 ++++++++++++++++++++++++++++++-
 version.h   |  2 +-
 3 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index 66c24d5..e3f5c49 100644
--- a/Makefile
+++ b/Makefile
@@ -58,7 +58,7 @@ all : $(PROGRAMS)
 #
 
 dmidecode : dmidecode.o dmiopt.o dmioem.o util.o
-	$(CC) $(LDFLAGS) dmidecode.o dmiopt.o dmioem.o util.o -o $@
+	$(CC) $(LDFLAGS) dmidecode.o dmiopt.o dmioem.o util.o -ldmifs -o $@
 
 biosdecode : biosdecode.o util.o
 	$(CC) $(LDFLAGS) biosdecode.o util.o -o $@
diff --git a/dmidecode.c b/dmidecode.c
index 2fedddc..7d3c133 100644
--- a/dmidecode.c
+++ b/dmidecode.c
@@ -57,6 +57,7 @@
 #include <strings.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <libdmifs.h>
 
 #include "version.h"
 #include "config.h"
@@ -4535,6 +4536,28 @@ static int smbios_decode(u8 *buf, const char *devmem)
 	return 1;
 }
 
+static void dmifs_smbios_decode(void)
+{
+	u16 ver;
+	u8 *smbios;
+	struct dmi_table *dt;
+
+	dt = dmi_get_table();
+	if (!dt)
+		return;
+
+	smbios = dt->smbios;
+
+	ver = get_smbios_version(dt->smbios);
+	dmi_table(DWORD(smbios + 0x18), dmi_get_raw_data(dt->dmi_list),
+		  WORD(smbios + 0x16), WORD(smbios + 0x1C), ver);
+
+	if (opt.flags & FLAG_DUMP_BIN)
+		smbios_in_dumpfile(dt->smbios);
+
+	dmi_put_table(dt);
+}
+
 static int legacy_decode(u8 *buf, const char *devmem)
 {
 	u16 len;
@@ -4692,7 +4715,13 @@ int main(int argc, char * const argv[])
 		goto done;
 	}
 
-	/* First try EFI (ia64, Intel-based Mac) */
+	/* First try dmi sysfs */
+	if (dmifs_is_exist()) {
+		dmifs_smbios_decode();
+		goto exit_free;
+	}
+
+	/* Second try EFI (ia64, Intel-based Mac) */
 	efi = address_from_efi(&fp);
 	switch (efi)
 	{
diff --git a/version.h b/version.h
index 140d334..ce7ffaf 100644
--- a/version.h
+++ b/version.h
@@ -1 +1 @@
-#define VERSION "2.12"
+#define VERSION "2.12-dmifs"
-- 
1.9.3