Browse Source

[build] Replace obsolete makerom.pl with quick script using Option::ROM

The only remaining useful function of makerom.pl is to correct the ROM
and PnP checksums; the PCI IDs are set at link time, and padding is
performed using padimg.pl.

Option::ROM already provides a facility for correcting the checksums,
so we may as well just use this instead.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 14 years ago
parent
commit
d8c1f2e94f
5 changed files with 39 additions and 251 deletions
  1. 1
    1
      src/Makefile
  2. 0
    24
      src/Makefile.housekeeping
  3. 4
    0
      src/arch/i386/Makefile.pcbios
  4. 34
    0
      src/util/fixrom.pl
  5. 0
    226
      src/util/makerom.pl

+ 1
- 1
src/Makefile View File

@@ -32,7 +32,7 @@ OBJCOPY		:= $(CROSS_COMPILE)objcopy
32 32
 NM		:= $(CROSS_COMPILE)nm
33 33
 OBJDUMP		:= $(CROSS_COMPILE)objdump
34 34
 PARSEROM	:= $(PERL) ./util/parserom.pl
35
-MAKEROM		:= $(PERL) ./util/makerom.pl
35
+FIXROM		:= $(PERL) ./util/fixrom.pl
36 36
 SYMCHECK	:= $(PERL) ./util/symcheck.pl
37 37
 SORTOBJDUMP	:= $(PERL) ./util/sortobjdump.pl
38 38
 PADIMG		:= $(PERL) ./util/padimg.pl

+ 0
- 24
src/Makefile.housekeeping View File

@@ -614,15 +614,6 @@ TGT_LD_FLAGS	= $(foreach SYM,$(TGT_LD_PREFIX) $(TGT_LD_DRIVERS) obj_config,\
614 614
 		    -u $(SYM) --defsym check_$(SYM)=$(SYM) ) \
615 615
 		  $(patsubst %,--defsym %,$(TGT_LD_IDS))
616 616
 
617
-# Calculate makerom flags for the specific target
618
-# (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and derive the variables:
619
-#
620
-# TGT_MAKEROM_FLAGS : target-specific flags for makerom (e.g.
621
-#		      "-p 0x1186,0x1300")
622
-#
623
-TGT_MAKEROM_FLAGS = $(strip $(MAKEROM_FLAGS_$(TGT_ROM_NAME)) \
624
-       $(if $(TGT_PCI_VENDOR),$(strip -p $(TGT_PCI_VENDOR),$(TGT_PCI_DEVICE))))
625
-
626 617
 # Calculate list of debugging versions of objects to be included in
627 618
 # the target.
628 619
 #
@@ -653,8 +644,6 @@ $(BIN)/%.info :
653 644
 	@$(ECHO)
654 645
 	@$(ECHO) 'LD target flags      : $(TGT_LD_FLAGS)'
655 646
 	@$(ECHO)
656
-	@$(ECHO) 'makerom target flags : $(TGT_MAKEROM_FLAGS)'
657
-	@$(ECHO)
658 647
 	@$(ECHO) 'Debugging objects    : $(DEBUG_OBJS)'
659 648
 	@$(ECHO) 'Replaced objects     : $(DEBUG_ORIG_OBJS)'
660 649
 
@@ -863,19 +852,6 @@ $(BIN)/etherboot.% : $(BIN)/ipxe.%
863 852
 
864 853
 endif # defined(BIN)
865 854
 
866
-###############################################################################
867
-#
868
-# Rules for finalising files.  TGT_MAKEROM_FLAGS is defined as part of
869
-# the automatic build system and varies by target; it includes the
870
-# "-p 0x1234,0x5678" string to set the PCI IDs.
871
-#
872
-FINALISE_rom	= $(MAKEROM) $(MAKEROM_FLAGS) $(TGT_MAKEROM_FLAGS) \
873
-		  -i$(IDENT) -s 0 $@
874
-
875
-# Some ROMs require specific flags to be passed to makerom.pl
876
-#
877
-MAKEROM_FLAGS_3c503 = -3
878
-
879 855
 ###############################################################################
880 856
 #
881 857
 # The compression utilities

+ 4
- 0
src/arch/i386/Makefile.pcbios View File

@@ -26,6 +26,10 @@ PAD_rom		= $(PADIMG) --blksize=512 --byte=0xff $@
26 26
 PAD_dsk		= $(PADIMG) --blksize=512 $@
27 27
 PAD_hd		= $(PADIMG) --blksize=32768 $@
28 28
 
29
+# Finalisation rules
30
+#
31
+FINALISE_rom	= $(FIXROM) $@
32
+
29 33
 # rule to make a non-emulation ISO boot image
30 34
 NON_AUTO_MEDIA	+= iso
31 35
 %iso:	%lkrn util/geniso

+ 34
- 0
src/util/fixrom.pl View File

@@ -0,0 +1,34 @@
1
+#!/usr/bin/perl -w
2
+#
3
+# Copyright (C) 2010 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., 675 Mass Ave, Cambridge, MA 02139, USA.
18
+
19
+use strict;
20
+use warnings;
21
+
22
+use FindBin;
23
+use lib "$FindBin::Bin";
24
+use Option::ROM qw ( :all );
25
+
26
+my @romfiles = @ARGV;
27
+
28
+foreach my $romfile ( @romfiles ) {
29
+  my $rom = new Option::ROM;
30
+  $rom->load ( $romfile );
31
+  $rom->pnp_header->fix_checksum() if $rom->pnp_header;
32
+  $rom->fix_checksum();
33
+  $rom->save ( $romfile );
34
+}

+ 0
- 226
src/util/makerom.pl View File

@@ -1,226 +0,0 @@
1
-#!/usr/bin/perl -w
2
-
3
-use Getopt::Std;
4
-
5
-use constant MINROMSIZE => 8192;
6
-use constant MAXROMSIZE => 262144;
7
-
8
-use constant PCI_PTR_LOC => 0x18;	# from beginning of ROM
9
-use constant PCI_HDR_SIZE => 0x18;
10
-use constant PNP_PTR_LOC => 0x1a;	# from beginning of ROM
11
-use constant PNP_HDR_SIZE => 0x20;
12
-use constant PNP_CHKSUM_OFF => 0x9;	# bytes from beginning of PnP header
13
-use constant PNP_DEVICE_OFF => 0x10;	# bytes from beginning of PnP header
14
-use constant PCI_VEND_ID_OFF => 0x4;	# bytes from beginning of PCI header
15
-use constant PCI_DEV_ID_OFF => 0x6;	# bytes from beginning of PCI header
16
-use constant PCI_SIZE_OFF => 0x10;	# bytes from beginning of PCI header
17
-
18
-use constant UNDI_PTR_LOC => 0x16;	# from beginning of ROM
19
-use constant UNDI_HDR_SIZE => 0x16;
20
-use constant UNDI_CHKSUM_OFF => 0x05;
21
-
22
-use strict;
23
-
24
-use vars qw(%opts);
25
-
26
-use bytes;
27
-
28
-sub getromsize ($) {
29
-	my ($romref) = @_;
30
-	my $i;
31
-
32
-	print STDERR "BIOS extension ROM Image did not start with 0x55 0xAA\n"
33
-		if (substr($$romref, 0, 2) ne "\x55\xaa");
34
-	my $size = ord(substr($$romref, 2, 1)) * 512;
35
-	for ($i = MINROMSIZE; $i < MAXROMSIZE and $i < $size; $i *= 2) { }
36
-	print STDERR "$size is a strange size for a boot ROM\n"
37
-		if ($size > 0 and $i > $size);
38
-	return ($size);
39
-}
40
-
41
-sub addident ($) {
42
-	my ($romref) = @_;
43
-
44
-	return (0) unless (my $s = $opts{'i'});
45
-	# include the terminating NUL byte too
46
-	$s .= "\x00";
47
-	my $len = length($s);
48
-	# Put the identifier in only if the space is blank
49
-	my $pos = length($$romref) - $len - 2;
50
-	return (0) if (substr($$romref, $pos, $len) ne ("\xFF" x $len));
51
-	substr($$romref, $pos, $len) = $s;
52
-	return ($pos);
53
-}
54
-
55
-sub pcipnpheaders ($$) {
56
-	my ($romref, $identoffset) = @_;
57
-	my ($pci_hdr_offset, $pnp_hdr_offset);
58
-
59
-	$pci_hdr_offset = unpack('v', substr($$romref, PCI_PTR_LOC, 2));
60
-	$pnp_hdr_offset = unpack('v', substr($$romref, PNP_PTR_LOC, 2));
61
-	# Sanity checks
62
-	if ($pci_hdr_offset < PCI_PTR_LOC + 2
63
-		or $pci_hdr_offset > length($$romref) - PCI_HDR_SIZE
64
-		or $pnp_hdr_offset < PNP_PTR_LOC + 2
65
-		or $pnp_hdr_offset > length($$romref) - PNP_HDR_SIZE
66
-		or substr($$romref, $pci_hdr_offset, 4) ne 'PCIR'
67
-		or substr($$romref, $pnp_hdr_offset, 4) ne '$PnP') {
68
-		$pci_hdr_offset = $pnp_hdr_offset = 0;
69
-	} else {
70
-		printf "PCI header at %#x and PnP header at %#x\n",
71
-			$pci_hdr_offset, $pnp_hdr_offset if $opts{'v'};
72
-	}
73
-	if ($pci_hdr_offset > 0) {
74
-		my ($pci_vendor_id, $pci_device_id);
75
-		# if no -p option, just report what's there
76
-		if (!defined($opts{'p'})) {
77
-			$pci_vendor_id = unpack('v', substr($$romref, $pci_hdr_offset+PCI_VEND_ID_OFF, 2));
78
-			$pci_device_id = unpack('v', substr($$romref, $pci_hdr_offset+PCI_DEV_ID_OFF, 2));
79
-			printf "PCI Vendor ID %#x Device ID %#x\n",
80
-				$pci_vendor_id, $pci_device_id;
81
-		} else {
82
-			substr($$romref, $pci_hdr_offset + PCI_SIZE_OFF, 2)
83
-				= pack('v', length($$romref) / 512);
84
-			($pci_vendor_id, $pci_device_id) = split(/,/, $opts{'p'});
85
-			substr($$romref, $pci_hdr_offset+PCI_VEND_ID_OFF, 2)
86
-				= pack('v', oct($pci_vendor_id)) if ($pci_vendor_id);
87
-			substr($$romref, $pci_hdr_offset+PCI_DEV_ID_OFF, 2)
88
-				= pack('v', oct($pci_device_id)) if ($pci_device_id);
89
-		}
90
-	}
91
-	if ($pnp_hdr_offset > 0) {
92
-		if (defined($identoffset)) {
93
-			# Point to device id string at end of ROM image
94
-			substr($$romref, $pnp_hdr_offset+PNP_DEVICE_OFF, 2)
95
-				= pack('v', $identoffset);
96
-		}
97
-		substr($$romref, $pnp_hdr_offset+PNP_CHKSUM_OFF, 1) = "\x00";
98
-		my $sum = unpack('%8C*', substr($$romref, $pnp_hdr_offset,
99
-			PNP_HDR_SIZE));
100
-		substr($$romref, $pnp_hdr_offset+PNP_CHKSUM_OFF, 1) = chr(256 - $sum);
101
-	}
102
-}
103
-
104
-sub undiheaders ($) {
105
-	my ($romref) = @_;
106
-	my ($undi_hdr_offset);
107
-
108
-	$undi_hdr_offset = unpack('v', substr($$romref, UNDI_PTR_LOC, 2));
109
-	# Sanity checks
110
-	if ($undi_hdr_offset < UNDI_PTR_LOC + 2
111
-		or $undi_hdr_offset > length($$romref) - UNDI_HDR_SIZE
112
-		or substr($$romref, $undi_hdr_offset, 4) ne 'UNDI') {
113
-		$undi_hdr_offset = 0;
114
-	} else {
115
-		printf "UNDI header at %#x\n", $undi_hdr_offset if $opts{'v'};
116
-	}
117
-	if ($undi_hdr_offset > 0) {
118
-		substr($$romref, $undi_hdr_offset+UNDI_CHKSUM_OFF, 1) = "\x00";
119
-		my $sum = unpack('%8C*', substr($$romref, $undi_hdr_offset,
120
-			UNDI_HDR_SIZE));
121
-		substr($$romref, $undi_hdr_offset+UNDI_CHKSUM_OFF, 1) = chr(256 - $sum);
122
-	}
123
-}
124
-
125
-sub writerom ($$) {
126
-	my ($filename, $romref) = @_;
127
-
128
-	open(R, ">$filename") or die "$filename: $!\n";
129
-	print R $$romref;
130
-	close(R);
131
-}
132
-
133
-sub checksum ($) {
134
-	my ($romref) = @_;
135
-
136
-	substr($$romref, 6, 1) = "\x00";
137
-	my $sum = unpack('%8C*', $$romref);
138
-	substr($$romref, 6, 1) = chr(256 - $sum);
139
-	# Double check
140
-	$sum = unpack('%8C*', $$romref);
141
-	if ($sum != 0) {
142
-		print "Checksum fails\n"
143
-	} elsif ($opts{'v'}) {
144
-		print "Checksum ok\n";
145
-	}
146
-}
147
-
148
-sub makerom () {
149
-	my ($rom, $romsize);
150
-
151
-	getopts('3xi:p:s:v', \%opts);
152
-	$ARGV[0] or die "Usage: $0 [-s romsize] [-i ident] [-p vendorid,deviceid] [-x] [-3] rom-file\n";
153
-	open(R, $ARGV[0]) or die "$ARGV[0]: $!\n";
154
-	# Read in the whole ROM in one gulp
155
-	my $filesize = read(R, $rom, MAXROMSIZE+1);
156
-	close(R);
157
-	defined($filesize) and $filesize >= 3 or die "Cannot get first 3 bytes of file\n";
158
-	print "$filesize bytes read\n" if $opts{'v'};
159
-	# If PXE image, just fill the length field and write it out
160
-	if ($opts{'x'}) {
161
-		substr($rom, 2, 1) = chr((length($rom) + 511) / 512);
162
-		writerom($ARGV[0], \$rom);
163
-		return;
164
-	}
165
-	# Size specified with -s overrides value in 3rd byte in image
166
-	# -s 0 means round up to next 512 byte block
167
-	if (defined($opts{'s'})) {
168
-		if (($romsize = oct($opts{'s'})) <= 0) {
169
-			# NB: This roundup trick only works on powers of 2
170
-			$romsize = ($filesize + 511) & ~511
171
-		}
172
-	} else {
173
-		# Shrink romsize down to the smallest power of two that will do
174
-		for ($romsize = MAXROMSIZE;
175
-		     $romsize > MINROMSIZE and $romsize >= 2*$filesize;
176
-		     $romsize /= 2) { }
177
-	}
178
-	if ($filesize > $romsize) {
179
-		print STDERR "ROM size of $romsize not big enough for data, ";
180
-		# NB: This roundup trick only works on powers of 2
181
-		$romsize = ($filesize + 511) & ~511;
182
-		print "will use $romsize instead\n"
183
-	}
184
-	# Pad with 0xFF to $romsize
185
-	$rom .= "\xFF" x ($romsize - length($rom));
186
-	if ($romsize >= 128 * 1024) {
187
-		print "Warning: ROM size exceeds extension BIOS limit\n";
188
-	}
189
-	substr($rom, 2, 1) = chr(($romsize / 512) % 256);
190
-	print "ROM size is $romsize\n" if $opts{'v'};
191
-	# set the product string only if we don't have one yet
192
-	my $pnp_hdr_offset = unpack('v', substr($rom, PNP_PTR_LOC, 2));
193
-	my $identoffset = substr($rom, $pnp_hdr_offset+PNP_DEVICE_OFF, 2) eq "\0\0" ? addident(\$rom) : undef;
194
-	pcipnpheaders(\$rom, $identoffset);
195
-	undiheaders(\$rom);
196
-	# 3c503 requires last two bytes to be 0x80
197
-	substr($rom, MINROMSIZE-2, 2) = "\x80\x80"
198
-		if ($opts{'3'} and $romsize == MINROMSIZE);
199
-	checksum(\$rom);
200
-	writerom($ARGV[0], \$rom);
201
-}
202
-
203
-sub modrom () {
204
-	my ($rom);
205
-
206
-	getopts('p:v', \%opts);
207
-	$ARGV[0] or die "Usage: $0 [-p vendorid,deviceid] rom-file\n";
208
-	open(R, $ARGV[0]) or die "$ARGV[0]: $!\n";
209
-	# Read in the whole ROM in one gulp
210
-	my $filesize = read(R, $rom, MAXROMSIZE+1);
211
-	close(R);
212
-	defined($filesize) and $filesize >= 3 or die "Cannot get first 3 bytes of file\n";
213
-	print "$filesize bytes read\n" if $opts{'v'};
214
-	pcipnpheaders(\$rom, undef);
215
-	undiheaders(\$rom);
216
-	checksum(\$rom);
217
-	writerom($ARGV[0], \$rom);
218
-}
219
-
220
-# Main routine. See how we were called and behave accordingly
221
-if ($0 =~ m:modrom(\.pl)?$:) {
222
-	modrom();
223
-} else {
224
-	makerom();
225
-}
226
-exit(0);

Loading…
Cancel
Save