ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / scripts / extract-ikconfig
1 #! /bin/bash 
2 # extracts .config info from a [b]zImage file
3 # uses: binoffset (new), dd, zcat, strings, grep
4 # $arg1 is [b]zImage filename
5
6 TMPFILE=""
7
8 usage()
9 {
10         echo "  usage: extract-ikconfig [b]zImage_filename"
11 }
12
13 clean_up()
14 {
15         if [ -z $ISCOMP ]
16         then
17                 rm -f $TMPFILE
18         fi
19 }
20
21 if [ $# -lt 1 ]
22 then
23         usage
24         exit
25 fi
26
27 image=$1
28
29 # There are two gzip headers, as well as arches which don't compress their
30 # kernel.
31 GZHDR="0x1f 0x8b 0x08 0x00"
32 if [ `binoffset $image $GZHDR >/dev/null 2>&1 ; echo $?` -ne 0 ]
33 then
34         GZHDR="0x1f 0x8b 0x08 0x08"
35         if [ `binoffset $image $GZHDR >/dev/null 2>&1 ; echo $?` -ne 0 ]
36         then
37                 ISCOMP=0
38         fi
39 fi
40
41 PID=$$
42
43 # Extract and uncompress the kernel image if necessary
44 if [ -z $ISCOMP ]
45 then
46         TMPFILE="/tmp/`basename $image`.vmlin.$PID"
47         dd if=$image bs=1 skip=`binoffset $image $GZHDR` 2> /dev/null | zcat > $TMPFILE
48 else
49         TMPFILE=$image
50 fi
51
52 # Look for strings.
53 strings $TMPFILE | grep "CONFIG_BEGIN=n" > /dev/null
54 if [ $? -eq 0 ]
55 then
56         strings $TMPFILE | awk "/CONFIG_BEGIN=n/,/CONFIG_END=n/" > $image.oldconfig.$PID
57 else
58         echo "ERROR: Unable to extract kernel configuration information."
59         echo "       This kernel image may not have the config info."
60         clean_up
61         exit 1
62 fi
63
64 echo "Kernel configuration written to $image.oldconfig.$PID"
65 clean_up
66 exit 0