From patchwork Thu Aug 13 16:22:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Beno=C3=AEt_Th=C3=A9baudeau?= X-Patchwork-Id: 507081 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ozlabs.org (Postfix) with ESMTP id 9A5561402A3 for ; Fri, 14 Aug 2015 02:23:17 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id C32F89617F; Thu, 13 Aug 2015 16:23:16 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PVZQgkKd4skf; Thu, 13 Aug 2015 16:23:13 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by hemlock.osuosl.org (Postfix) with ESMTP id 0CDF896163; Thu, 13 Aug 2015 16:23:12 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 6811D1C224C for ; Thu, 13 Aug 2015 16:23:06 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 630A69612C for ; Thu, 13 Aug 2015 16:23:06 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NtDkKDQcJa-K for ; Thu, 13 Aug 2015 16:23:04 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from authsmtp.register.it (authsmtp76.register.it [195.110.101.60]) by hemlock.osuosl.org (Postfix) with ESMTP id 5834F96126 for ; Thu, 13 Aug 2015 16:23:03 +0000 (UTC) Received: from localhost.localdomain ([88.172.188.148]) by paganini33 with id 4GNy1r00V3CYkgw01GP2Jz; Thu, 13 Aug 2015 18:23:02 +0200 X-Rid: benoit@wsystem.com@88.172.188.148 From: =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= To: buildroot@buildroot.org Date: Thu, 13 Aug 2015 18:22:47 +0200 Message-Id: <1439482971-92878-2-git-send-email-benoit@wsystem.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1439482971-92878-1-git-send-email-benoit@wsystem.com> References: <1439482971-92878-1-git-send-email-benoit@wsystem.com> MIME-Version: 1.0 Cc: =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= Subject: [Buildroot] [PATCH 1/5] package/rpi-firmware: bump marking script version X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" Changes since last version: - add support for lz4-compressed kernels, - add copyright and license banners, - enable warnings and fix a few uses of undefined variables, - update from the rpi-4.0.y kernel. Signed-off-by: Benoît Thébaudeau --- package/rpi-firmware/mkknlimg | 246 +++++++++++++++++++++++++++--------------- 1 file changed, 159 insertions(+), 87 deletions(-) mode change 100755 => 100644 package/rpi-firmware/mkknlimg diff --git a/package/rpi-firmware/mkknlimg b/package/rpi-firmware/mkknlimg old mode 100755 new mode 100644 index f377947..33f8187 --- a/package/rpi-firmware/mkknlimg +++ b/package/rpi-firmware/mkknlimg @@ -1,25 +1,51 @@ #!/usr/bin/env perl # # Originaly from: https://github.com/raspberrypi/tools/blob/master/mkimage/mkknlimg -# Original cset : 92a2df13b887f4799554bf92c4fc78d53668c868 +# Original cset : f5642106425d430e1f82ee064121a5fd0e05a386 +# +# ---------------------------------------------------------------------- +# mkknlimg by Phil Elwell for Raspberry Pi +# based on extract-ikconfig by Dick Streefland +# +# (c) 2009,2010 Dick Streefland +# (c) 2014,2015 Raspberry Pi (Trading) Limited +# +# Licensed under the terms of the GNU General Public License. +# ---------------------------------------------------------------------- use strict; +use warnings; use integer; +use constant FLAG_PI => 1; +use constant FLAG_DTOK => 2; +use constant FLAG_DDTK => 4; +use constant FLAG_283X => 8; + my $trailer_magic = 'RPTL'; my $tmpfile1 = "/tmp/mkknlimg_$$.1"; my $tmpfile2 = "/tmp/mkknlimg_$$.2"; my $dtok = 0; +my $ddtk = 0; +my $is_283x = 0; -while ($ARGV[0] =~ /^-/) +while (@ARGV && ($ARGV[0] =~ /^-/)) { my $arg = shift(@ARGV); if ($arg eq '--dtok') { $dtok = 1; } + elsif ($arg eq '--ddtk') + { + $ddtk = 1; + } + elsif ($arg eq '--283x') + { + $is_283x = 1; + } else { print ("* Unknown option '$arg'\n"); @@ -32,56 +58,68 @@ usage() if (@ARGV != 2); my $kernel_file = $ARGV[0]; my $out_file = $ARGV[1]; -my @wanted_config_lines = -( - 'CONFIG_BCM2708_DT' -); +if (! -r $kernel_file) +{ + print ("* File '$kernel_file' not found\n"); + usage(); +} -my @wanted_strings = -( - 'bcm2708_fb', - 'brcm,bcm2708-pinctrl', - 'brcm,bcm2835-gpio', - 'of_find_property' -); +my $wanted_configs = +{ + 'CONFIG_BCM2708_DT' => FLAG_PI | FLAG_DTOK, + 'CONFIG_ARCH_BCM2835' => FLAG_PI | FLAG_DTOK | FLAG_283X, +}; + +my $wanted_strings = +{ + 'bcm2708_fb' => FLAG_PI, + 'brcm,bcm2835-mmc' => FLAG_PI, + 'brcm,bcm2835-sdhost' => FLAG_PI, + 'brcm,bcm2708-pinctrl' => FLAG_PI | FLAG_DTOK, + 'brcm,bcm2835-gpio' => FLAG_PI | FLAG_DTOK, + 'brcm,bcm2835-pm-wdt' => FLAG_PI | FLAG_DTOK | FLAG_283X, + 'of_overlay_apply' => FLAG_DTOK | FLAG_DDTK, +}; my $res = try_extract($kernel_file, $tmpfile1); - -$res = try_decompress('\037\213\010', 'xy', 'gunzip', 0, - $kernel_file, $tmpfile1, $tmpfile2) if (!$res); -$res = try_decompress('\3757zXZ\000', 'abcde', 'unxz --single-stream', -1, - $kernel_file, $tmpfile1, $tmpfile2) if (!$res); -$res = try_decompress('BZh', 'xy', 'bunzip2', 0, - $kernel_file, $tmpfile1, $tmpfile2) if (!$res); -$res = try_decompress('\135\0\0\0', 'xxx', 'unlzma', 0, - $kernel_file, $tmpfile1, $tmpfile2) if (!$res); -$res = try_decompress('\211\114\132', 'xy', 'lzop -d', 0, - $kernel_file, $tmpfile1, $tmpfile2) if (!$res); +$res ||= try_decompress('\037\213\010', 'xy', 'gunzip', 0, + $kernel_file, $tmpfile1, $tmpfile2); +$res ||= try_decompress('\3757zXZ\000', 'abcde', 'unxz --single-stream', -1, + $kernel_file, $tmpfile1, $tmpfile2); +$res ||= try_decompress('BZh', 'xy', 'bunzip2', 0, + $kernel_file, $tmpfile1, $tmpfile2); +$res ||= try_decompress('\135\0\0\0', 'xxx', 'unlzma', 0, + $kernel_file, $tmpfile1, $tmpfile2); +$res ||= try_decompress('\211\114\132', 'xy', 'lzop -d', 0, + $kernel_file, $tmpfile1, $tmpfile2); +$res ||= try_decompress('\002\041\114\030', 'xy', 'lz4 -d', 1, + $kernel_file, $tmpfile1, $tmpfile2); my $append_trailer; my $trailer; +my $kver = '?'; + +$append_trailer = $dtok; if ($res) { - print("Version: $res->{''}\n"); + $kver = $res->{'kver'} || '?'; + my $flags = $res->{'flags'}; + print("Version: $kver\n"); - $append_trailer = $dtok; - if (!$dtok) + if ($flags & FLAG_PI) { - if (config_bool($res, 'bcm2708_fb')) - { - $dtok ||= config_bool($res, 'CONFIG_BCM2708_DT'); - $dtok ||= config_bool($res, 'brcm,bcm2708-pinctrl'); - $dtok ||= config_bool($res, 'brcm,bcm2835-gpio'); - $append_trailer = 1; - } - else - { - print ("* This doesn't look like a Raspberry Pi kernel. In pass-through mode.\n"); - } + $append_trailer = 1; + $dtok ||= ($flags & FLAG_DTOK) != 0; + $is_283x ||= ($flags & FLAG_283X) != 0; + $ddtk ||= ($flags & FLAG_DDTK) != 0; + } + else + { + print ("* This doesn't look like a Raspberry Pi kernel. In pass-through mode.\n"); } } -else +elsif (!$dtok) { print ("* Is this a valid kernel? In pass-through mode.\n"); } @@ -89,12 +127,16 @@ else if ($append_trailer) { printf("DT: %s\n", $dtok ? "y" : "n"); + printf("DDT: %s\n", $ddtk ? "y" : "n"); + printf("283x: %s\n", $is_283x ? "y" : "n"); my @atoms; push @atoms, [ $trailer_magic, pack('V', 0) ]; - push @atoms, [ 'KVer', $res->{''} ]; + push @atoms, [ 'KVer', $kver ]; push @atoms, [ 'DTOK', pack('V', $dtok) ]; + push @atoms, [ 'DDTK', pack('V', $ddtk) ]; + push @atoms, [ '283x', pack('V', $is_283x) ]; $trailer = pack_trailer(\@atoms); $atoms[0]->[1] = pack('V', length($trailer)); @@ -102,17 +144,31 @@ if ($append_trailer) $trailer = pack_trailer(\@atoms); } -die "* Failed to open '$kernel_file'\n" if (!open(my $ifh, '<', $kernel_file)); -die "* Failed to create '$out_file'\n" if (!open(my $ofh, '>', $out_file)); - -my $copybuf; +my $ofh; my $total_len = 0; -while (1) + +if ($out_file eq $kernel_file) { + die "* Failed to open '$out_file' for append\n" + if (!open($ofh, '>>', $out_file)); + $total_len = tell($ofh); +} +else +{ + die "* Failed to open '$kernel_file'\n" + if (!open(my $ifh, '<', $kernel_file)); + die "* Failed to create '$out_file'\n" + if (!open($ofh, '>', $out_file)); + + my $copybuf; + while (1) + { my $bytes = sysread($ifh, $copybuf, 64*1024); last if (!$bytes); syswrite($ofh, $copybuf, $bytes); $total_len += $bytes; + } + close($ifh); } if ($trailer) @@ -122,7 +178,6 @@ if ($trailer) syswrite($ofh, $trailer); } -close($ifh); close($ofh); exit($trailer ? 0 : 1); @@ -135,7 +190,7 @@ END { sub usage { - print ("Usage: mkknlimg [--dtok] \n"); + print ("Usage: mkknlimg [--dtok] [--283x] \n"); exit(1); } @@ -149,40 +204,9 @@ sub try_extract chomp($ver); - my $res = { ''=>$ver }; - my $string_pattern = '^('.join('|', @wanted_strings).')$'; - - my @matches = `strings \"$knl\" | grep -E \"$string_pattern\"`; - foreach my $match (@matches) - { - chomp($match); - $res->{$match} = 1; - } - - my $config_pattern = '^('.join('|', @wanted_config_lines).')=(.*)$'; - my $cf1 = 'IKCFG_ST\037\213\010'; - my $cf2 = '0123456789'; - - my $pos = `tr "$cf1\n$cf2" "\n$cf2=" < "$knl" | grep -abo "^$cf2"`; - if ($pos) - { - $pos =~ s/:.*[\r\n]*$//s; - $pos += 8; - my $err = (system("tail -c+$pos \"$knl\" | zcat > $tmp 2> /dev/null") >> 8); - if (($err == 0) || ($err == 2)) - { - if (open(my $fh, '<', $tmp)) - { - while (my $line = <$fh>) - { - chomp($line); - $res->{$1} = $2 if ($line =~ /$config_pattern/); - } - - close($fh); - } - } - } + my $res = { 'kver'=>$ver }; + $res->{'flags'} = strings_to_flags($knl, $wanted_strings) | + configs_to_flags($knl, $tmp, $wanted_configs); return $res; } @@ -197,6 +221,7 @@ sub try_decompress { chomp($pos); $pos = (split(/[\r\n]+/, $pos))[$idx]; + return undef if (!defined($pos)); $pos =~ s/:.*[\r\n]*$//s; my $cmd = "tail -c+$pos \"$knl\" | $zcat > $tmp2 2> /dev/null"; my $err = (system($cmd) >> 8); @@ -208,6 +233,59 @@ sub try_decompress return undef; } + +sub strings_to_flags +{ + my ($knl, $strings) = @_; + my $string_pattern = '^('.join('|', keys(%$strings)).')$'; + my $flags = 0; + + my @matches = `strings \"$knl\" | grep -E \"$string_pattern\"`; + foreach my $match (@matches) + { + chomp($match); + $flags |= $strings->{$match}; + } + + return $flags; +} + +sub configs_to_flags +{ + my ($knl, $tmp, $configs) = @_; + my $config_pattern = '^('.join('|', keys(%$configs)).')=(.*)$'; + my $cf1 = 'IKCFG_ST\037\213\010'; + my $cf2 = '0123456789'; + my $flags = 0; + + my $pos = `tr "$cf1\n$cf2" "\n$cf2=" < "$knl" | grep -abo "^$cf2"`; + if ($pos) + { + $pos =~ s/:.*[\r\n]*$//s; + $pos += 8; + my $err = (system("tail -c+$pos \"$knl\" | zcat > $tmp 2> /dev/null") >> 8); + if (($err == 0) || ($err == 2)) + { + if (open(my $fh, '<', $tmp)) + { + while (my $line = <$fh>) + { + chomp($line); + if (($line =~ /$config_pattern/) && + (($2 eq 'y') || ($2 eq 'm'))) + { + $flags |= $configs->{$1}; + } + } + + close($fh); + } + } + } + + return $flags; +} + sub pack_trailer { my ($atoms) = @_; @@ -219,9 +297,3 @@ sub pack_trailer } return $trailer; } - -sub config_bool -{ - my ($configs, $wanted) = @_; - return (($configs->{$wanted} eq 'y') || ($configs->{$wanted} eq '1')); -}