mirror of
https://github.com/xcat2/xNBA.git
synced 2024-11-22 01:21:45 +00:00
[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>
This commit is contained in:
parent
b363d19a16
commit
7741546a40
@ -47,13 +47,13 @@ To get qemu running is fairly simple:
|
||||
|
||||
8. Build gPXE floppy disk images and pad to 1.44MB
|
||||
pushd ../../src
|
||||
make bin/rtl8139.pdsk
|
||||
make bin/rtl8139.dsk
|
||||
popd
|
||||
|
||||
9. Start qemu
|
||||
./qemu/i386-softmmu/qemu -L qemu/pc-bios \
|
||||
-net nic,model=rtl8139 -net tap,ifname=tap0 \
|
||||
-boot a -fda ../../src/bin/rtl8139.pdsk
|
||||
-boot a -fda ../../src/bin/rtl8139.dsk
|
||||
|
||||
You should see qemu start up, load up gPXE and attempt to boot from
|
||||
the network.
|
||||
|
@ -35,6 +35,7 @@ PARSEROM := $(PERL) ./util/parserom.pl
|
||||
MAKEROM := $(PERL) ./util/makerom.pl
|
||||
SYMCHECK := $(PERL) ./util/symcheck.pl
|
||||
SORTOBJDUMP := $(PERL) ./util/sortobjdump.pl
|
||||
PADIMG := $(PERL) ./util/padimg.pl
|
||||
NRV2B := ./util/nrv2b
|
||||
ZBIN := ./util/zbin
|
||||
ELF2EFI32 := ./util/elf2efi32
|
||||
|
@ -724,6 +724,7 @@ define media_template
|
||||
@$(ECHO_E) '$$(BIN)/%.$(1) : $$(BIN)/%.$(1).zbin' \
|
||||
'\n\t$$(QM)$(ECHO) " [FINISH] $$@"' \
|
||||
'\n\t$$(Q)$$(CP) $$< $$@' \
|
||||
'\n\t$$(Q)$$(PAD_$(1))' \
|
||||
'\n\t$$(Q)$$(FINALISE_$(1))' \
|
||||
> $(2)
|
||||
|
||||
|
@ -114,13 +114,6 @@ NON_AUTO_MEDIA += fd0
|
||||
$(Q)dd if=$< bs=512 conv=sync of=/dev/fd0
|
||||
$(Q)sync
|
||||
|
||||
# rule to create padded disk images
|
||||
NON_AUTO_MEDIA += pdsk
|
||||
%pdsk : %dsk
|
||||
$(QM)$(ECHO) " [DSKPAD] $@"
|
||||
$(Q)cp $< $@
|
||||
$(Q)$(PERL) ./util/dskpad.pl $@
|
||||
|
||||
# Add NON_AUTO_MEDIA to the media list, so that they show up in the
|
||||
# output of "make"
|
||||
#
|
||||
|
@ -27,6 +27,12 @@ MEDIA += raw
|
||||
MEDIA += com
|
||||
MEDIA += exe
|
||||
|
||||
# Padding rules
|
||||
#
|
||||
PAD_rom = $(PADIMG) --blksize=512 --byte=0xff $@
|
||||
PAD_dsk = $(PADIMG) --blksize=512 $@
|
||||
PAD_hd = $(PADIMG) --blksize=512 $@
|
||||
|
||||
# rule to make a non-emulation ISO boot image
|
||||
NON_AUTO_MEDIA += iso
|
||||
%iso: %lkrn util/geniso
|
||||
|
@ -1,12 +0,0 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use constant FLOPPYSIZE => 1440 * 1024;
|
||||
|
||||
while ( my $filename = shift ) {
|
||||
die "$filename is not a file\n" unless -f $filename;
|
||||
die "$filename is too large\n" unless ( -s $filename <= FLOPPYSIZE );
|
||||
truncate $filename, FLOPPYSIZE or die "Could not truncate: $!\n";
|
||||
}
|
44
src/util/padimg.pl
Executable file
44
src/util/padimg.pl
Executable file
@ -0,0 +1,44 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Getopt::Long;
|
||||
use Fcntl;
|
||||
|
||||
my $verbosity = 0;
|
||||
my $blksize = 512;
|
||||
my $byte = 0;
|
||||
|
||||
my $opts = {
|
||||
'verbose|v+' => sub { $verbosity++; },
|
||||
'quiet|q+' => sub { $verbosity--; },
|
||||
'blksize|s=o' => sub { $blksize = $_[1]; },
|
||||
'byte|b=o' => sub { $byte = $_[1]; },
|
||||
};
|
||||
|
||||
Getopt::Long::Configure ( 'bundling', 'auto_abbrev' );
|
||||
GetOptions ( { map { /^(\w+)/; $1 => $opts->{$_} } keys %$opts }, keys %$opts )
|
||||
or die "Could not parse command-line options\n";
|
||||
|
||||
while ( my $filename = shift ) {
|
||||
die "$filename is not a file\n" unless -f $filename;
|
||||
my $oldsize = -s $filename;
|
||||
my $newsize = ( ( $oldsize + $blksize - 1 ) & ~( $blksize - 1 ) );
|
||||
my $padsize = ( $newsize - $oldsize );
|
||||
next unless $padsize;
|
||||
if ( $verbosity >= 1 ) {
|
||||
printf "Padding %s from %d to %d bytes with %d x 0x%02x\n",
|
||||
$filename, $oldsize, $newsize, $padsize, $byte;
|
||||
}
|
||||
if ( $byte ) {
|
||||
sysopen ( my $fh, $filename, ( O_WRONLY | O_APPEND ) )
|
||||
or die "Could not open $filename for appending: $!\n";
|
||||
syswrite $fh, ( chr ( $byte ) x $padsize )
|
||||
or die "Could not append to $filename: $!\n";
|
||||
close ( $fh );
|
||||
} else {
|
||||
truncate $filename, $newsize
|
||||
or die "Could not resize $filename: $!\n";
|
||||
}
|
||||
die "Failed to pad $filename\n" unless -s $filename == $newsize;
|
||||
}
|
Loading…
Reference in New Issue
Block a user