[util] Improve processing of ROM images in Option::ROM
[ipxe.git] / src / util / disrom.pl
1 #!/usr/bin/perl -w
2 #
3 # Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
4 #
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.
9 #
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.
14 #
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
18 # 02110-1301, USA.
19
20 use strict;
21 use warnings;
22
23 use FindBin;
24 use lib "$FindBin::Bin";
25 use Option::ROM qw ( :all );
26
27 my $romfile = shift || "-";
28 my $rom = new Option::ROM;
29 $rom->load ( $romfile );
30
31 my $index = 0;
32
33 do {
34 die "Not an option ROM image\n"
35 unless $rom->{signature} == ROM_SIGNATURE;
36
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;
41
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} );
52 printf "\n";
53
54 my $pci = $rom->pci_header();
55 if ( $pci ) {
56 printf "PCI header:\n\n";
57 printf " %-16s %s\n", "Signature:", $pci->{signature};
58 printf " %-16s 0x%04x\n", "Vendor ID:", $pci->{vendor_id};
59 printf " %-16s 0x%04x\n", "Device ID:", $pci->{device_id};
60 if ( $pci->{device_list} ) {
61 printf " %-16s %s\n", "Device list:",
62 ( join ( ", ", map { sprintf "0x%04x", $_ } $pci->device_list ) );
63 }
64 printf " %-16s 0x%02x%02x%02x\n", "Device class:",
65 $pci->{base_class}, $pci->{sub_class}, $pci->{prog_intf};
66 printf " %-16s 0x%04x (%d)\n", "Image length:",
67 $pci->{image_length}, ( $pci->{image_length} * 512 );
68 printf " %-16s 0x%04x (%d)\n", "Runtime length:",
69 $pci->{runtime_length}, ( $pci->{runtime_length} * 512 );
70 printf " %-16s 0x%02x\n", "Code type:", $pci->{code_type};
71 if ( exists $pci->{conf_header} ) {
72 printf " %-16s 0x%04x\n", "Config header:", $pci->{conf_header};
73 printf " %-16s 0x%04x\n", "CLP entry:", $pci->{clp_entry};
74 }
75 printf "\n";
76 }
77
78 my $pnp = $rom->pnp_header();
79 if ( $pnp ) {
80 printf "PnP header:\n\n";
81 printf " %-16s %s\n", "Signature:", $pnp->{signature};
82 printf " %-16s 0x%02x (%s0x%02x)\n", "Checksum:", $pnp->{checksum},
83 ( ( $pnp->checksum == 0 ) ? "" : "INCORRECT: " ), $pnp->checksum;
84 printf " %-16s 0x%04x \"%s\"\n", "Manufacturer:",
85 $pnp->{manufacturer}, $pnp->manufacturer;
86 printf " %-16s 0x%04x \"%s\"\n", "Product:",
87 $pnp->{product}, $pnp->product;
88 printf " %-16s 0x%04x\n", "BCV:", $pnp->{bcv};
89 printf " %-16s 0x%04x\n", "BDV:", $pnp->{bdv};
90 printf " %-16s 0x%04x\n", "BEV:", $pnp->{bev};
91 printf "\n";
92 }
93
94 my $undi = $rom->undi_header();
95 if ( $undi ) {
96 printf "UNDI header:\n\n";
97 printf " %-16s %s\n", "Signature:", $undi->{signature};
98 printf " %-16s 0x%02x (%s0x%02x)\n", "Checksum:", $undi->{checksum},
99 ( ( $undi->checksum == 0 ) ? "" : "INCORRECT: " ), $undi->checksum;
100 printf " %-16s %d.%d.%d\n", "UNDI version:", $undi->{version_major},
101 $undi->{version_minor}, $undi->{version_revision};
102 printf " %-16s 0x%04x\n", "Loader entry:", $undi->{loader_entry};
103 printf " %-16s 0x%04x\n", "Stack size:", $undi->{stack_size};
104 printf " %-16s 0x%04x\n", "Data size:", $undi->{data_size};
105 printf " %-16s 0x%04x\n", "Code size:", $undi->{code_size};
106 printf " %-16s %s\n", "Bus type:", $undi->{bus_type};
107 printf "\n";
108 }
109
110 my $ipxe = $rom->ipxe_header();
111 if ( $ipxe ) {
112 printf "iPXE header:\n\n";
113 printf " %-16s 0x%02x (%s0x%02x)\n", "Checksum:", $ipxe->{checksum},
114 ( ( $ipxe->checksum == 0 ) ? "" : "INCORRECT: " ), $ipxe->checksum;
115 printf " %-16s 0x%02x (%d)\n", "Shrunk length:",
116 $ipxe->{shrunk_length}, ( $ipxe->{shrunk_length} * 512 );
117 printf " %-16s 0x%08x\n", "Build ID:", $ipxe->{build_id};
118 printf "\n";
119 }
120
121 } while ( $rom = $rom->next_image );