Commit 7b76bfc86757ca5e7b0a62f50003752da77c115b

Authored by Dick Streefland
Committed by Steven Rostedt
1 parent 0eca52a927

kconfig: simplification of scripts/extract-ikconfig

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 tr/grep/tail/zcat only, and can be invoked from
anywhere. The binoffset.c program has been removed. This script
requires GNU grep 2.5 (released 2002-03-13) or higher, because the -o
option was introduced in that version.

Signed-off-by: Dick Streefland <dick@streefland.net>
LKML-Reference: <20091006203540.GA14634@streefland.net>
Tested-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Sam Ravnborg <sam@ravnborg.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

Showing 4 changed files with 44 additions and 248 deletions Inline Diff

Documentation/dontdiff
1 *.a 1 *.a
2 *.aux 2 *.aux
3 *.bin 3 *.bin
4 *.cpio 4 *.cpio
5 *.csp 5 *.csp
6 *.dsp 6 *.dsp
7 *.dvi 7 *.dvi
8 *.elf 8 *.elf
9 *.eps 9 *.eps
10 *.fw 10 *.fw
11 *.gen.S 11 *.gen.S
12 *.gif 12 *.gif
13 *.grep 13 *.grep
14 *.grp 14 *.grp
15 *.gz 15 *.gz
16 *.html 16 *.html
17 *.i 17 *.i
18 *.jpeg 18 *.jpeg
19 *.ko 19 *.ko
20 *.log 20 *.log
21 *.lst 21 *.lst
22 *.moc 22 *.moc
23 *.mod.c 23 *.mod.c
24 *.o 24 *.o
25 *.o.* 25 *.o.*
26 *.orig 26 *.orig
27 *.out 27 *.out
28 *.pdf 28 *.pdf
29 *.png 29 *.png
30 *.ps 30 *.ps
31 *.rej 31 *.rej
32 *.s 32 *.s
33 *.sgml 33 *.sgml
34 *.so 34 *.so
35 *.so.dbg 35 *.so.dbg
36 *.symtypes 36 *.symtypes
37 *.tab.c 37 *.tab.c
38 *.tab.h 38 *.tab.h
39 *.tex 39 *.tex
40 *.ver 40 *.ver
41 *.xml 41 *.xml
42 *_MODULES 42 *_MODULES
43 *_vga16.c 43 *_vga16.c
44 *~ 44 *~
45 *.9 45 *.9
46 *.9.gz 46 *.9.gz
47 .* 47 .*
48 .mm 48 .mm
49 53c700_d.h 49 53c700_d.h
50 CVS 50 CVS
51 ChangeSet 51 ChangeSet
52 Image 52 Image
53 Kerntypes 53 Kerntypes
54 Module.markers 54 Module.markers
55 Module.symvers 55 Module.symvers
56 PENDING 56 PENDING
57 SCCS 57 SCCS
58 System.map* 58 System.map*
59 TAGS 59 TAGS
60 aic7*reg.h* 60 aic7*reg.h*
61 aic7*reg_print.c* 61 aic7*reg_print.c*
62 aic7*seq.h* 62 aic7*seq.h*
63 aicasm 63 aicasm
64 aicdb.h* 64 aicdb.h*
65 asm-offsets.h 65 asm-offsets.h
66 asm_offsets.h 66 asm_offsets.h
67 autoconf.h* 67 autoconf.h*
68 bbootsect 68 bbootsect
69 bin2c 69 bin2c
70 binkernel.spec 70 binkernel.spec
71 binoffset
72 bootsect 71 bootsect
73 bounds.h 72 bounds.h
74 bsetup 73 bsetup
75 btfixupprep 74 btfixupprep
76 build 75 build
77 bvmlinux 76 bvmlinux
78 bzImage* 77 bzImage*
79 classlist.h* 78 classlist.h*
80 comp*.log 79 comp*.log
81 compile.h* 80 compile.h*
82 conf 81 conf
83 config 82 config
84 config-* 83 config-*
85 config_data.h* 84 config_data.h*
86 config_data.gz* 85 config_data.gz*
87 conmakehash 86 conmakehash
88 consolemap_deftbl.c* 87 consolemap_deftbl.c*
89 cpustr.h 88 cpustr.h
90 crc32table.h* 89 crc32table.h*
91 cscope.* 90 cscope.*
92 defkeymap.c 91 defkeymap.c
93 devlist.h* 92 devlist.h*
94 docproc 93 docproc
95 elf2ecoff 94 elf2ecoff
96 elfconfig.h* 95 elfconfig.h*
97 fixdep 96 fixdep
98 fore200e_mkfirm 97 fore200e_mkfirm
99 fore200e_pca_fw.c* 98 fore200e_pca_fw.c*
100 gconf 99 gconf
101 gen-devlist 100 gen-devlist
102 gen_crc32table 101 gen_crc32table
103 gen_init_cpio 102 gen_init_cpio
104 genksyms 103 genksyms
105 *_gray256.c 104 *_gray256.c
106 ihex2fw 105 ihex2fw
107 ikconfig.h* 106 ikconfig.h*
108 initramfs_data.cpio 107 initramfs_data.cpio
109 initramfs_data.cpio.gz 108 initramfs_data.cpio.gz
110 initramfs_list 109 initramfs_list
111 kallsyms 110 kallsyms
112 kconfig 111 kconfig
113 keywords.c 112 keywords.c
114 ksym.c* 113 ksym.c*
115 ksym.h* 114 ksym.h*
116 kxgettext 115 kxgettext
117 lkc_defs.h 116 lkc_defs.h
118 lex.c 117 lex.c
119 lex.*.c 118 lex.*.c
120 logo_*.c 119 logo_*.c
121 logo_*_clut224.c 120 logo_*_clut224.c
122 logo_*_mono.c 121 logo_*_mono.c
123 lxdialog 122 lxdialog
124 mach-types 123 mach-types
125 mach-types.h 124 mach-types.h
126 machtypes.h 125 machtypes.h
127 map 126 map
128 maui_boot.h 127 maui_boot.h
129 mconf 128 mconf
130 miboot* 129 miboot*
131 mk_elfconfig 130 mk_elfconfig
132 mkboot 131 mkboot
133 mkbugboot 132 mkbugboot
134 mkcpustr 133 mkcpustr
135 mkdep 134 mkdep
136 mkprep 135 mkprep
137 mktables 136 mktables
138 mktree 137 mktree
139 modpost 138 modpost
140 modules.order 139 modules.order
141 modversions.h* 140 modversions.h*
142 ncscope.* 141 ncscope.*
143 offset.h 142 offset.h
144 offsets.h 143 offsets.h
145 oui.c* 144 oui.c*
146 parse.c 145 parse.c
147 parse.h 146 parse.h
148 patches* 147 patches*
149 pca200e.bin 148 pca200e.bin
150 pca200e_ecd.bin2 149 pca200e_ecd.bin2
151 piggy.gz 150 piggy.gz
152 piggyback 151 piggyback
153 pnmtologo 152 pnmtologo
154 ppc_defs.h* 153 ppc_defs.h*
155 pss_boot.h 154 pss_boot.h
156 qconf 155 qconf
157 raid6altivec*.c 156 raid6altivec*.c
158 raid6int*.c 157 raid6int*.c
159 raid6tables.c 158 raid6tables.c
160 relocs 159 relocs
161 series 160 series
162 setup 161 setup
163 setup.bin 162 setup.bin
164 setup.elf 163 setup.elf
165 sImage 164 sImage
166 sm_tbl* 165 sm_tbl*
167 split-include 166 split-include
168 syscalltab.h 167 syscalltab.h
169 tags 168 tags
170 tftpboot.img 169 tftpboot.img
171 timeconst.h 170 timeconst.h
172 times.h* 171 times.h*
173 trix_boot.h 172 trix_boot.h
174 utsrelease.h* 173 utsrelease.h*
175 vdso-syms.lds 174 vdso-syms.lds
176 vdso.lds 175 vdso.lds
177 vdso32-int80-syms.lds 176 vdso32-int80-syms.lds
178 vdso32-syms.lds 177 vdso32-syms.lds
179 vdso32-syscall-syms.lds 178 vdso32-syscall-syms.lds
180 vdso32-sysenter-syms.lds 179 vdso32-sysenter-syms.lds
181 vdso32.lds 180 vdso32.lds
182 vdso32.so.dbg 181 vdso32.so.dbg
183 vdso64.lds 182 vdso64.lds
184 vdso64.so.dbg 183 vdso64.so.dbg
185 version.h* 184 version.h*
186 vmlinux 185 vmlinux
187 vmlinux-* 186 vmlinux-*
188 vmlinux.aout 187 vmlinux.aout
189 vmlinux.lds 188 vmlinux.lds
190 vsyscall.lds 189 vsyscall.lds
191 vsyscall_32.lds 190 vsyscall_32.lds
192 wanxlfw.inc 191 wanxlfw.inc
193 uImage 192 uImage
194 unifdef 193 unifdef
195 wakeup.bin 194 wakeup.bin
196 wakeup.elf 195 wakeup.elf
197 wakeup.lds 196 wakeup.lds
198 zImage* 197 zImage*
199 zconf.hash.c 198 zconf.hash.c
200 199
1 # 1 #
2 # Generated files 2 # Generated files
3 # 3 #
4 conmakehash 4 conmakehash
5 kallsyms 5 kallsyms
6 pnmtologo 6 pnmtologo
7 bin2c 7 bin2c
8 unifdef 8 unifdef
9 binoffset
10 ihex2fw 9 ihex2fw
11 10
scripts/binoffset.c
1 /*************************************************************************** File was deleted
2 * binoffset.c
3 * (C) 2002 Randy Dunlap <rdunlap@xenotime.net>
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 # binoffset.c:
20 # - searches a (binary) file for a specified (binary) pattern
21 # - returns the offset of the located pattern or ~0 if not found
22 # - exits with exit status 0 normally or non-0 if pattern is not found
23 # or any other error occurs.
24
25 ****************************************************************/
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <errno.h>
31 #include <unistd.h>
32 #include <fcntl.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <sys/mman.h>
36
37 #define VERSION "0.1"
38 #define BUF_SIZE (16 * 1024)
39 #define PAT_SIZE 100
40
41 char *progname;
42 char *inputname;
43 int inputfd;
44 unsigned int bix; /* buf index */
45 unsigned char patterns [PAT_SIZE] = {0}; /* byte-sized pattern array */
46 int pat_len; /* actual number of pattern bytes */
47 unsigned char *madr; /* mmap address */
48 size_t filesize;
49 int num_matches = 0;
50 off_t firstloc = 0;
51
52 void usage (void)
53 {
54 fprintf (stderr, "%s ver. %s\n", progname, VERSION);
55 fprintf (stderr, "usage: %s filename pattern_bytes\n",
56 progname);
57 fprintf (stderr, " [prints location of pattern_bytes in file]\n");
58 exit (1);
59 }
60
61 void get_pattern (int pat_count, char *pats [])
62 {
63 int ix, err, tmp;
64
65 #ifdef DEBUG
66 fprintf (stderr,"get_pattern: count = %d\n", pat_count);
67 for (ix = 0; ix < pat_count; ix++)
68 fprintf (stderr, " pat # %d: [%s]\n", ix, pats[ix]);
69 #endif
70
71 for (ix = 0; ix < pat_count; ix++) {
72 tmp = 0;
73 err = sscanf (pats[ix], "%5i", &tmp);
74 if (err != 1 || tmp > 0xff) {
75 fprintf (stderr, "pattern or value error in pattern # %d [%s]\n",
76 ix, pats[ix]);
77 usage ();
78 }
79 patterns [ix] = tmp;
80 }
81 pat_len = pat_count;
82 }
83
84 void search_pattern (void)
85 {
86 for (bix = 0; bix < filesize; bix++) {
87 if (madr[bix] == patterns[0]) {
88 if (memcmp (&madr[bix], patterns, pat_len) == 0) {
89 if (num_matches == 0)
90 firstloc = bix;
91 num_matches++;
92 }
93 }
94 }
95 }
96
97 #ifdef NOTDEF
98 size_t get_filesize (int fd)
99 {
100 off_t end_off = lseek (fd, 0, SEEK_END);
101 lseek (fd, 0, SEEK_SET);
102 return (size_t) end_off;
103 }
104 #endif
105
106 size_t get_filesize (int fd)
107 {
108 int err;
109 struct stat stat;
110
111 err = fstat (fd, &stat);
112 fprintf (stderr, "filesize: %ld\n", err < 0 ? (long)err : stat.st_size);
113 if (err < 0)
114 return err;
115 return (size_t) stat.st_size;
116 }
117
118 int main (int argc, char *argv [])
119 {
120 progname = argv[0];
121
122 if (argc < 3)
123 usage ();
124
125 get_pattern (argc - 2, argv + 2);
126
127 inputname = argv[1];
128
129 inputfd = open (inputname, O_RDONLY);
130 if (inputfd == -1) {
131 fprintf (stderr, "%s: cannot open '%s'\n",
132 progname, inputname);
133 exit (3);
134 }
135
136 filesize = get_filesize (inputfd);
137
138 madr = mmap (0, filesize, PROT_READ, MAP_PRIVATE, inputfd, 0);
139 if (madr == MAP_FAILED) {
140 fprintf (stderr, "mmap error = %d\n", errno);
141 close (inputfd);
142 exit (4);
143 }
144
145 search_pattern ();
146
147 if (munmap (madr, filesize))
148 fprintf (stderr, "munmap error = %d\n", errno);
149
150 if (close (inputfd))
151 fprintf (stderr, "%s: error %d closing '%s'\n",
152 progname, errno, inputname);
153
154 fprintf (stderr, "number of pattern matches = %d\n", num_matches);
155 if (num_matches == 0)
156 firstloc = ~0;
157 printf ("%ld\n", firstloc);
158 fprintf (stderr, "%ld\n", firstloc);
159
160 exit (num_matches ? 0 : 2);
161 }
162
163 /* end binoffset.c */
164 1 /***************************************************************************
scripts/extract-ikconfig
1 #!/bin/sh 1 #!/bin/sh
2 # extracts .config info from a [b]zImage file 2 # ----------------------------------------------------------------------
3 # uses: binoffset (new), dd, zcat, strings, grep 3 # extract-ikconfig - Extract the .config file from a kernel image
4 # $arg1 is [b]zImage filename 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, Dick Streefland <dick@streefland.net>
11 # Licensed under the terms of the GNU General Public License.
12 # ----------------------------------------------------------------------
5 13
6 binoffset="./scripts/binoffset" 14 gz1='\037\213\010'
7 test -e $binoffset || cc -o $binoffset ./scripts/binoffset.c || exit 1 15 gz2='01'
16 cf1='IKCFG_ST\037\213\010'
17 cf2='0123456789'
8 18
9 IKCFG_ST="0x49 0x4b 0x43 0x46 0x47 0x5f 0x53 0x54" 19 dump_config()
10 IKCFG_ED="0x49 0x4b 0x43 0x46 0x47 0x5f 0x45 0x44"
11 dump_config() {
12 file="$1"
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`
20 [ "$?" != "0" ] && end="-1"
21 if [ "$end" -eq "-1" ]; then
22 return
23 fi
24
25 start=`expr $start + 8`
26 size=`expr $end - $start`
27
28 dd if="$file" ibs=1 skip="$start" count="$size" 2>/dev/null | zcat
29
30 clean_up
31 exit 0
32 }
33
34
35 usage()
36 { 20 {
37 echo " usage: extract-ikconfig [b]zImage_filename" 21 if pos=`tr "$cf1\n$cf2" "\n$cf2=" < "$1" | grep -abo "^$cf2"`
38 } 22 then
39 23 pos=${pos%%:*}
40 clean_up() 24 tail -c+$(($pos+8)) "$1" | zcat -q
41 { 25 exit 0
42 if [ "$TMPFILE" != "" ]; then
43 rm -f $TMPFILE
44 fi 26 fi
45 } 27 }
46 28
47 if [ $# -lt 1 ] 29 # Check invocation:
30 me=${0##*/}
31 img=$1
32 if [ $# -ne 1 -o ! -s "$img" ]
48 then 33 then
49 usage 34 echo "Usage: $me <kernel-image>" >&2
50 exit 1 35 exit 2
51 fi 36 fi
52 37
53 TMPFILE=`mktemp -t ikconfig-XXXXXX` || exit 1 38 # Initial attempt for uncompressed images or objects:
54 image="$1" 39 dump_config "$img"
55 40
56 # vmlinux: Attempt to dump the configuration from the file directly 41 # That didn't work, so decompress and try again:
57 dump_config "$image" 42 tmp=/tmp/ikconfig$$
43 trap "rm -f $tmp" 0
44 for pos in `tr "$gz1\n$gz2" "\n$gz2=" < "$img" | grep -abo "^$gz2"`
45 do
46 pos=${pos%%:*}
47 tail -c+$pos "$img" | zcat 2> /dev/null > $tmp
48 dump_config $tmp
49 done
58 50
59 GZHDR1="0x1f 0x8b 0x08 0x00" 51 # Bail out:
60 GZHDR2="0x1f 0x8b 0x08 0x08" 52 echo "$me: Cannot find kernel config." >&2
61
62 ELFHDR="0x7f 0x45 0x4c 0x46"
63
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"