| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #!/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 |  | 
|  | 6 | binoffset="./scripts/binoffset" | 
| Alexey Dobriyan | ff45e99 | 2006-03-24 03:15:56 -0800 | [diff] [blame] | 7 | test -e $binoffset || cc -o $binoffset ./scripts/binoffset.c || exit 1 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 |  | 
|  | 9 | IKCFG_ST="0x49 0x4b 0x43 0x46 0x47 0x5f 0x53 0x54" | 
|  | 10 | IKCFG_ED="0x49 0x4b 0x43 0x46 0x47 0x5f 0x45 0x44" | 
| Werner Almesberger | efddd79 | 2008-11-12 16:39:35 -0200 | [diff] [blame] | 11 | dump_config() { | 
|  | 12 | file="$1" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 |  | 
|  | 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 Rostedt | fd3132d | 2009-04-30 12:19:56 -0400 | [diff] [blame] | 20 | [ "$?" != "0" ] && end="-1" | 
|  | 21 | if [ "$end" -eq "-1" ]; then | 
|  | 22 | return | 
|  | 23 | fi | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 |  | 
| Werner Almesberger | efddd79 | 2008-11-12 16:39:35 -0200 | [diff] [blame] | 25 | start=`expr $start + 8` | 
|  | 26 | size=`expr $end - $start` | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 |  | 
| Alexey Dobriyan | 008accb | 2006-03-24 03:15:56 -0800 | [diff] [blame] | 28 | dd if="$file" ibs=1 skip="$start" count="$size" 2>/dev/null | zcat | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 |  | 
|  | 30 | clean_up | 
|  | 31 | exit 0 | 
|  | 32 | } | 
|  | 33 |  | 
|  | 34 |  | 
|  | 35 | usage() | 
|  | 36 | { | 
|  | 37 | echo "  usage: extract-ikconfig [b]zImage_filename" | 
|  | 38 | } | 
|  | 39 |  | 
|  | 40 | clean_up() | 
|  | 41 | { | 
|  | 42 | if [ "$TMPFILE" != "" ]; then | 
|  | 43 | rm -f $TMPFILE | 
|  | 44 | fi | 
|  | 45 | } | 
|  | 46 |  | 
|  | 47 | if [ $# -lt 1 ] | 
|  | 48 | then | 
|  | 49 | usage | 
|  | 50 | exit 1 | 
|  | 51 | fi | 
|  | 52 |  | 
| Alexey Dobriyan | 66f9f59 | 2006-03-24 03:15:55 -0800 | [diff] [blame] | 53 | TMPFILE=`mktemp -t ikconfig-XXXXXX` || exit 1 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | image="$1" | 
|  | 55 |  | 
|  | 56 | # vmlinux: Attempt to dump the configuration from the file directly | 
|  | 57 | dump_config "$image" | 
|  | 58 |  | 
|  | 59 | GZHDR1="0x1f 0x8b 0x08 0x00" | 
|  | 60 | GZHDR2="0x1f 0x8b 0x08 0x08" | 
|  | 61 |  | 
| Steven Rostedt | 6be51ff | 2009-04-30 12:22:20 -0400 | [diff] [blame] | 62 | ELFHDR="0x7f 0x45 0x4c 0x46" | 
|  | 63 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | # vmlinux.gz: Check for a compressed images | 
|  | 65 | off=`$binoffset "$image" $GZHDR1 2>/dev/null` | 
|  | 66 | [ "$?" != "0" ] && off="-1" | 
|  | 67 | if [ "$off" -eq "-1" ]; then | 
|  | 68 | off=`$binoffset "$image" $GZHDR2 2>/dev/null` | 
|  | 69 | [ "$?" != "0" ] && off="-1" | 
|  | 70 | fi | 
|  | 71 | if [ "$off" -eq "0" ]; then | 
|  | 72 | zcat <"$image" >"$TMPFILE" | 
|  | 73 | dump_config "$TMPFILE" | 
|  | 74 | elif [ "$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" | 
| Steven Rostedt | 6be51ff | 2009-04-30 12:22:20 -0400 | [diff] [blame] | 78 |  | 
|  | 79 | # check if this is simply an ELF file | 
|  | 80 | else | 
|  | 81 | off=`$binoffset "$image" $ELFHDR 2>/dev/null` | 
|  | 82 | [ "$?" != "0" ] && off="-1" | 
|  | 83 | if [ "$off" -eq "0" ]; then | 
|  | 84 | dump_config "$image" | 
|  | 85 | fi | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | fi | 
|  | 87 |  | 
|  | 88 | echo "ERROR: Unable to extract kernel configuration information." | 
|  | 89 | echo "       This kernel image may not have the config info." | 
|  | 90 |  | 
|  | 91 | clean_up | 
|  | 92 | exit 1 |