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