[e16e8f2] | 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. |
---|
| 11 | ## |
---|
| 12 | ## ----------------------------------------------------------------------- |
---|
| 13 | |
---|
| 14 | # |
---|
| 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 |
---|
| 19 | |
---|
| 20 | eval { use bytes; }; |
---|
| 21 | |
---|
| 22 | ($out,$file16,$file32) = @ARGV; |
---|
| 23 | |
---|
| 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 }; |
---|
| 28 | |
---|
| 29 | @info = stat(FILE); |
---|
| 30 | $size = $info[7]; |
---|
| 31 | |
---|
| 32 | $sectors = ($size + 511) >> 9; |
---|
| 33 | $xsize = $sectors << 9; |
---|
| 34 | |
---|
| 35 | read(FILE, $f16, $size); |
---|
| 36 | |
---|
| 37 | print OUT $f16; |
---|
| 38 | |
---|
| 39 | if ( $size != $xsize ) { |
---|
| 40 | # Pad to a sector boundary |
---|
| 41 | print OUT "\0" x ($xsize-$size); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | seek(OUT, 0x1f1, SEEK_SET); # setup_sects |
---|
| 45 | # All sectors are setup except the first |
---|
| 46 | print OUT pack("C", $sectors-1); |
---|
| 47 | |
---|
| 48 | seek(OUT, $xsize, SEEK_SET); |
---|
| 49 | close(FILE); |
---|
| 50 | |
---|
| 51 | open(FILE, "+< $file32\0") or die "$0: Cannot open file: $file32\n"; |
---|
| 52 | |
---|
| 53 | while ( ($n = read(FILE, $f32, 65536)) > 0 ) { |
---|
| 54 | print OUT $f32; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | close(FILE); |
---|
| 58 | close(OUT); |
---|