Browse Source

[build] Pad .rom, .dsk, and .hd images to 512-byte boundaries

QEMU will silently round down a disk or ROM image file to the nearest
512 bytes.  Fix by always padding .rom, .dsk and .hd images to the
nearest 512-byte boundary.

Originally-fixed-by: Stefan Hajnoczi <stefanha@gmail.com>
tags/v0.9.8
Michael Brown 15 years ago
parent
commit
7741546a40

+ 2
- 2
contrib/bochs/README.qemu View File

47
 
47
 
48
 8.  Build gPXE floppy disk images and pad to 1.44MB
48
 8.  Build gPXE floppy disk images and pad to 1.44MB
49
       pushd ../../src
49
       pushd ../../src
50
-      make bin/rtl8139.pdsk
50
+      make bin/rtl8139.dsk
51
       popd
51
       popd
52
 
52
 
53
 9.  Start qemu
53
 9.  Start qemu
54
       ./qemu/i386-softmmu/qemu -L qemu/pc-bios \
54
       ./qemu/i386-softmmu/qemu -L qemu/pc-bios \
55
 			       -net nic,model=rtl8139 -net tap,ifname=tap0 \
55
 			       -net nic,model=rtl8139 -net tap,ifname=tap0 \
56
-			       -boot a -fda ../../src/bin/rtl8139.pdsk 
56
+			       -boot a -fda ../../src/bin/rtl8139.dsk
57
 
57
 
58
 You should see qemu start up, load up gPXE and attempt to boot from
58
 You should see qemu start up, load up gPXE and attempt to boot from
59
 the network.
59
 the network.

+ 1
- 0
src/Makefile View File

35
 MAKEROM		:= $(PERL) ./util/makerom.pl
35
 MAKEROM		:= $(PERL) ./util/makerom.pl
36
 SYMCHECK	:= $(PERL) ./util/symcheck.pl
36
 SYMCHECK	:= $(PERL) ./util/symcheck.pl
37
 SORTOBJDUMP	:= $(PERL) ./util/sortobjdump.pl
37
 SORTOBJDUMP	:= $(PERL) ./util/sortobjdump.pl
38
+PADIMG		:= $(PERL) ./util/padimg.pl
38
 NRV2B		:= ./util/nrv2b
39
 NRV2B		:= ./util/nrv2b
39
 ZBIN		:= ./util/zbin
40
 ZBIN		:= ./util/zbin
40
 ELF2EFI32	:= ./util/elf2efi32
41
 ELF2EFI32	:= ./util/elf2efi32

+ 1
- 0
src/Makefile.housekeeping View File

724
 	@$(ECHO_E) '$$(BIN)/%.$(1) : $$(BIN)/%.$(1).zbin' \
724
 	@$(ECHO_E) '$$(BIN)/%.$(1) : $$(BIN)/%.$(1).zbin' \
725
 		  '\n\t$$(QM)$(ECHO) "  [FINISH] $$@"' \
725
 		  '\n\t$$(QM)$(ECHO) "  [FINISH] $$@"' \
726
 		  '\n\t$$(Q)$$(CP) $$< $$@' \
726
 		  '\n\t$$(Q)$$(CP) $$< $$@' \
727
+		  '\n\t$$(Q)$$(PAD_$(1))' \
727
 		  '\n\t$$(Q)$$(FINALISE_$(1))' \
728
 		  '\n\t$$(Q)$$(FINALISE_$(1))' \
728
 		> $(2)
729
 		> $(2)
729
 
730
 

+ 0
- 7
src/arch/i386/Makefile View File

114
 	$(Q)dd if=$< bs=512 conv=sync of=/dev/fd0
114
 	$(Q)dd if=$< bs=512 conv=sync of=/dev/fd0
115
 	$(Q)sync
115
 	$(Q)sync
116
 
116
 
117
-# rule to create padded disk images
118
-NON_AUTO_MEDIA	+= pdsk
119
-%pdsk : %dsk
120
-	$(QM)$(ECHO) "  [DSKPAD] $@"
121
-	$(Q)cp $< $@
122
-	$(Q)$(PERL) ./util/dskpad.pl $@
123
-
124
 # Add NON_AUTO_MEDIA to the media list, so that they show up in the
117
 # Add NON_AUTO_MEDIA to the media list, so that they show up in the
125
 # output of "make"
118
 # output of "make"
126
 #
119
 #

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

27
 MEDIA		+= com
27
 MEDIA		+= com
28
 MEDIA		+= exe
28
 MEDIA		+= exe
29
 
29
 
30
+# Padding rules
31
+#
32
+PAD_rom		= $(PADIMG) --blksize=512 --byte=0xff $@
33
+PAD_dsk		= $(PADIMG) --blksize=512 $@
34
+PAD_hd		= $(PADIMG) --blksize=512 $@
35
+
30
 # rule to make a non-emulation ISO boot image
36
 # rule to make a non-emulation ISO boot image
31
 NON_AUTO_MEDIA	+= iso
37
 NON_AUTO_MEDIA	+= iso
32
 %iso:	%lkrn util/geniso
38
 %iso:	%lkrn util/geniso

+ 0
- 12
src/util/dskpad.pl View File

1
-#!/usr/bin/perl -w
2
-
3
-use strict;
4
-use warnings;
5
-
6
-use constant FLOPPYSIZE => 1440 * 1024;
7
-
8
-while ( my $filename = shift ) {
9
-  die "$filename is not a file\n" unless -f $filename;
10
-  die "$filename is too large\n" unless ( -s $filename <= FLOPPYSIZE );
11
-  truncate $filename, FLOPPYSIZE or die "Could not truncate: $!\n";
12
-}

+ 44
- 0
src/util/padimg.pl View File

1
+#!/usr/bin/perl -w
2
+
3
+use strict;
4
+use warnings;
5
+use Getopt::Long;
6
+use Fcntl;
7
+
8
+my $verbosity = 0;
9
+my $blksize = 512;
10
+my $byte = 0;
11
+
12
+my $opts = {
13
+  'verbose|v+' => sub { $verbosity++; },
14
+  'quiet|q+' => sub { $verbosity--; },
15
+  'blksize|s=o' => sub { $blksize = $_[1]; },
16
+  'byte|b=o' => sub { $byte = $_[1]; },
17
+};
18
+
19
+Getopt::Long::Configure ( 'bundling', 'auto_abbrev' );
20
+GetOptions ( { map { /^(\w+)/; $1 => $opts->{$_} } keys %$opts }, keys %$opts )
21
+    or die "Could not parse command-line options\n";
22
+
23
+while ( my $filename = shift ) {
24
+  die "$filename is not a file\n" unless -f $filename;
25
+  my $oldsize = -s $filename;
26
+  my $newsize = ( ( $oldsize + $blksize - 1 ) & ~( $blksize - 1 ) );
27
+  my $padsize = ( $newsize - $oldsize );
28
+  next unless $padsize;
29
+  if ( $verbosity >= 1 ) {
30
+      printf "Padding %s from %d to %d bytes with %d x 0x%02x\n",
31
+	     $filename, $oldsize, $newsize, $padsize, $byte;
32
+  }
33
+  if ( $byte ) {
34
+    sysopen ( my $fh, $filename, ( O_WRONLY | O_APPEND ) )
35
+	or die "Could not open $filename for appending: $!\n";
36
+    syswrite $fh, ( chr ( $byte ) x $padsize )
37
+	or die "Could not append to $filename: $!\n";
38
+    close ( $fh );
39
+  } else {
40
+    truncate $filename, $newsize
41
+	or die "Could not resize $filename: $!\n";
42
+  }
43
+  die "Failed to pad $filename\n" unless -s $filename == $newsize;
44
+}

Loading…
Cancel
Save