mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Amerigo Wang <xiyou.wangcong@gmail.com>
To: Dick Streefland <dick@streefland.net>
Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kconfig: simplification of scripts/extract-ikconfig
Date: Wed, 24 Jun 2009 10:15:06 +0800	[thread overview]
Message-ID: <20090624021506.GA5871@cr0.nay.redhat.com> (raw)
In-Reply-To: <20090623225245.GA10443@streefland.net>

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@streefland.net>

<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

  reply	other threads:[~2009-06-24  2:13 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-23 22:52 Dick Streefland
2009-06-24  2:15 ` Amerigo Wang [this message]
2009-06-24 11:46   ` Dick Streefland
2009-06-24 13:31     ` Dick Streefland
2009-06-29  2:51       ` Amerigo Wang
2009-06-29 11:36         ` Dick Streefland
2009-07-09  2:38           ` Amerigo Wang
2009-07-09  8:26             ` Dick Streefland
2009-07-10  7:55               ` Amerigo Wang
2009-07-10  9:54                 ` Dick Streefland
2009-07-17 21:17                   ` Sam Ravnborg
2009-07-17 23:08                     ` Dick Streefland
2009-07-18  7:06                       ` Sam Ravnborg
2009-10-06 20:35 Dick Streefland
2009-10-07  2:11 ` Steven Rostedt
2009-10-07  8:41   ` Dick Streefland
2009-10-07 13:20     ` Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090624021506.GA5871@cr0.nay.redhat.com \
    --to=xiyou.wangcong@gmail.com \
    --cc=dick@streefland.net \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®