summaryrefslogtreecommitdiff
path: root/scripts/extract-ikconfig
blob: 8e526d3709660c3db53e30dbae881321374872d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#! /bin/bash 
# extracts .config info from a [b]zImage file
# uses: binoffset (new), dd, zcat, strings, grep
# $arg1 is [b]zImage filename

TMPFILE=""

usage()
{
	echo "  usage: extract-ikconfig [b]zImage_filename"
}

clean_up()
{
	if [ -z $ISCOMP ]
	then
		rm -f $TMPFILE
	fi
}

if [ $# -lt 1 ]
then
	usage
	exit
fi

image=$1

# There are two gzip headers, as well as arches which don't compress their
# kernel.
GZHDR="0x1f 0x8b 0x08 0x00"
if [ `binoffset $image $GZHDR >/dev/null 2>&1 ; echo $?` -ne 0 ]
then
	GZHDR="0x1f 0x8b 0x08 0x08"
	if [ `binoffset $image $GZHDR >/dev/null 2>&1 ; echo $?` -ne 0 ]
	then
		ISCOMP=0
	fi
fi

PID=$$

# Extract and uncompress the kernel image if necessary
if [ -z $ISCOMP ]
then
	TMPFILE="/tmp/`basename $image`.vmlin.$PID"
	dd if=$image bs=1 skip=`binoffset $image $GZHDR` 2> /dev/null | zcat > $TMPFILE
else
	TMPFILE=$image
fi

# Look for strings.
strings $TMPFILE | grep "CONFIG_BEGIN=n" > /dev/null
if [ $? -eq 0 ]
then
	strings $TMPFILE | awk "/CONFIG_BEGIN=n/,/CONFIG_END=n/" > $image.oldconfig.$PID
else
	echo "ERROR: Unable to extract kernel configuration information."
	echo "       This kernel image may not have the config info."
	clean_up
	exit 1
fi

echo "Kernel configuration written to $image.oldconfig.$PID"
clean_up
exit 0