2001-07-30 19:32:03 +00:00
|
|
|
#!/usr/bin/perl -w
|
2006-07-02 19:47:05 +00:00
|
|
|
# vi: set sw=4 ts=4:
|
2001-07-30 19:32:03 +00:00
|
|
|
# Copyright (c) 2001 David Schleef <ds@schleef.org>
|
2003-07-14 21:21:08 +00:00
|
|
|
# Copyright (c) 2001 Erik Andersen <andersen@codepoet.org>
|
2006-03-21 16:35:50 +00:00
|
|
|
# Copyright (c) 2001 Stuart Hughes <seh@zee2.com>
|
2002-10-08 21:33:51 +00:00
|
|
|
# Copyright (c) 2002 Steven J. Hill <shill@broadcom.com>
|
2006-03-21 16:35:50 +00:00
|
|
|
# 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 08:29:22 +00:00
|
|
|
# This program is free software; you can redistribute it and/or modify it
|
2001-07-30 19:32:03 +00:00
|
|
|
# under the same terms as Perl itself.
|
2009-05-06 00:14:12 +00:00
|
|
|
use Getopt::Long qw(:config no_auto_abbrev no_ignore_case);
|
2001-07-30 19:32:03 +00:00
|
|
|
use File::Find;
|
2006-03-21 16:35:50 +00:00
|
|
|
use strict;
|
2001-07-30 19:32:03 +00:00
|
|
|
|
|
|
|
# Set up some default values
|
2006-03-21 16:35:50 +00:00
|
|
|
my $kdir="";
|
2001-07-30 19:32:03 +00:00
|
|
|
my $basedir="";
|
2006-03-21 16:35:50 +00:00
|
|
|
my $kernel="";
|
|
|
|
my $kernelsyms="";
|
2007-07-13 04:37:12 +00:00
|
|
|
my $symprefix="";
|
2009-05-06 00:14:12 +00:00
|
|
|
my $all=0;
|
|
|
|
my $quick=0;
|
|
|
|
my $errsyms=0;
|
2002-10-08 21:33:51 +00:00
|
|
|
my $stdout=0;
|
2001-07-30 19:32:03 +00:00
|
|
|
my $verbose=0;
|
2006-03-21 16:35:50 +00:00
|
|
|
my $help=0;
|
2006-06-02 21:30:40 +00:00
|
|
|
my $nm = $ENV{'NM'} || "nm";
|
2006-03-21 16:35:50 +00:00
|
|
|
|
|
|
|
# more globals
|
|
|
|
my (@liblist) = ();
|
|
|
|
my $exp = {};
|
|
|
|
my $dep = {};
|
|
|
|
my $mod = {};
|
|
|
|
|
|
|
|
my $usage = <<TXT;
|
2006-09-17 16:28:10 +00:00
|
|
|
$0 -b basedir { -k <vmlinux> | -F <System.map> } [options]...
|
2006-03-21 16:35:50 +00:00
|
|
|
Where:
|
2007-07-13 04:37:12 +00:00
|
|
|
-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 00:14:12 +00:00
|
|
|
-a --all : Probe all modules (default/only thing supported)
|
|
|
|
-e --errsyms : Report any symbols not supplied by modules/kernel
|
2006-03-21 16:35:50 +00:00
|
|
|
TXT
|
2001-07-30 19:32:03 +00:00
|
|
|
|
|
|
|
# get command-line options
|
|
|
|
GetOptions(
|
2007-07-13 04:37:12 +00:00
|
|
|
"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 00:14:12 +00:00
|
|
|
"all|a" => \$all,
|
|
|
|
# unsupported options
|
|
|
|
"quick|A" => \$quick,
|
|
|
|
# ignored options (for historical usage)
|
|
|
|
"quiet|q",
|
|
|
|
"root|r",
|
|
|
|
"unresolved-error|u"
|
2001-07-30 19:32:03 +00:00
|
|
|
);
|
|
|
|
|
2006-03-21 16:35:50 +00:00
|
|
|
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 00:14:12 +00:00
|
|
|
die "sorry, -A/--quick is not supported" if $quick;
|
|
|
|
die "--errsyms requires --kernelsyms" if $errsyms && !$kernelsyms;
|
2001-07-30 19:32:03 +00:00
|
|
|
|
2006-03-21 16:35:50 +00:00
|
|
|
# Strip any trailing or multiple slashes from basedir
|
2009-05-06 00:14:12 +00:00
|
|
|
$basedir =~ s-/+$--g;
|
2006-03-21 16:35:50 +00:00
|
|
|
|
|
|
|
# The base directory should contain /lib/modules somewhere
|
2001-07-30 19:32:03 +00:00
|
|
|
if($basedir !~ m-/lib/modules-) {
|
|
|
|
warn "WARNING: base directory does not match ..../lib/modules\n";
|
|
|
|
}
|
|
|
|
|
2006-03-21 16:35:50 +00:00
|
|
|
# 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 08:29:22 +00:00
|
|
|
find sub {
|
2006-03-21 16:35:50 +00:00
|
|
|
my $file;
|
2004-03-15 08:29:22 +00:00
|
|
|
if ( -f $_ && ! -d $_ ) {
|
2001-07-30 19:32:03 +00:00
|
|
|
$file = $File::Find::name;
|
2006-03-21 16:35:50 +00:00
|
|
|
if ( $file =~ /\.k?o$/ ) {
|
2001-07-30 19:32:03 +00:00
|
|
|
push(@liblist, $file);
|
2006-03-21 16:35:50 +00:00
|
|
|
warn "$file\n" if $verbose;
|
2001-07-30 19:32:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}, $basedir;
|
2006-03-21 16:35:50 +00:00
|
|
|
warn "**** Finished locating modules\n" if $verbose;
|
2001-07-30 19:32:03 +00:00
|
|
|
|
2006-03-21 16:35:50 +00:00
|
|
|
foreach my $obj ( @liblist ){
|
2001-07-30 19:32:03 +00:00
|
|
|
# turn the input file name into a target tag name
|
2006-03-21 16:35:50 +00:00
|
|
|
my ($tgtname) = $obj =~ m-(/lib/modules/.*)$-;
|
|
|
|
|
|
|
|
warn "\nMODULE = $tgtname\n" if $verbose;
|
|
|
|
|
|
|
|
# get a list of symbols
|
2006-06-02 21:30:40 +00:00
|
|
|
my @output=`$nm $obj`;
|
2006-03-21 16:35:50 +00:00
|
|
|
|
|
|
|
build_ref_tables($tgtname, \@output, $exp, $dep);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# vmlinux is a special name that is only used to resolve symbols
|
|
|
|
my $tgtname = 'vmlinux';
|
2006-06-02 21:30:40 +00:00
|
|
|
my @output = $kernelsyms ? `cat $kernelsyms` : `$nm $kernel`;
|
2006-03-21 16:35:50 +00:00
|
|
|
warn "\nMODULE = $tgtname\n" if $verbose;
|
|
|
|
build_ref_tables($tgtname, \@output, $exp, $dep);
|
|
|
|
|
2006-05-26 01:48:17 +00:00
|
|
|
# resolve the dependencies for each module
|
|
|
|
# reduce dependencies: remove unresolvable and resolved from vmlinux/System.map
|
2006-03-21 16:35:50 +00:00
|
|
|
# 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 00:14:12 +00:00
|
|
|
# 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 04:28:48 +00:00
|
|
|
sub add_mod_deps
|
|
|
|
{
|
|
|
|
my ($depth, $mod, $mod2, $module, $this_module) = @_;
|
|
|
|
|
|
|
|
$depth .= " ";
|
|
|
|
warn "${depth}loading deps of module: $this_module\n" if $verbose;
|
2010-11-16 12:15:00 +00:00
|
|
|
if (length($depth) > 50) {
|
|
|
|
die "too much recursion (circular dependencies in modules?)";
|
|
|
|
}
|
2009-07-09 04:28:48 +00:00
|
|
|
|
|
|
|
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 00:14:12 +00:00
|
|
|
foreach my $module (keys %$mod) {
|
2009-07-09 04:28:48 +00:00
|
|
|
warn "filling out module: $module\n" if $verbose;
|
|
|
|
@{$mod2->{$module}} = ();
|
|
|
|
add_mod_deps ("", $mod, \$mod2, $module, $module);
|
2009-05-06 00:14:12 +00:00
|
|
|
}
|
|
|
|
|
2006-03-21 16:35:50 +00:00
|
|
|
# figure out where the output should go
|
|
|
|
if ($stdout == 0) {
|
2009-07-09 04:28:48 +00:00
|
|
|
warn "writing $basedir/modules.dep\n" if $verbose;
|
2006-03-21 16:35:50 +00:00
|
|
|
open(STDOUT, ">$basedir/modules.dep")
|
|
|
|
or die "cannot open $basedir/modules.dep: $!";
|
|
|
|
}
|
2011-09-09 16:58:08 +00:00
|
|
|
my $kseries = $basedir =~ m,/2\.4\.[^/]*, ? '2.4' : 'others';
|
2006-03-21 16:35:50 +00:00
|
|
|
|
|
|
|
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-30 19:32:03 +00:00
|
|
|
} else {
|
2009-05-06 00:14:12 +00:00
|
|
|
my $shortmod = $module;
|
|
|
|
$shortmod =~ s:^/lib/modules/[^/]*/::;
|
|
|
|
print "$shortmod:";
|
|
|
|
my @sorted = @{$mod2->{$module}};
|
|
|
|
printf " " if @sorted;
|
2006-03-21 16:35:50 +00:00
|
|
|
print join(" ",@sorted);
|
|
|
|
print "\n";
|
2001-07-30 19:32:03 +00:00
|
|
|
}
|
2006-03-21 16:35:50 +00:00
|
|
|
}
|
2001-07-30 19:32:03 +00:00
|
|
|
|
|
|
|
|
2006-03-21 16:35:50 +00:00
|
|
|
sub build_ref_tables
|
|
|
|
{
|
|
|
|
my ($name, $sym_ar, $exp, $dep) = @_;
|
|
|
|
|
2009-05-06 00:14:12 +00:00
|
|
|
my $ksymtab = grep m/ ${symprefix}__ksymtab/, @$sym_ar;
|
2001-07-30 19:32:03 +00:00
|
|
|
|
|
|
|
# gather the exported symbols
|
|
|
|
if($ksymtab){
|
|
|
|
# explicitly exported
|
2006-03-21 16:35:50 +00:00
|
|
|
foreach ( @$sym_ar ) {
|
2009-05-06 00:14:12 +00:00
|
|
|
/ ${symprefix}__ksymtab_(.*)$/ and do {
|
|
|
|
my $sym = ${symprefix} . $1;
|
|
|
|
warn "sym = $sym\n" if $verbose;
|
|
|
|
$exp->{$sym} = $name;
|
2001-07-30 19:32:03 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
# exporting all symbols
|
2006-03-21 16:35:50 +00:00
|
|
|
foreach ( @$sym_ar ) {
|
2007-11-18 06:13:58 +00:00
|
|
|
/ [ABCDGRSTW] (.*)$/ and do {
|
2001-07-30 19:32:03 +00:00
|
|
|
warn "syma = $1\n" if $verbose;
|
2006-03-21 16:35:50 +00:00
|
|
|
$exp->{$1} = $name;
|
2001-07-30 19:32:03 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2006-03-21 16:35:50 +00:00
|
|
|
|
|
|
|
# this takes makes sure modules with no dependencies get listed
|
2007-07-13 04:37:12 +00:00
|
|
|
push @{$dep->{$name}}, $symprefix . 'printk' unless $name eq 'vmlinux';
|
2006-03-21 16:35:50 +00:00
|
|
|
|
2001-07-30 19:32:03 +00:00
|
|
|
# gather the unresolved symbols
|
2006-03-21 16:35:50 +00:00
|
|
|
foreach ( @$sym_ar ) {
|
2009-05-06 00:14:12 +00:00
|
|
|
!/ ${symprefix}__this_module/ && / U (.*)$/ and do {
|
2001-07-30 19:32:03 +00:00
|
|
|
warn "und = $1\n" if $verbose;
|
2006-03-21 16:35:50 +00:00
|
|
|
push @{$dep->{$name}}, $1;
|
2001-07-30 19:32:03 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub bydep
|
|
|
|
{
|
|
|
|
foreach my $f ( keys %{$mod->{$b}} ) {
|
|
|
|
if($f eq $a) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__END__
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
2006-03-21 16:35:50 +00:00
|
|
|
depmod.pl - a cross platform script to generate kernel module
|
|
|
|
dependency lists (modules.conf) which can then be used by modprobe
|
2006-09-17 16:28:10 +00:00
|
|
|
on the target platform.
|
2006-03-21 16:35:50 +00:00
|
|
|
|
|
|
|
It supports Linux 2.4 and 2.6 styles of modules.conf (auto-detected)
|
2001-07-30 19:32:03 +00:00
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
2002-10-08 21:33:51 +00:00
|
|
|
depmod.pl [OPTION]... [basedir]...
|
2001-07-30 19:32:03 +00:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2006-03-21 16:35:50 +00:00
|
|
|
depmod.pl -F linux/System.map -b target/lib/modules/2.6.11
|
2001-07-30 19:32:03 +00:00
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
The purpose of this script is to automagically generate a list of of kernel
|
2006-05-26 01:48:17 +00:00
|
|
|
module dependencies. This script produces dependency lists that should be
|
2001-07-30 19:32:03 +00:00
|
|
|
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 16:28:10 +00:00
|
|
|
defaults to the /lib/modules directory.
|
2006-03-21 16:35:50 +00:00
|
|
|
|
|
|
|
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-30 19:32:03 +00:00
|
|
|
|
|
|
|
=item B<-k --kernel>
|
|
|
|
|
2006-03-21 16:35:50 +00:00
|
|
|
Kernel binary for the target (vmlinux). You must either supply a kernel binary
|
2001-07-30 19:32:03 +00:00
|
|
|
or a kernel symbol file (using the -F option).
|
|
|
|
|
|
|
|
=item B<-F --kernelsyms>
|
|
|
|
|
2006-03-21 16:35:50 +00:00
|
|
|
Kernel symbol file for the target (System.map).
|
2001-07-30 19:32:03 +00:00
|
|
|
|
|
|
|
=item B<-n --stdout>
|
|
|
|
|
2006-03-21 16:35:50 +00:00
|
|
|
Write to stdout instead of modules.dep
|
2001-07-30 19:32:03 +00:00
|
|
|
kernel binary for the target (using the -k option).
|
|
|
|
|
|
|
|
=item B<--verbose>
|
|
|
|
|
2006-03-21 16:35:50 +00:00
|
|
|
Verbose (debug) output
|
2001-07-30 19:32:03 +00:00
|
|
|
|
|
|
|
=back
|
|
|
|
|
2006-03-21 16:35:50 +00:00
|
|
|
=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-30 19:32:03 +00:00
|
|
|
|
2004-03-15 08:29:22 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify it
|
2001-07-30 19:32:03 +00:00
|
|
|
under the same terms as Perl itself.
|
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
|
|
|
David Schleef <ds@schleef.org>
|
|
|
|
|
|
|
|
=cut
|