blob: 42d6bcefb400bc3d96c8897eb85f9cc9fd892521 [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"
Alexey Dobriyanff45e992006-03-24 03:15:56 -08007test -e $binoffset || cc -o $binoffset ./scripts/binoffset.c || exit 1
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
9IKCFG_ST="0x49 0x4b 0x43 0x46 0x47 0x5f 0x53 0x54"
10IKCFG_ED="0x49 0x4b 0x43 0x46 0x47 0x5f 0x45 0x44"
Werner Almesbergerefddd792008-11-12 16:39:35 -020011dump_config() {
12 file="$1"
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14 start=`$binoffset $file $IKCFG_ST 2>/dev/null`
15 [ "$?" != "0" ] && start="-1"
16 if [ "$start" -eq "-1" ]; then
17 return
18 fi
19 end=`$binoffset $file $IKCFG_ED 2>/dev/null`
Steven Rostedtfd3132d2009-04-30 12:19:56 -040020 [ "$?" != "0" ] && end="-1"
21 if [ "$end" -eq "-1" ]; then
22 return
23 fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Werner Almesbergerefddd792008-11-12 16:39:35 -020025 start=`expr $start + 8`
26 size=`expr $end - $start`
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Alexey Dobriyan008accb2006-03-24 03:15:56 -080028 dd if="$file" ibs=1 skip="$start" count="$size" 2>/dev/null | zcat
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30 clean_up
31 exit 0
32}
33
34
35usage()
36{
37 echo " usage: extract-ikconfig [b]zImage_filename"
38}
39
40clean_up()
41{
42 if [ "$TMPFILE" != "" ]; then
43 rm -f $TMPFILE
44 fi
45}
46
47if [ $# -lt 1 ]
48then
49 usage
50 exit 1
51fi
52
Alexey Dobriyan66f9f592006-03-24 03:15:55 -080053TMPFILE=`mktemp -t ikconfig-XXXXXX` || exit 1
Linus Torvalds1da177e2005-04-16 15:20:36 -070054image="$1"
55
56# vmlinux: Attempt to dump the configuration from the file directly
57dump_config "$image"
58
59GZHDR1="0x1f 0x8b 0x08 0x00"
60GZHDR2="0x1f 0x8b 0x08 0x08"
61
62# vmlinux.gz: Check for a compressed images
63off=`$binoffset "$image" $GZHDR1 2>/dev/null`
64[ "$?" != "0" ] && off="-1"
65if [ "$off" -eq "-1" ]; then
66 off=`$binoffset "$image" $GZHDR2 2>/dev/null`
67 [ "$?" != "0" ] && off="-1"
68fi
69if [ "$off" -eq "0" ]; then
70 zcat <"$image" >"$TMPFILE"
71 dump_config "$TMPFILE"
72elif [ "$off" -ne "-1" ]; then
73 (dd ibs="$off" skip=1 count=0 && dd bs=512k) <"$image" 2>/dev/null | \
74 zcat >"$TMPFILE"
75 dump_config "$TMPFILE"
76fi
77
78echo "ERROR: Unable to extract kernel configuration information."
79echo " This kernel image may not have the config info."
80
81clean_up
82exit 1