summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Vignaud <thierry.vignaud@gmail.com>2016-05-08 15:23:52 +0200
committerThomas Backlund <tmb@mageia.org>2016-09-25 18:19:33 +0300
commit8368cfb7f887199bc366c9ce233cc1fb30b0b066 (patch)
treebed5b54006f6330a5ddcb5b7d09ed8003ce187b1
parent47a242eb87e4f48a38a4f68d2b584c689e7cb517 (diff)
downloaddrakx-8368cfb7f887199bc366c9ce233cc1fb30b0b066.tar
drakx-8368cfb7f887199bc366c9ce233cc1fb30b0b066.tar.gz
drakx-8368cfb7f887199bc366c9ce233cc1fb30b0b066.tar.bz2
drakx-8368cfb7f887199bc366c9ce233cc1fb30b0b066.tar.xz
drakx-8368cfb7f887199bc366c9ce233cc1fb30b0b066.zip
I should have put that script in git years ago
(cherry picked from commit 77b42146a38816672bf69044a2a9b207e7c20769)
-rw-r--r--perl-install/Makefile5
-rwxr-xr-xtools/find-drivers-needing-nonfree-firmware93
2 files changed, 98 insertions, 0 deletions
diff --git a/perl-install/Makefile b/perl-install/Makefile
index 0fec1e311..caf2d849b 100644
--- a/perl-install/Makefile
+++ b/perl-install/Makefile
@@ -84,3 +84,8 @@ check_perl_checker:
rm -f share/po/libDrakX.pot install/share/po/DrakX.pot
@make -C share/po libDrakX.pot
@make -C install/share/po DrakX.pot
+
+list_firmwares.pm:
+ ../tools/find-drivers-needing-nonfree-firmware
+
+.PHONY: list_firmwares.pm
diff --git a/tools/find-drivers-needing-nonfree-firmware b/tools/find-drivers-needing-nonfree-firmware
new file mode 100755
index 000000000..f0614fcf3
--- /dev/null
+++ b/tools/find-drivers-needing-nonfree-firmware
@@ -0,0 +1,93 @@
+#!/usr/bin/perl
+use MDK::Common;
+use Data::Dumper;
+use Data::Dumper::Perltidy;
+
+my $debug = member('--debug', @ARGV);
+
+my $path = '../../cache';
+my %cache = (
+ version => "$path/version.txt",
+ modules => "$path/modules.txt",
+ firmwares => "$path/firmwares.txt",
+ modinfo => "$path/modinfo.",
+ );
+
+mkdir_p($path) if !-d $path;
+# version of main kernel flavor:
+my $kernel = chomp_(cat_($cache{version}));
+if (!$kernel) {
+ # get regular flavor:
+ ($kernel) = split('\|', chomp_(`urpmq -f kernel-desktop-latest`));
+ # get real package name:
+ $kernel =~ s/-latest//;
+ # drop arch as it confuses urpmq:
+ $kernel =~ s/\.[^.]*$//;
+ output($cache{version}, $kernel);
+}
+warn ">> GOT '$kernel'\n" if $debug;
+
+# list of modules:
+my @modules = cat_($cache{modules});
+if (!@modules) {
+ @modules = grep { /\.ko/ } `urpmq -l $kernel`;
+ output($cache{modules}, @modules);
+}
+@modules = map { chomp; $_ } @modules;
+
+# list of those module firmwares:
+my %firmwares;
+{
+ my @firmwares = cat_($cache{firmwares});
+ if (!@firmwares) {
+ @firmwares = `urpmf --qf '%name-%version-%release.%arch:%files' /lib/firmware/ |sort -u`;
+ output($cache{firmwares}, @firmwares);
+ }
+ %firmwares = map { chomp; s!^(.*):/lib/firmware/!!; $_ => $1 } @firmwares;
+}
+
+#warn Data::Dumper->Dump([ \@modules ], [ 'modules' ]);
+warn Data::Dumper->Dump([ \%firmwares ], [ 'firmwares' ]) if $debug;
+
+# compute list of module that needs nonfree firmwares:
+my @non_free_fw_drivers;
+foreach (@modules) {
+ my ($raw) = m!([^/]*)$!;
+ my $cache = $cache{modinfo} . $raw;
+ my @firmwares = cat_($cache);
+ # speedup: cache might exists but being empty:
+ if (!-e $cache) {
+ #warn ">> run '/sbin/modinfo $_ | grep firmware:'\n" if $debug;
+ @firmwares = `/sbin/modinfo $_ | grep firmware:`;
+ output($cache, @firmwares);
+ }
+ @firmwares = map { chomp; s/^.*:\s+//; $_ } @firmwares;
+ next if !@firmwares;
+ warn Data::Dumper->Dump([ \@firmwares ], [ 'firmware' ]) if $debug;
+ if (any { $firmwares{$_} && $firmwares{$_} =~ /nonfree/ } @firmwares) {
+ push @non_free_fw_drivers, $_;
+ #last;
+ }
+}
+
+# cleaning:
+@non_free_fw_drivers = sort map { s!.*/!!; s!\.ko.*$!!; $_ } @non_free_fw_drivers;
+
+#$Data::Dumper::Perltidy::ARGV = '-it=2 -l 100';
+#warn Dumper(\@non_free_fw_drivers) . "\n";
+
+# Pretty dump:
+my $sep = ' ';
+my $s = $sep . 'qw(' . join(' ', @non_free_fw_drivers) . ')';
+$s =~ s/(.{70}\S*)\s+/$1\n$sep/g;
+
+output('list_firmwares.pm',
+ q(# This list is autogenerated ; Do NOT alter manually.
+
+package list_firmwares;
+
+our @modules_with_nonfree_firmware =
+),
+ $s, ";\n\n1;\n");
+
+