0089-scripts-Multi-platform-support-for-mkknlimg-and-knli.patch 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. From 5e591b39b106e20e3f8128cbd46a20d01eedb185 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/381] scripts: Multi-platform support for mkknlimg and
  5. 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
  9. multiple platforms.
  10. This patch adds '270X' and '283X' tags to indicate support for RPi and
  11. upstream platforms, respectively. '283x' (note lower case 'x') is left
  12. for old firmware, and is only set if the image only supports upstream
  13. builds.
  14. ---
  15. scripts/knlinfo | 2 +
  16. scripts/mkknlimg | 136 +++++++++++++++++++++++++++++++------------------------
  17. 2 files changed, 80 insertions(+), 58 deletions(-)
  18. --- a/scripts/knlinfo
  19. +++ b/scripts/knlinfo
  20. @@ -18,6 +18,8 @@ my %atom_formats =
  21. (
  22. 'DTOK' => \&format_bool,
  23. 'KVer' => \&format_string,
  24. + '270X' => \&format_bool,
  25. + '283X' => \&format_bool,
  26. '283x' => \&format_bool,
  27. );
  28. --- a/scripts/mkknlimg
  29. +++ b/scripts/mkknlimg
  30. @@ -13,12 +13,20 @@ use strict;
  31. use warnings;
  32. use integer;
  33. +use constant FLAG_PI => 0x01;
  34. +use constant FLAG_DTOK => 0x02;
  35. +use constant FLAG_DDTK => 0x04;
  36. +use constant FLAG_270X => 0x08;
  37. +use constant FLAG_283X => 0x10;
  38. +
  39. my $trailer_magic = 'RPTL';
  40. my $tmpfile1 = "/tmp/mkknlimg_$$.1";
  41. my $tmpfile2 = "/tmp/mkknlimg_$$.2";
  42. my $dtok = 0;
  43. +my $ddtk = 0;
  44. +my $is_270x = 0;
  45. my $is_283x = 0;
  46. while (@ARGV && ($ARGV[0] =~ /^-/))
  47. @@ -28,6 +36,14 @@ while (@ARGV && ($ARGV[0] =~ /^-/))
  48. {
  49. $dtok = 1;
  50. }
  51. + elsif ($arg eq '--ddtk')
  52. + {
  53. + $ddtk = 1;
  54. + }
  55. + elsif ($arg eq '--270x')
  56. + {
  57. + $is_270x = 1;
  58. + }
  59. elsif ($arg eq '--283x')
  60. {
  61. $is_283x = 1;
  62. @@ -50,30 +66,33 @@ if (! -r $kernel_file)
  63. usage();
  64. }
  65. -my @wanted_strings =
  66. -(
  67. - 'bcm2708_fb',
  68. - 'brcm,bcm2835-mmc',
  69. - 'brcm,bcm2835-sdhost',
  70. - 'brcm,bcm2708-pinctrl',
  71. - 'brcm,bcm2835-gpio',
  72. - 'brcm,bcm2835',
  73. - 'brcm,bcm2836'
  74. -);
  75. +my $wanted_strings =
  76. +{
  77. + 'bcm2708_fb' => FLAG_PI,
  78. + 'brcm,bcm2835-mmc' => FLAG_PI,
  79. + 'brcm,bcm2835-sdhost' => FLAG_PI,
  80. + 'brcm,bcm2708-pinctrl' => FLAG_PI | FLAG_DTOK,
  81. + 'brcm,bcm2835-gpio' => FLAG_PI | FLAG_DTOK,
  82. + 'brcm,bcm2708' => FLAG_PI | FLAG_DTOK | FLAG_270X,
  83. + 'brcm,bcm2709' => FLAG_PI | FLAG_DTOK | FLAG_270X,
  84. + 'brcm,bcm2835' => FLAG_PI | FLAG_DTOK | FLAG_283X,
  85. + 'brcm,bcm2836' => FLAG_PI | FLAG_DTOK | FLAG_283X,
  86. + 'of_overlay_apply' => FLAG_DTOK | FLAG_DDTK,
  87. +};
  88. my $res = try_extract($kernel_file, $tmpfile1);
  89. -$res = try_decompress('\037\213\010', 'xy', 'gunzip', 0,
  90. - $kernel_file, $tmpfile1, $tmpfile2) if (!$res);
  91. -$res = try_decompress('\3757zXZ\000', 'abcde', 'unxz --single-stream', -1,
  92. - $kernel_file, $tmpfile1, $tmpfile2) if (!$res);
  93. -$res = try_decompress('BZh', 'xy', 'bunzip2', 0,
  94. - $kernel_file, $tmpfile1, $tmpfile2) if (!$res);
  95. -$res = try_decompress('\135\0\0\0', 'xxx', 'unlzma', 0,
  96. - $kernel_file, $tmpfile1, $tmpfile2) if (!$res);
  97. -$res = try_decompress('\211\114\132', 'xy', 'lzop -d', 0,
  98. - $kernel_file, $tmpfile1, $tmpfile2) if (!$res);
  99. -$res = try_decompress('\002\041\114\030', 'xy', 'lz4 -d', 1,
  100. - $kernel_file, $tmpfile1, $tmpfile2) if (!$res);
  101. +$res ||= try_decompress('\037\213\010', 'xy', 'gunzip', 0,
  102. + $kernel_file, $tmpfile1, $tmpfile2);
  103. +$res ||= try_decompress('\3757zXZ\000', 'abcde', 'unxz --single-stream', -1,
  104. + $kernel_file, $tmpfile1, $tmpfile2);
  105. +$res ||= try_decompress('BZh', 'xy', 'bunzip2', 0,
  106. + $kernel_file, $tmpfile1, $tmpfile2);
  107. +$res ||= try_decompress('\135\0\0\0', 'xxx', 'unlzma', 0,
  108. + $kernel_file, $tmpfile1, $tmpfile2);
  109. +$res ||= try_decompress('\211\114\132', 'xy', 'lzop -d', 0,
  110. + $kernel_file, $tmpfile1, $tmpfile2);
  111. +$res ||= try_decompress('\002\041\114\030', 'xy', 'lz4 -d', 1,
  112. + $kernel_file, $tmpfile1, $tmpfile2);
  113. my $append_trailer;
  114. my $trailer;
  115. @@ -83,27 +102,21 @@ $append_trailer = $dtok;
  116. if ($res)
  117. {
  118. - $kver = $res->{''} || '?';
  119. + $kver = $res->{'kver'} || '?';
  120. + my $flags = $res->{'flags'};
  121. print("Version: $kver\n");
  122. - $append_trailer = $dtok;
  123. - if (!$dtok)
  124. + if ($flags & FLAG_PI)
  125. {
  126. - if (config_bool($res, 'bcm2708_fb') ||
  127. - config_bool($res, 'brcm,bcm2835-mmc') ||
  128. - config_bool($res, 'brcm,bcm2835-sdhost'))
  129. - {
  130. - $dtok ||= config_bool($res, 'brcm,bcm2708-pinctrl');
  131. - $dtok ||= config_bool($res, 'brcm,bcm2835-gpio');
  132. - $is_283x ||= config_bool($res, 'brcm,bcm2835');
  133. - $is_283x ||= config_bool($res, 'brcm,bcm2836');
  134. - $dtok ||= $is_283x;
  135. - $append_trailer = 1;
  136. - }
  137. - else
  138. - {
  139. - print ("* This doesn't look like a Raspberry Pi kernel. In pass-through mode.\n");
  140. - }
  141. + $append_trailer = 1;
  142. + $dtok ||= ($flags & FLAG_DTOK) != 0;
  143. + $is_270x ||= ($flags & FLAG_270X) != 0;
  144. + $is_283x ||= ($flags & FLAG_283X) != 0;
  145. + $ddtk ||= ($flags & FLAG_DDTK) != 0;
  146. + }
  147. + else
  148. + {
  149. + print ("* This doesn't look like a Raspberry Pi kernel. In pass-through mode.\n");
  150. }
  151. }
  152. elsif (!$dtok)
  153. @@ -114,6 +127,8 @@ elsif (!$dtok)
  154. if ($append_trailer)
  155. {
  156. printf("DT: %s\n", $dtok ? "y" : "n");
  157. + printf("DDT: %s\n", $ddtk ? "y" : "n") if ($ddtk);
  158. + printf("270x: %s\n", $is_270x ? "y" : "n");
  159. printf("283x: %s\n", $is_283x ? "y" : "n");
  160. my @atoms;
  161. @@ -121,7 +136,10 @@ if ($append_trailer)
  162. push @atoms, [ $trailer_magic, pack('V', 0) ];
  163. push @atoms, [ 'KVer', $kver ];
  164. push @atoms, [ 'DTOK', pack('V', $dtok) ];
  165. - push @atoms, [ '283x', pack('V', $is_283x) ];
  166. + push @atoms, [ 'DDTK', pack('V', $ddtk) ] if ($ddtk);
  167. + push @atoms, [ '270X', pack('V', $is_270x) ];
  168. + push @atoms, [ '283X', pack('V', $is_283x) ];
  169. + push @atoms, [ '283x', pack('V', $is_283x && !$is_270x) ];
  170. $trailer = pack_trailer(\@atoms);
  171. $atoms[0]->[1] = pack('V', length($trailer));
  172. @@ -175,7 +193,7 @@ END {
  173. sub usage
  174. {
  175. - print ("Usage: mkknlimg [--dtok] [--283x] <vmlinux|zImage|bzImage> <outfile>\n");
  176. + print ("Usage: mkknlimg [--dtok] [--270x] [--283x] <vmlinux|zImage|bzImage> <outfile>\n");
  177. exit(1);
  178. }
  179. @@ -189,15 +207,8 @@ sub try_extract
  180. chomp($ver);
  181. - my $res = { ''=>$ver };
  182. - my $string_pattern = '^('.join('|', @wanted_strings).')$';
  183. -
  184. - my @matches = `strings \"$knl\" | grep -E \"$string_pattern\"`;
  185. - foreach my $match (@matches)
  186. - {
  187. - chomp($match);
  188. - $res->{$match} = 1;
  189. - }
  190. + my $res = { 'kver'=>$ver };
  191. + $res->{'flags'} = strings_to_flags($knl, $wanted_strings);
  192. return $res;
  193. }
  194. @@ -224,6 +235,22 @@ sub try_decompress
  195. return undef;
  196. }
  197. +sub strings_to_flags
  198. +{
  199. + my ($knl, $strings) = @_;
  200. + my $string_pattern = '^('.join('|', keys(%$strings)).')$';
  201. + my $flags = 0;
  202. +
  203. + my @matches = `strings \"$knl\" | grep -E \"$string_pattern\"`;
  204. + foreach my $match (@matches)
  205. + {
  206. + chomp($match);
  207. + $flags |= $strings->{$match};
  208. + }
  209. +
  210. + return $flags;
  211. +}
  212. +
  213. sub pack_trailer
  214. {
  215. my ($atoms) = @_;
  216. @@ -235,10 +262,3 @@ sub pack_trailer
  217. }
  218. return $trailer;
  219. }
  220. -
  221. -sub config_bool
  222. -{
  223. - my ($configs, $wanted) = @_;
  224. - my $val = $configs->{$wanted} || 'n';
  225. - return (($val eq 'y') || ($val eq '1'));
  226. -}