summaryrefslogtreecommitdiffstats
path: root/kernel/check_module_list.pl
blob: e028c1d72b73e117e7d0dc17106ed9d151a0ca67 (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
#!/usr/bin/perl

use lib './'; # use the local version of list_modules.pm

use strict;
use MDK::Common;
use File::Basename;
use list_modules;

if (@ARGV != 1) {
    print "Usage: check_module_list.pl kernel-desktop-<version>.rpm\n";
    exit(1);
}
my $rpm = $ARGV[0];
-f $rpm or die "Could not find RPM file '$rpm'\n";

my $kernel_version;
if ($rpm =~ /^kernel-(\w+)-(\d+\.\d+\.\d+)-(\d+\.mga\d+)/) {
    $kernel_version = "$2-$1-$3";
} else {
    die "Failed to extract kernel version from RPM file name\n";
}
print "* kernel version : $kernel_version\n";

my $cmd1 = "rpm2cpio $rpm | cpio --extract --to-stdout --quiet ./lib/modules/$kernel_version/modules.dep | sort";
open(my $pipe1, '-|', $cmd1) or die "Failed to execute '$cmd1: $!'\n";

my @module_list;
while (<$pipe1>) {
    my ($module, $discard) = split(':', $_);
    push @module_list, $module;
}

my $cmd2 = "rpm2cpio $rpm | cpio --extract --to-stdout --quiet ./lib/modules/$kernel_version/modules.alias";
open(my $pipe2, '-|', $cmd2) or die "Failed to execute '$cmd2': $!\n";

my %module_types;
while (<$pipe2>) {
    if ($_ =~ /alias\s+([a-z*]+):(\S+) (\S+)/) {
        $module_types{$3} = $1 if $1 eq 'pci'    || $1 eq 'usb'   || $1 eq 'firewire'
                               || $1 eq 'pcmcia' || $1 eq 'dmi'   || $1 eq 'acpi'
                               || $1 eq 'hid'    || $1 eq 'serio' || $1 eq 'mdio';
    }
}

my $cmd3 = "rpm2cpio $rpm | cpio --extract --to-stdout --quiet ./lib/modules/$kernel_version/modules.description";
open(my $pipe3, '-|', $cmd3) or die "Failed to execute '$cmd3': $!\n";

my %module_descriptions;
while (<$pipe3>) {
    if ($_ =~ /^(\S+)\s+(.*)$/) {
        $module_descriptions{$1} = $2;
    }
}

my $cmd4 = "rpm2cpio $rpm | cpio --extract --to-stdout --quiet ./lib/modules/$kernel_version/modules.builtin";
open(my $pipe4, '-|', $cmd4) or die "Failed to execute '$cmd4: $!'\n";

my %builtin_modules;
while (<$pipe4>) {
    chomp($_);
    my $path = dirname($_);
    my $name = basename($_, '.ko');
    $builtin_modules{$name} = $path;
}

print "**********************************************\n";
print "* Listing driver modules found in the RPM file\n";
print "**********************************************\n";

my %listed_in_rpm;
my %listed_in_drakx;

foreach (@module_list) {
    my $path = dirname($_);
    my $name = basename($_, ".ko.xz");
    $listed_in_rpm{$name} = 1;
    my $module_name = $name =~ s/-/_/gr;
    my $type = $module_types{$module_name};
    $type ||= 'snd-sof' if $path =~ m|sound/soc/sof|;
    $type ||= 'platform' if $path =~ m|drivers/platform/x86|;
    # skip if this is not a recognised driver type
    next if !defined($type);
    my $category = list_modules::module2category($name);
    if ($category) {
        print("# $path $name $type $category\n");
        $listed_in_drakx{$name} = 1;
    } else {
        my $description = $module_descriptions{$name};
        print("  $path $name $type '$description'\n");
    }
}

print "******************************************\n";
print "* Listing modules found in list_modules.pm\n";
print "******************************************\n";

my @mk = sort(keys %list_modules::l);
foreach my $mc (@mk) {
    my $ml = $list_modules::l{$mc};
    my @sk = sort(keys %{$ml});
    foreach my $sc (@sk) {
        my $sl = ${$ml}{$sc};
        foreach my $name (@$sl) {
            if ($listed_in_drakx{$name}) {
                print '# ';
            } elsif ($listed_in_rpm{$name}) {
                print '  ';
            } elsif ($builtin_modules{$name}) {
                print '= ';
            } else {
                print '! ';
            }
            print "$mc/$sc $name\n" 
        }
    }
}

1;