summaryrefslogtreecommitdiffstats
path: root/kernel/modules.pl
blob: 0cd7932241fa1e33173fabd74a4fa10bc630e02b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
use strict;


BEGIN {
    #- for testing purpose
    (my $f = __FILE__) =~ s|/[^/]*$||;
    push @INC, $f;
}

use MDK::Common;
use list_modules;


my @skip_big_modules_on_stage1 = (
qw(
olympic
sk98lin acenic
3c90x
ns83820
aironet4500_card aironet4500_core com20020-pci hamachi starfire winbond-840
fealnx

dc395x_trm
BusLogic seagate fdomain g_NCR5380
)
);

my @skip_modules_on_stage1 = (
  qw(sktr tmspci ibmtr abyss), # alt token ring
  qw(old_tulip rtl8139),
  qw(3c501 3c503 3c505 3c507 3c515), # unused, hopefully?
  'ataraid',  # ad-hoc raid which is unsupported in stage1 anyway
  if_(arch() =~ /alpha|ppc/, qw(sb1000)),
  qw(
  tg3 r8169
  apa1480_cb
  imm ppa plip
  3w-xxxx pci2220i qla2x00 i2o_block
  eata_pio eata_dma
  qla2200 qla2300
  iph5526
  ),
  'in2000', 'pas16', 'a100u2w', 'cpqfc',
  'AM53C974', # deprecated by tmscsim
  qw(ac3200 at1700 atp ni5010 ni52 ni65),  #- unused from Jeff
  "u14-34f", #- duplicate from ultrastor.o
);

my @modules_always_on_stage1 = qw(floppy);

my %images = (
    network => 'fs/network network/raw bus/pcmcia network/main',
    hd      => 'disk/raw fs/local|loopback disk/scsi|hardware_raid',
    other   => 'disk/scsi|hardware_raid network/main ONLY_BIG fs/cdrom disk/cdrom|raw fs/network network/raw',
    pcmcia  => 'fs/cdrom disk/cdrom|raw|pcmcia bus/pcmcia fs/network network/pcmcia|raw',
    cdrom   => 'fs/cdrom disk/cdrom|raw|scsi',
    usb     => 'fs/cdrom|local|loopback disk/cdrom|raw bus/usb disk/usb fs/network network/usb|raw bus/firewire disk/firewire',
    all     => 'fs/cdrom disk/cdrom|raw bus/usb disk/usb|scsi fs/loopback|local bus/pcmcia disk/pcmcia|hardware_raid fs/network network/main|pcmcia|usb|raw bus/firewire disk/firewire',
);

my $verbose = "@ARGV" =~ /-v/;
images() if "@ARGV" =~ /images/;
check() if "@ARGV" =~ /check/;
pci_modules4stage1($1) if "@ARGV" =~ /pci_modules4stage1:(.*)/;

sub images {
    load_dependencies('modules.dep');

    while (my ($image, $l) = each %images) {
	my @modules = @modules_always_on_stage1;
	foreach (split(' ', $l)) { 
	    if (/ONLY_BIG/) {
		@modules = intersection(\@modules, \@skip_big_modules_on_stage1);
		next;
	    }
	    push @modules, category2modules($_);
	}

	if ($image !~ /all/) {
	    @modules = difference2(\@modules, \@skip_modules_on_stage1);
	}
	if ($image !~ /other|all/) {
	    @modules = difference2(\@modules, \@skip_big_modules_on_stage1)
	}
	@modules = map { dependencies_closure($_) } @modules;
	printf qq(%s_modules="%s"\n), $image, join(" ", map { "$_.o" } @modules);
    }
}

sub pci_modules4stage1 {
    print "$_\n" foreach difference2([ category2modules($_[0]) ], \@skip_modules_on_stage1);
}

sub check {
    my $error;
    my %listed;
    my %big_modules_categories;
    while (my ($t1, $l) = each %list_modules::l) {
	while (my ($t2, $l) = each %$l) {
	    ref $l or die "bad $l in $t1/$t2";
	    foreach (@$l) {
		$listed{$_} = 1; 
		push @{$big_modules_categories{$t1}{$t2}}, $_ if member($_, @skip_modules_on_stage1);
	    }
	}
    }

    # remove accepted categories for other.img
    delete $big_modules_categories{disk}{hardware_raid};
    delete $big_modules_categories{disk}{scsi};
    delete $big_modules_categories{network}{main};

    if (map { %$_ } values %big_modules_categories) {
	my @l = map { "$_/" . join('|', sort keys %{$big_modules_categories{$_}}) } sort keys %big_modules_categories;
	print STDERR "WEIRD CATEGORIES USED FOR other.img: ", join(" ", @l), "\n";
	if ($verbose) {
	    while (my ($t1, $t2s) = each %big_modules_categories) {
		print "$t1/$_ used for other.img: ", join(" ", @{$t2s->{$_}}), "\n" foreach keys %$t2s;
	    }
	}
	$error = 1;
    }

    my %module2category;
    my %deprecated_modules = %listed;
    my $not_listed = sub {
	my ($msg, $verbose, @l) = @_;
	my %not_listed;
	foreach (@l) {
	    my ($mod) = m|([^/]*)\.o(\.gz)?$| or next;
	    delete $deprecated_modules{$mod};
	    next if $listed{$mod};
	    s|.*?mdk(BOOT)?/||;
	    s|kernel/||; s|drivers/||; s|3rdparty/||;
	    $_ = dirname $_;
	    $_ = dirname $_ if $mod eq basename($_);
	    $module2category{$mod} = $_;
	    push @{$not_listed{$_}}, $mod;
	}
	if ($verbose) {
	    print "$msg $_: ", join(" ", @{$not_listed{$_}}), "\n" foreach sort keys %not_listed;
	}
    };
    $not_listed->('NOT LISTED', 1, `cd all.kernels/2.4* ; find -name "*.o" -o -name "*.o.gz"`);
    $not_listed->('not listed', $verbose, `rpm -qpl /RPMS/kernel-2.4*`);
    print "bad/old modules : ", join(" ", sort keys %deprecated_modules), "\n" if %deprecated_modules;

    {
	require '/usr/bin/merge2pcitable.pl';
	my $pcitable = read_pcitable("/usr/share/ldetect-lst/pcitable");
	my $usbtable = read_pcitable("/usr/share/ldetect-lst/usbtable");

	my @l = uniq grep { !/:/ && $_ ne 'unknown' } map { $_->[0] } values %$pcitable;
	if (my @l = difference2(\@l, [ keys %listed ])) {
	    my %not_listed;
	    push @{$not_listed{$module2category{$_}}}, $_ foreach @l;
	    print STDERR "PCITABLE MODULES NOT LISTED $_: ", join(" ", @{$not_listed{$_}}), "\n" foreach sort keys %not_listed;
	    #$error = 1;
	}

	my @l = uniq grep { !/:/ && $_ ne 'unknown' } map { $_->[0] } values %$usbtable;
	if (my @l = difference2(\@l, [ keys %listed ])) {
	    my %not_listed;
	    push @{$not_listed{$module2category{$_}}}, $_ foreach @l;
	    if ($verbose) {
		print "usbtable modules not listed $_: ", join(" ", @{$not_listed{$_}}), "\n" foreach sort keys %not_listed;
	    }
	}
    }

    exit $error;
}