Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / 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 do {
32
33   die "Not an option ROM image\n"
34       unless $rom->{signature} == ROM_SIGNATURE;
35
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;
40
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};
50   printf "\n";
51
52   my $pci = $rom->pci_header();
53   if ( $pci ) {
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     printf "  %-16s 0x%02x%02x%02x\n", "Device class:",
59            $pci->{base_class}, $pci->{sub_class}, $pci->{prog_intf};
60     printf "  %-16s 0x%04x (%d)\n", "Image length:",
61            $pci->{image_length}, ( $pci->{image_length} * 512 );
62     printf "  %-16s 0x%04x (%d)\n", "Runtime length:",
63            $pci->{runtime_length}, ( $pci->{runtime_length} * 512 );
64     printf "  %-16s 0x%02x\n", "Code type:", $pci->{code_type};
65     if ( exists $pci->{conf_header} ) {
66       printf "  %-16s 0x%04x\n", "Config header:", $pci->{conf_header};
67       printf "  %-16s 0x%04x\n", "CLP entry:", $pci->{clp_entry};
68     }
69     printf "\n";
70   }
71
72   my $pnp = $rom->pnp_header();
73   if ( $pnp ) {
74     printf "PnP header:\n\n";
75     printf "  %-16s %s\n", "Signature:", $pnp->{signature};
76     printf "  %-16s 0x%02x (%s0x%02x)\n", "Checksum:", $pnp->{checksum},
77            ( ( $pnp->checksum == 0 ) ? "" : "INCORRECT: " ), $pnp->checksum;
78     printf "  %-16s 0x%04x \"%s\"\n", "Manufacturer:",
79            $pnp->{manufacturer}, $pnp->manufacturer;
80     printf "  %-16s 0x%04x \"%s\"\n", "Product:",
81            $pnp->{product}, $pnp->product;
82     printf "  %-16s 0x%04x\n", "BCV:", $pnp->{bcv};
83     printf "  %-16s 0x%04x\n", "BDV:", $pnp->{bdv};
84     printf "  %-16s 0x%04x\n", "BEV:", $pnp->{bev};
85     printf "\n";
86   }
87
88   my $undi = $rom->undi_header();
89   if ( $undi ) {
90     printf "UNDI header:\n\n";
91     printf "  %-16s %s\n", "Signature:", $undi->{signature};
92     printf "  %-16s 0x%02x (%s0x%02x)\n", "Checksum:", $undi->{checksum},
93            ( ( $undi->checksum == 0 ) ? "" : "INCORRECT: " ), $undi->checksum;
94     printf "  %-16s %d.%d.%d\n", "UNDI version:", $undi->{version_major},
95            $undi->{version_minor}, $undi->{version_revision};
96     printf "  %-16s 0x%04x\n", "Loader entry:", $undi->{loader_entry};
97     printf "  %-16s 0x%04x\n", "Stack size:", $undi->{stack_size};
98     printf "  %-16s 0x%04x\n", "Data size:", $undi->{data_size};
99     printf "  %-16s 0x%04x\n", "Code size:", $undi->{code_size};
100     printf "  %-16s %s\n", "Bus type:", $undi->{bus_type};
101     printf "\n";
102   }
103
104   my $ipxe = $rom->ipxe_header();
105   if ( $ipxe ) {
106     printf "iPXE header:\n\n";
107     printf "  %-16s 0x%02x (%s0x%02x)\n", "Checksum:", $ipxe->{checksum},
108            ( ( $ipxe->checksum == 0 ) ? "" : "INCORRECT: " ), $ipxe->checksum;
109     printf "  %-16s 0x%02x (%d)\n", "Shrunk length:",
110            $ipxe->{shrunk_length}, ( $ipxe->{shrunk_length} * 512 );
111     printf "  %-16s 0x%08x\n", "Build ID:", $ipxe->{build_id};
112     printf "\n";
113   }
114
115 } while ( $rom = $rom->next_image );