4
Copyright (C) 2001 Dell Computer Corporation <Matt_Domsch@dell.com>
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
#include <netinet/in.h>
30
#include "unparse_path.h"
37
dump_raw_data(void *data, uint64_t length)
39
char buffer1[80], buffer2[80], *b1, *b2, c;
40
unsigned char *p = data;
41
unsigned long column=0;
42
uint64_t length_printed = 0;
43
const char maxcolumn = 16;
44
while (length_printed < length) {
48
column < maxcolumn && length_printed < length;
50
b1 += sprintf(b1, "%02x ",(unsigned int) *p);
51
if (*p < 32 || *p > 126) c = '.';
53
b2 += sprintf(b2, "%c", c);
57
/* pad out the line */
58
for (; column < maxcolumn; column++)
60
b1 += sprintf(b1, " ");
61
b2 += sprintf(b2, " ");
64
printf("%s\t%s\n", buffer1, buffer2);
71
unparse_raw(char *buffer, uint8_t *p, uint64_t length)
73
uint64_t i; unsigned char c;
75
for (i=0; i<length; i++) {
77
//if (c < 32 || c > 127) c = '.';
78
q += sprintf(q, "%02x", c);
84
unparse_raw_text(char *buffer, uint8_t *p, uint64_t length)
86
uint64_t i; unsigned char c;
88
for (i=0; i<length; i++) {
90
if (c < 32 || c > 127) c = '.';
91
q += sprintf(q, "%c", c);
97
unparse_ipv4_port(char *buffer, uint32_t ipaddr, uint16_t port)
100
// ipaddr = nltoh(ipaddr);
101
// port = nstoh(port);
102
ip = (unsigned char *)&ipaddr;
103
return sprintf(buffer, "%hhu.%hhu.%hhu.%hhu:%hu",
104
ip[0], ip[1], ip[2], ip[3],
110
unparse_acpi_path(char *buffer, EFI_DEVICE_PATH *path)
112
ACPI_DEVICE_PATH *acpi = (ACPI_DEVICE_PATH *)path;
114
switch (path->subtype) {
116
return sprintf(buffer, "ACPI(%x,%x)", acpi->_HID, acpi->_UID);
119
return unparse_raw(buffer, (uint8_t *)path, path->length);
126
unparse_vendor_path(char *buffer, VENDOR_DEVICE_PATH *path)
128
char text_guid[40], *p = buffer, *q = (uint8_t *)path + 20;
129
efi_guid_unparse(&path->vendor_guid, text_guid);
130
p += sprintf(p, "Vendor(%s,", text_guid);
131
p += unparse_raw(p, q, path->length - 20);
132
p += sprintf(p, ")");
137
unparse_hardware_path(char *buffer, EFI_DEVICE_PATH *path)
139
PCI_DEVICE_PATH *pci = (PCI_DEVICE_PATH *)path;
140
PCCARD_DEVICE_PATH *pccard = (PCCARD_DEVICE_PATH *)path;
141
MEMORY_MAPPED_DEVICE_PATH *mm = (MEMORY_MAPPED_DEVICE_PATH *)path;
142
CONTROLLER_DEVICE_PATH *ctlr = (CONTROLLER_DEVICE_PATH *)path;
144
switch (path->subtype) {
146
return sprintf(buffer, "PCI(%x,%x)",
147
pci->function, pci->device);
150
return sprintf(buffer, "PCCARD(%x)", pccard->socket);
153
return sprintf(buffer, "MM(%x,%llx,%llx)",
158
return unparse_vendor_path(buffer, (VENDOR_DEVICE_PATH *)path);
162
return sprintf(buffer, "Controller(%x)", ctlr->controller);
166
return unparse_raw(buffer, (uint8_t *)path, path->length);
173
unparse_messaging_path(char *buffer, EFI_DEVICE_PATH *path)
175
ATAPI_DEVICE_PATH *atapi = (ATAPI_DEVICE_PATH *)path;
176
SCSI_DEVICE_PATH *scsi = (SCSI_DEVICE_PATH *)path;
177
FIBRE_CHANNEL_DEVICE_PATH *fc = (FIBRE_CHANNEL_DEVICE_PATH *)path;
178
I1394_DEVICE_PATH *i1394 = (I1394_DEVICE_PATH *)path;
179
USB_DEVICE_PATH *usb = (USB_DEVICE_PATH *)path;
180
MAC_ADDR_DEVICE_PATH *mac = (MAC_ADDR_DEVICE_PATH *)path;
181
USB_CLASS_DEVICE_PATH *usbclass = (USB_CLASS_DEVICE_PATH *)path;
182
I2O_DEVICE_PATH *i2o = (I2O_DEVICE_PATH *)path;
183
IPv4_DEVICE_PATH *ipv4 = (IPv4_DEVICE_PATH *)path;
184
IPv6_DEVICE_PATH *ipv6 = (IPv6_DEVICE_PATH *)path;
187
switch (path->subtype) {
189
return sprintf(buffer, "ATAPI(%x,%x,%x)",
190
atapi->primary_secondary,
191
atapi->slave_master, atapi->lun);
194
return sprintf(buffer, "SCSI(%x,%x)", scsi->id, scsi->lun);
198
return sprintf(buffer, "FC(%llx,%llx)", fc->wwn, fc->lun);
201
return sprintf(buffer, "1394(%llx)", i1394->guid);
204
return sprintf(buffer, "USB(%x,%x)", usb->port, usb->endpoint);
207
return sprintf(buffer, "I2O(%x)", i2o->tid);
210
p += sprintf(p, "MAC(");
211
p += unparse_raw(p, mac->macaddr, 6);
212
p += sprintf(p, ",%hhx)", mac->iftype);
213
return (int) (p - buffer);
216
p += sprintf(p, "IPv4(");
217
p += unparse_ipv4_port(p, ipv4->local_ip, ipv4->local_port);
218
p += sprintf(p, "<->");
219
p += unparse_ipv4_port(p, ipv4->remote_ip, ipv4->remote_port);
220
p += sprintf(p, ",%hx, %hhx", ipv4->protocol, ipv4->static_addr);
221
return (int) (p - buffer);
225
return sprintf(buffer, "USBClass(%hx,%hx,%hhx,%hhx,%hhx)",
226
usbclass->vendor, usbclass->product,
227
usbclass->class, usbclass->subclass,
231
return unparse_raw(buffer, (uint8_t *)path, path->length);
238
unparse_media_hard_drive_path(char *buffer, EFI_DEVICE_PATH *path)
240
HARDDRIVE_DEVICE_PATH *hd = (HARDDRIVE_DEVICE_PATH *)path;
241
char text_uuid[40], *sig=text_uuid;
243
switch (hd->signature_type) {
245
sprintf(sig, "None");
248
sprintf(sig, "%08x", *(uint32_t *)hd->signature);
251
efi_guid_unparse((efi_guid_t *)hd->signature, sig);
257
return sprintf(buffer, "HD(%x,%llx,%llx,%s)",
258
hd->part_num, hd->start, hd->size, sig);
264
unparse_media_path(char *buffer, EFI_DEVICE_PATH *path)
267
CDROM_DEVICE_PATH *cdrom = (CDROM_DEVICE_PATH *)path;
268
MEDIA_PROTOCOL_DEVICE_PATH *media = (MEDIA_PROTOCOL_DEVICE_PATH *)path;
269
FILE_PATH_DEVICE_PATH *file = (FILE_PATH_DEVICE_PATH *)path;
270
char text_guid[40], *p = buffer;
272
memset(file_name, 0, sizeof(file_name));
274
switch (path->subtype) {
276
return unparse_media_hard_drive_path(buffer, path);
279
return sprintf(buffer, "CD-ROM(%x,%llx,%llx)",
280
cdrom->boot_entry, cdrom->start, cdrom->size);
283
return unparse_vendor_path(buffer, (VENDOR_DEVICE_PATH *)path);
286
efichar_to_char(file_name, file->path_name, 80);
287
return sprintf(p, "File(%s)", file_name);
290
efi_guid_unparse(&media->guid, text_guid);
291
return sprintf(buffer, "Media(%s)", text_guid);
300
unparse_bios_path(char *buffer, EFI_DEVICE_PATH *path)
302
BIOS_BOOT_SPEC_DEVICE_PATH *bios = (BIOS_BOOT_SPEC_DEVICE_PATH *)path;
303
char *p = buffer, *q = (uint8_t *)path + 8;
304
p += sprintf(p, "BIOS(%x,%x,",
305
bios->device_type, bios->status_flag);
306
p += unparse_raw(p, q, path->length - 8);
307
p += sprintf(p, ")");
313
unparse_path(char *buffer, EFI_DEVICE_PATH *path, uint16_t pathsize)
315
uint16_t parsed_length = 0;
319
while (parsed_length < pathsize && !exit_now) {
320
switch (path->type) {
322
p += unparse_hardware_path(p, path);
325
p += unparse_acpi_path(p, path);
328
p += unparse_messaging_path(p, path);
331
p += unparse_media_path(p, path);
334
p += unparse_bios_path(p, path);
343
printf("\nwierd path");
344
dump_raw_data(path, 4);
347
// p += sprintf(p, "\\");
348
parsed_length += path->length;
349
path = (EFI_DEVICE_PATH *) ((uint8_t *)path + path->length);
358
unparse_var(efi_variable_t *var)
361
memset(buffer, 0, sizeof(buffer));
363
unparse_path(buffer, (EFI_DEVICE_PATH *)var->Data, var->DataSize);
364
printf("%s\n", buffer);
368
compare_hardware_path_pci(EFI_DEVICE_PATH *path,
369
int device, int func)
371
uint8_t *p = ((void *)path) + OFFSET_OF(EFI_DEVICE_PATH, data);
372
uint8_t path_device, path_func;
374
switch (path->subtype) {
377
path_func = *(uint8_t *)p;
378
path_device = *(uint8_t *)(p+1);
380
return !(path_func == func && path_device == device);
390
compare_hardware_path_scsi(EFI_DEVICE_PATH *path, int id, int lun)
392
uint8_t *p = ((void *)path) + OFFSET_OF(EFI_DEVICE_PATH, data);
393
uint16_t path_id, path_lun;
395
switch (path->subtype) {
398
path_id = *(uint16_t *)p;
399
path_lun = *(uint16_t *)(p+2);
401
return !(path_id == id && path_lun == lun);
410
compare_hardware_path_acpi(EFI_DEVICE_PATH *path, int bus)
412
uint8_t *p = ((void *)path) + OFFSET_OF(EFI_DEVICE_PATH, data);
415
switch (path->subtype) {
418
_HID = *(uint32_t *)p;
419
_UID = *(uint32_t *)(p+4);
421
/* FIXME: Need to convert _HID and _UID to bus number */
432
compare_media_path_harddrive(EFI_DEVICE_PATH *path, uint32_t num,
433
uint64_t start, uint64_t size)
435
HARDDRIVE_DEVICE_PATH *p = (HARDDRIVE_DEVICE_PATH *)path;
438
switch (path->subtype) {
441
return !(p->part_num == num
454
compare_pci_scsi_disk_blk(efi_variable_t *var,
455
int bus, int device, int func,
456
int host, int channel, int id, int lun,
457
uint64_t start, uint64_t size)
460
EFI_DEVICE_PATH *path = (EFI_DEVICE_PATH *) var->Data;
461
uint64_t parsed_length = 0;
465
while (parsed_length < var->DataSize && !exit_now && !rc) {
466
switch (path->type) {
469
rc = compare_hardware_path_pci(path, device, func);
473
rc = compare_hardware_path_acpi(path, bus);
476
/* Messaging (SCSI) */
477
rc = compare_messaging_path_scsi(path, id, lun);
480
/* Media (Hard Drive) */
481
rc = compare_media_path_harddrive(path, 0,
488
case 0x05: /* BIOS */
492
parsed_length += path->length;
493
path = var->Data + parsed_length;
515
printf("Usage: dumppath filename\n");
516
printf("\t where filename is a blkXXXX EFI variable from /proc/efi/vars\n");
520
main(int argc, char **argv)
532
fd = open(argv[1], O_RDONLY);
534
perror("Failed to open file.");
537
size = read(fd, &var, sizeof(var));
538
if (size == -1 || size < sizeof(var)) {
539
perror("Failed to read file.");