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

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