1 From 8a51551a8e90b0af9ca4d1519e4ab3c4e3f0e672 Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.org>
3 Date: Wed, 11 Nov 2015 11:38:59 +0000
4 Subject: [PATCH 089/304] scripts: Multi-platform support for mkknlimg and
7 The firmware uses tags in the kernel trailer to choose which dtb file
8 to load. Current firmware loads bcm2835-*.dtb if the '283x' tag is true,
9 otherwise it loads bcm270*.dtb. This scheme breaks if an image supports
12 This patch adds '270X' and '283X' tags to indicate support for RPi and
13 upstream platforms, respectively. '283x' (note lower case 'x') is left
14 for old firmware, and is only set if the image only supports upstream
18 scripts/mkknlimg | 136 +++++++++++++++++++++++++++++++------------------------
19 2 files changed, 80 insertions(+), 58 deletions(-)
23 @@ -18,6 +18,8 @@ my %atom_formats =
25 'DTOK' => \&format_bool,
26 'KVer' => \&format_string,
27 + '270X' => \&format_bool,
28 + '283X' => \&format_bool,
29 '283x' => \&format_bool,
32 --- a/scripts/mkknlimg
33 +++ b/scripts/mkknlimg
34 @@ -13,12 +13,20 @@ use strict;
38 +use constant FLAG_PI => 0x01;
39 +use constant FLAG_DTOK => 0x02;
40 +use constant FLAG_DDTK => 0x04;
41 +use constant FLAG_270X => 0x08;
42 +use constant FLAG_283X => 0x10;
44 my $trailer_magic = 'RPTL';
46 my $tmpfile1 = "/tmp/mkknlimg_$$.1";
47 my $tmpfile2 = "/tmp/mkknlimg_$$.2";
54 while (@ARGV && ($ARGV[0] =~ /^-/))
55 @@ -28,6 +36,14 @@ while (@ARGV && ($ARGV[0] =~ /^-/))
59 + elsif ($arg eq '--ddtk')
63 + elsif ($arg eq '--270x')
67 elsif ($arg eq '--283x')
70 @@ -50,30 +66,33 @@ if (! -r $kernel_file)
78 - 'brcm,bcm2835-sdhost',
79 - 'brcm,bcm2708-pinctrl',
80 - 'brcm,bcm2835-gpio',
86 + 'bcm2708_fb' => FLAG_PI,
87 + 'brcm,bcm2835-mmc' => FLAG_PI,
88 + 'brcm,bcm2835-sdhost' => FLAG_PI,
89 + 'brcm,bcm2708-pinctrl' => FLAG_PI | FLAG_DTOK,
90 + 'brcm,bcm2835-gpio' => FLAG_PI | FLAG_DTOK,
91 + 'brcm,bcm2708' => FLAG_PI | FLAG_DTOK | FLAG_270X,
92 + 'brcm,bcm2709' => FLAG_PI | FLAG_DTOK | FLAG_270X,
93 + 'brcm,bcm2835' => FLAG_PI | FLAG_DTOK | FLAG_283X,
94 + 'brcm,bcm2836' => FLAG_PI | FLAG_DTOK | FLAG_283X,
95 + 'of_overlay_apply' => FLAG_DTOK | FLAG_DDTK,
98 my $res = try_extract($kernel_file, $tmpfile1);
99 -$res = try_decompress('\037\213\010', 'xy', 'gunzip', 0,
100 - $kernel_file, $tmpfile1, $tmpfile2) if (!$res);
101 -$res = try_decompress('\3757zXZ\000', 'abcde', 'unxz --single-stream', -1,
102 - $kernel_file, $tmpfile1, $tmpfile2) if (!$res);
103 -$res = try_decompress('BZh', 'xy', 'bunzip2', 0,
104 - $kernel_file, $tmpfile1, $tmpfile2) if (!$res);
105 -$res = try_decompress('\135\0\0\0', 'xxx', 'unlzma', 0,
106 - $kernel_file, $tmpfile1, $tmpfile2) if (!$res);
107 -$res = try_decompress('\211\114\132', 'xy', 'lzop -d', 0,
108 - $kernel_file, $tmpfile1, $tmpfile2) if (!$res);
109 -$res = try_decompress('\002\041\114\030', 'xy', 'lz4 -d', 1,
110 - $kernel_file, $tmpfile1, $tmpfile2) if (!$res);
111 +$res ||= try_decompress('\037\213\010', 'xy', 'gunzip', 0,
112 + $kernel_file, $tmpfile1, $tmpfile2);
113 +$res ||= try_decompress('\3757zXZ\000', 'abcde', 'unxz --single-stream', -1,
114 + $kernel_file, $tmpfile1, $tmpfile2);
115 +$res ||= try_decompress('BZh', 'xy', 'bunzip2', 0,
116 + $kernel_file, $tmpfile1, $tmpfile2);
117 +$res ||= try_decompress('\135\0\0\0', 'xxx', 'unlzma', 0,
118 + $kernel_file, $tmpfile1, $tmpfile2);
119 +$res ||= try_decompress('\211\114\132', 'xy', 'lzop -d', 0,
120 + $kernel_file, $tmpfile1, $tmpfile2);
121 +$res ||= try_decompress('\002\041\114\030', 'xy', 'lz4 -d', 1,
122 + $kernel_file, $tmpfile1, $tmpfile2);
126 @@ -83,27 +102,21 @@ $append_trailer = $dtok;
130 - $kver = $res->{''} || '?';
131 + $kver = $res->{'kver'} || '?';
132 + my $flags = $res->{'flags'};
133 print("Version: $kver\n");
135 - $append_trailer = $dtok;
137 + if ($flags & FLAG_PI)
139 - if (config_bool($res, 'bcm2708_fb') ||
140 - config_bool($res, 'brcm,bcm2835-mmc') ||
141 - config_bool($res, 'brcm,bcm2835-sdhost'))
143 - $dtok ||= config_bool($res, 'brcm,bcm2708-pinctrl');
144 - $dtok ||= config_bool($res, 'brcm,bcm2835-gpio');
145 - $is_283x ||= config_bool($res, 'brcm,bcm2835');
146 - $is_283x ||= config_bool($res, 'brcm,bcm2836');
147 - $dtok ||= $is_283x;
148 - $append_trailer = 1;
152 - print ("* This doesn't look like a Raspberry Pi kernel. In pass-through mode.\n");
154 + $append_trailer = 1;
155 + $dtok ||= ($flags & FLAG_DTOK) != 0;
156 + $is_270x ||= ($flags & FLAG_270X) != 0;
157 + $is_283x ||= ($flags & FLAG_283X) != 0;
158 + $ddtk ||= ($flags & FLAG_DDTK) != 0;
162 + print ("* This doesn't look like a Raspberry Pi kernel. In pass-through mode.\n");
166 @@ -114,6 +127,8 @@ elsif (!$dtok)
169 printf("DT: %s\n", $dtok ? "y" : "n");
170 + printf("DDT: %s\n", $ddtk ? "y" : "n") if ($ddtk);
171 + printf("270x: %s\n", $is_270x ? "y" : "n");
172 printf("283x: %s\n", $is_283x ? "y" : "n");
175 @@ -121,7 +136,10 @@ if ($append_trailer)
176 push @atoms, [ $trailer_magic, pack('V', 0) ];
177 push @atoms, [ 'KVer', $kver ];
178 push @atoms, [ 'DTOK', pack('V', $dtok) ];
179 - push @atoms, [ '283x', pack('V', $is_283x) ];
180 + push @atoms, [ 'DDTK', pack('V', $ddtk) ] if ($ddtk);
181 + push @atoms, [ '270X', pack('V', $is_270x) ];
182 + push @atoms, [ '283X', pack('V', $is_283x) ];
183 + push @atoms, [ '283x', pack('V', $is_283x && !$is_270x) ];
185 $trailer = pack_trailer(\@atoms);
186 $atoms[0]->[1] = pack('V', length($trailer));
187 @@ -175,7 +193,7 @@ END {
191 - print ("Usage: mkknlimg [--dtok] [--283x] <vmlinux|zImage|bzImage> <outfile>\n");
192 + print ("Usage: mkknlimg [--dtok] [--270x] [--283x] <vmlinux|zImage|bzImage> <outfile>\n");
196 @@ -189,15 +207,8 @@ sub try_extract
200 - my $res = { ''=>$ver };
201 - my $string_pattern = '^('.join('|', @wanted_strings).')$';
203 - my @matches = `strings \"$knl\" | grep -E \"$string_pattern\"`;
204 - foreach my $match (@matches)
207 - $res->{$match} = 1;
209 + my $res = { 'kver'=>$ver };
210 + $res->{'flags'} = strings_to_flags($knl, $wanted_strings);
214 @@ -224,6 +235,22 @@ sub try_decompress
218 +sub strings_to_flags
220 + my ($knl, $strings) = @_;
221 + my $string_pattern = '^('.join('|', keys(%$strings)).')$';
224 + my @matches = `strings \"$knl\" | grep -E \"$string_pattern\"`;
225 + foreach my $match (@matches)
228 + $flags |= $strings->{$match};
237 @@ -235,10 +262,3 @@ sub pack_trailer
244 - my ($configs, $wanted) = @_;
245 - my $val = $configs->{$wanted} || 'n';
246 - return (($val eq 'y') || ($val eq '1'));