X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=scripts%2Fextract-ikconfig;h=8e526d3709660c3db53e30dbae881321374872d4;hb=27879d9d66f2dea19cfcd0e1df8358a33447f45b;hp=d9f9f34b22abb1eb8dd6995e06ffe25ac230a4a2;hpb=a91482bdcc2e0f6035702e46f1b99043a0893346;p=linux-2.6.git diff --git a/scripts/extract-ikconfig b/scripts/extract-ikconfig index d9f9f34b2..8e526d370 100755 --- a/scripts/extract-ikconfig +++ b/scripts/extract-ikconfig @@ -1,31 +1,9 @@ -#!/bin/sh +#! /bin/bash # extracts .config info from a [b]zImage file # uses: binoffset (new), dd, zcat, strings, grep # $arg1 is [b]zImage filename -binoffset="./scripts/binoffset" - -IKCFG_ST="0x49 0x4b 0x43 0x46 0x47 0x5f 0x53 0x54" -IKCFG_ED="0x49 0x4b 0x43 0x46 0x47 0x5f 0x45 0x44" -function dump_config { - typeset file="$1" - - start=`$binoffset $file $IKCFG_ST 2>/dev/null` - [ "$?" != "0" ] && start="-1" - if [ "$start" -eq "-1" ]; then - return - fi - end=`$binoffset $file $IKCFG_ED 2>/dev/null` - - let start="$start + 8" - let size="$end - $start" - - head --bytes="$end" "$file" | tail --bytes="$size" | zcat - - clean_up - exit 0 -} - +TMPFILE="" usage() { @@ -34,7 +12,8 @@ usage() clean_up() { - if [ "$TMPFILE" != "" ]; then + if [ -z $ISCOMP ] + then rm -f $TMPFILE fi } @@ -42,36 +21,46 @@ clean_up() if [ $# -lt 1 ] then usage - exit 1 + exit fi -TMPFILE="/tmp/ikconfig-$$" -image="$1" +image=$1 -# vmlinux: Attempt to dump the configuration from the file directly -dump_config "$image" +# 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 -GZHDR1="0x1f 0x8b 0x08 0x00" -GZHDR2="0x1f 0x8b 0x08 0x08" +PID=$$ -# vmlinux.gz: Check for a compressed images -off=`$binoffset "$image" $GZHDR1 2>/dev/null` -[ "$?" != "0" ] && off="-1" -if [ "$off" -eq "-1" ]; then - off=`$binoffset "$image" $GZHDR2 2>/dev/null` - [ "$?" != "0" ] && off="-1" -fi -if [ "$off" -eq "0" ]; then - zcat <"$image" >"$TMPFILE" - dump_config "$TMPFILE" -elif [ "$off" -ne "-1" ]; then - (dd ibs="$off" skip=1 count=0 && dd bs=512k) <"$image" 2>/dev/null | \ - zcat >"$TMPFILE" - dump_config "$TMPFILE" +# 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 -echo "ERROR: Unable to extract kernel configuration information." -echo " This kernel image may not have the config info." +# 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 1 +exit 0