1 From 0fda3a1eb42445783633e477f261575222c3470b 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] scripts: Multi-platform support for mkknlimg and knlinfo
6 The firmware uses tags in the kernel trailer to choose which dtb file
7 to load. Current firmware loads bcm2835-*.dtb if the '283x' tag is true,
8 otherwise it loads bcm270*.dtb. This scheme breaks if an image supports
11 This patch adds '270X' and '283X' tags to indicate support for RPi and
12 upstream platforms, respectively. '283x' (note lower case 'x') is left
13 for old firmware, and is only set if the image only supports upstream
17 scripts/mkknlimg | 136 +++++++++++++++++++++++++++++++------------------------
18 2 files changed, 80 insertions(+), 58 deletions(-)
22 @@ -18,6 +18,8 @@ my %atom_formats =
24 'DTOK' => \&format_bool,
25 'KVer' => \&format_string,
26 + '270X' => \&format_bool,
27 + '283X' => \&format_bool,
28 '283x' => \&format_bool,
31 --- a/scripts/mkknlimg
32 +++ b/scripts/mkknlimg
33 @@ -13,12 +13,20 @@ use strict;
37 +use constant FLAG_PI => 0x01;
38 +use constant FLAG_DTOK => 0x02;
39 +use constant FLAG_DDTK => 0x04;
40 +use constant FLAG_270X => 0x08;
41 +use constant FLAG_283X => 0x10;
43 my $trailer_magic = 'RPTL';
45 my $tmpfile1 = "/tmp/mkknlimg_$$.1";
46 my $tmpfile2 = "/tmp/mkknlimg_$$.2";
53 while (@ARGV && ($ARGV[0] =~ /^-/))
54 @@ -28,6 +36,14 @@ while (@ARGV && ($ARGV[0] =~ /^-/))
58 + elsif ($arg eq '--ddtk')
62 + elsif ($arg eq '--270x')
66 elsif ($arg eq '--283x')
69 @@ -50,30 +66,33 @@ if (! -r $kernel_file)
77 - 'brcm,bcm2835-sdhost',
78 - 'brcm,bcm2708-pinctrl',
79 - 'brcm,bcm2835-gpio',
85 + 'bcm2708_fb' => FLAG_PI,
86 + 'brcm,bcm2835-mmc' => FLAG_PI,
87 + 'brcm,bcm2835-sdhost' => FLAG_PI,
88 + 'brcm,bcm2708-pinctrl' => FLAG_PI | FLAG_DTOK,
89 + 'brcm,bcm2835-gpio' => FLAG_PI | FLAG_DTOK,
90 + 'brcm,bcm2708' => FLAG_PI | FLAG_DTOK | FLAG_270X,
91 + 'brcm,bcm2709' => FLAG_PI | FLAG_DTOK | FLAG_270X,
92 + 'brcm,bcm2835' => FLAG_PI | FLAG_DTOK | FLAG_283X,
93 + 'brcm,bcm2836' => FLAG_PI | FLAG_DTOK | FLAG_283X,
94 + 'of_overlay_apply' => FLAG_DTOK | FLAG_DDTK,
97 my $res = try_extract($kernel_file, $tmpfile1);
98 -$res = try_decompress('\037\213\010', 'xy', 'gunzip', 0,
99 - $kernel_file, $tmpfile1, $tmpfile2) if (!$res);
100 -$res = try_decompress('\3757zXZ\000', 'abcde', 'unxz --single-stream', -1,
101 - $kernel_file, $tmpfile1, $tmpfile2) if (!$res);
102 -$res = try_decompress('BZh', 'xy', 'bunzip2', 0,
103 - $kernel_file, $tmpfile1, $tmpfile2) if (!$res);
104 -$res = try_decompress('\135\0\0\0', 'xxx', 'unlzma', 0,
105 - $kernel_file, $tmpfile1, $tmpfile2) if (!$res);
106 -$res = try_decompress('\211\114\132', 'xy', 'lzop -d', 0,
107 - $kernel_file, $tmpfile1, $tmpfile2) if (!$res);
108 -$res = try_decompress('\002\041\114\030', 'xy', 'lz4 -d', 1,
109 - $kernel_file, $tmpfile1, $tmpfile2) if (!$res);
110 +$res ||= try_decompress('\037\213\010', 'xy', 'gunzip', 0,
111 + $kernel_file, $tmpfile1, $tmpfile2);
112 +$res ||= try_decompress('\3757zXZ\000', 'abcde', 'unxz --single-stream', -1,
113 + $kernel_file, $tmpfile1, $tmpfile2);
114 +$res ||= try_decompress('BZh', 'xy', 'bunzip2', 0,
115 + $kernel_file, $tmpfile1, $tmpfile2);
116 +$res ||= try_decompress('\135\0\0\0', 'xxx', 'unlzma', 0,
117 + $kernel_file, $tmpfile1, $tmpfile2);
118 +$res ||= try_decompress('\211\114\132', 'xy', 'lzop -d', 0,
119 + $kernel_file, $tmpfile1, $tmpfile2);
120 +$res ||= try_decompress('\002\041\114\030', 'xy', 'lz4 -d', 1,
121 + $kernel_file, $tmpfile1, $tmpfile2);
125 @@ -83,27 +102,21 @@ $append_trailer = $dtok;
129 - $kver = $res->{''} || '?';
130 + $kver = $res->{'kver'} || '?';
131 + my $flags = $res->{'flags'};
132 print("Version: $kver\n");
134 - $append_trailer = $dtok;
136 + if ($flags & FLAG_PI)
138 - if (config_bool($res, 'bcm2708_fb') ||
139 - config_bool($res, 'brcm,bcm2835-mmc') ||
140 - config_bool($res, 'brcm,bcm2835-sdhost'))
142 - $dtok ||= config_bool($res, 'brcm,bcm2708-pinctrl');
143 - $dtok ||= config_bool($res, 'brcm,bcm2835-gpio');
144 - $is_283x ||= config_bool($res, 'brcm,bcm2835');
145 - $is_283x ||= config_bool($res, 'brcm,bcm2836');
146 - $dtok ||= $is_283x;
147 - $append_trailer = 1;
151 - print ("* This doesn't look like a Raspberry Pi kernel. In pass-through mode.\n");
153 + $append_trailer = 1;
154 + $dtok ||= ($flags & FLAG_DTOK) != 0;
155 + $is_270x ||= ($flags & FLAG_270X) != 0;
156 + $is_283x ||= ($flags & FLAG_283X) != 0;
157 + $ddtk ||= ($flags & FLAG_DDTK) != 0;
161 + print ("* This doesn't look like a Raspberry Pi kernel. In pass-through mode.\n");
165 @@ -114,6 +127,8 @@ elsif (!$dtok)
168 printf("DT: %s\n", $dtok ? "y" : "n");
169 + printf("DDT: %s\n", $ddtk ? "y" : "n") if ($ddtk);
170 + printf("270x: %s\n", $is_270x ? "y" : "n");
171 printf("283x: %s\n", $is_283x ? "y" : "n");
174 @@ -121,7 +136,10 @@ if ($append_trailer)
175 push @atoms, [ $trailer_magic, pack('V', 0) ];
176 push @atoms, [ 'KVer', $kver ];
177 push @atoms, [ 'DTOK', pack('V', $dtok) ];
178 - push @atoms, [ '283x', pack('V', $is_283x) ];
179 + push @atoms, [ 'DDTK', pack('V', $ddtk) ] if ($ddtk);
180 + push @atoms, [ '270X', pack('V', $is_270x) ];
181 + push @atoms, [ '283X', pack('V', $is_283x) ];
182 + push @atoms, [ '283x', pack('V', $is_283x && !$is_270x) ];
184 $trailer = pack_trailer(\@atoms);
185 $atoms[0]->[1] = pack('V', length($trailer));
186 @@ -175,7 +193,7 @@ END {
190 - print ("Usage: mkknlimg [--dtok] [--283x] <vmlinux|zImage|bzImage> <outfile>\n");
191 + print ("Usage: mkknlimg [--dtok] [--270x] [--283x] <vmlinux|zImage|bzImage> <outfile>\n");
195 @@ -189,15 +207,8 @@ sub try_extract
199 - my $res = { ''=>$ver };
200 - my $string_pattern = '^('.join('|', @wanted_strings).')$';
202 - my @matches = `strings \"$knl\" | grep -E \"$string_pattern\"`;
203 - foreach my $match (@matches)
206 - $res->{$match} = 1;
208 + my $res = { 'kver'=>$ver };
209 + $res->{'flags'} = strings_to_flags($knl, $wanted_strings);
213 @@ -224,6 +235,22 @@ sub try_decompress
217 +sub strings_to_flags
219 + my ($knl, $strings) = @_;
220 + my $string_pattern = '^('.join('|', keys(%$strings)).')$';
223 + my @matches = `strings \"$knl\" | grep -E \"$string_pattern\"`;
224 + foreach my $match (@matches)
227 + $flags |= $strings->{$match};
236 @@ -235,10 +262,3 @@ sub pack_trailer
243 - my ($configs, $wanted) = @_;
244 - my $val = $configs->{$wanted} || 'n';
245 - return (($val eq 'y') || ($val eq '1'));