Skip to content

Commit 02b421e

Browse files
committed
Make it possible for --string to print decoded binary data rather than
only DMI strings. Add four such string keywords.
1 parent 1a7eb2f commit 02b421e

File tree

4 files changed

+38
-20
lines changed

4 files changed

+38
-20
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ dmidecode.o : dmidecode.c version.h types.h util.h config.h dmidecode.h \
6060
dmiopt.h
6161
$(CC) $(CFLAGS) -c $< -o $@
6262

63-
dmiopt.o : dmiopt.c config.h types.h dmiopt.h
63+
dmiopt.o : dmiopt.c config.h types.h dmidecode.h dmiopt.h
6464
$(CC) $(CFLAGS) -c $< -o $@
6565

6666
biosdecode.o : biosdecode.c version.h types.h util.h config.h

dmidecode.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -3851,7 +3851,14 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem)
38513851
&& opt.string_offset
38523852
&& opt.string_offset<h->length)
38533853
{
3854-
printf("%s\n", dmi_string(h, data[opt.string_offset]));
3854+
if (opt.string_lookup != NULL)
3855+
printf("%s\n", opt.string_lookup(data[opt.string_offset]));
3856+
else if (opt.string_print != NULL) {
3857+
opt.string_print(data+opt.string_offset);
3858+
printf("\n");
3859+
}
3860+
else
3861+
printf("%s\n", dmi_string(h, data[opt.string_offset]));
38553862
}
38563863

38573864
data=next;

dmiopt.c

+27-18
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "config.h"
2828
#include "types.h"
29+
#include "dmidecode.h"
2930
#include "dmiopt.h"
3031

3132

@@ -146,30 +147,36 @@ struct string_keyword
146147
const char *keyword;
147148
u8 type;
148149
u8 offset;
150+
const char *(*lookup)(u8);
151+
void (*print)(u8 *);
149152
};
150153

151154
/* This lookup table could admittedly be reworked for improved performance.
152155
Due to the low count of items in there at the moment, it did not seem
153156
worth the additional code complexity though. */
154157
static const struct string_keyword opt_string_keyword[]={
155-
{ "bios-vendor", 0, 0x04 },
156-
{ "bios-version", 0, 0x05 },
157-
{ "bios-release-date", 0, 0x08 },
158-
{ "system-manufacturer", 1, 0x04 },
159-
{ "system-product-name", 1, 0x05 },
160-
{ "system-version", 1, 0x06 },
161-
{ "system-serial-number", 1, 0x07 },
162-
{ "baseboard-manufacturer", 2, 0x04 },
163-
{ "baseboard-product-name", 2, 0x05 },
164-
{ "baseboard-version", 2, 0x06 },
165-
{ "baseboard-serial-number", 2, 0x07 },
166-
{ "baseboard-asset-tag", 2, 0x08 },
167-
{ "chassis-manufacturer", 3, 0x04 },
168-
{ "chassis-version", 3, 0x06 },
169-
{ "chassis-serial-number", 3, 0x07 },
170-
{ "chassis-asset-tag", 3, 0x08 },
171-
{ "processor-manufacturer", 4, 0x07 },
172-
{ "processor-version", 4, 0x10 },
158+
{ "bios-vendor", 0, 0x04, NULL, NULL },
159+
{ "bios-version", 0, 0x05, NULL, NULL },
160+
{ "bios-release-date", 0, 0x08, NULL, NULL },
161+
{ "system-manufacturer", 1, 0x04, NULL, NULL },
162+
{ "system-product-name", 1, 0x05, NULL, NULL },
163+
{ "system-version", 1, 0x06, NULL, NULL },
164+
{ "system-serial-number", 1, 0x07, NULL, NULL },
165+
{ "system-uuid", 1, 0x08, NULL, dmi_system_uuid },
166+
{ "baseboard-manufacturer", 2, 0x04, NULL, NULL },
167+
{ "baseboard-product-name", 2, 0x05, NULL, NULL },
168+
{ "baseboard-version", 2, 0x06, NULL, NULL },
169+
{ "baseboard-serial-number", 2, 0x07, NULL, NULL },
170+
{ "baseboard-asset-tag", 2, 0x08, NULL, NULL },
171+
{ "chassis-manufacturer", 3, 0x04, NULL, NULL },
172+
{ "chassis-type", 3, 0x05, dmi_chassis_type, NULL },
173+
{ "chassis-version", 3, 0x06, NULL, NULL },
174+
{ "chassis-serial-number", 3, 0x07, NULL, NULL },
175+
{ "chassis-asset-tag", 3, 0x08, NULL, NULL },
176+
{ "processor-family", 4, 0x06, dmi_processor_family, NULL },
177+
{ "processor-manufacturer", 4, 0x07, NULL, NULL },
178+
{ "processor-version", 4, 0x10, NULL, NULL },
179+
{ "processor-frequency", 4, 0x16, NULL, dmi_processor_frequency },
173180
};
174181

175182
static void print_opt_string_list(void)
@@ -199,6 +206,8 @@ static int parse_opt_string(const char *arg)
199206
{
200207
opt.string_type=opt_string_keyword[i].type;
201208
opt.string_offset=opt_string_keyword[i].offset;
209+
opt.string_lookup=opt_string_keyword[i].lookup;
210+
opt.string_print=opt_string_keyword[i].print;
202211
return 0;
203212
}
204213
}

dmiopt.h

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ struct opt
2626
u8 *type;
2727
u8 string_type;
2828
u8 string_offset;
29+
const char *(*string_lookup)(u8);
30+
void (*string_print)(u8 *);
2931
};
3032
extern struct opt opt;
3133

0 commit comments

Comments
 (0)