Re: [PATCH] kconfig: simplification of scripts/extract-ikconfig

From: Amerigo Wang
Date: Tue Jun 23 2009 - 22:13:24 EST


On Wed, Jun 24, 2009 at 12:52:45AM +0200, Dick Streefland wrote:
>I've rewritten the extract-ikconfig script to extract the kernel
>configuration from a kernel compiled with CONFIG_IKCONFIG. The main
>motivation for the rewrite was to remove the dependency on the
>external C program binoffset.c, which is compiled on the initial run.
>
>The binoffset executable is invoked with a relative path, which means
>that the old script can only be run from the top of the kernel tree,
>and only when you have write permission in the scripts directory.
>The new script uses echo/grep/tail/zcat only, and can be invoked from
>anywhere. The binoffset.c program has been removed.
>
>Signed-off-by: Dick Streefland <dick@xxxxxxxxxxxxxx>

<snip>

>+gzip_header=`/bin/echo -en '\x1f\x8b\x08'`
>+ikconfig_header="IKCFG_ST$gzip_header"
>+
>+dump_config()
> {
>- echo " usage: extract-ikconfig [b]zImage_filename"
>-}
>-
>-clean_up()
>-{
>- if [ "$TMPFILE" != "" ]; then
>- rm -f $TMPFILE
>+ if pos=`grep -abo "$ikconfig_header" "$1"`


Are you sure this 'grep' works well?

My tests on a binary file told me no.

>+ then
>+ pos=${pos%%:*}
>+ tail -c+$(($pos+8+1)) "$1" | zcat -q
>+ exit 0
> fi
> }
>
>-if [ $# -lt 1 ]
>+# Check invocation:
>+me=${0##*/}
>+img=$1
>+if [ $# -ne 1 -o ! -s "$img" ]
> then
>- usage
>- exit 1
>+ echo "Usage: $me <kernel-image>" >&2
>+ exit 2
> fi
>
>-TMPFILE=`mktemp -t ikconfig-XXXXXX` || exit 1
>-image="$1"
>-
>-# vmlinux: Attempt to dump the configuration from the file directly
>-dump_config "$image"
>-
>-GZHDR1="0x1f 0x8b 0x08 0x00"
>-GZHDR2="0x1f 0x8b 0x08 0x08"
>-
>-# 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"
>-fi
>-
>-echo "ERROR: Unable to extract kernel configuration information."
>-echo " This kernel image may not have the config info."
>-
>-clean_up
>+# Initial attempt for uncompressed images or objects:
>+dump_config "$img"
>+
>+# That didn't work, so decompress and try again:
>+tmp=/tmp/ikconfig$$
>+trap "rm -f $tmp" 0


Why do you use trap instead of doing this explicitly
on exit?


>+for pos in `grep -abo "$gzip_header" "$img"`

Also here...

Can we have more than one $gzip_header? But even if yes,
grep only reports the first one I am afraid, or at least,
the first one in one "line".

>+do
>+ pos=${pos%%:*}
>+ tail -c+$(($pos+1)) "$img" | zcat -q > $tmp
>+ dump_config $tmp
>+done
>+
>+# Bail out:
>+echo "$me: Cannot find kernel config." >&2
> exit 1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/