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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
|
#!/usr/bin/perl
# © 2021-2023 Cyril Brulebois <kibi@debian.org>
#
# Generate ready-to-use .patterns files so that one can use grep to
# 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.
# src:firmware-nonfree.
#
# See: https://salsa.debian.org/kernel-team/firmware-nonfree/-/merge_requests/19
use strict;
use warnings;
use File::Slurp;
use Getopt::Long;
use YAML::XS;
my $SOF = 'firmware-sof-signed';
my $output_dir = '.';
my $verbose;
my $pkgname;
GetOptions( "output-dir=s" => \$output_dir,
"verbose" => \$verbose,
"package=s" => \$pkgname)
or die "Error in command line arguments";
sub format_alias {
return map { $a = $_; $a =~ s/[*]/.*/g; "^$a\$\n" } @_;
}
sub generate_patterns_from_components {
my $input = shift;
my $content;
print STDERR " processing $input\n"
if $verbose;
if ($input =~ /\.gz$/) {
$content = `zcat $input`;
}
elsif ($input =~ /\.xz$/) {
$content = `xzcat $input`;
}
else {
die "only gz and xz suffixes are supported";
}
foreach my $array (Load $content) {
next if not defined $array->{Provides};
next if not defined $array->{Provides}->{modaliases};
print STDERR " found modaliases entries for firmware package ", $array->{Package}, "\n"
if $verbose;
next if $pkgname ne $array->{Package};
my $patterns_file = "$output_dir/$pkgname.patterns";
printf STDERR " writing %4d 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} } ));
return 1;
}
return 0;
}
# 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 2025-05-14 (linux-image-6.12.29-amd64, 6.12.29-1).
#
# XXX: To be kept in sync! (#1029175)
sub generate_patterns_for_firmware_sof_intel_workaround {
# 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:
#
# for x in $(dpkg -L linux-image-6.12.29-amd64 | egrep '(kernel/sound/soc/sof/.*\.ko|/snd-soc-.*sof.*\.ko).xz$'); do /usr/sbin/modinfo $x | awk '/^alias:/ { print $2 }'; done | sort -u
my @sof_aliases = qw(
auxiliary:snd_sof.acp-probes
auxiliary:snd_sof.hda-probes
pci:v00001022d000015E2sv*sd*bc*sc*i*
pci:v00008086d000002C8sv*sd*bc*sc*i*
pci:v00008086d000006C8sv*sd*bc*sc*i*
pci:v00008086d0000119Asv*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*
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*
pci:v00008086d00005A98sv*sd*bc*sc*i*
pci:v00008086d00007728sv*sd*bc*sc*i*
pci:v00008086d00007A50sv*sd*bc*sc*i*
pci:v00008086d00007AD0sv*sd*bc*sc*i*
pci:v00008086d00007E28sv*sd*bc*sc*i*
pci:v00008086d00007F50sv*sd*bc*sc*i*
pci:v00008086d00009D70sv*sd*bc*sc*i*
pci:v00008086d00009D71sv*sd*bc*sc*i*
pci:v00008086d00009DC8sv*sd*bc*sc*i*
pci:v00008086d0000A0C8sv*sd*bc*sc*i*
pci:v00008086d0000A348sv*sd*bc*sc*i*
pci:v00008086d0000A3F0sv*sd*bc*sc*i*
pci:v00008086d0000A828sv*sd*bc*sc*i*
pci:v00008086d0000E328sv*sd*bc*sc*i*
pci:v00008086d0000E428sv*sd*bc*sc*i*
platform:adl_cs35l41
platform:adl_cs42l42_def
platform:adl_da7219_def
platform:adl_es83x6_c1_h02
platform:adl_lt6911_hdmi_ssp
platform:adl_mx98357_rt5682
platform:adl_nau8825_def
platform:adl_rt1019p_8825
platform:adl_rt5682_c1_h02
platform:adl_rt5682_def
platform:arl_es83x6_c1_h02
platform:arl_lt6911_hdmi_ssp
platform:arl_rt5682_c1_h02
platform:cml_da7219_def
platform:cml_rt5682_def
platform:glk_cs4242_mx98357a
platform:glk_da7219_def
platform:glk_rt5682_def
platform:icl_rt5682_def
platform:jsl_cs4242_mx98360a
platform:jsl_da7219_def
platform:jsl_rt5682_def
platform:mtl_cs42l42_def
platform:mtl_da7219_def
platform:mtl_es83x6_c1_h02
platform:mtl_lt6911_hdmi_ssp
platform:mtl_nau8825_def
platform:mtl_rt5682_c1_h02
platform:mtl_rt5682_def
platform:rpl_cs42l42_def
platform:rpl_da7219_def
platform:rpl_es83x6_c1_h02
platform:rpl_lt6911_hdmi_ssp
platform:rpl_mx98357_rt5682
platform:rpl_nau8825_def
platform:rpl_rt5682_c1_h02
platform:rpl_rt5682_def
platform:sof-audio
platform:sof-essx8336
platform:sof_rt5682
platform:sof_sdw
platform:sof_ssp_amp
platform:tgl_rt1308_hdmi_ssp
platform:tgl_rt5682_def
);
print STDERR " deploying manual workaround for $SOF\n"
if $verbose;
my $sof_file = $output_dir . "/" . $SOF . ".patterns";
printf STDERR " writing %4d entries to %s (using the workaround)\n",
(scalar @sof_aliases),
$sof_file;
write_file($sof_file,
format_alias(@sof_aliases));
}
print STDERR "Looking up patterns for package $pkgname\n"
if $verbose;
# Make sure the output directory exists:
die "missing output directory $output_dir"
if ! -d $output_dir;
# Search for the specified package in the Components-* files, and
# generate patterns when it's found:
my $done;
foreach my $components (@ARGV) {
die "missing metadata file $components"
if ! -f $components;
$done = generate_patterns_from_components($components);
last if $done;
}
# Only apply the workaround when relevant:
generate_patterns_for_firmware_sof_intel_workaround()
if ! $done and $pkgname eq $SOF;
print STDERR "Done with package $pkgname\n"
if $verbose;
|