[go: up one dir, main page]

Menu

[f88464]: / tools / markdt  Maximize  Restore  History

Download this file

60 lines (50 with data), 1.5 kB

#!/usr/bin/env perl

# ----------------------------------------------------------------------
# markdt by Timo Teräs
# based on mkknlimg by Phil Elwell for Raspberry Pi
# based on extract-ikconfig Dick Streefland
#
# (c) 2009,2010 Dick Streefland <dick@streefland.net>
# (c) 2014,2015 Raspberry Pi (Trading) Limited <info@raspberrypi.org>
# (c) 2015 Timo Teräs <timo.teras@iki.fi>
#
# Licensed under the terms of the GNU General Public License.
# ----------------------------------------------------------------------

use strict;
use integer;

usage() if (@ARGV != 1);

my $out_file = $ARGV[0];
my $trailer_magic = 'RPTL';
my $trailer;
my $dtok = 1;
my $ddtk = 0;
my $is_283x = 0;
my $ofh;
my $total_len = 0;

sub pack_trailer
{
	my ($atoms) = @_;
	my $trailer = pack('VV', 0, 0);
	for (my $i = $#$atoms; $i>=0; $i--)
	{
		my $atom = $atoms->[$i];
		$trailer .= pack('a*x!4Va4', $atom->[1], length($atom->[1]), $atom->[0]);
	}
	return $trailer;
}

# Construct the trailer
my @atoms;
push @atoms, [ $trailer_magic, pack('V', 0) ];
push @atoms, [ 'DTOK', pack('V', $dtok) ];
push @atoms, [ 'DDTK', pack('V', $ddtk) ];
push @atoms, [ '283x', pack('V', $is_283x) ];

$trailer = pack_trailer(\@atoms);
$atoms[0]->[1] = pack('V', length($trailer));
$trailer = pack_trailer(\@atoms);

# Write the trailer aligned to 4-byte boundary
die "* Failed to open '$out_file' for append\n" if (!open($ofh, '>>', $out_file));
$total_len = tell($ofh);
syswrite($ofh, "\x000\x000\x000", (-$total_len & 0x3));
syswrite($ofh, $trailer);
close($ofh);
exit(0);