do not preallocate cor_connid_reuse_item
[cor.git] / scripts / get_dvb_firmware
blob1a90802410bc44022e97a24df833c0c55c1ddd55
1 #!/usr/bin/env perl
2 # SPDX-License-Identifier: GPL-2.0-or-later
3 # DVB firmware extractor
5 # (c) 2004 Andrew de Quincey
8 use File::Temp qw/ tempdir /;
9 use IO::Handle;
11 @components = ( "sp8870", "sp887x", "tda10045", "tda10046",
12 "tda10046lifeview", "av7110", "dec2000t", "dec2540t",
13 "dec3000s", "vp7041", "vp7049", "dibusb", "nxt2002", "nxt2004",
14 "or51211", "or51132_qam", "or51132_vsb", "bluebird",
15 "opera1", "cx231xx", "cx18", "cx23885", "pvrusb2", "mpc718",
16 "af9015", "ngene", "az6027", "lme2510_lg", "lme2510c_s7395",
17 "lme2510c_s7395_old", "drxk", "drxk_terratec_h5",
18 "drxk_hauppauge_hvr930c", "tda10071", "it9135", "drxk_pctv",
19 "drxk_terratec_htc_stick", "sms1xxx_hcw", "si2165");
21 # Check args
22 syntax() if (scalar(@ARGV) != 1);
23 $cid = $ARGV[0];
25 # Do it!
26 for ($i=0; $i < scalar(@components); $i++) {
27 if ($cid eq $components[$i]) {
28 $outfile = eval($cid);
29 die $@ if $@;
30 print STDERR <<EOF;
31 Firmware(s) $outfile extracted successfully.
32 Now copy it(them) to either /usr/lib/hotplug/firmware or /lib/firmware
33 (depending on configuration of firmware hotplug).
34 EOF
35 exit(0);
39 # If we get here, it wasn't found
40 print STDERR "Unknown component \"$cid\"\n";
41 syntax();
46 # ---------------------------------------------------------------
47 # Firmware-specific extraction subroutines
49 sub sp8870 {
50 my $sourcefile = "tt_Premium_217g.zip";
51 my $url = "http://www.softwarepatch.pl/9999ccd06a4813cb827dbb0005071c71/$sourcefile";
52 my $hash = "53970ec17a538945a6d8cb608a7b3899";
53 my $outfile = "dvb-fe-sp8870.fw";
54 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
56 checkstandard();
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);
63 $outfile;
66 sub 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);
74 checkstandard();
75 checkunshield();
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);
83 $outfile;
86 sub 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);
93 checkstandard();
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);
101 $outfile;
104 sub tda10046 {
105 my $sourcefile = "TT_PCI_2.19h_28_11_2006.zip";
106 my $url = "http://technotrend.com.ua/download/software/219/$sourcefile";
107 my $hash = "6a7e1e2f2644b162ff0502367553c72d";
108 my $outfile = "dvb-fe-tda10046.fw";
109 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
111 checkstandard();
113 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);
119 $outfile;
122 sub tda10046lifeview {
123 my $sourcefile = "7%5Cdrv_2.11.02.zip";
124 my $url = "http://www.lifeview.hk/dbimages/document/$sourcefile";
125 my $hash = "1ea24dee4eea8fe971686981f34fd2e0";
126 my $outfile = "dvb-fe-tda10046.fw";
127 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
129 checkstandard();
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);
137 $outfile;
140 sub av7110 {
141 my $sourcefile = "dvb-ttpci-01.fw-261d";
142 my $url = "https://linuxtv.org/downloads/firmware/$sourcefile";
143 my $hash = "603431b6259715a8e88f376a53b64e2f";
144 my $outfile = "dvb-ttpci-01.fw";
146 checkstandard();
148 wgetfile($sourcefile, $url);
149 verify($sourcefile, $hash);
150 copy($sourcefile, $outfile);
152 $outfile;
155 sub 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);
162 checkstandard();
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);
169 $outfile;
172 sub 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);
179 checkstandard();
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);
186 $outfile;
189 sub 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);
196 checkstandard();
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);
203 $outfile;
205 sub opera1{
206 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 0);
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");
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);
242 $fwfile1.",".$fwfile2;
245 sub 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);
252 checkstandard();
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");
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);
273 verify("$tmpdir/fwtmp3", $hash);
274 copy("$tmpdir/fwtmp3", $outfile);
276 $outfile;
279 sub 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";
284 checkstandard();
286 wgetfile($fwfile, $url);
287 verify($fwfile, $hash);
289 $fwfile;
292 sub dibusb {
293 my $url = "https://linuxtv.org/downloads/firmware/dvb-usb-dibusb-5.0.0.11.fw";
294 my $outfile = "dvb-dibusb-5.0.0.11.fw";
295 my $hash = "fa490295a527360ca16dcdf3224ca243";
297 checkstandard();
299 wgetfile($outfile, $url);
300 verify($outfile,$hash);
302 $outfile;
305 sub nxt2002 {
306 my $sourcefile = "Technisat_DVB-PC_4_4_COMPACT.zip";
307 my $url = "http://www.bbti.us/download/windows/$sourcefile";
308 my $hash = "476befae8c7c1bb9648954060b1eec1f";
309 my $outfile = "dvb-fe-nxt2002.fw";
310 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
312 checkstandard();
314 wgetfile($sourcefile, $url);
315 unzip($sourcefile, $tmpdir);
316 verify("$tmpdir/SkyNET.sys", $hash);
317 extract("$tmpdir/SkyNET.sys", 331624, 5908, $outfile);
319 $outfile;
322 sub nxt2004 {
323 my $sourcefile = "AVerTVHD_MCE_A180_Drv_v1.2.2.16.zip";
324 my $url = "http://www.avermedia-usa.com/support/Drivers/$sourcefile";
325 my $hash = "111cb885b1e009188346d72acfed024c";
326 my $outfile = "dvb-fe-nxt2004.fw";
327 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
329 checkstandard();
331 wgetfile($sourcefile, $url);
332 unzip($sourcefile, $tmpdir);
333 verify("$tmpdir/3xHybrid.sys", $hash);
334 extract("$tmpdir/3xHybrid.sys", 465304, 9584, $outfile);
336 $outfile;
339 sub or51211 {
340 my $fwfile = "dvb-fe-or51211.fw";
341 my $url = "https://linuxtv.org/downloads/firmware/$fwfile";
342 my $hash = "d830949c771a289505bf9eafc225d491";
344 checkstandard();
346 wgetfile($fwfile, $url);
347 verify($fwfile, $hash);
349 $fwfile;
352 sub cx231xx {
353 my $fwfile = "v4l-cx231xx-avcore-01.fw";
354 my $url = "https://linuxtv.org/downloads/firmware/$fwfile";
355 my $hash = "7d3bb956dc9df0eafded2b56ba57cc42";
357 checkstandard();
359 wgetfile($fwfile, $url);
360 verify($fwfile, $hash);
362 $fwfile;
365 sub cx18 {
366 my $url = "https://linuxtv.org/downloads/firmware/";
368 my %files = (
369 'v4l-cx23418-apu.fw' => '588f081b562f5c653a3db1ad8f65939a',
370 'v4l-cx23418-cpu.fw' => 'b6c7ed64bc44b1a6e0840adaeac39d79',
371 'v4l-cx23418-dig.fw' => '95bc688d3e7599fd5800161e9971cc55',
374 checkstandard();
376 my $allfiles;
377 foreach my $fwfile (keys %files) {
378 wgetfile($fwfile, "$url/$fwfile");
379 verify($fwfile, $files{$fwfile});
380 $allfiles .= " $fwfile";
383 $allfiles =~ s/^\s//;
385 $allfiles;
388 sub 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);
394 checkstandard();
395 wgetfile($archive, $url);
396 unzip($archive, $tmpdir);
398 my $sourcefile = "$tmpdir/Yuan MPC718 TV Tuner Card 2.13.10.1016/mpc718_32bit/yuanrap.sys";
399 my $found = 0;
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;
406 # Block scope because we change the line terminator variable $/
407 my $prevlen = 0;
408 my $currlen;
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.
416 local $/ = "\x5d\x01"; # MT352 "TUNER GO"
418 while (<IN>) {
419 $currlen = length($_);
420 if ($prevlen == $currlen && $currlen <= 64) {
421 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;
427 $prevlen = $currlen;
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";
436 $fwfile;
439 sub cx23885 {
440 my $url = "https://linuxtv.org/downloads/firmware/";
442 my %files = (
443 'v4l-cx23885-avcore-01.fw' => 'a9f8f5d901a7fb42f552e1ee6384f3bb',
444 'v4l-cx23885-enc.fw' => 'a9f8f5d901a7fb42f552e1ee6384f3bb',
447 checkstandard();
449 my $allfiles;
450 foreach my $fwfile (keys %files) {
451 wgetfile($fwfile, "$url/$fwfile");
452 verify($fwfile, $files{$fwfile});
453 $allfiles .= " $fwfile";
456 $allfiles =~ s/^\s//;
458 $allfiles;
461 sub pvrusb2 {
462 my $url = "https://linuxtv.org/downloads/firmware/";
464 my %files = (
465 'v4l-cx25840.fw' => 'dadb79e9904fc8af96e8111d9cb59320',
468 checkstandard();
470 my $allfiles;
471 foreach my $fwfile (keys %files) {
472 wgetfile($fwfile, "$url/$fwfile");
473 verify($fwfile, $files{$fwfile});
474 $allfiles .= " $fwfile";
477 $allfiles =~ s/^\s//;
479 $allfiles;
482 sub or51132_qam {
483 my $fwfile = "dvb-fe-or51132-qam.fw";
484 my $url = "https://linuxtv.org/downloads/firmware/$fwfile";
485 my $hash = "7702e8938612de46ccadfe9b413cb3b5";
487 checkstandard();
489 wgetfile($fwfile, $url);
490 verify($fwfile, $hash);
492 $fwfile;
495 sub or51132_vsb {
496 my $fwfile = "dvb-fe-or51132-vsb.fw";
497 my $url = "https://linuxtv.org/downloads/firmware/$fwfile";
498 my $hash = "c16208e02f36fc439a557ad4c613364a";
500 checkstandard();
502 wgetfile($fwfile, $url);
503 verify($fwfile, $hash);
505 $fwfile;
508 sub bluebird {
509 my $url = "https://linuxtv.org/download/dvb/firmware/dvb-usb-bluebird-01.fw";
510 my $outfile = "dvb-usb-bluebird-01.fw";
511 my $hash = "658397cb9eba9101af9031302671f49d";
513 checkstandard();
515 wgetfile($outfile, $url);
516 verify($outfile,$hash);
518 $outfile;
521 sub af9015 {
522 my $sourcefile = "download.ashx?file=57";
523 my $url = "http://www.ite.com.tw/EN/Services/$sourcefile";
524 my $hash = "e3f08935158038d385ad382442f4bb2d";
525 my $outfile = "dvb-usb-af9015.fw";
526 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
527 my $fwoffset = 0x25690;
528 my $fwlength = 18725;
529 my ($chunklength, $buf, $rcount);
531 checkstandard();
533 wgetfile($sourcefile, $url);
534 unzip($sourcefile, $tmpdir);
535 verify("$tmpdir/Driver/Files/AF15BDA.sys", $hash);
537 open INFILE, '<', "$tmpdir/Driver/Files/AF15BDA.sys";
538 open OUTFILE, '>', $outfile;
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;
551 close OUTFILE;
552 close INFILE;
555 sub 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";
561 my $url2 = "http://l4m-daten.de/downloads/firmware/dvb-s2/linux/all/";
562 my $file3 = "ngene_18.fw";
563 my $hash3 = "ebce3ea769a53e3e0b0197c3b3f127e3";
565 checkstandard();
567 wgetfile($file1, $url . $file1);
568 verify($file1, $hash1);
570 wgetfile($file2, $url . $file2);
571 verify($file2, $hash2);
573 wgetfile($file3, $url2 . $file3);
574 verify($file3, $hash3);
576 "$file1, $file2, $file3";
579 sub az6027{
580 my $firmware = "dvb-usb-az6027-03.fw";
581 my $url = "http://linux.terratec.de/files/TERRATEC_S7/$firmware";
583 wgetfile($firmware, $url);
585 $firmware;
588 sub lme2510_lg {
589 my $sourcefile = "LMEBDA_DVBS.sys";
590 my $hash = "fc6017ad01e79890a97ec53bea157ed2";
591 my $outfile = "dvb-usb-lme2510-lg.fw";
592 my $hasho = "caa065d5fdbd2c09ad57b399bbf55cad";
594 checkstandard();
596 verify($sourcefile, $hash);
597 extract($sourcefile, 4168, 3841, $outfile);
598 verify($outfile, $hasho);
599 $outfile;
602 sub lme2510c_s7395 {
603 my $sourcefile = "US2A0D.sys";
604 my $hash = "b0155a8083fb822a3bd47bc360e74601";
605 my $outfile = "dvb-usb-lme2510c-s7395.fw";
606 my $hasho = "3a3cf1aeebd17b6ddc04cebe131e94cf";
608 checkstandard();
610 verify($sourcefile, $hash);
611 extract($sourcefile, 37248, 3720, $outfile);
612 verify($outfile, $hasho);
613 $outfile;
616 sub 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";
622 checkstandard();
624 verify($sourcefile, $hash);
625 extract($sourcefile, 4208, 3881, $outfile);
626 verify($outfile, $hasho);
627 $outfile;
630 sub 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";
638 checkstandard();
640 wgetfile($zipfile, $url . $zipfile);
641 verify($zipfile, $hash);
642 unzip($zipfile, $tmpdir);
643 extract("$tmpdir/$drvfile", 0x14dd8, 15634, "$fwfile");
645 "$fwfile"
648 sub 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";
656 checkstandard();
658 wgetfile($zipfile, $url . $zipfile);
659 verify($zipfile, $hash);
660 unzip($zipfile, $tmpdir);
661 extract("$tmpdir/$drvfile", 0x117b0, 42692, "$fwfile");
663 "$fwfile"
666 sub drxk_terratec_h5 {
667 my $url = "https://linuxtv.org/downloads/firmware/";
668 my $hash = "19000dada8e2741162ccc50cc91fa7f1";
669 my $fwfile = "dvb-usb-terratec-h5-drxk.fw";
671 checkstandard();
673 wgetfile($fwfile, $url . $fwfile);
674 verify($fwfile, $hash);
676 "$fwfile"
679 sub drxk_terratec_htc_stick {
680 my $url = "http://ftp.terratec.de/Receiver/Cinergy_HTC_Stick/Updates/History/";
681 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";
687 checkstandard();
689 wgetfile($zipfile, $url . $zipfile);
690 verify($zipfile, $hash);
691 unzip($zipfile, $tmpdir);
692 extract("$tmpdir/$drvfile", 0x4e5c0, 42692, "$fwfile");
694 "$fwfile"
697 sub it9135 {
698 my $url = "http://www.ite.com.tw/uploads/firmware/v3.25.0.0/";
699 my $file1 = "dvb-usb-it9135-01.zip";
700 my $fwfile1 = "dvb-usb-it9135-01.fw";
701 my $hash1 = "02fcf11174eda84745dae7e61c5ff9ba";
702 my $file2 = "dvb-usb-it9135-02.zip";
703 my $fwfile2 = "dvb-usb-it9135-02.fw";
704 my $hash2 = "d5e1437dc24358578e07999475d4cac9";
706 checkstandard();
708 wgetfile($file1, $url . $file1);
709 unzip($file1, "");
710 verify("$fwfile1", $hash1);
712 wgetfile($file2, $url . $file2);
713 unzip($file2, "");
714 verify("$fwfile2", $hash2);
716 "$file1 $file2"
719 sub tda10071 {
720 my $sourcefile = "PCTV_460e_reference.zip";
721 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);
726 checkstandard();
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);
733 "$fwfile";
736 sub 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);
743 checkstandard();
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);
750 "$fwfile";
753 sub 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",
761 checkstandard();
763 my $allfiles;
764 foreach my $fwfile (keys %files) {
765 wgetfile($fwfile, "$url/$fwfile");
766 verify($fwfile, $files{$fwfile});
767 $allfiles .= " $fwfile";
770 $allfiles =~ s/^\s//;
772 $allfiles;
775 sub 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);
782 checkstandard();
784 wgetfile($sourcefile, $url . $sourcefile);
785 verify($sourcefile, $hash);
786 unzip($sourcefile, $tmpdir);
787 extract("$tmpdir/Driver10/Hcw10bda.sys", 0x80788, 0x81E08-0x80788, "$tmpdir/fw1");
789 delzero("$tmpdir/fw1","$tmpdir/fw1-1");
790 #verify("$tmpdir/fw1","5e0909858fdf0b5b09ad48b9fe622e70");
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");
803 "$fwfile";
806 # ---------------------------------------------------------------
807 # Utilities
809 sub 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";
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";
816 if (system("which wget > /dev/null 2>&1")) {
817 die "This firmware requires the wget command - see http://wget.sunsite.dk/\n";
821 sub 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";
827 sub wgetfile {
828 my ($sourcefile, $url) = @_;
830 if (! -f $sourcefile) {
831 system("wget -O \"$sourcefile\" \"$url\"") and die "wget failed - unable to download firmware";
835 sub unzip {
836 my ($sourcefile, $todir) = @_;
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");
844 sub unshield {
845 my ($sourcefile, $todir) = @_;
847 system("unshield x -d \"$todir\" \"$sourcefile\" > /dev/null" ) and die ("unshield failed - unable to extract firmware");
850 sub verify {
851 my ($filename, $hash) = @_;
852 my ($testhash);
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);
862 sub copy {
863 my ($from, $to) = @_;
865 system("cp -f \"$from\" \"$to\"") and die ("cp failed");
868 sub extract {
869 my ($infile, $offset, $length, $outfile) = @_;
870 my ($chunklength, $buf, $rcount);
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);
880 $rcount = sysread(INFILE, $buf, $chunklength);
881 die "Ran out of data\n" if ($rcount != $chunklength);
882 syswrite(OUTFILE, $buf);
883 $length -= $rcount;
885 close INFILE;
886 close OUTFILE;
889 sub appendfile {
890 my ($FH, $infile) = @_;
891 my ($buf);
893 open INFILE, "<$infile";
894 while(1) {
895 $rcount = sysread(INFILE, $buf, 2048);
896 last if ($rcount == 0);
897 print $FH $buf;
899 close(INFILE);
902 sub delzero{
903 my ($infile,$outfile) =@_;
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";
917 close(INFILE);
918 close(OUTFILE);
921 sub syntax() {
922 print STDERR "syntax: get_dvb_firmware <component>\n";
923 print STDERR "Supported components:\n";
924 @components = sort @components;
925 for($i=0; $i < scalar(@components); $i++) {
926 print STDERR "\t" . $components[$i] . "\n";
928 exit(1);