aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/extract-ikconfig
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/extract-ikconfig')
-rwxr-xr-xscripts/extract-ikconfig130
1 files changed, 52 insertions, 78 deletions
diff --git a/scripts/extract-ikconfig b/scripts/extract-ikconfig
index de233ff43c1c..1512c0a755ac 100755
--- a/scripts/extract-ikconfig
+++ b/scripts/extract-ikconfig
@@ -1,92 +1,66 @@
1#!/bin/sh 1#!/bin/sh
2# extracts .config info from a [b]zImage file 2# ----------------------------------------------------------------------
3# uses: binoffset (new), dd, zcat, strings, grep 3# extract-ikconfig - Extract the .config file from a kernel image
4# $arg1 is [b]zImage filename 4#
5 5# This will only work when the kernel was compiled with CONFIG_IKCONFIG.
6binoffset="./scripts/binoffset" 6#
7test -e $binoffset || cc -o $binoffset ./scripts/binoffset.c || exit 1 7# The obscure use of the "tr" filter is to work around older versions of
8 8# "grep" that report the byte offset of the line instead of the pattern.
9IKCFG_ST="0x49 0x4b 0x43 0x46 0x47 0x5f 0x53 0x54" 9#
10IKCFG_ED="0x49 0x4b 0x43 0x46 0x47 0x5f 0x45 0x44" 10# (c) 2009,2010 Dick Streefland <dick@streefland.net>
11dump_config() { 11# Licensed under the terms of the GNU General Public License.
12 file="$1" 12# ----------------------------------------------------------------------
13 13
14 start=`$binoffset $file $IKCFG_ST 2>/dev/null` 14cf1='IKCFG_ST\037\213\010'
15 [ "$?" != "0" ] && start="-1" 15cf2='0123456789'
16 if [ "$start" -eq "-1" ]; then 16
17 return 17dump_config()
18 fi
19 end=`$binoffset $file $IKCFG_ED 2>/dev/null`
20 [ "$?" != "0" ] && end="-1"
21 if [ "$end" -eq "-1" ]; then
22 return
23 fi
24
25 start=`expr $start + 8`
26 size=`expr $end - $start`
27
28 dd if="$file" ibs=1 skip="$start" count="$size" 2>/dev/null | zcat
29
30 clean_up
31 exit 0
32}
33
34
35usage()
36{ 18{
37 echo " usage: extract-ikconfig [b]zImage_filename" 19 if pos=`tr "$cf1\n$cf2" "\n$cf2=" < "$1" | grep -abo "^$cf2"`
20 then
21 pos=${pos%%:*}
22 tail -c+$(($pos+8)) "$1" | zcat > $tmp1 2> /dev/null
23 if [ $? != 1 ]
24 then # exit status must be 0 or 2 (trailing garbage warning)
25 cat $tmp1
26 exit 0
27 fi
28 fi
38} 29}
39 30
40clean_up() 31try_decompress()
41{ 32{
42 if [ "$TMPFILE" != "" ]; then 33 for pos in `tr "$1\n$2" "\n$2=" < "$img" | grep -abo "^$2"`
43 rm -f $TMPFILE 34 do
44 fi 35 pos=${pos%%:*}
36 tail -c+$pos "$img" | $3 > $tmp2 2> /dev/null
37 dump_config $tmp2
38 done
45} 39}
46 40
47if [ $# -lt 1 ] 41# Check invocation:
42me=${0##*/}
43img=$1
44if [ $# -ne 1 -o ! -s "$img" ]
48then 45then
49 usage 46 echo "Usage: $me <kernel-image>" >&2
50 exit 1 47 exit 2
51fi 48fi
52 49
53TMPFILE=`mktemp -t ikconfig-XXXXXX` || exit 1 50# Prepare temp files:
54image="$1" 51tmp1=/tmp/ikconfig$$.1
55 52tmp2=/tmp/ikconfig$$.2
56# vmlinux: Attempt to dump the configuration from the file directly 53trap "rm -f $tmp1 $tmp2" 0
57dump_config "$image"
58
59GZHDR1="0x1f 0x8b 0x08 0x00"
60GZHDR2="0x1f 0x8b 0x08 0x08"
61
62ELFHDR="0x7f 0x45 0x4c 0x46"
63 54
64# vmlinux.gz: Check for a compressed images 55# Initial attempt for uncompressed images or objects:
65off=`$binoffset "$image" $GZHDR1 2>/dev/null` 56dump_config "$img"
66[ "$?" != "0" ] && off="-1"
67if [ "$off" -eq "-1" ]; then
68 off=`$binoffset "$image" $GZHDR2 2>/dev/null`
69 [ "$?" != "0" ] && off="-1"
70fi
71if [ "$off" -eq "0" ]; then
72 zcat <"$image" >"$TMPFILE"
73 dump_config "$TMPFILE"
74elif [ "$off" -ne "-1" ]; then
75 (dd ibs="$off" skip=1 count=0 && dd bs=512k) <"$image" 2>/dev/null | \
76 zcat >"$TMPFILE"
77 dump_config "$TMPFILE"
78
79# check if this is simply an ELF file
80else
81 off=`$binoffset "$image" $ELFHDR 2>/dev/null`
82 [ "$?" != "0" ] && off="-1"
83 if [ "$off" -eq "0" ]; then
84 dump_config "$image"
85 fi
86fi
87 57
88echo "ERROR: Unable to extract kernel configuration information." 58# That didn't work, so retry after decompression.
89echo " This kernel image may not have the config info." 59try_decompress '\037\213\010' xy gunzip
60try_decompress 'BZh' xy bunzip2
61try_decompress '\135\0\0\0' xxx unlzma
62try_decompress '\211\114\132' xy 'lzop -d'
90 63
91clean_up 64# Bail out:
65echo "$me: Cannot find kernel config." >&2
92exit 1 66exit 1