10bd75fe5de7c977c30371a63b7bc1a0f4a1db22
[openwrt/svn-archive/archive.git] / target / linux / brcm2708 / patches-4.4 / 0090-scripts-Multi-platform-support-for-mkknlimg-and-knli.patch
1 From 6e5a9e29f92463a7c3e0230f8c8ea9001bda2bff 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 090/156] scripts: Multi-platform support for mkknlimg and
5 knlinfo
6
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
10 multiple platforms.
11
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
15 builds.
16 ---
17 scripts/knlinfo | 2 +
18 scripts/mkknlimg | 136 +++++++++++++++++++++++++++++++------------------------
19 2 files changed, 80 insertions(+), 58 deletions(-)
20
21 --- a/scripts/knlinfo
22 +++ b/scripts/knlinfo
23 @@ -18,6 +18,8 @@ my %atom_formats =
24 (
25 'DTOK' => \&format_bool,
26 'KVer' => \&format_string,
27 + '270X' => \&format_bool,
28 + '283X' => \&format_bool,
29 '283x' => \&format_bool,
30 );
31
32 --- a/scripts/mkknlimg
33 +++ b/scripts/mkknlimg
34 @@ -13,12 +13,20 @@ use strict;
35 use warnings;
36 use integer;
37
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;
43 +
44 my $trailer_magic = 'RPTL';
45
46 my $tmpfile1 = "/tmp/mkknlimg_$$.1";
47 my $tmpfile2 = "/tmp/mkknlimg_$$.2";
48
49 my $dtok = 0;
50 +my $ddtk = 0;
51 +my $is_270x = 0;
52 my $is_283x = 0;
53
54 while (@ARGV && ($ARGV[0] =~ /^-/))
55 @@ -28,6 +36,14 @@ while (@ARGV && ($ARGV[0] =~ /^-/))
56 {
57 $dtok = 1;
58 }
59 + elsif ($arg eq '--ddtk')
60 + {
61 + $ddtk = 1;
62 + }
63 + elsif ($arg eq '--270x')
64 + {
65 + $is_270x = 1;
66 + }
67 elsif ($arg eq '--283x')
68 {
69 $is_283x = 1;
70 @@ -50,30 +66,33 @@ if (! -r $kernel_file)
71 usage();
72 }
73
74 -my @wanted_strings =
75 -(
76 - 'bcm2708_fb',
77 - 'brcm,bcm2835-mmc',
78 - 'brcm,bcm2835-sdhost',
79 - 'brcm,bcm2708-pinctrl',
80 - 'brcm,bcm2835-gpio',
81 - 'brcm,bcm2835',
82 - 'brcm,bcm2836'
83 -);
84 +my $wanted_strings =
85 +{
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,
96 +};
97
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);
123
124 my $append_trailer;
125 my $trailer;
126 @@ -83,27 +102,21 @@ $append_trailer = $dtok;
127
128 if ($res)
129 {
130 - $kver = $res->{''} || '?';
131 + $kver = $res->{'kver'} || '?';
132 + my $flags = $res->{'flags'};
133 print("Version: $kver\n");
134
135 - $append_trailer = $dtok;
136 - if (!$dtok)
137 + if ($flags & FLAG_PI)
138 {
139 - if (config_bool($res, 'bcm2708_fb') ||
140 - config_bool($res, 'brcm,bcm2835-mmc') ||
141 - config_bool($res, 'brcm,bcm2835-sdhost'))
142 - {
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;
149 - }
150 - else
151 - {
152 - print ("* This doesn't look like a Raspberry Pi kernel. In pass-through mode.\n");
153 - }
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;
159 + }
160 + else
161 + {
162 + print ("* This doesn't look like a Raspberry Pi kernel. In pass-through mode.\n");
163 }
164 }
165 elsif (!$dtok)
166 @@ -114,6 +127,8 @@ elsif (!$dtok)
167 if ($append_trailer)
168 {
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");
173
174 my @atoms;
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) ];
184
185 $trailer = pack_trailer(\@atoms);
186 $atoms[0]->[1] = pack('V', length($trailer));
187 @@ -175,7 +193,7 @@ END {
188
189 sub usage
190 {
191 - print ("Usage: mkknlimg [--dtok] [--283x] <vmlinux|zImage|bzImage> <outfile>\n");
192 + print ("Usage: mkknlimg [--dtok] [--270x] [--283x] <vmlinux|zImage|bzImage> <outfile>\n");
193 exit(1);
194 }
195
196 @@ -189,15 +207,8 @@ sub try_extract
197
198 chomp($ver);
199
200 - my $res = { ''=>$ver };
201 - my $string_pattern = '^('.join('|', @wanted_strings).')$';
202 -
203 - my @matches = `strings \"$knl\" | grep -E \"$string_pattern\"`;
204 - foreach my $match (@matches)
205 - {
206 - chomp($match);
207 - $res->{$match} = 1;
208 - }
209 + my $res = { 'kver'=>$ver };
210 + $res->{'flags'} = strings_to_flags($knl, $wanted_strings);
211
212 return $res;
213 }
214 @@ -224,6 +235,22 @@ sub try_decompress
215 return undef;
216 }
217
218 +sub strings_to_flags
219 +{
220 + my ($knl, $strings) = @_;
221 + my $string_pattern = '^('.join('|', keys(%$strings)).')$';
222 + my $flags = 0;
223 +
224 + my @matches = `strings \"$knl\" | grep -E \"$string_pattern\"`;
225 + foreach my $match (@matches)
226 + {
227 + chomp($match);
228 + $flags |= $strings->{$match};
229 + }
230 +
231 + return $flags;
232 +}
233 +
234 sub pack_trailer
235 {
236 my ($atoms) = @_;
237 @@ -235,10 +262,3 @@ sub pack_trailer
238 }
239 return $trailer;
240 }
241 -
242 -sub config_bool
243 -{
244 - my ($configs, $wanted) = @_;
245 - my $val = $configs->{$wanted} || 'n';
246 - return (($val eq 'y') || ($val eq '1'));
247 -}