2001-07-31 01:02:03 +05:30
|
|
|
#!/usr/bin/perl -w
|
2006-07-03 01:17:05 +05:30
|
|
|
# vi: set sw=4 ts=4:
|
2001-07-31 01:02:03 +05:30
|
|
|
# Copyright (c) 2001 David Schleef <ds@schleef.org>
|
2003-07-15 02:51:08 +05:30
|
|
|
# Copyright (c) 2001 Erik Andersen <andersen@codepoet.org>
|
2006-03-21 22:05:50 +05:30
|
|
|
# Copyright (c) 2001 Stuart Hughes <seh@zee2.com>
|
2002-10-09 03:03:51 +05:30
|
|
|
# Copyright (c) 2002 Steven J. Hill <shill@broadcom.com>
|
2006-03-21 22:05:50 +05:30
|
|
|
# Copyright (c) 2006 Freescale Semiconductor, Inc <stuarth@freescale.com>
|
|
|
|
#
|
|
|
|
# History:
|
|
|
|
# March 2006: Stuart Hughes <stuarth@freescale.com>.
|
|
|
|
# Significant updates, including implementing the '-F' option
|
|
|
|
# and adding support for 2.6 kernels.
|
|
|
|
|
2004-03-15 13:59:22 +05:30
|
|
|
# This program is free software; you can redistribute it and/or modify it
|
2001-07-31 01:02:03 +05:30
|
|
|
# under the same terms as Perl itself.
|
2009-05-06 05:44:12 +05:30
|
|
|
use Getopt::Long qw(:config no_auto_abbrev no_ignore_case);
|
2001-07-31 01:02:03 +05:30
|
|
|
use File::Find;
|
2006-03-21 22:05:50 +05:30
|
|
|
use strict;
|
2001-07-31 01:02:03 +05:30
|
|
|
|
|
|
|
# Set up some default values
|
2006-03-21 22:05:50 +05:30
|
|
|
my $kdir="";
|
2001-07-31 01:02:03 +05:30
|
|
|
my $basedir="";
|
2006-03-21 22:05:50 +05:30
|
|
|
my $kernel="";
|
|
|
|
my $kernelsyms="";
|
2007-07-13 10:07:12 +05:30
|
|
|
my $symprefix="";
|
2009-05-06 05:44:12 +05:30
|
|
|
my $all=0;
|
|
|
|
my $quick=0;
|
|
|
|
my $errsyms=0;
|
2002-10-09 03:03:51 +05:30
|
|
|
my $stdout=0;
|
2001-07-31 01:02:03 +05:30
|
|
|
my $verbose=0;
|
2006-03-21 22:05:50 +05:30
|
|
|
my $help=0;
|
2006-06-03 03:00:40 +05:30
|
|
|
my $nm = $ENV{'NM'} || "nm";
|
2006-03-21 22:05:50 +05:30
|
|
|
|
|
|
|
# more globals
|
|
|
|
my (@liblist) = ();
|
|
|
|
my $exp = {};
|
|
|
|
my $dep = {};
|
|
|
|
my $mod = {};
|
|
|
|
|
|
|
|
my $usage = <<TXT;
|
2006-09-17 21:58:10 +05:30
|
|
|
$0 -b basedir { -k <vmlinux> | -F <System.map> } [options]...
|
2006-03-21 22:05:50 +05:30
|
|
|
Where:
|
2007-07-13 10:07:12 +05:30
|
|
|
-h --help : Show this help screen
|
|
|
|
-b --basedir : Modules base directory (e.g /lib/modules/<2.x.y>)
|
|
|
|
-k --kernel : Kernel binary for the target (e.g. vmlinux)
|
|
|
|
-F --kernelsyms : Kernel symbol file (e.g. System.map)
|
|
|
|
-n --stdout : Write to stdout instead of <basedir>/modules.dep
|
|
|
|
-v --verbose : Print out lots of debugging stuff
|
|
|
|
-P --symbol-prefix : Symbol prefix
|
2009-05-06 05:44:12 +05:30
|
|
|
-a --all : Probe all modules (default/only thing supported)
|
|
|
|
-e --errsyms : Report any symbols not supplied by modules/kernel
|
2006-03-21 22:05:50 +05:30
|
|
|
TXT
|
2001-07-31 01:02:03 +05:30
|
|
|
|
|
|
|
# get command-line options
|
|
|
|
GetOptions(
|
2007-07-13 10:07:12 +05:30
|
|
|
"help|h" => \$help,
|
|
|
|
"basedir|b=s" => \$basedir,
|
|
|
|
"kernel|k=s" => \$kernel,
|
|
|
|
"kernelsyms|F=s" => \$kernelsyms,
|
|
|
|
"stdout|n" => \$stdout,
|
|
|
|
"verbose|v" => \$verbose,
|
|
|
|
"symbol-prefix|P=s" => \$symprefix,
|
2009-05-06 05:44:12 +05:30
|
|
|
"all|a" => \$all,
|
|
|
|
# unsupported options
|
|
|
|
"quick|A" => \$quick,
|
|
|
|
# ignored options (for historical usage)
|
|
|
|
"quiet|q",
|
|
|
|
"root|r",
|
|
|
|
"unresolved-error|u"
|
2001-07-31 01:02:03 +05:30
|
|
|
);
|
|
|
|
|
2006-03-21 22:05:50 +05:30
|
|
|
die $usage if $help;
|
|
|
|
die $usage unless $basedir && ( $kernel || $kernelsyms );
|
|
|
|
die "can't use both -k and -F\n\n$usage" if $kernel && $kernelsyms;
|
2009-05-06 05:44:12 +05:30
|
|
|
die "sorry, -A/--quick is not supported" if $quick;
|
|
|
|
die "--errsyms requires --kernelsyms" if $errsyms && !$kernelsyms;
|
2001-07-31 01:02:03 +05:30
|
|
|
|
2006-03-21 22:05:50 +05:30
|
|
|
# Strip any trailing or multiple slashes from basedir
|
2009-05-06 05:44:12 +05:30
|
|
|
$basedir =~ s-/+$--g;
|
2006-03-21 22:05:50 +05:30
|
|
|
|
|
|
|
# The base directory should contain /lib/modules somewhere
|
2001-07-31 01:02:03 +05:30
|
|
|
if($basedir !~ m-/lib/modules-) {
|
|
|
|
warn "WARNING: base directory does not match ..../lib/modules\n";
|
|
|
|
}
|
|
|
|
|
2006-03-21 22:05:50 +05:30
|
|
|
# if no kernel version is contained in the basedir, try to find one
|
|
|
|
if($basedir !~ m-/lib/modules/\d\.\d-) {
|
|
|
|
opendir(BD, $basedir) or die "can't open basedir $basedir : $!\n";
|
|
|
|
foreach ( readdir(BD) ) {
|
|
|
|
next if /^\.\.?$/;
|
|
|
|
next unless -d "$basedir/$_";
|
|
|
|
warn "dir = $_\n" if $verbose;
|
|
|
|
if( /^\d\.\d/ ) {
|
|
|
|
$kdir = $_;
|
|
|
|
warn("Guessed module directory as $basedir/$kdir\n");
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(BD);
|
|
|
|
die "Cannot find a kernel version under $basedir\n" unless $kdir;
|
|
|
|
$basedir = "$basedir/$kdir";
|
|
|
|
}
|
|
|
|
|
|
|
|
# Find the list of .o or .ko files living under $basedir
|
|
|
|
warn "**** Locating all modules\n" if $verbose;
|
2004-03-15 13:59:22 +05:30
|
|
|
find sub {
|
2006-03-21 22:05:50 +05:30
|
|
|
my $file;
|
2004-03-15 13:59:22 +05:30
|
|
|
if ( -f $_ && ! -d $_ ) {
|
2001-07-31 01:02:03 +05:30
|
|
|
$file = $File::Find::name;
|
2006-03-21 22:05:50 +05:30
|
|
|
if ( $file =~ /\.k?o$/ ) {
|
2001-07-31 01:02:03 +05:30
|
|
|
push(@liblist, $file);
|
2006-03-21 22:05:50 +05:30
|
|
|
warn "$file\n" if $verbose;
|
2001-07-31 01:02:03 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}, $basedir;
|
2006-03-21 22:05:50 +05:30
|
|
|
warn "**** Finished locating modules\n" if $verbose;
|
2001-07-31 01:02:03 +05:30
|
|
|
|
2006-03-21 22:05:50 +05:30
|
|
|
foreach my $obj ( @liblist ){
|
2001-07-31 01:02:03 +05:30
|
|
|
# turn the input file name into a target tag name
|
2006-03-21 22:05:50 +05:30
|
|
|
my ($tgtname) = $obj =~ m-(/lib/modules/.*)$-;
|
|
|
|
|
|
|
|
warn "\nMODULE = $tgtname\n" if $verbose;
|
|
|
|
|
|
|
|
# get a list of symbols
|
2006-06-03 03:00:40 +05:30
|
|
|
my @output=`$nm $obj`;
|
2006-03-21 22:05:50 +05:30
|
|
|
|
|
|
|
build_ref_tables($tgtname, \@output, $exp, $dep);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# vmlinux is a special name that is only used to resolve symbols
|
|
|
|
my $tgtname = 'vmlinux';
|
2006-06-03 03:00:40 +05:30
|
|
|
my @output = $kernelsyms ? `cat $kernelsyms` : `$nm $kernel`;
|
2006-03-21 22:05:50 +05:30
|
|
|
warn "\nMODULE = $tgtname\n" if $verbose;
|
|
|
|
build_ref_tables($tgtname, \@output, $exp, $dep);
|
|
|
|
|
2006-05-26 07:18:17 +05:30
|
|
|
# resolve the dependencies for each module
|
|
|
|
# reduce dependencies: remove unresolvable and resolved from vmlinux/System.map
|
2006-03-21 22:05:50 +05:30
|
|
|
# remove duplicates
|
|
|
|
foreach my $module (keys %$dep) {
|
|
|
|
warn "reducing module: $module\n" if $verbose;
|
|
|
|
$mod->{$module} = {};
|
|
|
|
foreach (@{$dep->{$module}}) {
|
|
|
|
if( $exp->{$_} ) {
|
|
|
|
warn "resolved symbol $_ in file $exp->{$_}\n" if $verbose;
|
|
|
|
next if $exp->{$_} =~ /vmlinux/;
|
|
|
|
$mod->{$module}{$exp->{$_}} = 1;
|
|
|
|
} else {
|
|
|
|
warn "unresolved symbol $_ in file $module\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-06 05:44:12 +05:30
|
|
|
# build a complete dependency list for each module and make sure it
|
|
|
|
# is kept in order proper order
|
|
|
|
my $mod2 = {};
|
|
|
|
sub maybe_unshift
|
|
|
|
{
|
|
|
|
my ($array, $ele) = @_;
|
|
|
|
# chop off the leading path /lib/modules/<kver>/ as modprobe
|
|
|
|
# will handle relative paths just fine
|
|
|
|
$ele =~ s:^/lib/modules/[^/]*/::;
|
|
|
|
foreach (@{$array}) {
|
|
|
|
if ($_ eq $ele) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unshift (@{$array}, $ele);
|
|
|
|
}
|
2009-07-09 09:58:48 +05:30
|
|
|
sub add_mod_deps
|
|
|
|
{
|
|
|
|
my ($depth, $mod, $mod2, $module, $this_module) = @_;
|
|
|
|
|
|
|
|
$depth .= " ";
|
|
|
|
warn "${depth}loading deps of module: $this_module\n" if $verbose;
|
|
|
|
|
|
|
|
foreach my $md (keys %{$mod->{$this_module}}) {
|
|
|
|
add_mod_deps ($depth, $mod, $mod2, $module, $md);
|
|
|
|
warn "${depth} outputting $md\n" if $verbose;
|
|
|
|
maybe_unshift (\@{$$mod2->{$module}}, $md);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!%{$mod->{$this_module}}) {
|
|
|
|
warn "${depth} no deps\n" if $verbose;
|
|
|
|
}
|
|
|
|
}
|
2009-05-06 05:44:12 +05:30
|
|
|
foreach my $module (keys %$mod) {
|
2009-07-09 09:58:48 +05:30
|
|
|
warn "filling out module: $module\n" if $verbose;
|
|
|
|
@{$mod2->{$module}} = ();
|
|
|
|
add_mod_deps ("", $mod, \$mod2, $module, $module);
|
2009-05-06 05:44:12 +05:30
|
|
|
}
|
|
|
|
|
2006-03-21 22:05:50 +05:30
|
|
|
# figure out where the output should go
|
|
|
|
if ($stdout == 0) {
|
2009-07-09 09:58:48 +05:30
|
|
|
warn "writing $basedir/modules.dep\n" if $verbose;
|
2006-03-21 22:05:50 +05:30
|
|
|
open(STDOUT, ">$basedir/modules.dep")
|
|
|
|
or die "cannot open $basedir/modules.dep: $!";
|
|
|
|
}
|
|
|
|
my $kseries = $basedir =~ m,/2\.6\.[^/]*, ? '2.6' : '2.4';
|
|
|
|
|
|
|
|
foreach my $module ( keys %$mod ) {
|
|
|
|
if($kseries eq '2.4') {
|
|
|
|
print "$module:\t";
|
|
|
|
my @sorted = sort bydep keys %{$mod->{$module}};
|
|
|
|
print join(" \\\n\t",@sorted);
|
|
|
|
print "\n\n";
|
2001-07-31 01:02:03 +05:30
|
|
|
} else {
|
2009-05-06 05:44:12 +05:30
|
|
|
my $shortmod = $module;
|
|
|
|
$shortmod =~ s:^/lib/modules/[^/]*/::;
|
|
|
|
print "$shortmod:";
|
|
|
|
my @sorted = @{$mod2->{$module}};
|
|
|
|
printf " " if @sorted;
|
2006-03-21 22:05:50 +05:30
|
|
|
print join(" ",@sorted);
|
|
|
|
print "\n";
|
2001-07-31 01:02:03 +05:30
|
|
|
}
|
2006-03-21 22:05:50 +05:30
|
|
|
}
|
2001-07-31 01:02:03 +05:30
|
|
|
|
|
|
|
|
2006-03-21 22:05:50 +05:30
|
|
|
sub build_ref_tables
|
|
|
|
{
|
|
|
|
my ($name, $sym_ar, $exp, $dep) = @_;
|
|
|
|
|
2009-05-06 05:44:12 +05:30
|
|
|
my $ksymtab = grep m/ ${symprefix}__ksymtab/, @$sym_ar;
|
2001-07-31 01:02:03 +05:30
|
|
|
|
|
|
|
# gather the exported symbols
|
|
|
|
if($ksymtab){
|
|
|
|
# explicitly exported
|
2006-03-21 22:05:50 +05:30
|
|
|
foreach ( @$sym_ar ) {
|
2009-05-06 05:44:12 +05:30
|
|
|
/ ${symprefix}__ksymtab_(.*)$/ and do {
|
|
|
|
my $sym = ${symprefix} . $1;
|
|
|
|
warn "sym = $sym\n" if $verbose;
|
|
|
|
$exp->{$sym} = $name;
|
2001-07-31 01:02:03 +05:30
|
|
|
};
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
# exporting all symbols
|
2006-03-21 22:05:50 +05:30
|
|
|
foreach ( @$sym_ar ) {
|
2007-11-18 11:43:58 +05:30
|
|
|
/ [ABCDGRSTW] (.*)$/ and do {
|
2001-07-31 01:02:03 +05:30
|
|
|
warn "syma = $1\n" if $verbose;
|
2006-03-21 22:05:50 +05:30
|
|
|
$exp->{$1} = $name;
|
2001-07-31 01:02:03 +05:30
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2006-03-21 22:05:50 +05:30
|
|
|
|
|
|
|
# this takes makes sure modules with no dependencies get listed
|
2007-07-13 10:07:12 +05:30
|
|
|
push @{$dep->{$name}}, $symprefix . 'printk' unless $name eq 'vmlinux';
|
2006-03-21 22:05:50 +05:30
|
|
|
|
2001-07-31 01:02:03 +05:30
|
|
|
# gather the unresolved symbols
|
2006-03-21 22:05:50 +05:30
|
|
|
foreach ( @$sym_ar ) {
|
2009-05-06 05:44:12 +05:30
|
|
|
!/ ${symprefix}__this_module/ && / U (.*)$/ and do {
|
2001-07-31 01:02:03 +05:30
|
|
|
warn "und = $1\n" if $verbose;
|
2006-03-21 22:05:50 +05:30
|
|
|
push @{$dep->{$name}}, $1;
|
2001-07-31 01:02:03 +05:30
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub bydep
|
|
|
|
{
|
|
|
|
foreach my $f ( keys %{$mod->{$b}} ) {
|
|
|
|
if($f eq $a) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__END__
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
2006-03-21 22:05:50 +05:30
|
|
|
depmod.pl - a cross platform script to generate kernel module
|
|
|
|
dependency lists (modules.conf) which can then be used by modprobe
|
2006-09-17 21:58:10 +05:30
|
|
|
on the target platform.
|
2006-03-21 22:05:50 +05:30
|
|
|
|
|
|
|
It supports Linux 2.4 and 2.6 styles of modules.conf (auto-detected)
|
2001-07-31 01:02:03 +05:30
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
2002-10-09 03:03:51 +05:30
|
|
|
depmod.pl [OPTION]... [basedir]...
|
2001-07-31 01:02:03 +05:30
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2006-03-21 22:05:50 +05:30
|
|
|
depmod.pl -F linux/System.map -b target/lib/modules/2.6.11
|
2001-07-31 01:02:03 +05:30
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
The purpose of this script is to automagically generate a list of of kernel
|
2006-05-26 07:18:17 +05:30
|
|
|
module dependencies. This script produces dependency lists that should be
|
2001-07-31 01:02:03 +05:30
|
|
|
identical to the depmod program from the modutils package. Unlike the depmod
|
|
|
|
binary, however, depmod.pl is designed to be run on your host system, not
|
|
|
|
on your target system.
|
|
|
|
|
|
|
|
This script was written by David Schleef <ds@schleef.org> to be used in
|
|
|
|
conjunction with the BusyBox modprobe applet.
|
|
|
|
|
|
|
|
=head1 OPTIONS
|
|
|
|
|
|
|
|
=over 4
|
|
|
|
|
|
|
|
=item B<-h --help>
|
|
|
|
|
|
|
|
This displays the help message.
|
|
|
|
|
|
|
|
=item B<-b --basedir>
|
|
|
|
|
|
|
|
The base directory uner which the target's modules will be found. This
|
2006-09-17 21:58:10 +05:30
|
|
|
defaults to the /lib/modules directory.
|
2006-03-21 22:05:50 +05:30
|
|
|
|
|
|
|
If you don't specify the kernel version, this script will search for
|
|
|
|
one under the specified based directory and use the first thing that
|
|
|
|
looks like a kernel version.
|
2001-07-31 01:02:03 +05:30
|
|
|
|
|
|
|
=item B<-k --kernel>
|
|
|
|
|
2006-03-21 22:05:50 +05:30
|
|
|
Kernel binary for the target (vmlinux). You must either supply a kernel binary
|
2001-07-31 01:02:03 +05:30
|
|
|
or a kernel symbol file (using the -F option).
|
|
|
|
|
|
|
|
=item B<-F --kernelsyms>
|
|
|
|
|
2006-03-21 22:05:50 +05:30
|
|
|
Kernel symbol file for the target (System.map).
|
2001-07-31 01:02:03 +05:30
|
|
|
|
|
|
|
=item B<-n --stdout>
|
|
|
|
|
2006-03-21 22:05:50 +05:30
|
|
|
Write to stdout instead of modules.dep
|
2001-07-31 01:02:03 +05:30
|
|
|
kernel binary for the target (using the -k option).
|
|
|
|
|
|
|
|
=item B<--verbose>
|
|
|
|
|
2006-03-21 22:05:50 +05:30
|
|
|
Verbose (debug) output
|
2001-07-31 01:02:03 +05:30
|
|
|
|
|
|
|
=back
|
|
|
|
|
2006-03-21 22:05:50 +05:30
|
|
|
=head1 COPYRIGHT AND LICENSE
|
|
|
|
|
|
|
|
Copyright (c) 2001 David Schleef <ds@schleef.org>
|
|
|
|
Copyright (c) 2001 Erik Andersen <andersen@codepoet.org>
|
|
|
|
Copyright (c) 2001 Stuart Hughes <seh@zee2.com>
|
|
|
|
Copyright (c) 2002 Steven J. Hill <shill@broadcom.com>
|
|
|
|
Copyright (c) 2006 Freescale Semiconductor, Inc <stuarth@freescale.com>
|
2001-07-31 01:02:03 +05:30
|
|
|
|
2004-03-15 13:59:22 +05:30
|
|
|
This program is free software; you can redistribute it and/or modify it
|
2001-07-31 01:02:03 +05:30
|
|
|
under the same terms as Perl itself.
|
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
|
|
|
David Schleef <ds@schleef.org>
|
|
|
|
|
|
|
|
=cut
|