libinstaller: Use SOURCE_DATE_EPOCH for synthesized modification time stamps
[syslinux.git] / memdisk / postprocess.pl
blobfcda4782eb811608d0908a1026e6b456bffe3d87
1 #!/usr/bin/perl
2 ## -----------------------------------------------------------------------
3 ##
4 ## Copyright 2001-2008 H. Peter Anvin - All Rights Reserved
5 ##
6 ## This program is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation, Inc., 53 Temple Place Ste 330,
9 ## Boston MA 02111-1307, USA; either version 2 of the License, or
10 ## (at your option) any later version; incorporated herein by reference.
12 ## -----------------------------------------------------------------------
15 # Postprocess the memdisk binary. Used during the 'make' process.
16 # We write memdisk16.bin out to the final memdisk kernel, pad it to an
17 # integral 512-byte sector length, write this number of sectors into the
18 # kernel header field "setup_sects", then append memdisk32.bin
20 eval { use bytes; };
22 ($out,$file16,$file32) = @ARGV;
24 open(OUT, "> $out\0") or die "$0: Cannot create file: $out\n";
25 eval { binmode OUT; };
26 open(FILE, "< $file16\0") or die "$0: Cannot open file: $file16\n";
27 eval { binmode FILE };
29 @info = stat(FILE);
30 $size = $info[7];
32 $sectors = ($size + 511) >> 9;
33 $xsize = $sectors << 9;
35 read(FILE, $f16, $size);
37 print OUT $f16;
39 if ( $size != $xsize ) {
40 # Pad to a sector boundary
41 print OUT "\0" x ($xsize-$size);
44 seek(OUT, 0x1f1, SEEK_SET); # setup_sects
45 # All sectors are setup except the first
46 print OUT pack("C", $sectors-1);
48 seek(OUT, $xsize, SEEK_SET);
49 close(FILE);
51 open(FILE, "+< $file32\0") or die "$0: Cannot open file: $file32\n";
53 while ( ($n = read(FILE, $f32, 65536)) > 0 ) {
54 print OUT $f32;
57 close(FILE);
58 close(OUT);