aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xexamples/depmod.pl65
1 files changed, 56 insertions, 9 deletions
diff --git a/examples/depmod.pl b/examples/depmod.pl
index c356d2715..6b47bad09 100755
--- a/examples/depmod.pl
+++ b/examples/depmod.pl
@@ -13,7 +13,7 @@
13 13
14# This program is free software; you can redistribute it and/or modify it 14# This program is free software; you can redistribute it and/or modify it
15# under the same terms as Perl itself. 15# under the same terms as Perl itself.
16use Getopt::Long; 16use Getopt::Long qw(:config no_auto_abbrev no_ignore_case);
17use File::Find; 17use File::Find;
18use strict; 18use strict;
19 19
@@ -23,6 +23,9 @@ my $basedir="";
23my $kernel=""; 23my $kernel="";
24my $kernelsyms=""; 24my $kernelsyms="";
25my $symprefix=""; 25my $symprefix="";
26my $all=0;
27my $quick=0;
28my $errsyms=0;
26my $stdout=0; 29my $stdout=0;
27my $verbose=0; 30my $verbose=0;
28my $help=0; 31my $help=0;
@@ -44,6 +47,8 @@ $0 -b basedir { -k <vmlinux> | -F <System.map> } [options]...
44 -n --stdout : Write to stdout instead of <basedir>/modules.dep 47 -n --stdout : Write to stdout instead of <basedir>/modules.dep
45 -v --verbose : Print out lots of debugging stuff 48 -v --verbose : Print out lots of debugging stuff
46 -P --symbol-prefix : Symbol prefix 49 -P --symbol-prefix : Symbol prefix
50 -a --all : Probe all modules (default/only thing supported)
51 -e --errsyms : Report any symbols not supplied by modules/kernel
47TXT 52TXT
48 53
49# get command-line options 54# get command-line options
@@ -55,14 +60,23 @@ GetOptions(
55 "stdout|n" => \$stdout, 60 "stdout|n" => \$stdout,
56 "verbose|v" => \$verbose, 61 "verbose|v" => \$verbose,
57 "symbol-prefix|P=s" => \$symprefix, 62 "symbol-prefix|P=s" => \$symprefix,
63 "all|a" => \$all,
64 # unsupported options
65 "quick|A" => \$quick,
66 # ignored options (for historical usage)
67 "quiet|q",
68 "root|r",
69 "unresolved-error|u"
58); 70);
59 71
60die $usage if $help; 72die $usage if $help;
61die $usage unless $basedir && ( $kernel || $kernelsyms ); 73die $usage unless $basedir && ( $kernel || $kernelsyms );
62die "can't use both -k and -F\n\n$usage" if $kernel && $kernelsyms; 74die "can't use both -k and -F\n\n$usage" if $kernel && $kernelsyms;
75die "sorry, -A/--quick is not supported" if $quick;
76die "--errsyms requires --kernelsyms" if $errsyms && !$kernelsyms;
63 77
64# Strip any trailing or multiple slashes from basedir 78# Strip any trailing or multiple slashes from basedir
65$basedir =~ s-(/)\1+-/-g; 79$basedir =~ s-/+$--g;
66 80
67# The base directory should contain /lib/modules somewhere 81# The base directory should contain /lib/modules somewhere
68if($basedir !~ m-/lib/modules-) { 82if($basedir !~ m-/lib/modules-) {
@@ -137,6 +151,35 @@ foreach my $module (keys %$dep) {
137 } 151 }
138} 152}
139 153
154# build a complete dependency list for each module and make sure it
155# is kept in order proper order
156my $mod2 = {};
157sub maybe_unshift
158{
159 my ($array, $ele) = @_;
160 # chop off the leading path /lib/modules/<kver>/ as modprobe
161 # will handle relative paths just fine
162 $ele =~ s:^/lib/modules/[^/]*/::;
163 foreach (@{$array}) {
164 if ($_ eq $ele) {
165 return;
166 }
167 }
168 unshift (@{$array}, $ele);
169}
170foreach my $module (keys %$mod) {
171 warn "filling out module: $module\n" if $verbose;
172 @{$mod2->{$module}} = ();
173 foreach my $md (keys %{$mod->{$module}}) {
174 foreach my $md2 (keys %{$mod->{$md}}) {
175 warn "outputting $md2\n" if $verbose;
176 maybe_unshift (\@{$mod2->{$module}}, $md2);
177 }
178 warn "outputting $md\n" if $verbose;
179 maybe_unshift (\@{$mod2->{$module}}, $md);
180 }
181}
182
140# figure out where the output should go 183# figure out where the output should go
141if ($stdout == 0) { 184if ($stdout == 0) {
142 open(STDOUT, ">$basedir/modules.dep") 185 open(STDOUT, ">$basedir/modules.dep")
@@ -151,8 +194,11 @@ foreach my $module ( keys %$mod ) {
151 print join(" \\\n\t",@sorted); 194 print join(" \\\n\t",@sorted);
152 print "\n\n"; 195 print "\n\n";
153 } else { 196 } else {
154 print "$module: "; 197 my $shortmod = $module;
155 my @sorted = sort bydep keys %{$mod->{$module}}; 198 $shortmod =~ s:^/lib/modules/[^/]*/::;
199 print "$shortmod:";
200 my @sorted = @{$mod2->{$module}};
201 printf " " if @sorted;
156 print join(" ",@sorted); 202 print join(" ",@sorted);
157 print "\n"; 203 print "\n";
158 } 204 }
@@ -163,15 +209,16 @@ sub build_ref_tables
163{ 209{
164 my ($name, $sym_ar, $exp, $dep) = @_; 210 my ($name, $sym_ar, $exp, $dep) = @_;
165 211
166 my $ksymtab = grep m/ __ksymtab/, @$sym_ar; 212 my $ksymtab = grep m/ ${symprefix}__ksymtab/, @$sym_ar;
167 213
168 # gather the exported symbols 214 # gather the exported symbols
169 if($ksymtab){ 215 if($ksymtab){
170 # explicitly exported 216 # explicitly exported
171 foreach ( @$sym_ar ) { 217 foreach ( @$sym_ar ) {
172 / __ksymtab_(.*)$/ and do { 218 / ${symprefix}__ksymtab_(.*)$/ and do {
173 warn "sym = $1\n" if $verbose; 219 my $sym = ${symprefix} . $1;
174 $exp->{$1} = $name; 220 warn "sym = $sym\n" if $verbose;
221 $exp->{$sym} = $name;
175 }; 222 };
176 } 223 }
177 } else { 224 } else {
@@ -189,7 +236,7 @@ sub build_ref_tables
189 236
190 # gather the unresolved symbols 237 # gather the unresolved symbols
191 foreach ( @$sym_ar ) { 238 foreach ( @$sym_ar ) {
192 !/ __this_module/ && / U (.*)$/ and do { 239 !/ ${symprefix}__this_module/ && / U (.*)$/ and do {
193 warn "und = $1\n" if $verbose; 240 warn "und = $1\n" if $verbose;
194 push @{$dep->{$name}}, $1; 241 push @{$dep->{$name}}, $1;
195 }; 242 };