3 # Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation; either version 2 of the
8 # License, or any later version.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 use lib "$FindBin::Bin";
25 use Option::ROM qw ( :all );
27 my $romfile = shift || "-";
28 my $rom = new Option::ROM;
29 $rom->load ( $romfile );
33 die "Not an option ROM image\n"
34 unless $rom->{signature} == ROM_SIGNATURE;
36 my $romlength = ( $rom->{length} * 512 );
37 my $filelength = $rom->length;
38 die "ROM image truncated (is $filelength, should be $romlength)\n"
39 if $filelength < $romlength;
41 printf "ROM header:\n\n";
42 printf " %-16s 0x%02x (%d)\n", "Length:",
43 $rom->{length}, ( $rom->{length} * 512 );
44 printf " %-16s 0x%02x (%s0x%02x)\n", "Checksum:", $rom->{checksum},
45 ( ( $rom->checksum == 0 ) ? "" : "INCORRECT: " ), $rom->checksum;
46 printf " %-16s 0x%04x\n", "Init:", $rom->{init};
47 printf " %-16s 0x%04x\n", "UNDI header:", $rom->{undi_header};
48 printf " %-16s 0x%04x\n", "PCI header:", $rom->{pci_header};
49 printf " %-16s 0x%04x\n", "PnP header:", $rom->{pnp_header};
52 my $pci = $rom->pci_header();
54 printf "PCI header:\n\n";
55 printf " %-16s %s\n", "Signature:", $pci->{signature};
56 printf " %-16s 0x%04x\n", "Vendor ID:", $pci->{vendor_id};
57 printf " %-16s 0x%04x\n", "Device ID:", $pci->{device_id};
58 if ( $pci->{device_list} ) {
59 printf " %-16s %s\n", "Device list:",
60 ( join ( ", ", map { sprintf "0x%04x", $_ } $pci->device_list ) );
62 printf " %-16s 0x%02x%02x%02x\n", "Device class:",
63 $pci->{base_class}, $pci->{sub_class}, $pci->{prog_intf};
64 printf " %-16s 0x%04x (%d)\n", "Image length:",
65 $pci->{image_length}, ( $pci->{image_length} * 512 );
66 printf " %-16s 0x%04x (%d)\n", "Runtime length:",
67 $pci->{runtime_length}, ( $pci->{runtime_length} * 512 );
68 printf " %-16s 0x%02x\n", "Code type:", $pci->{code_type};
69 if ( exists $pci->{conf_header} ) {
70 printf " %-16s 0x%04x\n", "Config header:", $pci->{conf_header};
71 printf " %-16s 0x%04x\n", "CLP entry:", $pci->{clp_entry};
76 my $pnp = $rom->pnp_header();
78 printf "PnP header:\n\n";
79 printf " %-16s %s\n", "Signature:", $pnp->{signature};
80 printf " %-16s 0x%02x (%s0x%02x)\n", "Checksum:", $pnp->{checksum},
81 ( ( $pnp->checksum == 0 ) ? "" : "INCORRECT: " ), $pnp->checksum;
82 printf " %-16s 0x%04x \"%s\"\n", "Manufacturer:",
83 $pnp->{manufacturer}, $pnp->manufacturer;
84 printf " %-16s 0x%04x \"%s\"\n", "Product:",
85 $pnp->{product}, $pnp->product;
86 printf " %-16s 0x%04x\n", "BCV:", $pnp->{bcv};
87 printf " %-16s 0x%04x\n", "BDV:", $pnp->{bdv};
88 printf " %-16s 0x%04x\n", "BEV:", $pnp->{bev};
92 my $undi = $rom->undi_header();
94 printf "UNDI header:\n\n";
95 printf " %-16s %s\n", "Signature:", $undi->{signature};
96 printf " %-16s 0x%02x (%s0x%02x)\n", "Checksum:", $undi->{checksum},
97 ( ( $undi->checksum == 0 ) ? "" : "INCORRECT: " ), $undi->checksum;
98 printf " %-16s %d.%d.%d\n", "UNDI version:", $undi->{version_major},
99 $undi->{version_minor}, $undi->{version_revision};
100 printf " %-16s 0x%04x\n", "Loader entry:", $undi->{loader_entry};
101 printf " %-16s 0x%04x\n", "Stack size:", $undi->{stack_size};
102 printf " %-16s 0x%04x\n", "Data size:", $undi->{data_size};
103 printf " %-16s 0x%04x\n", "Code size:", $undi->{code_size};
104 printf " %-16s %s\n", "Bus type:", $undi->{bus_type};
108 my $ipxe = $rom->ipxe_header();
110 printf "iPXE header:\n\n";
111 printf " %-16s 0x%02x (%s0x%02x)\n", "Checksum:", $ipxe->{checksum},
112 ( ( $ipxe->checksum == 0 ) ? "" : "INCORRECT: " ), $ipxe->checksum;
113 printf " %-16s 0x%02x (%d)\n", "Shrunk length:",
114 $ipxe->{shrunk_length}, ( $ipxe->{shrunk_length} * 512 );
115 printf " %-16s 0x%08x\n", "Build ID:", $ipxe->{build_id};
119 } while ( $rom = $rom->next_image );