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 );
34 die "Not an option ROM image\n"
35 unless $rom->{signature
} == ROM_SIGNATURE
;
37 my $romlength = ( $rom->{length} * 512 );
38 my $filelength = $rom->length;
39 die "ROM image truncated (is $filelength, should be $romlength)\n"
40 if $filelength < $romlength;
42 printf "Index: %d, offset: 0x%08x\n\n", $index++, $rom->file_offset;
43 printf "ROM header:\n\n";
44 printf " %-16s 0x%02x (%d)\n", "Length:",
45 $rom->{length}, ( $rom->{length} * 512 );
46 printf " %-16s 0x%02x (%s0x%02x)\n", "Checksum:", $rom->{checksum
},
47 ( ( $rom->checksum () == 0 ) ?
"" : "INCORRECT: " ), $rom->checksum () if ( exists $rom->{checksum
} );
48 printf " %-16s 0x%04x\n", "Init:", $rom->{init
} if ( defined $rom->{init
} );
49 printf " %-16s 0x%04x\n", "UNDI header:", $rom->{undi_header
} if ( exists $rom->{undi_header
} );
50 printf " %-16s 0x%04x\n", "PCI header:", $rom->{pci_header
};
51 printf " %-16s 0x%04x\n", "PnP header:", $rom->{pnp_header
} if ( exists $rom->{pnp_header
} );
54 my $efi = $rom->efi_header();
56 printf "EFI header:\n\n";
57 printf " %-16s 0x%04x (%d)\n", "Init size:",
58 $efi->{init_size
}, ( $efi->{init_size
} * 512 );
59 printf " %-16s 0x%08x\n", "EFI Signature:", $efi->{efi_signature
};
60 printf " %-16s 0x%04x\n", "EFI Subsystem:", $efi->{efi_subsystem
};
61 printf " %-16s 0x%04x\n", "EFI Machine type:", $efi->{efi_machine_type
};
62 printf " %-16s 0x%04x\n", "Compression type:", $efi->{compression_type
};
63 printf " %-16s 0x%04x\n", "EFI Image offset:", $efi->{efi_image_offset
};
67 my $pci = $rom->pci_header();
69 printf "PCI header:\n\n";
70 printf " %-16s %s\n", "Signature:", $pci->{signature
};
71 printf " %-16s 0x%04x\n", "Vendor ID:", $pci->{vendor_id
};
72 printf " %-16s 0x%04x\n", "Device ID:", $pci->{device_id
};
73 if ( $pci->{device_list
} ) {
74 printf " %-16s %s\n", "Device list:",
75 ( join ( ", ", map { sprintf "0x%04x", $_ } $pci->device_list ) );
77 printf " %-16s 0x%02x%02x%02x\n", "Device class:",
78 $pci->{base_class
}, $pci->{sub_class
}, $pci->{prog_intf
};
79 printf " %-16s 0x%04x (%d)\n", "Image length:",
80 $pci->{image_length
}, ( $pci->{image_length
} * 512 );
81 printf " %-16s 0x%04x (%d)\n", "Runtime length:",
82 $pci->{runtime_length
}, ( $pci->{runtime_length
} * 512 );
83 printf " %-16s 0x%02x\n", "Code type:", $pci->{code_type
};
84 if ( exists $pci->{conf_header
} ) {
85 printf " %-16s 0x%04x\n", "Config header:", $pci->{conf_header
};
86 printf " %-16s 0x%04x\n", "CLP entry:", $pci->{clp_entry
};
91 my $pnp = $rom->pnp_header();
93 printf "PnP header:\n\n";
94 printf " %-16s %s\n", "Signature:", $pnp->{signature
};
95 printf " %-16s 0x%02x (%s0x%02x)\n", "Checksum:", $pnp->{checksum
},
96 ( ( $pnp->checksum == 0 ) ?
"" : "INCORRECT: " ), $pnp->checksum;
97 printf " %-16s 0x%04x \"%s\"\n", "Manufacturer:",
98 $pnp->{manufacturer
}, $pnp->manufacturer;
99 printf " %-16s 0x%04x \"%s\"\n", "Product:",
100 $pnp->{product
}, $pnp->product;
101 printf " %-16s 0x%04x\n", "BCV:", $pnp->{bcv
};
102 printf " %-16s 0x%04x\n", "BDV:", $pnp->{bdv
};
103 printf " %-16s 0x%04x\n", "BEV:", $pnp->{bev
};
107 my $undi = $rom->undi_header();
109 printf "UNDI header:\n\n";
110 printf " %-16s %s\n", "Signature:", $undi->{signature
};
111 printf " %-16s 0x%02x (%s0x%02x)\n", "Checksum:", $undi->{checksum
},
112 ( ( $undi->checksum == 0 ) ?
"" : "INCORRECT: " ), $undi->checksum;
113 printf " %-16s %d.%d.%d\n", "UNDI version:", $undi->{version_major
},
114 $undi->{version_minor
}, $undi->{version_revision
};
115 printf " %-16s 0x%04x\n", "Loader entry:", $undi->{loader_entry
};
116 printf " %-16s 0x%04x\n", "Stack size:", $undi->{stack_size
};
117 printf " %-16s 0x%04x\n", "Data size:", $undi->{data_size
};
118 printf " %-16s 0x%04x\n", "Code size:", $undi->{code_size
};
119 printf " %-16s %s\n", "Bus type:", $undi->{bus_type
};
123 my $ipxe = $rom->ipxe_header();
125 printf "iPXE header:\n\n";
126 printf " %-16s 0x%02x (%s0x%02x)\n", "Checksum:", $ipxe->{checksum
},
127 ( ( $ipxe->checksum == 0 ) ?
"" : "INCORRECT: " ), $ipxe->checksum;
128 printf " %-16s 0x%02x (%d)\n", "Shrunk length:",
129 $ipxe->{shrunk_length
}, ( $ipxe->{shrunk_length
} * 512 );
130 printf " %-16s 0x%08x\n", "Build ID:", $ipxe->{build_id
};
134 } while ( $rom = $rom->next_image );