Skip to content

Commit 78519cd

Browse files
committed
New option --from-dump, read the DMI data from a binary file.
1 parent f23bf3e commit 78519cd

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

dmidecode.c

+29-3
Original file line numberDiff line numberDiff line change
@@ -3877,9 +3877,12 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem)
38773877
if(!(opt.flags & FLAG_QUIET))
38783878
{
38793879
if(opt.type==NULL)
3880-
printf("%u structures occupying %u bytes.\n"
3881-
"Table at 0x%08X.\n",
3882-
num, len, base);
3880+
{
3881+
printf("%u structures occupying %u bytes.\n",
3882+
num, len);
3883+
if(!(opt.flags & FLAG_FROM_DUMP))
3884+
printf("Table at 0x%08X.\n", base);
3885+
}
38833886
printf("\n");
38843887
}
38853888

@@ -4138,6 +4141,29 @@ int main(int argc, char * const argv[])
41384141
if(!(opt.flags & FLAG_QUIET))
41394142
printf("# dmidecode %s\n", VERSION);
41404143

4144+
/* Read from dump if so instructed */
4145+
if(opt.flags & FLAG_FROM_DUMP)
4146+
{
4147+
printf("Reading SMBIOS/DMI data from file %s.\n", opt.dumpfile);
4148+
if((buf=mem_chunk(0, 0x20, opt.dumpfile))==NULL)
4149+
{
4150+
ret=1;
4151+
goto exit_free;
4152+
}
4153+
4154+
if(memcmp(buf, "_SM_", 4)==0)
4155+
{
4156+
if(smbios_decode(buf, opt.dumpfile))
4157+
found++;
4158+
}
4159+
else if(memcmp(buf, "_DMI_", 5)==0)
4160+
{
4161+
if (legacy_decode(buf, opt.dumpfile))
4162+
found++;
4163+
}
4164+
goto done;
4165+
}
4166+
41414167
/* First try EFI (ia64, Intel-based Mac) */
41424168
efi=address_from_efi(&fp);
41434169
switch(efi)

dmiopt.c

+11
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ int parse_command_line(int argc, char * const argv[])
224224
{ "type", required_argument, NULL, 't' },
225225
{ "dump", no_argument, NULL, 'u' },
226226
{ "dump-bin", required_argument, NULL, 'B' },
227+
{ "from-dump", required_argument, NULL, 'F' },
227228
{ "version", no_argument, NULL, 'V' },
228229
{ 0, 0, 0, 0 }
229230
};
@@ -235,6 +236,10 @@ int parse_command_line(int argc, char * const argv[])
235236
opt.flags|=FLAG_DUMP_BIN;
236237
opt.dumpfile=optarg;
237238
break;
239+
case 'F':
240+
opt.flags|=FLAG_FROM_DUMP;
241+
opt.dumpfile=optarg;
242+
break;
238243
case 'd':
239244
opt.devmem=optarg;
240245
break;
@@ -297,6 +302,11 @@ int parse_command_line(int argc, char * const argv[])
297302
fprintf(stderr, "Options --dump-bin, --string and --type are mutually exclusive\n");
298303
return -1;
299304
}
305+
if((opt.flags & FLAG_FROM_DUMP) && (opt.flags & FLAG_DUMP_BIN))
306+
{
307+
fprintf(stderr, "Options --from-dump and --dump-bin are mutually exclusive\n");
308+
return -1;
309+
}
300310

301311
return 0;
302312
}
@@ -313,6 +323,7 @@ void print_help(void)
313323
" -t, --type TYPE Only display the entries of given type\n"
314324
" -u, --dump Do not decode the entries\n"
315325
" --dump-bin FILE Dump the DMI data to a binary file\n"
326+
" --from-dump FILE Read the DMI data from a binary file\n"
316327
" -V, --version Display the version and exit\n";
317328

318329
printf("%s", help);

dmiopt.h

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ extern struct opt opt;
4343
#define FLAG_DUMP (1<<2)
4444
#define FLAG_QUIET (1<<3)
4545
#define FLAG_DUMP_BIN (1<<4)
46+
#define FLAG_FROM_DUMP (1<<5)
4647

4748
int parse_command_line(int argc, char * const argv[]);
4849
void print_help(void);

0 commit comments

Comments
 (0)