#!/usr/bin/perl # Zero-pads the stage2 bootloader binary out to a fixed size (STAGE2_SECTORS # * 512 bytes), so the kernel's on-disk starting sector is predictable # regardless of stage2's actual compiled size. Errors out if stage2 has # grown past that budget instead of silently truncating it. my $size = $ARGV[1] || die "usage: padstage2.pl \n"; open(F, $ARGV[0]) || die "open $ARGV[0]: $!"; my $n = sysread(F, my $buf, $size + 1); close(F); if ($n > $size) { print STDERR "stage2 too large: $n bytes (max $size)\n"; exit 1; } print STDERR "stage2 is $n bytes (max $size)\n"; $buf .= "\0" x ($size - $n); open(F, ">$ARGV[0]") || die "open >$ARGV[0]: $!"; print F $buf; close(F);