VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   33 Branches   55 Tags
^1da177e4c3f4 (Linus Torvalds  2005-04-16 15:20:36 -0700  1) #!/bin/sh
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200  2) # ----------------------------------------------------------------------
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200  3) # extract-ikconfig - Extract the .config file from a kernel image
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200  4) #
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200  5) # This will only work when the kernel was compiled with CONFIG_IKCONFIG.
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200  6) #
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200  7) # The obscure use of the "tr" filter is to work around older versions of
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200  8) # "grep" that report the byte offset of the line instead of the pattern.
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200  9) #
532cf2907ac3b (Dick Streefland 2010-10-23 00:02:44 +0200 10) # (c) 2009,2010 Dick Streefland <dick@streefland.net>
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200 11) # Licensed under the terms of the GNU General Public License.
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200 12) # ----------------------------------------------------------------------
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200 13) 
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200 14) cf1='IKCFG_ST\037\213\010'
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200 15) cf2='0123456789'
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200 16) 
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200 17) dump_config()
^1da177e4c3f4 (Linus Torvalds  2005-04-16 15:20:36 -0700 18) {
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200 19) 	if	pos=`tr "$cf1\n$cf2" "\n$cf2=" < "$1" | grep -abo "^$cf2"`
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200 20) 	then
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200 21) 		pos=${pos%%:*}
532cf2907ac3b (Dick Streefland 2010-10-23 00:02:44 +0200 22) 		tail -c+$(($pos+8)) "$1" | zcat > $tmp1 2> /dev/null
532cf2907ac3b (Dick Streefland 2010-10-23 00:02:44 +0200 23) 		if	[ $? != 1 ]
532cf2907ac3b (Dick Streefland 2010-10-23 00:02:44 +0200 24) 		then	# exit status must be 0 or 2 (trailing garbage warning)
532cf2907ac3b (Dick Streefland 2010-10-23 00:02:44 +0200 25) 			cat $tmp1
532cf2907ac3b (Dick Streefland 2010-10-23 00:02:44 +0200 26) 			exit 0
532cf2907ac3b (Dick Streefland 2010-10-23 00:02:44 +0200 27) 		fi
^1da177e4c3f4 (Linus Torvalds  2005-04-16 15:20:36 -0700 28) 	fi
^1da177e4c3f4 (Linus Torvalds  2005-04-16 15:20:36 -0700 29) }
^1da177e4c3f4 (Linus Torvalds  2005-04-16 15:20:36 -0700 30) 
532cf2907ac3b (Dick Streefland 2010-10-23 00:02:44 +0200 31) try_decompress()
532cf2907ac3b (Dick Streefland 2010-10-23 00:02:44 +0200 32) {
532cf2907ac3b (Dick Streefland 2010-10-23 00:02:44 +0200 33) 	for	pos in `tr "$1\n$2" "\n$2=" < "$img" | grep -abo "^$2"`
532cf2907ac3b (Dick Streefland 2010-10-23 00:02:44 +0200 34) 	do
532cf2907ac3b (Dick Streefland 2010-10-23 00:02:44 +0200 35) 		pos=${pos%%:*}
532cf2907ac3b (Dick Streefland 2010-10-23 00:02:44 +0200 36) 		tail -c+$pos "$img" | $3 > $tmp2 2> /dev/null
532cf2907ac3b (Dick Streefland 2010-10-23 00:02:44 +0200 37) 		dump_config $tmp2
532cf2907ac3b (Dick Streefland 2010-10-23 00:02:44 +0200 38) 	done
532cf2907ac3b (Dick Streefland 2010-10-23 00:02:44 +0200 39) }
532cf2907ac3b (Dick Streefland 2010-10-23 00:02:44 +0200 40) 
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200 41) # Check invocation:
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200 42) me=${0##*/}
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200 43) img=$1
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200 44) if	[ $# -ne 1 -o ! -s "$img" ]
^1da177e4c3f4 (Linus Torvalds  2005-04-16 15:20:36 -0700 45) then
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200 46) 	echo "Usage: $me <kernel-image>" >&2
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200 47) 	exit 2
^1da177e4c3f4 (Linus Torvalds  2005-04-16 15:20:36 -0700 48) fi
^1da177e4c3f4 (Linus Torvalds  2005-04-16 15:20:36 -0700 49) 
532cf2907ac3b (Dick Streefland 2010-10-23 00:02:44 +0200 50) # Prepare temp files:
532cf2907ac3b (Dick Streefland 2010-10-23 00:02:44 +0200 51) tmp1=/tmp/ikconfig$$.1
532cf2907ac3b (Dick Streefland 2010-10-23 00:02:44 +0200 52) tmp2=/tmp/ikconfig$$.2
532cf2907ac3b (Dick Streefland 2010-10-23 00:02:44 +0200 53) trap "rm -f $tmp1 $tmp2" 0
532cf2907ac3b (Dick Streefland 2010-10-23 00:02:44 +0200 54) 
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200 55) # Initial attempt for uncompressed images or objects:
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200 56) dump_config "$img"
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200 57) 
532cf2907ac3b (Dick Streefland 2010-10-23 00:02:44 +0200 58) # That didn't work, so retry after decompression.
ab94e4666d5ce (Dick Streefland 2011-01-24 00:44:57 +0100 59) try_decompress '\037\213\010' xy    gunzip
ab94e4666d5ce (Dick Streefland 2011-01-24 00:44:57 +0100 60) try_decompress '\3757zXZ\000' abcde unxz
ab94e4666d5ce (Dick Streefland 2011-01-24 00:44:57 +0100 61) try_decompress 'BZh'          xy    bunzip2
ab94e4666d5ce (Dick Streefland 2011-01-24 00:44:57 +0100 62) try_decompress '\135\0\0\0'   xxx   unlzma
ab94e4666d5ce (Dick Streefland 2011-01-24 00:44:57 +0100 63) try_decompress '\211\114\132' xy    'lzop -d'
99b2cdde83726 (Alex Pilon      2015-04-14 00:38:33 -0400 64) try_decompress '\002\041\114\030' xyy 'lz4 -d -l'
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200 65) 
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200 66) # Bail out:
7b76bfc86757c (Dick Streefland 2009-10-06 22:35:40 +0200 67) echo "$me: Cannot find kernel config." >&2
^1da177e4c3f4 (Linus Torvalds  2005-04-16 15:20:36 -0700 68) exit 1