7 if (scalar(@ARGV) != 2) {
8 print STDERR "usage: make_payload.pl <cfg-file> <out-file>\n";
12 my $config_file = shift @ARGV;
13 my $out_file = shift @ARGV;
15 open (CFGFILE, "$config_file");
21 my @region_names = ();
24 foreach $line (@cfg) {
26 ($file, $dst) = split(/:/, $line);
27 push @region_names, $file;
28 $region_map{$file} = hex($dst); #unpack('N', pack("h8",$dst));
29 print "" . hex($dst) . "\n";
35 my $fh = new FileHandle(">$out_file");
38 syswrite $fh, pack('L', $magic), 4;
39 syswrite $fh, pack('L', $num_regions), 4;
41 foreach $file (@region_names) {
42 my $size = (-s $file);
44 print "$file to " . $region_map{$file}. " ($size bytes)\n";
45 syswrite $fh, pack('L', $size), 4;
46 syswrite $fh, pack('L', $region_map{$file}), 4;
51 while (($file = shift @region_names)) {
52 my $in_fh = new FileHandle("<$file");
53 (defined $in_fh) || die "Couldn't open $file: $!\n";
56 my $buf = chr(0) x 1024;
58 while (($n = sysread($in_fh, $buf, 1024)) > 0) {
59 syswrite($fh, $buf, $n);