Przeglądaj źródła

[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 lat temu
rodzic
commit
7741546a40

+ 2
- 2
contrib/bochs/README.qemu Wyświetl plik

@@ -47,13 +47,13 @@ To get qemu running is fairly simple:
47 47
 
48 48
 8.  Build gPXE floppy disk images and pad to 1.44MB
49 49
       pushd ../../src
50
-      make bin/rtl8139.pdsk
50
+      make bin/rtl8139.dsk
51 51
       popd
52 52
 
53 53
 9.  Start qemu
54 54
       ./qemu/i386-softmmu/qemu -L qemu/pc-bios \
55 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 58
 You should see qemu start up, load up gPXE and attempt to boot from
59 59
 the network.

+ 1
- 0
src/Makefile Wyświetl plik

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

+ 1
- 0
src/Makefile.housekeeping Wyświetl plik

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

+ 0
- 7
src/arch/i386/Makefile Wyświetl plik

@@ -114,13 +114,6 @@ NON_AUTO_MEDIA	+= fd0
114 114
 	$(Q)dd if=$< bs=512 conv=sync of=/dev/fd0
115 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 117
 # Add NON_AUTO_MEDIA to the media list, so that they show up in the
125 118
 # output of "make"
126 119
 #

+ 6
- 0
src/arch/i386/Makefile.pcbios Wyświetl plik

@@ -27,6 +27,12 @@ MEDIA		+= raw
27 27
 MEDIA		+= com
28 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 36
 # rule to make a non-emulation ISO boot image
31 37
 NON_AUTO_MEDIA	+= iso
32 38
 %iso:	%lkrn util/geniso

+ 0
- 12
src/util/dskpad.pl Wyświetl plik

@@ -1,12 +0,0 @@
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 Wyświetl plik

@@ -0,0 +1,44 @@
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
+}

Ładowanie…
Anuluj
Zapisz