#!/usr/bin/perl -w # # Program to display key information about a boot ROM # including PCI and PnP structures # # GPL, Ken Yap 2001 # use bytes; sub getid ($) { my ($offset) = @_; return '' if ($offset == 0 or $offset > $len); my ($string) = unpack('Z32', substr($data, $offset, 32)); return ($string); } sub dispci { my ($pcidata) = substr($data, $pci, 0x18); my ($dummy, $vendorid, $deviceid, $vpd, $pcilen, $pcirev, $class1, $class2, $class3, $imglen, $coderev, $codetype, $indicator) = unpack('a4v4C4v2C2', $pcidata); $imglen *= 512; my $vendorstr = sprintf('%#04x', $vendorid); my $devicestr = sprintf('%#04x', $deviceid); my $coderevstr = sprintf('%#04x', $coderev); print <= $len or $pnp >= $len) { print "$file: Not a PCI PnP ROM image\n"; return; } if (substr($data, $pci, 4) ne 'PCIR' or substr($data, $pnp, 4) ne '$PnP') { print "$file: No PCI and PNP structures, not a PCI PNP ROM image\n"; return; } &dispci(); &dispnp(); } $file = $#ARGV >= 0 ? $ARGV[0] : '-'; open(F, "$file") or die "$file: $!\n"; binmode(F); # Handle up to 64kB ROM images $len = read(F, $data, 64*1024); close(F); defined($len) or die "$file: $!\n"; substr($data, 0, 2) eq "\x55\xAA" or die "$file: Not a boot ROM image\n"; my ($codelen) = unpack('C', substr($data, 2, 1)); $codelen *= 512; if ($codelen < $len) { my $pad = $len - $codelen; print "Image is $codelen bytes and has $pad bytes of padding following\n"; $data = substr($data, 0, $codelen); } elsif ($codelen > $len) { print "Image should be $codelen bytes but is truncated to $len bytes\n";} &pcipnp(); ($csum) = unpack('%8C*', $data); print "ROM checksum: $csum \n"; exit(0);