]> git.pld-linux.org Git - projects/geninitrd.git/blame - extract-ikconfig
Timeout here is not a good idea. rootfs cannot be mounted and kernel oopses due to...
[projects/geninitrd.git] / extract-ikconfig
CommitLineData
8eb849e6
ER
1#!/bin/sh
2# ----------------------------------------------------------------------
3# extract-ikconfig - Extract the .config file from a kernel image
4#
5# This will only work when the kernel was compiled with CONFIG_IKCONFIG.
6#
7# The obscure use of the "tr" filter is to work around older versions of
8# "grep" that report the byte offset of the line instead of the pattern.
9#
10# (c) 2009,2010 Dick Streefland <dick@streefland.net>
11# Licensed under the terms of the GNU General Public License.
12# ----------------------------------------------------------------------
13
14cf1='IKCFG_ST\037\213\010'
15cf2='0123456789'
16
17dump_config()
18{
19 if pos=`tr "$cf1\n$cf2" "\n$cf2=" < "$1" | grep -abo "^$cf2"`
20 then
21 pos=${pos%%:*}
22 tail -c+$(($pos+8)) "$1" | zcat > $tmp1 2> /dev/null
23 if [ $? != 1 ]
24 then # exit status must be 0 or 2 (trailing garbage warning)
25 cat $tmp1
26 exit 0
27 fi
28 fi
29}
30
31try_decompress()
32{
33 for pos in `tr "$1\n$2" "\n$2=" < "$img" | grep -abo "^$2"`
34 do
35 pos=${pos%%:*}
36 tail -c+$pos "$img" | $3 > $tmp2 2> /dev/null
37 dump_config $tmp2
38 done
39}
40
41# Check invocation:
42me=${0##*/}
43img=$1
44if [ $# -ne 1 -o ! -s "$img" ]
45then
46 echo "Usage: $me <kernel-image>" >&2
47 exit 2
48fi
49
50# Prepare temp files:
3969b8b1
ER
51tmp1=$(mktemp)
52tmp2=$(mktemp)
8eb849e6
ER
53trap "rm -f $tmp1 $tmp2" 0
54
55# Initial attempt for uncompressed images or objects:
56dump_config "$img"
57
58# That didn't work, so retry after decompression.
59try_decompress '\037\213\010' xy gunzip
f41055ab 60try_decompress '\3757zXZ\000' xy xzdec
8eb849e6
ER
61try_decompress 'BZh' xy bunzip2
62try_decompress '\135\0\0\0' xxx unlzma
63try_decompress '\211\114\132' xy 'lzop -d'
64
65# Bail out:
66echo "$me: Cannot find kernel config." >&2
67exit 1
This page took 1.764012 seconds and 4 git commands to generate.