summaryrefslogtreecommitdiffstats
path: root/src/util/makerom.pl
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/makerom.pl')
-rwxr-xr-xsrc/util/makerom.pl30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/util/makerom.pl b/src/util/makerom.pl
index aed3a569..68c3be98 100755
--- a/src/util/makerom.pl
+++ b/src/util/makerom.pl
@@ -130,14 +130,14 @@ sub writerom ($$) {
close(R);
}
-sub checksum ($) {
- my ($romref) = @_;
+sub checksum ($$) {
+ my ($romref, $romsize) = @_;
substr($$romref, 6, 1) = "\x00";
- my $sum = unpack('%8C*', $$romref);
+ my $sum = unpack('%8C*', substr($$romref, 0, $romsize));
substr($$romref, 6, 1) = chr(256 - $sum);
# Double check
- $sum = unpack('%8C*', $$romref);
+ $sum = unpack('%8C*', substr($$romref, 0, $romsize));
if ($sum != 0) {
print "Checksum fails\n"
} elsif ($opts{'v'}) {
@@ -146,10 +146,10 @@ sub checksum ($) {
}
sub makerom () {
- my ($rom, $romsize);
+ my ($rom, $romsize, $stubsize);
- getopts('3xi:p:s:v', \%opts);
- $ARGV[0] or die "Usage: $0 [-s romsize] [-i ident] [-p vendorid,deviceid] [-x] [-3] rom-file\n";
+ getopts('3xni:p:s:v', \%opts);
+ $ARGV[0] or die "Usage: $0 [-s romsize] [-i ident] [-p vendorid,deviceid] [-n] [-x] [-3] rom-file\n";
open(R, $ARGV[0]) or die "$ARGV[0]: $!\n";
# Read in the whole ROM in one gulp
my $filesize = read(R, $rom, MAXROMSIZE+1);
@@ -183,10 +183,16 @@ sub makerom () {
}
# Pad with 0xFF to $romsize
$rom .= "\xFF" x ($romsize - length($rom));
- if ($romsize >= 128 * 1024) {
- print "Warning: ROM size exceeds extension BIOS limit\n";
+ # If this is a stub ROM, don't force header size to the full amount
+ if (!$opts{'n'}) {
+ if ($romsize >= 128 * 1024) {
+ print "Warning: ROM size exceeds extension BIOS limit\n";
+ }
+ substr($rom, 2, 1) = chr(($romsize / 512) % 256);
+ } else {
+ $stubsize = ord(substr($rom, 2, 1)) * 512;
+ print "Stub size is $stubsize\n" if $opts{'v'};
}
- substr($rom, 2, 1) = chr(($romsize / 512) % 256);
print "ROM size is $romsize\n" if $opts{'v'};
# set the product string only if we don't have one yet
my $pnp_hdr_offset = unpack('v', substr($rom, PNP_PTR_LOC, 2));
@@ -196,7 +202,7 @@ sub makerom () {
# 3c503 requires last two bytes to be 0x80
substr($rom, MINROMSIZE-2, 2) = "\x80\x80"
if ($opts{'3'} and $romsize == MINROMSIZE);
- checksum(\$rom);
+ checksum(\$rom, $opts{'n'} ? $stubsize : $romsize);
writerom($ARGV[0], \$rom);
}
@@ -213,7 +219,7 @@ sub modrom () {
print "$filesize bytes read\n" if $opts{'v'};
pcipnpheaders(\$rom, undef);
undiheaders(\$rom);
- checksum(\$rom);
+ checksum(\$rom, ord(substr($rom, 2, 1)) * 512);
writerom($ARGV[0], \$rom);
}