]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - Documentation/dvb/get_dvb_firmware
Merge branch 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux-2.6
[mirror_ubuntu-zesty-kernel.git] / Documentation / dvb / get_dvb_firmware
1 #!/usr/bin/perl
2 # DVB firmware extractor
3 #
4 # (c) 2004 Andrew de Quincey
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 #
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 use File::Temp qw/ tempdir /;
22 use IO::Handle;
23
24 @components = ( "sp8870", "sp887x", "tda10045", "tda10046", "av7110", "dec2000t",
25 "dec2540t", "dec3000s", "vp7041", "dibusb", "nxt2002", "nxt2004",
26 "or51211", "or51132_qam", "or51132_vsb");
27
28 # Check args
29 syntax() if (scalar(@ARGV) != 1);
30 $cid = $ARGV[0];
31
32 # Do it!
33 for ($i=0; $i < scalar(@components); $i++) {
34 if ($cid eq $components[$i]) {
35 $outfile = eval($cid);
36 die $@ if $@;
37 print STDERR "Firmware $outfile extracted successfully. Now copy it to either /lib/firmware or /usr/lib/hotplug/firmware/ (depending on your hotplug version).\n";
38 exit(0);
39 }
40 }
41
42 # If we get here, it wasn't found
43 print STDERR "Unknown component \"$cid\"\n";
44 syntax();
45
46
47
48
49 # ---------------------------------------------------------------
50 # Firmware-specific extraction subroutines
51
52 sub sp8870 {
53 my $sourcefile = "tt_Premium_217g.zip";
54 my $url = "http://www.technotrend.de/new/217g/$sourcefile";
55 my $hash = "53970ec17a538945a6d8cb608a7b3899";
56 my $outfile = "dvb-fe-sp8870.fw";
57 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
58
59 checkstandard();
60
61 wgetfile($sourcefile, $url);
62 unzip($sourcefile, $tmpdir);
63 verify("$tmpdir/software/OEM/HE/App/boot/SC_MAIN.MC", $hash);
64 copy("$tmpdir/software/OEM/HE/App/boot/SC_MAIN.MC", $outfile);
65
66 $outfile;
67 }
68
69 sub sp887x {
70 my $sourcefile = "Dvbt1.3.57.6.zip";
71 my $url = "http://www.avermedia.com/software/$sourcefile";
72 my $cabfile = "DVBT Net Ver1.3.57.6/disk1/data1.cab";
73 my $hash = "237938d53a7f834c05c42b894ca68ac3";
74 my $outfile = "dvb-fe-sp887x.fw";
75 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
76
77 checkstandard();
78 checkunshield();
79
80 wgetfile($sourcefile, $url);
81 unzip($sourcefile, $tmpdir);
82 unshield("$tmpdir/$cabfile", $tmpdir);
83 verify("$tmpdir/ZEnglish/sc_main.mc", $hash);
84 copy("$tmpdir/ZEnglish/sc_main.mc", $outfile);
85
86 $outfile;
87 }
88
89 sub tda10045 {
90 my $sourcefile = "tt_budget_217g.zip";
91 my $url = "http://www.technotrend.de/new/217g/$sourcefile";
92 my $hash = "2105fd5bf37842fbcdfa4bfd58f3594a";
93 my $outfile = "dvb-fe-tda10045.fw";
94 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
95
96 checkstandard();
97
98 wgetfile($sourcefile, $url);
99 unzip($sourcefile, $tmpdir);
100 extract("$tmpdir/software/OEM/PCI/App/ttlcdacc.dll", 0x37ef9, 30555, "$tmpdir/fwtmp");
101 verify("$tmpdir/fwtmp", $hash);
102 copy("$tmpdir/fwtmp", $outfile);
103
104 $outfile;
105 }
106
107 sub tda10046 {
108 my $sourcefile = "tt_budget_217g.zip";
109 my $url = "http://www.technotrend.de/new/217g/$sourcefile";
110 my $hash = "6a7e1e2f2644b162ff0502367553c72d";
111 my $outfile = "dvb-fe-tda10046.fw";
112 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
113
114 checkstandard();
115
116 wgetfile($sourcefile, $url);
117 unzip($sourcefile, $tmpdir);
118 extract("$tmpdir/software/OEM/PCI/App/ttlcdacc.dll", 0x3f731, 24478, "$tmpdir/fwtmp");
119 verify("$tmpdir/fwtmp", $hash);
120 copy("$tmpdir/fwtmp", $outfile);
121
122 $outfile;
123 }
124
125 sub av7110 {
126 my $sourcefile = "dvb-ttpci-01.fw-261d";
127 my $url = "http://www.linuxtv.org/downloads/firmware/$sourcefile";
128 my $hash = "603431b6259715a8e88f376a53b64e2f";
129 my $outfile = "dvb-ttpci-01.fw";
130
131 checkstandard();
132
133 wgetfile($sourcefile, $url);
134 verify($sourcefile, $hash);
135 copy($sourcefile, $outfile);
136
137 $outfile;
138 }
139
140 sub dec2000t {
141 my $sourcefile = "dec217g.exe";
142 my $url = "http://hauppauge.lightpath.net/de/$sourcefile";
143 my $hash = "bd86f458cee4a8f0a8ce2d20c66215a9";
144 my $outfile = "dvb-ttusb-dec-2000t.fw";
145 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
146
147 checkstandard();
148
149 wgetfile($sourcefile, $url);
150 unzip($sourcefile, $tmpdir);
151 verify("$tmpdir/software/OEM/STB/App/Boot/STB_PC_T.bin", $hash);
152 copy("$tmpdir/software/OEM/STB/App/Boot/STB_PC_T.bin", $outfile);
153
154 $outfile;
155 }
156
157 sub dec2540t {
158 my $sourcefile = "dec217g.exe";
159 my $url = "http://hauppauge.lightpath.net/de/$sourcefile";
160 my $hash = "53e58f4f5b5c2930beee74a7681fed92";
161 my $outfile = "dvb-ttusb-dec-2540t.fw";
162 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
163
164 checkstandard();
165
166 wgetfile($sourcefile, $url);
167 unzip($sourcefile, $tmpdir);
168 verify("$tmpdir/software/OEM/STB/App/Boot/STB_PC_X.bin", $hash);
169 copy("$tmpdir/software/OEM/STB/App/Boot/STB_PC_X.bin", $outfile);
170
171 $outfile;
172 }
173
174 sub dec3000s {
175 my $sourcefile = "dec217g.exe";
176 my $url = "http://hauppauge.lightpath.net/de/$sourcefile";
177 my $hash = "b013ececea83f4d6d8d2a29ac7c1b448";
178 my $outfile = "dvb-ttusb-dec-3000s.fw";
179 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
180
181 checkstandard();
182
183 wgetfile($sourcefile, $url);
184 unzip($sourcefile, $tmpdir);
185 verify("$tmpdir/software/OEM/STB/App/Boot/STB_PC_S.bin", $hash);
186 copy("$tmpdir/software/OEM/STB/App/Boot/STB_PC_S.bin", $outfile);
187
188 $outfile;
189 }
190
191 sub vp7041 {
192 my $sourcefile = "2.422.zip";
193 my $url = "http://www.twinhan.com/files/driver/USB-Ter/$sourcefile";
194 my $hash = "e88c9372d1f66609a3e7b072c53fbcfe";
195 my $outfile = "dvb-vp7041-2.422.fw";
196 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
197
198 checkstandard();
199
200 wgetfile($sourcefile, $url);
201 unzip($sourcefile, $tmpdir);
202 extract("$tmpdir/VisionDTV/Drivers/Win2K&XP/UDTTload.sys", 12503, 3036, "$tmpdir/fwtmp1");
203 extract("$tmpdir/VisionDTV/Drivers/Win2K&XP/UDTTload.sys", 2207, 10274, "$tmpdir/fwtmp2");
204
205 my $CMD = "\000\001\000\222\177\000";
206 my $PAD = "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000";
207 my ($FW);
208 open $FW, ">$tmpdir/fwtmp3";
209 print $FW "$CMD\001$PAD";
210 print $FW "$CMD\001$PAD";
211 appendfile($FW, "$tmpdir/fwtmp1");
212 print $FW "$CMD\000$PAD";
213 print $FW "$CMD\001$PAD";
214 appendfile($FW, "$tmpdir/fwtmp2");
215 print $FW "$CMD\001$PAD";
216 print $FW "$CMD\000$PAD";
217 close($FW);
218
219 verify("$tmpdir/fwtmp3", $hash);
220 copy("$tmpdir/fwtmp3", $outfile);
221
222 $outfile;
223 }
224
225 sub dibusb {
226 my $url = "http://www.linuxtv.org/downloads/firmware/dvb-dibusb-5.0.0.11.fw";
227 my $outfile = "dvb-dibusb-5.0.0.11.fw";
228 my $hash = "fa490295a527360ca16dcdf3224ca243";
229
230 checkstandard();
231
232 wgetfile($outfile, $url);
233 verify($outfile,$hash);
234
235 $outfile;
236 }
237
238 sub nxt2002 {
239 my $sourcefile = "Broadband4PC_4_2_11.zip";
240 my $url = "http://www.bbti.us/download/windows/$sourcefile";
241 my $hash = "c6d2ea47a8f456d887ada0cfb718ff2a";
242 my $outfile = "dvb-fe-nxt2002.fw";
243 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
244
245 checkstandard();
246
247 wgetfile($sourcefile, $url);
248 unzip($sourcefile, $tmpdir);
249 verify("$tmpdir/SkyNETU.sys", $hash);
250 extract("$tmpdir/SkyNETU.sys", 375832, 5908, $outfile);
251
252 $outfile;
253 }
254
255 sub nxt2004 {
256 my $sourcefile = "AVerTVHD_MCE_A180_Drv_v1.2.2.16.zip";
257 my $url = "http://www.aver.com/support/Drivers/$sourcefile";
258 my $hash = "111cb885b1e009188346d72acfed024c";
259 my $outfile = "dvb-fe-nxt2004.fw";
260 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
261
262 checkstandard();
263
264 wgetfile($sourcefile, $url);
265 unzip($sourcefile, $tmpdir);
266 verify("$tmpdir/3xHybrid.sys", $hash);
267 extract("$tmpdir/3xHybrid.sys", 465304, 9584, $outfile);
268
269 $outfile;
270 }
271
272 sub or51211 {
273 my $fwfile = "dvb-fe-or51211.fw";
274 my $url = "http://linuxtv.org/downloads/firmware/$fwfile";
275 my $hash = "d830949c771a289505bf9eafc225d491";
276
277 checkstandard();
278
279 wgetfile($fwfile, $url);
280 verify($fwfile, $hash);
281
282 $fwfile;
283 }
284
285 sub or51132_qam {
286 my $fwfile = "dvb-fe-or51132-qam.fw";
287 my $url = "http://linuxtv.org/downloads/firmware/$fwfile";
288 my $hash = "7702e8938612de46ccadfe9b413cb3b5";
289
290 checkstandard();
291
292 wgetfile($fwfile, $url);
293 verify($fwfile, $hash);
294
295 $fwfile;
296 }
297
298 sub or51132_vsb {
299 my $fwfile = "dvb-fe-or51132-vsb.fw";
300 my $url = "http://linuxtv.org/downloads/firmware/$fwfile";
301 my $hash = "c16208e02f36fc439a557ad4c613364a";
302
303 checkstandard();
304
305 wgetfile($fwfile, $url);
306 verify($fwfile, $hash);
307
308 $fwfile;
309 }
310
311 # ---------------------------------------------------------------
312 # Utilities
313
314 sub checkstandard {
315 if (system("which unzip > /dev/null 2>&1")) {
316 die "This firmware requires the unzip command - see ftp://ftp.info-zip.org/pub/infozip/UnZip.html\n";
317 }
318 if (system("which md5sum > /dev/null 2>&1")) {
319 die "This firmware requires the md5sum command - see http://www.gnu.org/software/coreutils/\n";
320 }
321 if (system("which wget > /dev/null 2>&1")) {
322 die "This firmware requires the wget command - see http://wget.sunsite.dk/\n";
323 }
324 }
325
326 sub checkunshield {
327 if (system("which unshield > /dev/null 2>&1")) {
328 die "This firmware requires the unshield command - see http://sourceforge.net/projects/synce/\n";
329 }
330 }
331
332 sub wgetfile {
333 my ($sourcefile, $url) = @_;
334
335 if (! -f $sourcefile) {
336 system("wget -O \"$sourcefile\" \"$url\"") and die "wget failed - unable to download firmware";
337 }
338 }
339
340 sub unzip {
341 my ($sourcefile, $todir) = @_;
342
343 $status = system("unzip -q -o -d \"$todir\" \"$sourcefile\" 2>/dev/null" );
344 if ((($status >> 8) > 2) || (($status & 0xff) != 0)) {
345 die ("unzip failed - unable to extract firmware");
346 }
347 }
348
349 sub unshield {
350 my ($sourcefile, $todir) = @_;
351
352 system("unshield x -d \"$todir\" \"$sourcefile\" > /dev/null" ) and die ("unshield failed - unable to extract firmware");
353 }
354
355 sub verify {
356 my ($filename, $hash) = @_;
357 my ($testhash);
358
359 open(CMD, "md5sum \"$filename\"|");
360 $testhash = <CMD>;
361 $testhash =~ /([a-zA-Z0-9]*)/;
362 $testhash = $1;
363 close CMD;
364 die "Hash of extracted file does not match!\n" if ($testhash ne $hash);
365 }
366
367 sub copy {
368 my ($from, $to) = @_;
369
370 system("cp -f \"$from\" \"$to\"") and die ("cp failed");
371 }
372
373 sub extract {
374 my ($infile, $offset, $length, $outfile) = @_;
375 my ($chunklength, $buf, $rcount);
376
377 open INFILE, "<$infile";
378 open OUTFILE, ">$outfile";
379 sysseek(INFILE, $offset, SEEK_SET);
380 while($length > 0) {
381 # Calc chunk size
382 $chunklength = 2048;
383 $chunklength = $length if ($chunklength > $length);
384
385 $rcount = sysread(INFILE, $buf, $chunklength);
386 die "Ran out of data\n" if ($rcount != $chunklength);
387 syswrite(OUTFILE, $buf);
388 $length -= $rcount;
389 }
390 close INFILE;
391 close OUTFILE;
392 }
393
394 sub appendfile {
395 my ($FH, $infile) = @_;
396 my ($buf);
397
398 open INFILE, "<$infile";
399 while(1) {
400 $rcount = sysread(INFILE, $buf, 2048);
401 last if ($rcount == 0);
402 print $FH $buf;
403 }
404 close(INFILE);
405 }
406
407 sub syntax() {
408 print STDERR "syntax: get_dvb_firmware <component>\n";
409 print STDERR "Supported components:\n";
410 for($i=0; $i < scalar(@components); $i++) {
411 print STDERR "\t" . $components[$i] . "\n";
412 }
413 exit(1);
414 }