blob: 1a90802410bc44022e97a24df833c0c55c1ddd55 [file] [log] [blame]
Kamil Rytarowskicb77f0d2017-05-07 23:25:26 +02001#!/usr/bin/env perl
Thomas Gleixner74ba9202019-05-20 09:19:02 +02002# SPDX-License-Identifier: GPL-2.0-or-later
Linus Torvalds1da177e2005-04-16 15:20:36 -07003# DVB firmware extractor
4#
5# (c) 2004 Andrew de Quincey
6#
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
8use File::Temp qw/ tempdir /;
9use IO::Handle;
10
Giampiero Giancipoli3d8466e2006-02-07 06:49:09 -020011@components = ( "sp8870", "sp887x", "tda10045", "tda10046",
12 "tda10046lifeview", "av7110", "dec2000t", "dec2540t",
Antonio Ospitef6b70ec2012-12-10 17:37:16 -030013 "dec3000s", "vp7041", "vp7049", "dibusb", "nxt2002", "nxt2004",
Marco Gittler59800552007-07-04 19:18:34 -030014 "or51211", "or51132_qam", "or51132_vsb", "bluebird",
Antti Palosaari92540782009-09-12 09:43:25 -030015 "opera1", "cx231xx", "cx18", "cx23885", "pvrusb2", "mpc718",
Malcolm Priestleyd2f918b2010-09-02 17:29:30 -030016 "af9015", "ngene", "az6027", "lme2510_lg", "lme2510c_s7395",
Eddi De Pieri6fd7dba2011-11-21 06:43:52 -030017 "lme2510c_s7395_old", "drxk", "drxk_terratec_h5",
Malcolm Priestley7a016b02014-02-13 18:32:19 -030018 "drxk_hauppauge_hvr930c", "tda10071", "it9135", "drxk_pctv",
Matthias Schwarzott9ca72fa2014-07-22 17:12:11 -030019 "drxk_terratec_htc_stick", "sms1xxx_hcw", "si2165");
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21# Check args
22syntax() if (scalar(@ARGV) != 1);
23$cid = $ARGV[0];
24
25# Do it!
26for ($i=0; $i < scalar(@components); $i++) {
27 if ($cid eq $components[$i]) {
28 $outfile = eval($cid);
29 die $@ if $@;
Ville Skytt\ä12e66f62006-01-09 15:25:38 -020030 print STDERR <<EOF;
Mauro Carvalho Chehabb888c5d2009-03-23 10:57:15 -030031Firmware(s) $outfile extracted successfully.
Oliver Endriss87147ff2010-02-05 07:57:58 -030032Now copy it(them) to either /usr/lib/hotplug/firmware or /lib/firmware
Ville Skytt\ä12e66f62006-01-09 15:25:38 -020033(depending on configuration of firmware hotplug).
34EOF
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 exit(0);
36 }
37}
38
39# If we get here, it wasn't found
40print STDERR "Unknown component \"$cid\"\n";
41syntax();
42
43
44
45
46# ---------------------------------------------------------------
47# Firmware-specific extraction subroutines
48
49sub sp8870 {
50 my $sourcefile = "tt_Premium_217g.zip";
Michael Krufky302170a2007-06-15 19:14:52 -030051 my $url = "http://www.softwarepatch.pl/9999ccd06a4813cb827dbb0005071c71/$sourcefile";
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 my $hash = "53970ec17a538945a6d8cb608a7b3899";
53 my $outfile = "dvb-fe-sp8870.fw";
54 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
55
56 checkstandard();
57
58 wgetfile($sourcefile, $url);
59 unzip($sourcefile, $tmpdir);
60 verify("$tmpdir/software/OEM/HE/App/boot/SC_MAIN.MC", $hash);
61 copy("$tmpdir/software/OEM/HE/App/boot/SC_MAIN.MC", $outfile);
62
63 $outfile;
64}
65
66sub sp887x {
67 my $sourcefile = "Dvbt1.3.57.6.zip";
68 my $url = "http://www.avermedia.com/software/$sourcefile";
69 my $cabfile = "DVBT Net Ver1.3.57.6/disk1/data1.cab";
70 my $hash = "237938d53a7f834c05c42b894ca68ac3";
71 my $outfile = "dvb-fe-sp887x.fw";
72 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
73
74 checkstandard();
75 checkunshield();
76
77 wgetfile($sourcefile, $url);
78 unzip($sourcefile, $tmpdir);
79 unshield("$tmpdir/$cabfile", $tmpdir);
80 verify("$tmpdir/ZEnglish/sc_main.mc", $hash);
81 copy("$tmpdir/ZEnglish/sc_main.mc", $outfile);
82
83 $outfile;
84}
85
86sub tda10045 {
87 my $sourcefile = "tt_budget_217g.zip";
88 my $url = "http://www.technotrend.de/new/217g/$sourcefile";
89 my $hash = "2105fd5bf37842fbcdfa4bfd58f3594a";
90 my $outfile = "dvb-fe-tda10045.fw";
91 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
92
93 checkstandard();
94
95 wgetfile($sourcefile, $url);
96 unzip($sourcefile, $tmpdir);
97 extract("$tmpdir/software/OEM/PCI/App/ttlcdacc.dll", 0x37ef9, 30555, "$tmpdir/fwtmp");
98 verify("$tmpdir/fwtmp", $hash);
99 copy("$tmpdir/fwtmp", $outfile);
100
101 $outfile;
102}
103
104sub tda10046 {
Andreas Arensc545d6a2007-08-15 17:37:16 -0300105 my $sourcefile = "TT_PCI_2.19h_28_11_2006.zip";
Mauro Carvalho Chehab25ec43d2012-09-28 16:16:00 -0300106 my $url = "http://technotrend.com.ua/download/software/219/$sourcefile";
Andreas Arensc545d6a2007-08-15 17:37:16 -0300107 my $hash = "6a7e1e2f2644b162ff0502367553c72d";
108 my $outfile = "dvb-fe-tda10046.fw";
109 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Andreas Arensc545d6a2007-08-15 17:37:16 -0300111 checkstandard();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Andreas Arensc545d6a2007-08-15 17:37:16 -0300113 wgetfile($sourcefile, $url);
114 unzip($sourcefile, $tmpdir);
115 extract("$tmpdir/TT_PCI_2.19h_28_11_2006/software/OEM/PCI/App/ttlcdacc.dll", 0x65389, 24478, "$tmpdir/fwtmp");
116 verify("$tmpdir/fwtmp", $hash);
117 copy("$tmpdir/fwtmp", $outfile);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Andreas Arensc545d6a2007-08-15 17:37:16 -0300119 $outfile;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120}
121
Giampiero Giancipoli3d8466e2006-02-07 06:49:09 -0200122sub tda10046lifeview {
Joseba Goitia Gandiagad852d532009-04-09 18:29:16 -0300123 my $sourcefile = "7%5Cdrv_2.11.02.zip";
124 my $url = "http://www.lifeview.hk/dbimages/document/$sourcefile";
Giampiero Giancipoli3d8466e2006-02-07 06:49:09 -0200125 my $hash = "1ea24dee4eea8fe971686981f34fd2e0";
126 my $outfile = "dvb-fe-tda10046.fw";
127 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
128
129 checkstandard();
130
131 wgetfile($sourcefile, $url);
132 unzip($sourcefile, $tmpdir);
133 extract("$tmpdir/LVHybrid.sys", 0x8b088, 24602, "$tmpdir/fwtmp");
134 verify("$tmpdir/fwtmp", $hash);
135 copy("$tmpdir/fwtmp", $outfile);
136
137 $outfile;
138}
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140sub av7110 {
141 my $sourcefile = "dvb-ttpci-01.fw-261d";
Mauro Carvalho Chehab991ce922015-12-04 10:38:59 -0200142 my $url = "https://linuxtv.org/downloads/firmware/$sourcefile";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 my $hash = "603431b6259715a8e88f376a53b64e2f";
144 my $outfile = "dvb-ttpci-01.fw";
145
146 checkstandard();
147
148 wgetfile($sourcefile, $url);
149 verify($sourcefile, $hash);
150 copy($sourcefile, $outfile);
151
152 $outfile;
153}
154
155sub dec2000t {
156 my $sourcefile = "dec217g.exe";
157 my $url = "http://hauppauge.lightpath.net/de/$sourcefile";
158 my $hash = "bd86f458cee4a8f0a8ce2d20c66215a9";
159 my $outfile = "dvb-ttusb-dec-2000t.fw";
160 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
161
162 checkstandard();
163
164 wgetfile($sourcefile, $url);
165 unzip($sourcefile, $tmpdir);
166 verify("$tmpdir/software/OEM/STB/App/Boot/STB_PC_T.bin", $hash);
167 copy("$tmpdir/software/OEM/STB/App/Boot/STB_PC_T.bin", $outfile);
168
169 $outfile;
170}
171
172sub dec2540t {
173 my $sourcefile = "dec217g.exe";
174 my $url = "http://hauppauge.lightpath.net/de/$sourcefile";
175 my $hash = "53e58f4f5b5c2930beee74a7681fed92";
176 my $outfile = "dvb-ttusb-dec-2540t.fw";
177 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
178
179 checkstandard();
180
181 wgetfile($sourcefile, $url);
182 unzip($sourcefile, $tmpdir);
183 verify("$tmpdir/software/OEM/STB/App/Boot/STB_PC_X.bin", $hash);
184 copy("$tmpdir/software/OEM/STB/App/Boot/STB_PC_X.bin", $outfile);
185
186 $outfile;
187}
188
189sub dec3000s {
190 my $sourcefile = "dec217g.exe";
191 my $url = "http://hauppauge.lightpath.net/de/$sourcefile";
192 my $hash = "b013ececea83f4d6d8d2a29ac7c1b448";
193 my $outfile = "dvb-ttusb-dec-3000s.fw";
194 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
195
196 checkstandard();
197
198 wgetfile($sourcefile, $url);
199 unzip($sourcefile, $tmpdir);
200 verify("$tmpdir/software/OEM/STB/App/Boot/STB_PC_S.bin", $hash);
201 copy("$tmpdir/software/OEM/STB/App/Boot/STB_PC_S.bin", $outfile);
202
203 $outfile;
204}
Marco Gittler59800552007-07-04 19:18:34 -0300205sub opera1{
206 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 0);
207
208 checkstandard();
209 my $fwfile1="dvb-usb-opera1-fpga-01.fw";
210 my $fwfile2="dvb-usb-opera-01.fw";
211 extract("2830SCap2.sys", 0x62e8, 55024, "$tmpdir/opera1-fpga.fw");
212 extract("2830SLoad2.sys",0x3178,0x3685-0x3178,"$tmpdir/fw1part1");
213 extract("2830SLoad2.sys",0x0980,0x3150-0x0980,"$tmpdir/fw1part2");
214 delzero("$tmpdir/fw1part1","$tmpdir/fw1part1-1");
215 delzero("$tmpdir/fw1part2","$tmpdir/fw1part2-1");
216 verify("$tmpdir/fw1part1-1","5e0909858fdf0b5b09ad48b9fe622e70");
217 verify("$tmpdir/fw1part2-1","d6e146f321427e931df2c6fcadac37a1");
218 verify("$tmpdir/opera1-fpga.fw","0f8133f5e9051f5f3c1928f7e5a1b07d");
219
220 my $RES1="\x01\x92\x7f\x00\x01\x00";
221 my $RES0="\x01\x92\x7f\x00\x00\x00";
222 my $DAT1="\x01\x00\xe6\x00\x01\x00";
223 my $DAT0="\x01\x00\xe6\x00\x00\x00";
224 open FW,">$tmpdir/opera.fw";
225 print FW "$RES1";
226 print FW "$DAT1";
227 print FW "$RES1";
228 print FW "$DAT1";
229 appendfile(FW,"$tmpdir/fw1part1-1");
230 print FW "$RES0";
231 print FW "$DAT0";
232 print FW "$RES1";
233 print FW "$DAT1";
234 appendfile(FW,"$tmpdir/fw1part2-1");
235 print FW "$RES1";
236 print FW "$DAT1";
237 print FW "$RES0";
238 print FW "$DAT0";
239 copy ("$tmpdir/opera1-fpga.fw",$fwfile1);
240 copy ("$tmpdir/opera.fw",$fwfile2);
241
242 $fwfile1.",".$fwfile2;
243}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
245sub vp7041 {
246 my $sourcefile = "2.422.zip";
247 my $url = "http://www.twinhan.com/files/driver/USB-Ter/$sourcefile";
248 my $hash = "e88c9372d1f66609a3e7b072c53fbcfe";
249 my $outfile = "dvb-vp7041-2.422.fw";
250 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
251
252 checkstandard();
253
254 wgetfile($sourcefile, $url);
255 unzip($sourcefile, $tmpdir);
256 extract("$tmpdir/VisionDTV/Drivers/Win2K&XP/UDTTload.sys", 12503, 3036, "$tmpdir/fwtmp1");
257 extract("$tmpdir/VisionDTV/Drivers/Win2K&XP/UDTTload.sys", 2207, 10274, "$tmpdir/fwtmp2");
258
259 my $CMD = "\000\001\000\222\177\000";
260 my $PAD = "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000";
261 my ($FW);
262 open $FW, ">$tmpdir/fwtmp3";
263 print $FW "$CMD\001$PAD";
264 print $FW "$CMD\001$PAD";
265 appendfile($FW, "$tmpdir/fwtmp1");
266 print $FW "$CMD\000$PAD";
267 print $FW "$CMD\001$PAD";
268 appendfile($FW, "$tmpdir/fwtmp2");
269 print $FW "$CMD\001$PAD";
270 print $FW "$CMD\000$PAD";
271 close($FW);
272
273 verify("$tmpdir/fwtmp3", $hash);
274 copy("$tmpdir/fwtmp3", $outfile);
275
276 $outfile;
277}
278
Antonio Ospitef6b70ec2012-12-10 17:37:16 -0300279sub vp7049 {
280 my $fwfile = "dvb-usb-vp7049-0.95.fw";
281 my $url = "http://ao2.it/sites/default/files/blog/2012/11/06/linux-support-digicom-digitune-s-vp7049-udtt7049/$fwfile";
282 my $hash = "5609fd295168aea88b25ff43a6f79c36";
283
284 checkstandard();
285
286 wgetfile($fwfile, $url);
287 verify($fwfile, $hash);
288
289 $fwfile;
290}
291
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292sub dibusb {
Mauro Carvalho Chehab991ce922015-12-04 10:38:59 -0200293 my $url = "https://linuxtv.org/downloads/firmware/dvb-usb-dibusb-5.0.0.11.fw";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 my $outfile = "dvb-dibusb-5.0.0.11.fw";
295 my $hash = "fa490295a527360ca16dcdf3224ca243";
296
297 checkstandard();
298
299 wgetfile($outfile, $url);
300 verify($outfile,$hash);
301
302 $outfile;
303}
304
305sub nxt2002 {
Michael Krufkyba5f0a42006-04-23 01:55:38 -0300306 my $sourcefile = "Technisat_DVB-PC_4_4_COMPACT.zip";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 my $url = "http://www.bbti.us/download/windows/$sourcefile";
Michael Krufkyba5f0a42006-04-23 01:55:38 -0300308 my $hash = "476befae8c7c1bb9648954060b1eec1f";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 my $outfile = "dvb-fe-nxt2002.fw";
310 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
311
312 checkstandard();
Michael Krufky50c25ff2006-01-09 15:25:34 -0200313
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 wgetfile($sourcefile, $url);
315 unzip($sourcefile, $tmpdir);
Michael Krufkyba5f0a42006-04-23 01:55:38 -0300316 verify("$tmpdir/SkyNET.sys", $hash);
317 extract("$tmpdir/SkyNET.sys", 331624, 5908, $outfile);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
319 $outfile;
320}
321
Kirk Lapray04a45922005-11-08 21:35:46 -0800322sub nxt2004 {
323 my $sourcefile = "AVerTVHD_MCE_A180_Drv_v1.2.2.16.zip";
Jan Ceuleersf6a061b2009-06-11 16:20:23 -0300324 my $url = "http://www.avermedia-usa.com/support/Drivers/$sourcefile";
Kirk Lapray04a45922005-11-08 21:35:46 -0800325 my $hash = "111cb885b1e009188346d72acfed024c";
326 my $outfile = "dvb-fe-nxt2004.fw";
327 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
328
329 checkstandard();
330
331 wgetfile($sourcefile, $url);
332 unzip($sourcefile, $tmpdir);
333 verify("$tmpdir/3xHybrid.sys", $hash);
334 extract("$tmpdir/3xHybrid.sys", 465304, 9584, $outfile);
335
336 $outfile;
337}
338
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339sub or51211 {
340 my $fwfile = "dvb-fe-or51211.fw";
Mauro Carvalho Chehab991ce922015-12-04 10:38:59 -0200341 my $url = "https://linuxtv.org/downloads/firmware/$fwfile";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 my $hash = "d830949c771a289505bf9eafc225d491";
343
344 checkstandard();
345
346 wgetfile($fwfile, $url);
347 verify($fwfile, $hash);
348
349 $fwfile;
350}
351
Mauro Carvalho Chehab06e95092009-03-19 12:10:00 -0300352sub cx231xx {
353 my $fwfile = "v4l-cx231xx-avcore-01.fw";
Mauro Carvalho Chehab991ce922015-12-04 10:38:59 -0200354 my $url = "https://linuxtv.org/downloads/firmware/$fwfile";
Mauro Carvalho Chehab06e95092009-03-19 12:10:00 -0300355 my $hash = "7d3bb956dc9df0eafded2b56ba57cc42";
356
357 checkstandard();
358
359 wgetfile($fwfile, $url);
360 verify($fwfile, $hash);
361
362 $fwfile;
363}
364
Mauro Carvalho Chehabb888c5d2009-03-23 10:57:15 -0300365sub cx18 {
Mauro Carvalho Chehab991ce922015-12-04 10:38:59 -0200366 my $url = "https://linuxtv.org/downloads/firmware/";
Mauro Carvalho Chehabb888c5d2009-03-23 10:57:15 -0300367
368 my %files = (
369 'v4l-cx23418-apu.fw' => '588f081b562f5c653a3db1ad8f65939a',
370 'v4l-cx23418-cpu.fw' => 'b6c7ed64bc44b1a6e0840adaeac39d79',
371 'v4l-cx23418-dig.fw' => '95bc688d3e7599fd5800161e9971cc55',
372 );
373
374 checkstandard();
375
376 my $allfiles;
377 foreach my $fwfile (keys %files) {
378 wgetfile($fwfile, "$url/$fwfile");
379 verify($fwfile, $files{$fwfile});
380 $allfiles .= " $fwfile";
381 }
382
383 $allfiles =~ s/^\s//;
384
385 $allfiles;
386}
387
Andy Walls9f38a922009-07-03 11:33:17 -0300388sub mpc718 {
389 my $archive = 'Yuan MPC718 TV Tuner Card 2.13.10.1016.zip';
390 my $url = "ftp://ftp.work.acer-euro.com/desktop/aspire_idea510/vista/Drivers/$archive";
391 my $fwfile = "dvb-cx18-mpc718-mt352.fw";
392 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
393
394 checkstandard();
395 wgetfile($archive, $url);
396 unzip($archive, $tmpdir);
397
398 my $sourcefile = "$tmpdir/Yuan MPC718 TV Tuner Card 2.13.10.1016/mpc718_32bit/yuanrap.sys";
399 my $found = 0;
400
401 open IN, '<', $sourcefile or die "Couldn't open $sourcefile to extract $fwfile data\n";
402 binmode IN;
403 open OUT, '>', $fwfile;
404 binmode OUT;
405 {
406 # Block scope because we change the line terminator variable $/
407 my $prevlen = 0;
408 my $currlen;
409
410 # Buried in the data segment are 3 runs of almost identical
411 # register-value pairs that end in 0x5d 0x01 which is a "TUNER GO"
412 # command for the MT352.
413 # Pull out the middle run (because it's easy) of register-value
414 # pairs to make the "firmware" file.
415
416 local $/ = "\x5d\x01"; # MT352 "TUNER GO"
417
418 while (<IN>) {
419 $currlen = length($_);
Andy Walls0a684342009-07-05 16:22:45 -0300420 if ($prevlen == $currlen && $currlen <= 64) {
Andy Walls9f38a922009-07-03 11:33:17 -0300421 chop; chop; # Get rid of "TUNER GO"
422 s/^\0\0//; # get rid of leading 00 00 if it's there
423 printf OUT "$_";
424 $found = 1;
425 last;
426 }
Andy Walls0a684342009-07-05 16:22:45 -0300427 $prevlen = $currlen;
Andy Walls9f38a922009-07-03 11:33:17 -0300428 }
429 }
430 close OUT;
431 close IN;
432 if (!$found) {
433 unlink $fwfile;
434 die "Couldn't find valid register-value sequence in $sourcefile for $fwfile\n";
435 }
436 $fwfile;
437}
438
Mauro Carvalho Chehab5297e6f2009-03-23 11:46:19 -0300439sub cx23885 {
Mauro Carvalho Chehab991ce922015-12-04 10:38:59 -0200440 my $url = "https://linuxtv.org/downloads/firmware/";
Mauro Carvalho Chehab5297e6f2009-03-23 11:46:19 -0300441
442 my %files = (
443 'v4l-cx23885-avcore-01.fw' => 'a9f8f5d901a7fb42f552e1ee6384f3bb',
444 'v4l-cx23885-enc.fw' => 'a9f8f5d901a7fb42f552e1ee6384f3bb',
Mauro Carvalho Chehabf65a95b2009-03-23 12:35:03 -0300445 );
446
447 checkstandard();
448
449 my $allfiles;
450 foreach my $fwfile (keys %files) {
451 wgetfile($fwfile, "$url/$fwfile");
452 verify($fwfile, $files{$fwfile});
453 $allfiles .= " $fwfile";
454 }
455
456 $allfiles =~ s/^\s//;
457
458 $allfiles;
459}
460
461sub pvrusb2 {
Mauro Carvalho Chehab991ce922015-12-04 10:38:59 -0200462 my $url = "https://linuxtv.org/downloads/firmware/";
Mauro Carvalho Chehabf65a95b2009-03-23 12:35:03 -0300463
464 my %files = (
Mauro Carvalho Chehab5297e6f2009-03-23 11:46:19 -0300465 'v4l-cx25840.fw' => 'dadb79e9904fc8af96e8111d9cb59320',
466 );
467
468 checkstandard();
469
470 my $allfiles;
471 foreach my $fwfile (keys %files) {
472 wgetfile($fwfile, "$url/$fwfile");
473 verify($fwfile, $files{$fwfile});
474 $allfiles .= " $fwfile";
475 }
476
477 $allfiles =~ s/^\s//;
478
479 $allfiles;
480}
481
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482sub or51132_qam {
483 my $fwfile = "dvb-fe-or51132-qam.fw";
Mauro Carvalho Chehab991ce922015-12-04 10:38:59 -0200484 my $url = "https://linuxtv.org/downloads/firmware/$fwfile";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 my $hash = "7702e8938612de46ccadfe9b413cb3b5";
486
487 checkstandard();
488
489 wgetfile($fwfile, $url);
490 verify($fwfile, $hash);
491
492 $fwfile;
493}
494
495sub or51132_vsb {
496 my $fwfile = "dvb-fe-or51132-vsb.fw";
Mauro Carvalho Chehab991ce922015-12-04 10:38:59 -0200497 my $url = "https://linuxtv.org/downloads/firmware/$fwfile";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 my $hash = "c16208e02f36fc439a557ad4c613364a";
499
500 checkstandard();
501
502 wgetfile($fwfile, $url);
503 verify($fwfile, $hash);
504
505 $fwfile;
506}
507
Michael Krufkyd8e6acf2006-01-09 15:32:42 -0200508sub bluebird {
Mauro Carvalho Chehab991ce922015-12-04 10:38:59 -0200509 my $url = "https://linuxtv.org/download/dvb/firmware/dvb-usb-bluebird-01.fw";
Michael Krufkyd8e6acf2006-01-09 15:32:42 -0200510 my $outfile = "dvb-usb-bluebird-01.fw";
511 my $hash = "658397cb9eba9101af9031302671f49d";
512
513 checkstandard();
514
515 wgetfile($outfile, $url);
516 verify($outfile,$hash);
517
518 $outfile;
519}
520
Antti Palosaari92540782009-09-12 09:43:25 -0300521sub af9015 {
522 my $sourcefile = "download.ashx?file=57";
523 my $url = "http://www.ite.com.tw/EN/Services/$sourcefile";
Antti Palosaari4e9f5672010-05-14 15:24:28 -0300524 my $hash = "e3f08935158038d385ad382442f4bb2d";
Antti Palosaari92540782009-09-12 09:43:25 -0300525 my $outfile = "dvb-usb-af9015.fw";
526 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
Antti Palosaari4e9f5672010-05-14 15:24:28 -0300527 my $fwoffset = 0x25690;
528 my $fwlength = 18725;
Antti Palosaari92540782009-09-12 09:43:25 -0300529 my ($chunklength, $buf, $rcount);
530
531 checkstandard();
532
533 wgetfile($sourcefile, $url);
534 unzip($sourcefile, $tmpdir);
535 verify("$tmpdir/Driver/Files/AF15BDA.sys", $hash);
536
537 open INFILE, '<', "$tmpdir/Driver/Files/AF15BDA.sys";
538 open OUTFILE, '>', $outfile;
539
540 sysseek(INFILE, $fwoffset, SEEK_SET);
541 while($fwlength > 0) {
542 $chunklength = 55;
543 $chunklength = $fwlength if ($chunklength > $fwlength);
544 $rcount = sysread(INFILE, $buf, $chunklength);
545 die "Ran out of data\n" if ($rcount != $chunklength);
546 syswrite(OUTFILE, $buf);
547 sysread(INFILE, $buf, 8);
548 $fwlength -= $rcount + 8;
549 }
550
551 close OUTFILE;
552 close INFILE;
553}
554
Oliver Endrisse7e41d32010-02-05 07:52:44 -0300555sub ngene {
556 my $url = "http://www.digitaldevices.de/download/";
557 my $file1 = "ngene_15.fw";
558 my $hash1 = "d798d5a757121174f0dbc5f2833c0c85";
559 my $file2 = "ngene_17.fw";
560 my $hash2 = "26b687136e127b8ac24b81e0eeafc20b";
Oliver Endrissf33de4a2011-01-10 06:36:19 -0300561 my $url2 = "http://l4m-daten.de/downloads/firmware/dvb-s2/linux/all/";
562 my $file3 = "ngene_18.fw";
563 my $hash3 = "ebce3ea769a53e3e0b0197c3b3f127e3";
Oliver Endrisse7e41d32010-02-05 07:52:44 -0300564
565 checkstandard();
566
567 wgetfile($file1, $url . $file1);
568 verify($file1, $hash1);
569
570 wgetfile($file2, $url . $file2);
571 verify($file2, $hash2);
572
Oliver Endrissf33de4a2011-01-10 06:36:19 -0300573 wgetfile($file3, $url2 . $file3);
574 verify($file3, $hash3);
575
576 "$file1, $file2, $file3";
Oliver Endrisse7e41d32010-02-05 07:52:44 -0300577}
578
Renzo Dani89d328d2010-07-06 07:23:33 -0300579sub az6027{
Renzo Dani89d328d2010-07-06 07:23:33 -0300580 my $firmware = "dvb-usb-az6027-03.fw";
Renzo Dani873c07d2011-10-09 06:43:50 -0300581 my $url = "http://linux.terratec.de/files/TERRATEC_S7/$firmware";
Renzo Dani89d328d2010-07-06 07:23:33 -0300582
Renzo Dani873c07d2011-10-09 06:43:50 -0300583 wgetfile($firmware, $url);
Renzo Dani89d328d2010-07-06 07:23:33 -0300584
585 $firmware;
586}
Malcolm Priestleyd2f918b2010-09-02 17:29:30 -0300587
588sub lme2510_lg {
589 my $sourcefile = "LMEBDA_DVBS.sys";
590 my $hash = "fc6017ad01e79890a97ec53bea157ed2";
591 my $outfile = "dvb-usb-lme2510-lg.fw";
592 my $hasho = "caa065d5fdbd2c09ad57b399bbf55cad";
593
594 checkstandard();
595
596 verify($sourcefile, $hash);
597 extract($sourcefile, 4168, 3841, $outfile);
598 verify($outfile, $hasho);
599 $outfile;
600}
601
602sub lme2510c_s7395 {
603 my $sourcefile = "US2A0D.sys";
604 my $hash = "b0155a8083fb822a3bd47bc360e74601";
605 my $outfile = "dvb-usb-lme2510c-s7395.fw";
606 my $hasho = "3a3cf1aeebd17b6ddc04cebe131e94cf";
607
608 checkstandard();
609
610 verify($sourcefile, $hash);
611 extract($sourcefile, 37248, 3720, $outfile);
612 verify($outfile, $hasho);
613 $outfile;
614}
615
616sub lme2510c_s7395_old {
617 my $sourcefile = "LMEBDA_DVBS7395C.sys";
618 my $hash = "7572ae0eb9cdf91baabd7c0ba9e09b31";
619 my $outfile = "dvb-usb-lme2510c-s7395.fw";
620 my $hasho = "90430c5b435eb5c6f88fd44a9d950674";
621
622 checkstandard();
623
624 verify($sourcefile, $hash);
625 extract($sourcefile, 4208, 3881, $outfile);
626 verify($outfile, $hasho);
627 $outfile;
628}
629
Oliver Endrissf9004df2011-07-03 13:53:50 -0300630sub drxk {
631 my $url = "http://l4m-daten.de/files/";
632 my $zipfile = "DDTuner.zip";
633 my $hash = "f5a37b9a20a3534997997c0b1382a3e5";
634 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
635 my $drvfile = "DDTuner.sys";
636 my $fwfile = "drxk_a3.mc";
637
638 checkstandard();
639
640 wgetfile($zipfile, $url . $zipfile);
641 verify($zipfile, $hash);
642 unzip($zipfile, $tmpdir);
643 extract("$tmpdir/$drvfile", 0x14dd8, 15634, "$fwfile");
644
645 "$fwfile"
646}
647
Eddi De Pieri6fd7dba2011-11-21 06:43:52 -0300648sub drxk_hauppauge_hvr930c {
649 my $url = "http://www.wintvcd.co.uk/drivers/";
650 my $zipfile = "HVR-9x0_5_10_325_28153_SIGNED.zip";
651 my $hash = "83ab82e7e9480ec8bf1ae0155ca63c88";
652 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
653 my $drvfile = "HVR-900/emOEM.sys";
654 my $fwfile = "dvb-usb-hauppauge-hvr930c-drxk.fw";
655
656 checkstandard();
657
658 wgetfile($zipfile, $url . $zipfile);
659 verify($zipfile, $hash);
660 unzip($zipfile, $tmpdir);
661 extract("$tmpdir/$drvfile", 0x117b0, 42692, "$fwfile");
662
663 "$fwfile"
664}
665
Mauro Carvalho Chehab8b9456a2011-07-11 14:33:51 -0300666sub drxk_terratec_h5 {
Mauro Carvalho Chehab991ce922015-12-04 10:38:59 -0200667 my $url = "https://linuxtv.org/downloads/firmware/";
Mauro Carvalho Chehab8b9456a2011-07-11 14:33:51 -0300668 my $hash = "19000dada8e2741162ccc50cc91fa7f1";
669 my $fwfile = "dvb-usb-terratec-h5-drxk.fw";
670
671 checkstandard();
672
673 wgetfile($fwfile, $url . $fwfile);
674 verify($fwfile, $hash);
675
676 "$fwfile"
677}
678
Martin Blumenstingl7bdc0fb2012-06-12 18:19:26 -0300679sub drxk_terratec_htc_stick {
Martin Blumenstingl8cd70852013-01-01 08:54:26 -0300680 my $url = "http://ftp.terratec.de/Receiver/Cinergy_HTC_Stick/Updates/History/";
Martin Blumenstingl7bdc0fb2012-06-12 18:19:26 -0300681 my $zipfile = "Cinergy_HTC_Stick_Drv_5.09.1202.00_XP_Vista_7.exe";
682 my $hash = "6722a2442a05423b781721fbc069ed5e";
683 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 0);
684 my $drvfile = "Cinergy HTC Stick/BDA Driver 5.09.1202.00/Windows 32 Bit/emOEM.sys";
685 my $fwfile = "dvb-usb-terratec-htc-stick-drxk.fw";
686
687 checkstandard();
688
689 wgetfile($zipfile, $url . $zipfile);
690 verify($zipfile, $hash);
691 unzip($zipfile, $tmpdir);
692 extract("$tmpdir/$drvfile", 0x4e5c0, 42692, "$fwfile");
693
694 "$fwfile"
695}
696
Benjamin Larsson3188d542011-07-27 08:43:38 -0300697sub it9135 {
Bimow Chen7c5e3e52014-08-01 06:19:58 -0300698 my $url = "http://www.ite.com.tw/uploads/firmware/v3.25.0.0/";
699 my $file1 = "dvb-usb-it9135-01.zip";
Malcolm Priestley7330f7c2011-11-30 17:17:43 -0300700 my $fwfile1 = "dvb-usb-it9135-01.fw";
Bimow Chen7c5e3e52014-08-01 06:19:58 -0300701 my $hash1 = "02fcf11174eda84745dae7e61c5ff9ba";
702 my $file2 = "dvb-usb-it9135-02.zip";
Malcolm Priestley7330f7c2011-11-30 17:17:43 -0300703 my $fwfile2 = "dvb-usb-it9135-02.fw";
Bimow Chen7c5e3e52014-08-01 06:19:58 -0300704 my $hash2 = "d5e1437dc24358578e07999475d4cac9";
Malcolm Priestley7330f7c2011-11-30 17:17:43 -0300705
706 checkstandard();
707
Bimow Chen7c5e3e52014-08-01 06:19:58 -0300708 wgetfile($file1, $url . $file1);
709 unzip($file1, "");
710 verify("$fwfile1", $hash1);
Malcolm Priestley7330f7c2011-11-30 17:17:43 -0300711
Bimow Chen7c5e3e52014-08-01 06:19:58 -0300712 wgetfile($file2, $url . $file2);
713 unzip($file2, "");
714 verify("$fwfile2", $hash2);
715
716 "$file1 $file2"
Malcolm Priestley7330f7c2011-11-30 17:17:43 -0300717}
718
Antti Palosaari465301b12011-08-01 23:34:58 -0300719sub tda10071 {
Antti Palosaariead20952011-08-02 11:35:06 -0300720 my $sourcefile = "PCTV_460e_reference.zip";
Antti Palosaari465301b12011-08-01 23:34:58 -0300721 my $url = "ftp://ftp.pctvsystems.com/TV/driver/PCTV%2070e%2080e%20100e%20320e%20330e%20800e/";
722 my $hash = "4403de903bf2593464c8d74bbc200a57";
723 my $fwfile = "dvb-fe-tda10071.fw";
724 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
Benjamin Larsson3188d542011-07-27 08:43:38 -0300725
Antti Palosaari465301b12011-08-01 23:34:58 -0300726 checkstandard();
727
728 wgetfile($sourcefile, $url . $sourcefile);
729 verify($sourcefile, $hash);
730 unzip($sourcefile, $tmpdir);
731 extract("$tmpdir/PCTV\ 70e\ 80e\ 100e\ 320e\ 330e\ 800e/32\ bit/emOEM.sys", 0x67d38, 40504, $fwfile);
732
733 "$fwfile";
734}
Benjamin Larsson3188d542011-07-27 08:43:38 -0300735
Antti Palosaari662f9602012-03-19 11:48:18 -0300736sub drxk_pctv {
737 my $sourcefile = "PCTV_460e_reference.zip";
738 my $url = "ftp://ftp.pctvsystems.com/TV/driver/PCTV%2070e%2080e%20100e%20320e%20330e%20800e/";
739 my $hash = "4403de903bf2593464c8d74bbc200a57";
740 my $fwfile = "dvb-demod-drxk-pctv.fw";
741 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
742
743 checkstandard();
744
745 wgetfile($sourcefile, $url . $sourcefile);
746 verify($sourcefile, $hash);
747 unzip($sourcefile, $tmpdir);
748 extract("$tmpdir/PCTV\ 70e\ 80e\ 100e\ 320e\ 330e\ 800e/32\ bit/emOEM.sys", 0x72b80, 42692, $fwfile);
749
750 "$fwfile";
751}
752
Mauro Carvalho Chehabf244e6c2012-07-05 22:35:55 -0300753sub sms1xxx_hcw {
754 my $url = "http://steventoth.net/linux/sms1xxx/";
755 my %files = (
756 'sms1xxx-hcw-55xxx-dvbt-01.fw' => "afb6f9fb9a71d64392e8564ef9577e5a",
757 'sms1xxx-hcw-55xxx-dvbt-02.fw' => "b44807098ba26e52cbedeadc052ba58f",
758 'sms1xxx-hcw-55xxx-isdbt-02.fw' => "dae934eeea85225acbd63ce6cfe1c9e4",
759 );
760
761 checkstandard();
762
763 my $allfiles;
764 foreach my $fwfile (keys %files) {
765 wgetfile($fwfile, "$url/$fwfile");
766 verify($fwfile, $files{$fwfile});
767 $allfiles .= " $fwfile";
768 }
769
770 $allfiles =~ s/^\s//;
771
772 $allfiles;
773}
774
Matthias Schwarzott9ca72fa2014-07-22 17:12:11 -0300775sub si2165 {
776 my $sourcefile = "model_111xxx_122xxx_driver_6_0_119_31191_WHQL.zip";
777 my $url = "http://www.hauppauge.de/files/drivers/";
778 my $hash = "76633e7c76b0edee47c3ba18ded99336";
779 my $fwfile = "dvb-demod-si2165.fw";
780 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
781
782 checkstandard();
783
784 wgetfile($sourcefile, $url . $sourcefile);
785 verify($sourcefile, $hash);
786 unzip($sourcefile, $tmpdir);
787 extract("$tmpdir/Driver10/Hcw10bda.sys", 0x80788, 0x81E08-0x80788, "$tmpdir/fw1");
788
789 delzero("$tmpdir/fw1","$tmpdir/fw1-1");
790 #verify("$tmpdir/fw1","5e0909858fdf0b5b09ad48b9fe622e70");
791
792 my $CRC="\x0A\xCC";
793 my $BLOCKS_MAIN="\x27";
794 open FW,">$fwfile";
795 print FW "\x01\x00"; # just a version id for the driver itself
796 print FW "\x9A"; # fw version
797 print FW "\x00"; # padding
798 print FW "$BLOCKS_MAIN"; # number of blocks of main part
799 print FW "\x00"; # padding
800 print FW "$CRC"; # 16bit crc value of main part
801 appendfile(FW,"$tmpdir/fw1");
802
803 "$fwfile";
804}
805
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806# ---------------------------------------------------------------
807# Utilities
808
809sub checkstandard {
810 if (system("which unzip > /dev/null 2>&1")) {
811 die "This firmware requires the unzip command - see ftp://ftp.info-zip.org/pub/infozip/UnZip.html\n";
812 }
813 if (system("which md5sum > /dev/null 2>&1")) {
814 die "This firmware requires the md5sum command - see http://www.gnu.org/software/coreutils/\n";
815 }
816 if (system("which wget > /dev/null 2>&1")) {
817 die "This firmware requires the wget command - see http://wget.sunsite.dk/\n";
818 }
819}
820
821sub checkunshield {
822 if (system("which unshield > /dev/null 2>&1")) {
823 die "This firmware requires the unshield command - see http://sourceforge.net/projects/synce/\n";
824 }
825}
826
827sub wgetfile {
828 my ($sourcefile, $url) = @_;
829
830 if (! -f $sourcefile) {
831 system("wget -O \"$sourcefile\" \"$url\"") and die "wget failed - unable to download firmware";
832 }
833}
834
835sub unzip {
836 my ($sourcefile, $todir) = @_;
837
838 $status = system("unzip -q -o -d \"$todir\" \"$sourcefile\" 2>/dev/null" );
839 if ((($status >> 8) > 2) || (($status & 0xff) != 0)) {
840 die ("unzip failed - unable to extract firmware");
841 }
842}
843
844sub unshield {
845 my ($sourcefile, $todir) = @_;
846
847 system("unshield x -d \"$todir\" \"$sourcefile\" > /dev/null" ) and die ("unshield failed - unable to extract firmware");
848}
849
850sub verify {
851 my ($filename, $hash) = @_;
852 my ($testhash);
853
854 open(CMD, "md5sum \"$filename\"|");
855 $testhash = <CMD>;
856 $testhash =~ /([a-zA-Z0-9]*)/;
857 $testhash = $1;
858 close CMD;
859 die "Hash of extracted file does not match!\n" if ($testhash ne $hash);
860}
861
862sub copy {
863 my ($from, $to) = @_;
864
865 system("cp -f \"$from\" \"$to\"") and die ("cp failed");
866}
867
868sub extract {
869 my ($infile, $offset, $length, $outfile) = @_;
870 my ($chunklength, $buf, $rcount);
871
872 open INFILE, "<$infile";
873 open OUTFILE, ">$outfile";
874 sysseek(INFILE, $offset, SEEK_SET);
875 while($length > 0) {
876 # Calc chunk size
877 $chunklength = 2048;
878 $chunklength = $length if ($chunklength > $length);
879
880 $rcount = sysread(INFILE, $buf, $chunklength);
881 die "Ran out of data\n" if ($rcount != $chunklength);
882 syswrite(OUTFILE, $buf);
883 $length -= $rcount;
884 }
885 close INFILE;
886 close OUTFILE;
887}
888
889sub appendfile {
890 my ($FH, $infile) = @_;
891 my ($buf);
892
893 open INFILE, "<$infile";
894 while(1) {
895 $rcount = sysread(INFILE, $buf, 2048);
896 last if ($rcount == 0);
897 print $FH $buf;
898 }
899 close(INFILE);
900}
901
Marco Gittler59800552007-07-04 19:18:34 -0300902sub delzero{
903 my ($infile,$outfile) =@_;
904
905 open INFILE,"<$infile";
906 open OUTFILE,">$outfile";
907 while (1){
908 $rcount=sysread(INFILE,$buf,22);
909 $len=ord(substr($buf,0,1));
910 print OUTFILE substr($buf,0,1);
911 print OUTFILE substr($buf,2,$len+3);
912 last if ($rcount<1);
913 printf OUTFILE "%c",0;
914#print $len." ".length($buf)."\n";
915
916 }
917 close(INFILE);
918 close(OUTFILE);
919}
920
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921sub syntax() {
922 print STDERR "syntax: get_dvb_firmware <component>\n";
923 print STDERR "Supported components:\n";
Oliver Endriss87147ff2010-02-05 07:57:58 -0300924 @components = sort @components;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 for($i=0; $i < scalar(@components); $i++) {
926 print STDERR "\t" . $components[$i] . "\n";
927 }
928 exit(1);
929}