Debian Codegraph @

tools/generate_firmware_patterns

raw
1 #!/usr/bin/perl
2 # © 2021-2023 Cyril Brulebois <[email protected]>
3 #
4 # Generate ready-to-use .patterns files so that one can use grep to
5 # perform hardware to firmware-package lookups in the installer
6 # (see MODALIAS= lines in `udevadm info --export-db`), see the
7 # hw-detect component.
8 #
9 # Parameters: dists/<suite>/*/dep11/Components-<arch>.yml.(gz|xz)
10 #
11 # We're limiting ourselves to packages announcing Type: firmware, and
12 # they need to include such information in their metadata, e.g.
13 # src:firmware-nonfree.
14 #
15 # See: https://salsa.debian.org/kernel-team/firmware-nonfree/-/merge_requests/19
16
17 use strict;
18 use warnings;
19
20 use File::Slurp;
21 use Getopt::Long;
22 use YAML::XS;
23
24 my $SOF = 'firmware-sof-signed';
25
26 my $output_dir = '.';
27 my $verbose;
28 my $pkgname;
29
30 GetOptions( "output-dir=s" => \$output_dir,
31 "verbose" => \$verbose,
32 "package=s" => \$pkgname)
33 or die "Error in command line arguments";
34
35
36 sub format_alias {
37 return map { $a = $_; $a =~ s/[*]/.*/g; "^$a\$\n" } @_;
38 }
39
40
41 sub generate_patterns_from_components {
42 my $input = shift;
43 my $content;
44 print STDERR " processing $input\n"
45 if $verbose;
46
47 if ($input =~ /\.gz$/) {
48 $content = `zcat $input`;
49 }
50 elsif ($input =~ /\.xz$/) {
51 $content = `xzcat $input`;
52 }
53 else {
54 die "only gz and xz suffixes are supported";
55 }
56
57 foreach my $array (Load $content) {
58 next if not defined $array->{Provides};
59 next if not defined $array->{Provides}->{modaliases};
60
61 print STDERR " found modaliases entries for firmware package ", $array->{Package}, "\n"
62 if $verbose;
63
64 next if $pkgname ne $array->{Package};
65
66 my $patterns_file = "$output_dir/$pkgname.patterns";
67 printf STDERR " writing %4d entries to %s\n",
68 (scalar @{ $array->{Provides}->{modaliases} }),
69 $patterns_file;
70
71 # For each alias, anchor the pattern on the left (^) and on
72 # the right ($), and replace each '*' with '.*':
73 write_file($patterns_file,
74 format_alias( @{ $array->{Provides}->{modaliases} } ));
75 return 1;
76 }
77 return 0;
78 }
79
80
81 # Workaround for firmware-sof-signed, which doesn't advertise firmware
82 # files it might need through the MODULE_FIRMWARE() macro (meaning no
83 # chance to generate DEP-11 info from there): alias info manually
84 # extracted on 2025-05-14 (linux-image-6.12.29-amd64, 6.12.29-1).
85 #
86 # XXX: To be kept in sync! (#1029175)
87 sub generate_patterns_for_firmware_sof_intel_workaround {
88 # Extract on amd64, from the installed package, with the following
89 # command. Note that descending under intel/ would lead to no
90 # aliases, so stick to the top-level directory for sof:
91 #
92 # 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
93
94 my @sof_aliases = qw(
95 auxiliary:snd_sof.acp-probes
96 auxiliary:snd_sof.hda-probes
97 pci:v00001022d000015E2sv*sd*bc*sc*i*
98 pci:v00008086d000002C8sv*sd*bc*sc*i*
99 pci:v00008086d000006C8sv*sd*bc*sc*i*
100 pci:v00008086d0000119Asv*sd*bc*sc*i*
101 pci:v00008086d00003198sv*sd*bc*sc*i*
102 pci:v00008086d000034C8sv*sd*bc*sc*i*
103 pci:v00008086d000038C8sv*sd*bc*sc*i*
104 pci:v00008086d00003DC8sv*sd*bc*sc*i*
105 pci:v00008086d000043C8sv*sd*bc*sc*i*
106 pci:v00008086d00004B55sv*sd*bc*sc*i*
107 pci:v00008086d00004B58sv*sd*bc*sc*i*
108 pci:v00008086d00004DC8sv*sd*bc*sc*i*
109 pci:v00008086d000051C8sv*sd*bc*sc*i*
110 pci:v00008086d000051C9sv*sd*bc*sc*i*
111 pci:v00008086d000051CAsv*sd*bc*sc*i*
112 pci:v00008086d000051CBsv*sd*bc*sc*i*
113 pci:v00008086d000051CCsv*sd*bc*sc*i*
114 pci:v00008086d000051CDsv*sd*bc*sc*i*
115 pci:v00008086d000051CEsv*sd*bc*sc*i*
116 pci:v00008086d000051CFsv*sd*bc*sc*i*
117 pci:v00008086d000054C8sv*sd*bc*sc*i*
118 pci:v00008086d00005A98sv*sd*bc*sc*i*
119 pci:v00008086d00007728sv*sd*bc*sc*i*
120 pci:v00008086d00007A50sv*sd*bc*sc*i*
121 pci:v00008086d00007AD0sv*sd*bc*sc*i*
122 pci:v00008086d00007E28sv*sd*bc*sc*i*
123 pci:v00008086d00007F50sv*sd*bc*sc*i*
124 pci:v00008086d00009D70sv*sd*bc*sc*i*
125 pci:v00008086d00009D71sv*sd*bc*sc*i*
126 pci:v00008086d00009DC8sv*sd*bc*sc*i*
127 pci:v00008086d0000A0C8sv*sd*bc*sc*i*
128 pci:v00008086d0000A348sv*sd*bc*sc*i*
129 pci:v00008086d0000A3F0sv*sd*bc*sc*i*
130 pci:v00008086d0000A828sv*sd*bc*sc*i*
131 pci:v00008086d0000E328sv*sd*bc*sc*i*
132 pci:v00008086d0000E428sv*sd*bc*sc*i*
133 platform:adl_cs35l41
134 platform:adl_cs42l42_def
135 platform:adl_da7219_def
136 platform:adl_es83x6_c1_h02
137 platform:adl_lt6911_hdmi_ssp
138 platform:adl_mx98357_rt5682
139 platform:adl_nau8825_def
140 platform:adl_rt1019p_8825
141 platform:adl_rt5682_c1_h02
142 platform:adl_rt5682_def
143 platform:arl_es83x6_c1_h02
144 platform:arl_lt6911_hdmi_ssp
145 platform:arl_rt5682_c1_h02
146 platform:cml_da7219_def
147 platform:cml_rt5682_def
148 platform:glk_cs4242_mx98357a
149 platform:glk_da7219_def
150 platform:glk_rt5682_def
151 platform:icl_rt5682_def
152 platform:jsl_cs4242_mx98360a
153 platform:jsl_da7219_def
154 platform:jsl_rt5682_def
155 platform:mtl_cs42l42_def
156 platform:mtl_da7219_def
157 platform:mtl_es83x6_c1_h02
158 platform:mtl_lt6911_hdmi_ssp
159 platform:mtl_nau8825_def
160 platform:mtl_rt5682_c1_h02
161 platform:mtl_rt5682_def
162 platform:rpl_cs42l42_def
163 platform:rpl_da7219_def
164 platform:rpl_es83x6_c1_h02
165 platform:rpl_lt6911_hdmi_ssp
166 platform:rpl_mx98357_rt5682
167 platform:rpl_nau8825_def
168 platform:rpl_rt5682_c1_h02
169 platform:rpl_rt5682_def
170 platform:sof-audio
171 platform:sof-essx8336
172 platform:sof_rt5682
173 platform:sof_sdw
174 platform:sof_ssp_amp
175 platform:tgl_rt1308_hdmi_ssp
176 platform:tgl_rt5682_def
177 );
178
179 print STDERR " deploying manual workaround for $SOF\n"
180 if $verbose;
181
182 my $sof_file = $output_dir . "/" . $SOF . ".patterns";
183 printf STDERR " writing %4d entries to %s (using the workaround)\n",
184 (scalar @sof_aliases),
185 $sof_file;
186
187 write_file($sof_file,
188 format_alias(@sof_aliases));
189 }
190
191
192 print STDERR "Looking up patterns for package $pkgname\n"
193 if $verbose;
194
195 # Make sure the output directory exists:
196 die "missing output directory $output_dir"
197 if ! -d $output_dir;
198
199 # Search for the specified package in the Components-* files, and
200 # generate patterns when it's found:
201 my $done;
202 foreach my $components (@ARGV) {
203 die "missing metadata file $components"
204 if ! -f $components;
205 $done = generate_patterns_from_components($components);
206 last if $done;
207 }
208
209 # Only apply the workaround when relevant:
210 generate_patterns_for_firmware_sof_intel_workaround()
211 if ! $done and $pkgname eq $SOF;
212
213 print STDERR "Done with package $pkgname\n"
214 if $verbose;