2021-07-25 04:46:08 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# © 2021 Cyril Brulebois <kibi@debian.org>
|
|
|
|
#
|
2021-07-25 05:17:50 +00:00
|
|
|
# Generate ready-to-use .patterns files so that one can use grep to
|
2021-07-25 04:46:08 +00:00
|
|
|
# perform hardware to firmware-package lookups in the installer
|
|
|
|
# (see MODALIAS= lines in `udevadm info --export-db`), see the
|
|
|
|
# hw-detect component.
|
|
|
|
#
|
|
|
|
# Parameters: dists/<suite>/*/dep11/Components-<arch>.yml.(gz|xz)
|
|
|
|
#
|
|
|
|
# We're limiting ourselves to packages announcing Type: firmware, and
|
|
|
|
# they need to include such information in their metadata, e.g.
|
2021-08-22 14:17:41 +00:00
|
|
|
# src:firmware-nonfree.
|
2021-07-25 05:18:38 +00:00
|
|
|
#
|
|
|
|
# See: https://salsa.debian.org/kernel-team/firmware-nonfree/-/merge_requests/19
|
2021-07-25 04:46:08 +00:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2021-07-25 05:10:34 +00:00
|
|
|
use File::Path qw(make_path);
|
2021-07-25 04:46:08 +00:00
|
|
|
use File::Slurp;
|
2021-07-25 04:52:13 +00:00
|
|
|
use Getopt::Long;
|
2021-07-25 04:46:08 +00:00
|
|
|
use YAML::XS;
|
|
|
|
|
2021-07-25 05:16:56 +00:00
|
|
|
|
2021-07-25 04:52:13 +00:00
|
|
|
my $output_dir = '.';
|
|
|
|
my $verbose;
|
2021-07-25 17:18:26 +00:00
|
|
|
my $pkgname = "ALL";
|
|
|
|
|
2021-07-25 04:52:13 +00:00
|
|
|
GetOptions( "output-dir=s" => \$output_dir,
|
2021-07-25 17:18:26 +00:00
|
|
|
"verbose" => \$verbose,
|
|
|
|
"package=s" => \$pkgname)
|
2021-07-25 04:52:13 +00:00
|
|
|
or die "Error in command line arguments";
|
|
|
|
|
2021-07-25 04:46:08 +00:00
|
|
|
|
2021-07-25 06:28:53 +00:00
|
|
|
sub format_alias {
|
|
|
|
return map { $a = $_; $a =~ s/[*]/.*/g; "^$a\$\n" } @_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-25 04:46:08 +00:00
|
|
|
sub process_components {
|
|
|
|
my $input = shift;
|
|
|
|
my $content;
|
2021-07-25 04:52:13 +00:00
|
|
|
print STDERR "processing $input\n"
|
|
|
|
if $verbose;
|
2021-07-25 04:46:08 +00:00
|
|
|
|
|
|
|
if ($input =~ /\.gz$/) {
|
|
|
|
$content = `zcat $input`;
|
|
|
|
}
|
|
|
|
elsif ($input =~ /\.xz$/) {
|
|
|
|
$content = `xzcat $input`;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
die "only gz and xz suffixes are supported";
|
|
|
|
}
|
|
|
|
|
2021-07-25 06:16:44 +00:00
|
|
|
my @packages;
|
2021-07-25 04:46:08 +00:00
|
|
|
foreach my $array (Load $content) {
|
|
|
|
next if not defined $array->{Provides};
|
|
|
|
next if not defined $array->{Provides}->{modaliases};
|
|
|
|
|
2021-07-25 04:52:13 +00:00
|
|
|
print STDERR "found modaliases entries for firmware package ", $array->{Package}, "\n"
|
|
|
|
if $verbose;
|
2021-07-25 04:46:08 +00:00
|
|
|
|
2023-01-18 19:25:48 -01:00
|
|
|
if ($pkgname eq "ALL" or $pkgname eq $array->{Package}) {
|
|
|
|
|
|
|
|
my $patterns_file = $output_dir . "/" . $array->{Package} . ".patterns";
|
|
|
|
printf STDERR "writing %d entries to %s\n",
|
|
|
|
(scalar @{ $array->{Provides}->{modaliases} }),
|
|
|
|
$patterns_file;
|
|
|
|
|
|
|
|
# For each alias, anchor the pattern on the left (^) and on
|
|
|
|
# the right ($), and replace each '*' with '.*':
|
|
|
|
write_file($patterns_file,
|
|
|
|
format_alias( @{ $array->{Provides}->{modaliases} } ));
|
|
|
|
push @packages, $array->{Package};
|
|
|
|
}
|
2021-07-25 04:46:08 +00:00
|
|
|
}
|
2021-07-25 06:16:44 +00:00
|
|
|
return @packages;
|
2021-07-25 04:46:08 +00:00
|
|
|
}
|
2021-07-25 06:01:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Prepare output directory:
|
|
|
|
if (! -d $output_dir) {
|
|
|
|
print STDERR "creating output directory $output_dir\n"
|
|
|
|
if $verbose;
|
|
|
|
make_path($output_dir, { verbose => $verbose });
|
|
|
|
}
|
|
|
|
|
|
|
|
write_file("$output_dir/README.txt",
|
|
|
|
"These files help Debian Installer detect helpful firmware packages (via hw-detect).\n");
|
|
|
|
|
2021-07-25 17:18:26 +00:00
|
|
|
# Generate .patterns file to match firmware packages found in
|
2021-07-25 06:01:39 +00:00
|
|
|
# Components-* files:
|
2021-07-25 06:16:44 +00:00
|
|
|
my @all_packages;
|
2021-07-25 06:01:39 +00:00
|
|
|
foreach my $component (@ARGV) {
|
2021-07-25 06:16:44 +00:00
|
|
|
my @packages = process_components($component);
|
|
|
|
push @all_packages, @packages;
|
2021-07-25 06:01:39 +00:00
|
|
|
}
|
2021-07-25 06:16:44 +00:00
|
|
|
@all_packages = sort @all_packages;
|
2021-07-25 17:18:26 +00:00
|
|
|
print STDERR "firmware packages found across all components: @all_packages\n"
|
2021-07-25 06:16:44 +00:00
|
|
|
if $verbose;
|
2021-07-25 06:30:45 +00:00
|
|
|
|
|
|
|
# Workaround for firmware-sof-signed, which doesn't advertise firmware
|
|
|
|
# files it might need through the MODULE_FIRMWARE() macro (meaning no
|
|
|
|
# chance to generate DEP-11 info from there): alias info manually
|
|
|
|
# extracted on 2021-07-25 (linux-image-5.10.0-8-amd64, 5.10.46-2).
|
|
|
|
#
|
|
|
|
# XXX: To be kept in sync!
|
|
|
|
my $SOF = 'firmware-sof-signed';
|
|
|
|
if (! grep { $_ eq $SOF } @all_packages) {
|
2021-07-25 06:38:51 +00:00
|
|
|
|
2021-07-25 17:18:26 +00:00
|
|
|
if ($pkgname eq 'ALL' or $pkgname eq 'firmware-sof-signed') {
|
|
|
|
|
2023-01-18 19:25:48 -01:00
|
|
|
# Extract on amd64, from the installed package, with the following
|
|
|
|
# command. Note that descending under intel/ would lead to no
|
|
|
|
# aliases, so stick to the top-level directory for sof:
|
|
|
|
#
|
2023-01-18 19:43:28 -01:00
|
|
|
# for x in $(dpkg -L linux-image-6.1.0-1-amd64 | egrep '(kernel/sound/soc/sof/.*\.ko|/snd-soc-.*sof.*\.ko)$'); do /usr/sbin/modinfo $x | awk '/^alias:/ { print $2 }'; done | sort
|
2023-01-18 19:25:48 -01:00
|
|
|
|
|
|
|
my @sof_aliases = qw(
|
2023-01-18 19:43:28 -01:00
|
|
|
auxiliary:snd_sof.hda-probes
|
2023-01-18 19:25:48 -01:00
|
|
|
pci:v00008086d000002C8sv*sd*bc*sc*i*
|
|
|
|
pci:v00008086d000006C8sv*sd*bc*sc*i*
|
|
|
|
pci:v00008086d0000119Asv*sd*bc*sc*i*
|
|
|
|
pci:v00008086d00001A98sv*sd*bc*sc*i*
|
|
|
|
pci:v00008086d00003198sv*sd*bc*sc*i*
|
|
|
|
pci:v00008086d000034C8sv*sd*bc*sc*i*
|
|
|
|
pci:v00008086d000038C8sv*sd*bc*sc*i*
|
|
|
|
pci:v00008086d00003DC8sv*sd*bc*sc*i*
|
|
|
|
pci:v00008086d000043C8sv*sd*bc*sc*i*
|
|
|
|
pci:v00008086d00004B55sv*sd*bc*sc*i*
|
|
|
|
pci:v00008086d00004B58sv*sd*bc*sc*i*
|
|
|
|
pci:v00008086d00004DC8sv*sd*bc*sc*i*
|
2023-01-18 19:43:28 -01:00
|
|
|
pci:v00008086d000051C8sv*sd*bc*sc*i*
|
|
|
|
pci:v00008086d000051C9sv*sd*bc*sc*i*
|
|
|
|
pci:v00008086d000051CAsv*sd*bc*sc*i*
|
|
|
|
pci:v00008086d000051CBsv*sd*bc*sc*i*
|
|
|
|
pci:v00008086d000051CCsv*sd*bc*sc*i*
|
|
|
|
pci:v00008086d000051CDsv*sd*bc*sc*i*
|
|
|
|
pci:v00008086d000051CEsv*sd*bc*sc*i*
|
|
|
|
pci:v00008086d000051CFsv*sd*bc*sc*i*
|
|
|
|
pci:v00008086d000054C8sv*sd*bc*sc*i*
|
2023-01-18 19:25:48 -01:00
|
|
|
pci:v00008086d00005A98sv*sd*bc*sc*i*
|
2023-01-18 19:43:28 -01:00
|
|
|
pci:v00008086d00007A50sv*sd*bc*sc*i*
|
|
|
|
pci:v00008086d00007AD0sv*sd*bc*sc*i*
|
|
|
|
pci:v00008086d00007E28sv*sd*bc*sc*i*
|
|
|
|
pci:v00008086d00009D70sv*sd*bc*sc*i*
|
|
|
|
pci:v00008086d00009D71sv*sd*bc*sc*i*
|
2023-01-18 19:25:48 -01:00
|
|
|
pci:v00008086d00009DC8sv*sd*bc*sc*i*
|
|
|
|
pci:v00008086d0000A0C8sv*sd*bc*sc*i*
|
|
|
|
pci:v00008086d0000A348sv*sd*bc*sc*i*
|
|
|
|
pci:v00008086d0000A3F0sv*sd*bc*sc*i*
|
2023-01-18 19:43:28 -01:00
|
|
|
platform:adl_es83x6_c1_h02
|
|
|
|
platform:adl_max98390_rt5682
|
|
|
|
platform:adl_mx98357_rt5682
|
|
|
|
platform:adl_mx98360_rt5682
|
|
|
|
platform:adl_mx98373_rt5682
|
|
|
|
platform:adl_rt1019_rt5682s
|
|
|
|
platform:adl_rt5682
|
|
|
|
platform:cml_rt1015_rt5682
|
|
|
|
platform:jsl_rt5682_mx98360
|
2023-01-18 19:25:48 -01:00
|
|
|
platform:jsl_rt5682_rt1015
|
2023-01-18 19:43:28 -01:00
|
|
|
platform:jsl_rt5682_rt1015p
|
|
|
|
platform:mtl_mx98357_rt5682
|
2023-01-18 19:25:48 -01:00
|
|
|
platform:sof-audio
|
2023-01-18 19:43:28 -01:00
|
|
|
platform:sof-essx8336
|
2023-01-18 19:35:29 -01:00
|
|
|
platform:sof_rt5682
|
2023-01-18 19:25:48 -01:00
|
|
|
platform:sof_sdw
|
2023-01-18 19:43:28 -01:00
|
|
|
platform:tgl_mx98357_rt5682
|
|
|
|
platform:tgl_mx98373_rt5682
|
|
|
|
platform:tgl_rt1011_rt5682
|
2023-01-18 19:25:48 -01:00
|
|
|
);
|
|
|
|
|
|
|
|
print STDERR "deploying manual workaround for $SOF\n"
|
|
|
|
if $verbose;
|
|
|
|
|
|
|
|
my $sof_file = $output_dir . "/" . $SOF . ".patterns";
|
|
|
|
printf STDERR "writing %d entries to %s\n",
|
|
|
|
(scalar @sof_aliases),
|
|
|
|
$sof_file;
|
|
|
|
|
|
|
|
write_file($sof_file,
|
|
|
|
format_alias(@sof_aliases));
|
|
|
|
push @all_packages, $SOF;
|
2021-07-25 17:18:26 +00:00
|
|
|
}
|
2021-07-25 06:30:45 +00:00
|
|
|
}
|