diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/.gitignore | 1 | ||||
-rw-r--r-- | scripts/binoffset.c | 163 | ||||
-rwxr-xr-x | scripts/extract-ikconfig | 127 | ||||
-rw-r--r-- | scripts/kconfig/Makefile | 14 | ||||
-rw-r--r-- | scripts/kconfig/streamline_config.pl | 59 |
5 files changed, 113 insertions, 251 deletions
diff --git a/scripts/.gitignore b/scripts/.gitignore index 52cab46ae35a..c5d5db54c009 100644 --- a/scripts/.gitignore +++ b/scripts/.gitignore | |||
@@ -6,5 +6,4 @@ kallsyms | |||
6 | pnmtologo | 6 | pnmtologo |
7 | bin2c | 7 | bin2c |
8 | unifdef | 8 | unifdef |
9 | binoffset | ||
10 | ihex2fw | 9 | ihex2fw |
diff --git a/scripts/binoffset.c b/scripts/binoffset.c deleted file mode 100644 index 1a2e39b8e3e5..000000000000 --- a/scripts/binoffset.c +++ /dev/null | |||
@@ -1,163 +0,0 @@ | |||
1 | /*************************************************************************** | ||
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 */ | ||
diff --git a/scripts/extract-ikconfig b/scripts/extract-ikconfig index de233ff43c1c..37f30d36c944 100755 --- a/scripts/extract-ikconfig +++ b/scripts/extract-ikconfig | |||
@@ -1,92 +1,53 @@ | |||
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 | 5 | # This will only work when the kernel was compiled with CONFIG_IKCONFIG. | |
6 | binoffset="./scripts/binoffset" | 6 | # |
7 | test -e $binoffset || cc -o $binoffset ./scripts/binoffset.c || exit 1 | 7 | # The obscure use of the "tr" filter is to work around older versions of |
8 | 8 | # "grep" that report the byte offset of the line instead of the pattern. | |
9 | IKCFG_ST="0x49 0x4b 0x43 0x46 0x47 0x5f 0x53 0x54" | 9 | # |
10 | IKCFG_ED="0x49 0x4b 0x43 0x46 0x47 0x5f 0x45 0x44" | 10 | # (c) 2009, Dick Streefland <dick@streefland.net> |
11 | dump_config() { | 11 | # Licensed under the terms of the GNU General Public License. |
12 | file="$1" | 12 | # ---------------------------------------------------------------------- |
13 | 13 | ||
14 | start=`$binoffset $file $IKCFG_ST 2>/dev/null` | 14 | gz1='\037\213\010' |
15 | [ "$?" != "0" ] && start="-1" | 15 | gz2='01' |
16 | if [ "$start" -eq "-1" ]; then | 16 | cf1='IKCFG_ST\037\213\010' |
17 | return | 17 | cf2='0123456789' |
18 | fi | 18 | |
19 | end=`$binoffset $file $IKCFG_ED 2>/dev/null` | 19 | dump_config() |
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 | { | ||
37 | echo " usage: extract-ikconfig [b]zImage_filename" | ||
38 | } | ||
39 | |||
40 | clean_up() | ||
41 | { | 20 | { |
42 | if [ "$TMPFILE" != "" ]; then | 21 | if pos=`tr "$cf1\n$cf2" "\n$cf2=" < "$1" | grep -abo "^$cf2"` |
43 | rm -f $TMPFILE | 22 | then |
23 | pos=${pos%%:*} | ||
24 | tail -c+$(($pos+8)) "$1" | zcat -q | ||
25 | exit 0 | ||
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$$ |
58 | 43 | trap "rm -f $tmp" 0 | |
59 | GZHDR1="0x1f 0x8b 0x08 0x00" | 44 | for pos in `tr "$gz1\n$gz2" "\n$gz2=" < "$img" | grep -abo "^$gz2"` |
60 | GZHDR2="0x1f 0x8b 0x08 0x08" | 45 | do |
61 | 46 | pos=${pos%%:*} | |
62 | ELFHDR="0x7f 0x45 0x4c 0x46" | 47 | tail -c+$pos "$img" | zcat 2> /dev/null > $tmp |
63 | 48 | dump_config $tmp | |
64 | # vmlinux.gz: Check for a compressed images | 49 | done |
65 | off=`$binoffset "$image" $GZHDR1 2>/dev/null` | 50 | |
66 | [ "$?" != "0" ] && off="-1" | 51 | # Bail out: |
67 | if [ "$off" -eq "-1" ]; then | 52 | echo "$me: Cannot find kernel config." >&2 |
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" | ||
74 | elif [ "$off" -ne "-1" ]; then | ||
75 | (dd ibs="$off" skip=1 count=0 && dd bs=512k) <"$image" 2>/dev/null | \ | ||
76 | zcat >"$TMPFILE" | ||
77 | dump_config "$TMPFILE" | ||
78 | |||
79 | # check if this is simply an ELF file | ||
80 | else | ||
81 | off=`$binoffset "$image" $ELFHDR 2>/dev/null` | ||
82 | [ "$?" != "0" ] && off="-1" | ||
83 | if [ "$off" -eq "0" ]; then | ||
84 | dump_config "$image" | ||
85 | fi | ||
86 | fi | ||
87 | |||
88 | echo "ERROR: Unable to extract kernel configuration information." | ||
89 | echo " This kernel image may not have the config info." | ||
90 | |||
91 | clean_up | ||
92 | exit 1 | 53 | exit 1 |
diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile index 999e8a7d5bf7..186c46604d06 100644 --- a/scripts/kconfig/Makefile +++ b/scripts/kconfig/Makefile | |||
@@ -30,8 +30,17 @@ silentoldconfig: $(obj)/conf | |||
30 | $(Q)mkdir -p include/generated | 30 | $(Q)mkdir -p include/generated |
31 | $< -s $(Kconfig) | 31 | $< -s $(Kconfig) |
32 | 32 | ||
33 | # if no path is given, then use src directory to find file | ||
34 | ifdef LSMOD | ||
35 | LSMOD_F := $(LSMOD) | ||
36 | ifeq ($(findstring /,$(LSMOD)),) | ||
37 | LSMOD_F := $(objtree)/$(LSMOD) | ||
38 | endif | ||
39 | endif | ||
40 | |||
33 | localmodconfig: $(obj)/streamline_config.pl $(obj)/conf | 41 | localmodconfig: $(obj)/streamline_config.pl $(obj)/conf |
34 | $(Q)perl $< $(srctree) $(Kconfig) > .tmp.config | 42 | $(Q)mkdir -p include/generated |
43 | $(Q)perl $< $(srctree) $(Kconfig) $(LSMOD_F) > .tmp.config | ||
35 | $(Q)if [ -f .config ]; then \ | 44 | $(Q)if [ -f .config ]; then \ |
36 | cmp -s .tmp.config .config || \ | 45 | cmp -s .tmp.config .config || \ |
37 | (mv -f .config .config.old.1; \ | 46 | (mv -f .config .config.old.1; \ |
@@ -45,7 +54,8 @@ localmodconfig: $(obj)/streamline_config.pl $(obj)/conf | |||
45 | $(Q)rm -f .tmp.config | 54 | $(Q)rm -f .tmp.config |
46 | 55 | ||
47 | localyesconfig: $(obj)/streamline_config.pl $(obj)/conf | 56 | localyesconfig: $(obj)/streamline_config.pl $(obj)/conf |
48 | $(Q)perl $< $(srctree) $(Kconfig) > .tmp.config | 57 | $(Q)mkdir -p include/generated |
58 | $(Q)perl $< $(srctree) $(Kconfig) $(LSMOD_F) > .tmp.config | ||
49 | $(Q)sed -i s/=m/=y/ .tmp.config | 59 | $(Q)sed -i s/=m/=y/ .tmp.config |
50 | $(Q)if [ -f .config ]; then \ | 60 | $(Q)if [ -f .config ]; then \ |
51 | cmp -s .tmp.config .config || \ | 61 | cmp -s .tmp.config .config || \ |
diff --git a/scripts/kconfig/streamline_config.pl b/scripts/kconfig/streamline_config.pl index 0d800820c3cd..afbd54ac1d83 100644 --- a/scripts/kconfig/streamline_config.pl +++ b/scripts/kconfig/streamline_config.pl | |||
@@ -113,6 +113,7 @@ find_config; | |||
113 | # Get the build source and top level Kconfig file (passed in) | 113 | # Get the build source and top level Kconfig file (passed in) |
114 | my $ksource = $ARGV[0]; | 114 | my $ksource = $ARGV[0]; |
115 | my $kconfig = $ARGV[1]; | 115 | my $kconfig = $ARGV[1]; |
116 | my $lsmod_file = $ARGV[2]; | ||
116 | 117 | ||
117 | my @makefiles = `find $ksource -name Makefile`; | 118 | my @makefiles = `find $ksource -name Makefile`; |
118 | my %depends; | 119 | my %depends; |
@@ -121,6 +122,8 @@ my %prompts; | |||
121 | my %objects; | 122 | my %objects; |
122 | my $var; | 123 | my $var; |
123 | my $cont = 0; | 124 | my $cont = 0; |
125 | my $iflevel = 0; | ||
126 | my @ifdeps; | ||
124 | 127 | ||
125 | # prevent recursion | 128 | # prevent recursion |
126 | my %read_kconfigs; | 129 | my %read_kconfigs; |
@@ -146,6 +149,15 @@ sub read_kconfig { | |||
146 | $state = "NEW"; | 149 | $state = "NEW"; |
147 | $config = $1; | 150 | $config = $1; |
148 | 151 | ||
152 | for (my $i = 0; $i < $iflevel; $i++) { | ||
153 | if ($i) { | ||
154 | $depends{$config} .= " " . $ifdeps[$i]; | ||
155 | } else { | ||
156 | $depends{$config} = $ifdeps[$i]; | ||
157 | } | ||
158 | $state = "DEP"; | ||
159 | } | ||
160 | |||
149 | # collect the depends for the config | 161 | # collect the depends for the config |
150 | } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) { | 162 | } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) { |
151 | $state = "DEP"; | 163 | $state = "DEP"; |
@@ -166,6 +178,21 @@ sub read_kconfig { | |||
166 | # note if the config has a prompt | 178 | # note if the config has a prompt |
167 | $prompt{$config} = 1; | 179 | $prompt{$config} = 1; |
168 | 180 | ||
181 | # Check for if statements | ||
182 | } elsif (/^if\s+(.*\S)\s*$/) { | ||
183 | my $deps = $1; | ||
184 | # remove beginning and ending non text | ||
185 | $deps =~ s/^[^a-zA-Z0-9_]*//; | ||
186 | $deps =~ s/[^a-zA-Z0-9_]*$//; | ||
187 | |||
188 | my @deps = split /[^a-zA-Z0-9_]+/, $deps; | ||
189 | |||
190 | $ifdeps[$iflevel++] = join ':', @deps; | ||
191 | |||
192 | } elsif (/^endif/) { | ||
193 | |||
194 | $iflevel-- if ($iflevel); | ||
195 | |||
169 | # stop on "help" | 196 | # stop on "help" |
170 | } elsif (/^\s*help\s*$/) { | 197 | } elsif (/^\s*help\s*$/) { |
171 | $state = "NONE"; | 198 | $state = "NONE"; |
@@ -237,8 +264,36 @@ foreach my $makefile (@makefiles) { | |||
237 | 264 | ||
238 | my %modules; | 265 | my %modules; |
239 | 266 | ||
240 | # see what modules are loaded on this system | 267 | if (defined($lsmod_file)) { |
241 | open(LIN,"/sbin/lsmod|") || die "Cant lsmod"; | 268 | if ( ! -f $lsmod_file) { |
269 | die "$lsmod_file not found"; | ||
270 | } | ||
271 | if ( -x $lsmod_file) { | ||
272 | # the file is executable, run it | ||
273 | open(LIN, "$lsmod_file|"); | ||
274 | } else { | ||
275 | # Just read the contents | ||
276 | open(LIN, "$lsmod_file"); | ||
277 | } | ||
278 | } else { | ||
279 | |||
280 | # see what modules are loaded on this system | ||
281 | my $lsmod; | ||
282 | |||
283 | foreach $dir ( ("/sbin", "/bin", "/usr/sbin", "/usr/bin") ) { | ||
284 | if ( -x "$dir/lsmod" ) { | ||
285 | $lsmod = "$dir/lsmod"; | ||
286 | last; | ||
287 | } | ||
288 | } | ||
289 | if (!defined($lsmod)) { | ||
290 | # try just the path | ||
291 | $lsmod = "lsmod"; | ||
292 | } | ||
293 | |||
294 | open(LIN,"$lsmod|") || die "Can not call lsmod with $lsmod"; | ||
295 | } | ||
296 | |||
242 | while (<LIN>) { | 297 | while (<LIN>) { |
243 | next if (/^Module/); # Skip the first line. | 298 | next if (/^Module/); # Skip the first line. |
244 | if (/^(\S+)/) { | 299 | if (/^(\S+)/) { |