blob: d9f9f34b22abb1eb8dd6995e06ffe25ac230a4a2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#!/bin/sh
2# extracts .config info from a [b]zImage file
3# uses: binoffset (new), dd, zcat, strings, grep
4# $arg1 is [b]zImage filename
5
6binoffset="./scripts/binoffset"
7
8IKCFG_ST="0x49 0x4b 0x43 0x46 0x47 0x5f 0x53 0x54"
9IKCFG_ED="0x49 0x4b 0x43 0x46 0x47 0x5f 0x45 0x44"
10function dump_config {
11 typeset file="$1"
12
13 start=`$binoffset $file $IKCFG_ST 2>/dev/null`
14 [ "$?" != "0" ] && start="-1"
15 if [ "$start" -eq "-1" ]; then
16 return
17 fi
18 end=`$binoffset $file $IKCFG_ED 2>/dev/null`
19
20 let start="$start + 8"
21 let size="$end - $start"
22
23 head --bytes="$end" "$file" | tail --bytes="$size" | zcat
24
25 clean_up
26 exit 0
27}
28
29
30usage()
31{
32 echo " usage: extract-ikconfig [b]zImage_filename"
33}
34
35clean_up()
36{
37 if [ "$TMPFILE" != "" ]; then
38 rm -f $TMPFILE
39 fi
40}
41
42if [ $# -lt 1 ]
43then
44 usage
45 exit 1
46fi
47
48TMPFILE="/tmp/ikconfig-$$"
49image="$1"
50
51# vmlinux: Attempt to dump the configuration from the file directly
52dump_config "$image"
53
54GZHDR1="0x1f 0x8b 0x08 0x00"
55GZHDR2="0x1f 0x8b 0x08 0x08"
56
57# vmlinux.gz: Check for a compressed images
58off=`$binoffset "$image" $GZHDR1 2>/dev/null`
59[ "$?" != "0" ] && off="-1"
60if [ "$off" -eq "-1" ]; then
61 off=`$binoffset "$image" $GZHDR2 2>/dev/null`
62 [ "$?" != "0" ] && off="-1"
63fi
64if [ "$off" -eq "0" ]; then
65 zcat <"$image" >"$TMPFILE"
66 dump_config "$TMPFILE"
67elif [ "$off" -ne "-1" ]; then
68 (dd ibs="$off" skip=1 count=0 && dd bs=512k) <"$image" 2>/dev/null | \
69 zcat >"$TMPFILE"
70 dump_config "$TMPFILE"
71fi
72
73echo "ERROR: Unable to extract kernel configuration information."
74echo " This kernel image may not have the config info."
75
76clean_up
77exit 1