Skip to content

Commit 4e72120

Browse files
committed
New option --dump-bin, dump the DMI data to a sparse binary file.
1 parent 8c6bf0c commit 4e72120

File tree

7 files changed

+109
-2
lines changed

7 files changed

+109
-2
lines changed

CHANGELOG

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2008-02-16 Jean Delvare <[email protected]>
2+
3+
* util.c, util.h: New helper function write_dump.
4+
* dmidecode.c, dmiopt.c, dmiopt.h: New option --dump-bin, dump
5+
the DMI data to a sparse binary file.
6+
* dmidecode.8: Document the new option --dump-bin.
7+
18
2007-06-30 Jean Delvare <[email protected]>
29

310
* config.h: Add support for Solaris (x86 only, of course). Based

dmidecode.c

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3847,12 +3847,39 @@ static void to_dmi_header(struct dmi_header *h, u8 *data)
38473847
h->data=data;
38483848
}
38493849

3850+
static void dmi_table_dump(u32 base, u16 len, const char *devmem)
3851+
{
3852+
u8 *buf;
3853+
3854+
if(base+len>0xFFFFF)
3855+
{
3856+
fprintf(stderr, "Table is too far away in memory, can't dump, sorry.\n");
3857+
return;
3858+
}
3859+
3860+
if((buf=mem_chunk(base, len, devmem))==NULL)
3861+
{
3862+
fprintf(stderr, "Failed to read table, sorry.\n");
3863+
return;
3864+
}
3865+
3866+
printf("# Writing %d bytes to %s.\n", len, opt.dumpfile);
3867+
write_dump(base, len, buf, opt.dumpfile);
3868+
free(buf);
3869+
}
3870+
38503871
static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem)
38513872
{
38523873
u8 *buf;
38533874
u8 *data;
38543875
int i=0;
38553876

3877+
if(opt.flags & FLAG_DUMP_BIN)
3878+
{
3879+
dmi_table_dump(base, len, devmem);
3880+
return;
3881+
}
3882+
38563883
if(!(opt.flags & FLAG_QUIET))
38573884
{
38583885
if(opt.type==NULL)
@@ -4108,6 +4135,16 @@ int main(int argc, char * const argv[])
41084135
goto exit_free;
41094136
}
41104137

4138+
if(opt.flags & FLAG_DUMP_BIN)
4139+
{
4140+
printf("# Writing %d bytes to %s.\n", 0x10000, opt.dumpfile);
4141+
if(write_dump(0xF0000, 0x10000, buf, opt.dumpfile))
4142+
{
4143+
ret=2;
4144+
goto exit_free_buf;
4145+
}
4146+
}
4147+
41114148
for(fp=0; fp<=0xFFF0; fp+=16)
41124149
{
41134150
if(memcmp(buf+fp, "_SM_", 4)==0 && fp<=0xFFE0)
@@ -4126,11 +4163,11 @@ int main(int argc, char * const argv[])
41264163
}
41274164

41284165
done:
4129-
free(buf);
4130-
41314166
if(!found && !(opt.flags & FLAG_QUIET))
41324167
printf("# No SMBIOS nor DMI entry point found, sorry.\n");
41334168

4169+
exit_free_buf:
4170+
free(buf);
41344171
exit_free:
41354172
free(opt.type);
41364173

dmiopt.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,18 @@ int parse_command_line(int argc, char * const argv[])
223223
{ "string", required_argument, NULL, 's' },
224224
{ "type", required_argument, NULL, 't' },
225225
{ "dump", no_argument, NULL, 'u' },
226+
{ "dump-bin", required_argument, NULL, 'B' },
226227
{ "version", no_argument, NULL, 'V' },
227228
{ 0, 0, 0, 0 }
228229
};
229230

230231
while((option=getopt_long(argc, argv, optstring, longopts, NULL))!=-1)
231232
switch(option)
232233
{
234+
case 'B':
235+
opt.flags|=FLAG_DUMP_BIN;
236+
opt.dumpfile=optarg;
237+
break;
233238
case 'd':
234239
opt.devmem=optarg;
235240
break;
@@ -287,6 +292,11 @@ int parse_command_line(int argc, char * const argv[])
287292
fprintf(stderr, "Options --quiet and --dump are mutually exclusive\n");
288293
return -1;
289294
}
295+
if((opt.flags & FLAG_DUMP_BIN) && (opt.type!=NULL || opt.string!=NULL))
296+
{
297+
fprintf(stderr, "Options --dump-bin, --string and --type are mutually exclusive\n");
298+
return -1;
299+
}
290300

291301
return 0;
292302
}
@@ -302,6 +312,7 @@ void print_help(void)
302312
" -s, --string KEYWORD Only display the value of the given DMI string\n"
303313
" -t, --type TYPE Only display the entries of given type\n"
304314
" -u, --dump Do not decode the entries\n"
315+
" --dump-bin FILE Dump the DMI data to a sparse binary file\n"
305316
" -V, --version Display the version and exit\n";
306317

307318
printf("%s", help);

dmiopt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ struct opt
3434
unsigned int flags;
3535
u8 *type;
3636
const struct string_keyword *string;
37+
char *dumpfile;
3738
};
3839
extern struct opt opt;
3940

4041
#define FLAG_VERSION (1<<0)
4142
#define FLAG_HELP (1<<1)
4243
#define FLAG_DUMP (1<<2)
4344
#define FLAG_QUIET (1<<3)
45+
#define FLAG_DUMP_BIN (1<<4)
4446

4547
int parse_command_line(int argc, char * const argv[]);
4648
void print_help(void);

man/dmidecode.8

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ you. The strings attached to each entry are displayed as both
114114
hexadecimal and \s-1ASCII\s0. This option is mainly useful for debugging.
115115
Mutually exclusive with \fB--quiet\fR and \fB--string\fR.
116116
.TP
117+
.BR " " " " "--dump-bin FILE"
118+
Do not decode the entries, instead dump the DMI data to a sparse file
119+
in binary form. This is only supported when the DMI data lives in the
120+
first MB of memory, and only if the system doesn't use EFI to locate
121+
the DMI table. The generated file is suitable to pass to \fB--dev-mem\fR
122+
later. Mutually exclusive with \fB--type\fR and \fB--string\fR.
123+
.TP
117124
.BR "-h" ", " "--help"
118125
Display usage information and exit
119126
.TP

util.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,45 @@ void *mem_chunk(size_t base, size_t len, const char *devmem)
163163

164164
return p;
165165
}
166+
167+
int write_dump(size_t base, size_t len, const void *data, const char *dumpfile)
168+
{
169+
FILE *f;
170+
171+
f=fopen(dumpfile, "r+b");
172+
if(!f && errno==ENOENT)
173+
f=fopen(dumpfile, "wb");
174+
if(!f)
175+
{
176+
fprintf(stderr, "%s: ", dumpfile);
177+
perror("fopen");
178+
return -1;
179+
}
180+
181+
if(fseek(f, base, SEEK_SET)!=0)
182+
{
183+
fprintf(stderr, "%s: ", dumpfile);
184+
perror("fseek");
185+
goto err_close;
186+
}
187+
188+
if(fwrite(data, len, 1, f)!=1)
189+
{
190+
fprintf(stderr, "%s: ", dumpfile);
191+
perror("fwrite");
192+
goto err_close;
193+
}
194+
195+
if(fclose(f))
196+
{
197+
fprintf(stderr, "%s: ", dumpfile);
198+
perror("fclose");
199+
return -1;
200+
}
201+
202+
return 0;
203+
204+
err_close:
205+
fclose(f);
206+
return -1;
207+
}

util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66

77
int checksum(const u8 *buf, size_t len);
88
void *mem_chunk(size_t base, size_t len, const char *devmem);
9+
int write_dump(size_t base, size_t len, const void *data, const char *dumpfile);

0 commit comments

Comments
 (0)