aboutsummaryrefslogtreecommitdiffstats
path: root/main/linux-rpi/markdt
blob: ce4f19d776717d5489fcb2c14be18cc5610c5277 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/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 = 1;
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);