summaryrefslogtreecommitdiffstats
path: root/mdk-stage1/usb-resource/update-usb-ids.pl
blob: 2e66db638a4dc66e1ec355b1a059e8e1b718c2a4 (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
#!/usr/bin/perl


sub cat_ { local *F; open F, $_[0] or $_[1] ? die "cat of file $_[0] failed: $!\n" : return; my @l = <F>; wantarray ? @l : join '', @l }


-x "../mar/mar" or die "\t*FAILED* Sorry, need ../mar/mar binary\n";


my @usbtable_tmp = cat_("/usr/share/ldetect-lst/usbtable");
my @usbtable;
foreach (@usbtable_tmp) {
    next if /\s*#/;
    /\s*(\S+)\s+(\S+)\s+"(\S+)"\s+"([^"]*)"/ or next;
    push @usbtable, { 'vendor' => $1, 'id' => $2, 'module' => $3, 'description' => $4 };
}


print '
struct usb_module_map {
	unsigned short	vendor;     /* vendor */
	unsigned short	id;         /* device */
	const char      *name;      /* human readable name */
	const char      *module;    /* module to load */
};
';

print "#ifdef ENABLE_USB
struct pci_module_map usb_pci_ids[] = {

";

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

while (my ($k, $v) = each %$drivers) {
    $v->[0] =~ /^usb-/ or next;
    $k =~ /^(....)(....)/;
    printf qq|\t{ 0x%s, 0x%s, "", "%s" },\n|,
      $1, $2, $v->[0];
}

print "};
int usb_num_ids=sizeof(usb_pci_ids)/sizeof(struct pci_module_map);
#endif
";


my @t = ('usbnet');


foreach $type (@t) {
    my $modulez;
    foreach (glob("../../all.modules/*/${type}_modules.mar")) {
	-f $_ or die "\t*FAILED* Sorry, need $_ mar file\n";
	push @$modulez, (`../mar/mar -l $_`);
    }

    print "#ifdef ENABLE_".uc($type)."
struct usb_module_map ${type}_usb_ids[] = {
";
    foreach my $usbentry (@usbtable) {
	grep(/^\t$usbentry->{'module'}\.o\s/, @$modulez) or next;
	printf qq|\t{ %s, %s, "%s", "%s" },\n|,
	   $usbentry->{'vendor'}, $usbentry->{'id'}, $usbentry->{'description'}, $usbentry->{'module'};
    }

    print "};
int ${type}_usb_num_ids=sizeof(${type}_usb_ids)/sizeof(struct usb_module_map);
#endif
";

}