[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[dmidecode] Decoding of DMI dumps
From: |
phcoder |
Subject: |
[dmidecode] Decoding of DMI dumps |
Date: |
Sat, 06 Dec 2008 13:22:10 +0100 |
User-agent: |
Thunderbird 2.0.0.18 (X11/20081125) |
Hello I wrote a patch to be able to decode smbios/dmi dump. Just run
dmidecode -i <dump>
Vladimir 'phcoder' Serbinenko
diff -urbN orig/dmidecode-2.9/dmidecode.c dmidecode-2.9/dmidecode.c
--- orig/dmidecode-2.9/dmidecode.c 2007-02-26 13:01:44.000000000 +0100
+++ dmidecode-2.9/dmidecode.c 2008-12-05 21:11:37.000000000 +0100
@@ -3847,31 +3847,12 @@
h->data=data;
}
-static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem)
+static void dmi_table_data(u8 *buf, u16 len, int num, u16 ver)
{
- u8 *buf;
- u8 *data;
int i=0;
+ u8 *data=buf;
- if(!(opt.flags & FLAG_QUIET))
- {
- if(opt.type==NULL)
- printf("%u structures occupying %u bytes.\n"
- "Table at 0x%08X.\n",
- num, len, base);
- printf("\n");
- }
-
- if((buf=mem_chunk(base, len, devmem))==NULL)
- {
-#ifndef USE_MMAP
- printf("Table is unreachable, sorry. Try compiling dmidecode
with -DUSE_MMAP.\n");
-#endif
- return;
- }
-
- data=buf;
- while(i<num && data+4<=buf+len) /* 4 is the length of an SMBIOS
structure header */
+ while((i<num||num==-1) && data+4<=buf+len) /* 4 is the length of an SMBIOS
structure header */
{
u8 *next;
struct dmi_header h;
@@ -3948,7 +3929,7 @@
if(!(opt.flags & FLAG_QUIET))
{
- if(i!=num)
+ if(num!=-1 && i!=num)
printf("Wrong DMI structures count: %d announced, "
"only %d decoded.\n", num, i);
if(data-buf!=len)
@@ -3957,6 +3938,30 @@
len, (unsigned int)(data-buf));
}
+}
+
+static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem)
+{
+ u8 *buf;
+
+ if(!(opt.flags & FLAG_QUIET))
+ {
+ if(opt.type==NULL)
+ printf("%u structures occupying %u bytes.\n"
+ "Table at 0x%08X.\n",
+ num, len, base);
+ printf("\n");
+ }
+
+ if((buf=mem_chunk(base, len, devmem))==NULL)
+ {
+#ifndef USE_MMAP
+ printf("Table is unreachable, sorry. Try compiling dmidecode
with -DUSE_MMAP.\n");
+#endif
+ return;
+ }
+
+ dmi_table_data(buf,len,num,ver);
free(buf);
}
@@ -4078,6 +4083,22 @@
if(!(opt.flags & FLAG_QUIET))
printf("# dmidecode %s\n", VERSION);
+ if (opt.flags & FLAG_READFILE)
+ {
+ FILE *f;
+ int l;
+ f=fopen (opt.devmem, "rb");
+ fseek(f,0,SEEK_END);
+ l=ftell (f);
+ fseek(f,0,SEEK_SET);
+ buf=(char *)malloc (l);
+ fread (buf,1,l,f);
+ fclose (f);
+ free (buf);
+ ret=0;
+ dmi_table_data (buf,l,-1,0x22);
+ goto exit_free;
+ }
/* First try EFI (ia64, Intel-based Mac) */
efi=address_from_efi(&fp);
diff -urbN orig/dmidecode-2.9/dmiopt.c dmidecode-2.9/dmiopt.c
--- orig/dmidecode-2.9/dmiopt.c 2007-02-11 21:10:59.000000000 +0100
+++ dmidecode-2.9/dmiopt.c 2008-12-05 21:08:09.000000000 +0100
@@ -215,9 +215,10 @@
int parse_command_line(int argc, char * const argv[])
{
int option;
- const char *optstring = "d:hqs:t:uV";
+ const char *optstring = "d:hqs:t:uVi:";
struct option longopts[]={
{ "dev-mem", required_argument, NULL, 'd' },
+ { "input-file", required_argument, NULL, 'i' },
{ "help", no_argument, NULL, 'h' },
{ "quiet", no_argument, NULL, 'q' },
{ "string", required_argument, NULL, 's' },
@@ -230,6 +231,11 @@
while((option=getopt_long(argc, argv, optstring, longopts, NULL))!=-1)
switch(option)
{
+ case 'i':
+ opt.devmem=optarg;
+ opt.flags|=FLAG_READFILE;
+ break;
+
case 'd':
opt.devmem=optarg;
break;
diff -urbN orig/dmidecode-2.9/dmiopt.h dmidecode-2.9/dmiopt.h
--- orig/dmidecode-2.9/dmiopt.h 2005-09-14 21:57:30.000000000 +0200
+++ dmidecode-2.9/dmiopt.h 2008-11-18 22:03:32.000000000 +0100
@@ -41,6 +41,7 @@
#define FLAG_HELP (1<<1)
#define FLAG_DUMP (1<<2)
#define FLAG_QUIET (1<<3)
+#define FLAG_READFILE (1<<4)
int parse_command_line(int argc, char * const argv[]);
void print_help(void);
- [dmidecode] Decoding of DMI dumps,
phcoder <=