2011-06-10 16:21:32 +00:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
#
|
|
|
|
# generate_firmware_task
|
|
|
|
#
|
|
|
|
# Work out which firmware packages we need
|
|
|
|
# Several steps:
|
|
|
|
#
|
|
|
|
# 1. Look for packages which contain "firmware" or "microcode" in their package names
|
|
|
|
# 2. Check each of those packages to see if they contain files in /lib/firmware
|
|
|
|
# 3. For those that do, output the package name into the firmware task
|
|
|
|
#
|
|
|
|
# Copyright Steve McIntyre <93sam@debian.org> 2011
|
2023-01-26 21:22:40 -01:00
|
|
|
# Copyright Cyril Brulebois <kibi@debian.org> 2023
|
2011-06-10 16:21:32 +00:00
|
|
|
#
|
|
|
|
# GPL 2
|
|
|
|
#
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
2018-08-13 13:36:36 +00:00
|
|
|
my ($mirror, $codename, $archlist, $outfile, $localdebs, $backports);
|
2011-06-10 16:21:32 +00:00
|
|
|
my $date;
|
2023-01-26 21:22:40 -01:00
|
|
|
my (@pkgfiles, @bp_pkgfiles);
|
2012-03-05 15:13:17 -01:00
|
|
|
my ($pkg, $filename, $arch);
|
2011-06-10 16:21:32 +00:00
|
|
|
my %seen;
|
2023-01-26 21:22:40 -01:00
|
|
|
my @components;
|
|
|
|
|
2023-01-26 21:22:40 -01:00
|
|
|
|
|
|
|
sub contains_firmware($$) {
|
|
|
|
my $count = 0;
|
|
|
|
open (PKGLISTING, "dpkg --contents $mirror/$filename | grep ' ./lib/firmware/' |") or
|
|
|
|
die "Can't check package file $filename: $!\n";
|
|
|
|
while ($_ = <PKGLISTING>) {
|
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
if ($count) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-26 21:22:40 -01:00
|
|
|
sub check_packages($$@) {
|
|
|
|
my ($use_bp, $orig_mode, @pkgfiles) = @_;
|
2023-01-26 21:22:40 -01:00
|
|
|
|
2023-01-26 21:22:40 -01:00
|
|
|
for my $pkgfile (@pkgfiles) {
|
|
|
|
open (INPKG, "\$BASEDIR/tools/catz $pkgfile |") or die "Can't read input package files: $!\n";
|
|
|
|
$/ = ''; # Browse by paragraph
|
2023-01-26 21:22:40 -01:00
|
|
|
|
2023-01-26 21:22:40 -01:00
|
|
|
while (defined($_ = <INPKG>)) {
|
|
|
|
m/^Package: (\S+)/m and $pkg = $1;
|
|
|
|
m/^Filename: (\S+)/m and $filename = $1;
|
2023-01-26 21:22:40 -01:00
|
|
|
|
2023-01-26 21:22:40 -01:00
|
|
|
if (! ($pkg =~ /(microcode|firmware)/)) {
|
|
|
|
next;
|
|
|
|
}
|
2023-01-26 21:22:40 -01:00
|
|
|
|
2023-01-26 21:22:40 -01:00
|
|
|
if (!exists $seen{$filename}) {
|
|
|
|
$seen{$filename} = 1;
|
|
|
|
if (contains_firmware($mirror, $filename)) {
|
2023-01-27 05:38:40 -01:00
|
|
|
printf STDERR " %-35s (%s)\n", $pkg, $filename;
|
2023-01-26 21:22:40 -01:00
|
|
|
if ($orig_mode) {
|
|
|
|
if ($use_bp) {
|
|
|
|
print OUT "$pkg/$codename-backports\n";
|
|
|
|
} else {
|
|
|
|
print OUT "$pkg\n";
|
|
|
|
}
|
2023-01-26 21:22:40 -01:00
|
|
|
} else {
|
2023-01-26 21:22:40 -01:00
|
|
|
print "$filename $pkgfile\n";
|
2023-01-26 21:22:40 -01:00
|
|
|
}
|
2023-01-26 21:22:40 -01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-01-26 21:22:40 -01:00
|
|
|
close INPKG;
|
2023-01-26 21:22:40 -01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-26 21:22:40 -01:00
|
|
|
# Either the caller tells us explicitly which components to use, or we make this
|
|
|
|
# determination on our own, based on various environment variables:
|
|
|
|
sub read_env {
|
|
|
|
my $env_var = shift;
|
|
|
|
my $default = shift;
|
|
|
|
|
|
|
|
if (exists($ENV{$env_var})) {
|
|
|
|
return $ENV{$env_var};
|
|
|
|
}
|
|
|
|
# else
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Either the caller tells us explicitly which components to use, or we make this
|
|
|
|
# determination on our own, based on various environment variables, just like
|
|
|
|
# tools/apt-selection does:
|
|
|
|
@components = split /\ /, read_env('FIRMWARE_COMPONENTS', '');
|
|
|
|
if (!@components) {
|
|
|
|
@components = qw(main);
|
|
|
|
if (read_env('CONTRIB', 0) == 1) {
|
|
|
|
push @components, qw(contrib);
|
|
|
|
}
|
|
|
|
if (read_env('NONFREE', 0) == 1 or read_env('EXTRANONFREE', 0) == 1 or read_env('FORCE_FIRMWARE', 0) == 1) {
|
|
|
|
push @components, (split / /, read_env('NONFREE_COMPONENTS', ''));
|
|
|
|
}
|
|
|
|
}
|
2011-06-10 16:21:32 +00:00
|
|
|
$codename = $ENV{'CODENAME'};
|
|
|
|
$mirror = $ENV{'MIRROR'};
|
2012-03-05 12:41:01 -01:00
|
|
|
$localdebs = $ENV{'LOCALDEBS'};
|
2018-08-13 13:36:36 +00:00
|
|
|
$backports = $ENV{'BACKPORTS'};
|
2011-06-10 16:21:32 +00:00
|
|
|
$archlist = shift;
|
|
|
|
$outfile = shift;
|
|
|
|
|
|
|
|
if (!defined($codename) || !defined($mirror) ||
|
|
|
|
!defined($archlist) || !defined($outfile)) {
|
|
|
|
die "Error in arguments\n";
|
|
|
|
}
|
|
|
|
|
2012-03-05 15:13:17 -01:00
|
|
|
foreach $arch (split(' ', $archlist)) {
|
2023-01-26 21:22:40 -01:00
|
|
|
for my $component (@components) {
|
|
|
|
if (defined($backports)) {
|
2023-01-26 21:22:40 -01:00
|
|
|
push @bp_pkgfiles, "$mirror/dists/$codename-backports/$component/binary-$arch/Packages.gz";
|
|
|
|
push @bp_pkgfiles, "$mirror/dists/$codename-backports/$component/binary-$arch/Packages.xz";
|
2023-01-26 21:22:40 -01:00
|
|
|
}
|
2023-01-26 21:22:40 -01:00
|
|
|
push @pkgfiles, "$mirror/dists/$codename/$component/binary-$arch/Packages.gz";
|
|
|
|
push @pkgfiles, "$mirror/dists/$codename/$component/binary-$arch/Packages.xz";
|
2018-08-13 13:36:36 +00:00
|
|
|
}
|
2012-03-05 12:42:19 -01:00
|
|
|
}
|
|
|
|
|
2012-03-05 21:42:30 -01:00
|
|
|
if (defined($localdebs)) {
|
2023-01-26 21:22:40 -01:00
|
|
|
for my $component (@components) {
|
|
|
|
foreach $arch (split(' ', $archlist)) {
|
|
|
|
if (defined($backports)) {
|
2023-01-26 21:22:40 -01:00
|
|
|
push @bp_pkgfiles, "$localdebs/dists/$codename-backports/$component/binary-$arch/Packages.gz";
|
|
|
|
push @bp_pkgfiles, "$localdebs/dists/$codename-backports/$component/binary-$arch/Packages.xz";
|
2023-01-26 21:22:40 -01:00
|
|
|
}
|
2023-01-26 21:22:40 -01:00
|
|
|
push @pkgfiles, "$localdebs/dists/$codename/$component/binary-$arch/Packages.gz";
|
|
|
|
push @pkgfiles, "$localdebs/dists/$codename/$component/binary-$arch/Packages.xz";
|
2018-08-13 13:36:36 +00:00
|
|
|
}
|
2012-03-05 12:42:19 -01:00
|
|
|
}
|
2011-06-10 16:21:32 +00:00
|
|
|
}
|
|
|
|
|
2023-01-26 21:22:40 -01:00
|
|
|
# This special filename is an crude but easy way to distinguish the historical
|
|
|
|
# caller (top-level Makefile) from tools/make-firmware-image which should use
|
|
|
|
# the same logic, but is interested in the Filename for interesting firmware
|
|
|
|
# packages:
|
2023-01-26 21:22:40 -01:00
|
|
|
my $orig_mode = $outfile ne '--list-filenames-and-indices' ? 1 : 0;
|
2023-01-26 21:22:40 -01:00
|
|
|
if ($orig_mode) {
|
|
|
|
# Prepare the output file:
|
|
|
|
open (OUT, "> $outfile") or die "Can't open outfile for writing: $!\n";
|
|
|
|
|
|
|
|
$date = `date -u`;
|
|
|
|
chomp $date;
|
|
|
|
|
|
|
|
print OUT "/*\n";
|
|
|
|
print OUT " * 'firmware' task file; generated automatically by generate_firmware_task\n";
|
|
|
|
print OUT " * for \"$archlist\" on $date\n";
|
|
|
|
print OUT " * Do not edit - changes will not be preserved\n";
|
|
|
|
print OUT " */\n";
|
|
|
|
}
|
2011-06-10 16:21:32 +00:00
|
|
|
|
2023-01-26 21:22:40 -01:00
|
|
|
# Those function calls will either write the task to OUT (historical mode) or
|
|
|
|
# filenames to stdout (for make-firmware-image):
|
2018-08-13 13:36:36 +00:00
|
|
|
if (defined($backports)) {
|
2023-01-26 21:22:40 -01:00
|
|
|
check_packages(1, $orig_mode, @bp_pkgfiles);
|
2011-06-10 16:21:32 +00:00
|
|
|
}
|
2023-01-26 21:22:40 -01:00
|
|
|
check_packages(0, $orig_mode, @pkgfiles);
|
2011-06-10 16:21:32 +00:00
|
|
|
|
2023-01-26 21:22:40 -01:00
|
|
|
if ($orig_mode) {
|
|
|
|
close OUT;
|
|
|
|
}
|