0001 #!/usr/bin/env perl
0002 # SPDX-License-Identifier: GPL-2.0-or-later
0003 # DVB firmware extractor
0004 #
0005 # (c) 2004 Andrew de Quincey
0006 #
0007
0008 use File::Temp qw/ tempdir /;
0009 use IO::Handle;
0010
0011 @components = ( "sp8870", "sp887x", "tda10045", "tda10046",
0012 "tda10046lifeview", "av7110", "dec2000t", "dec2540t",
0013 "dec3000s", "vp7041", "vp7049", "dibusb", "nxt2002", "nxt2004",
0014 "or51211", "or51132_qam", "or51132_vsb", "bluebird",
0015 "opera1", "cx231xx", "cx18", "cx23885", "pvrusb2", "mpc718",
0016 "af9015", "ngene", "az6027", "lme2510_lg", "lme2510c_s7395",
0017 "lme2510c_s7395_old", "drxk", "drxk_terratec_h5",
0018 "drxk_hauppauge_hvr930c", "tda10071", "it9135", "drxk_pctv",
0019 "drxk_terratec_htc_stick", "sms1xxx_hcw", "si2165");
0020
0021 # Check args
0022 syntax() if (scalar(@ARGV) != 1);
0023 $cid = $ARGV[0];
0024
0025 # Do it!
0026 for ($i=0; $i < scalar(@components); $i++) {
0027 if ($cid eq $components[$i]) {
0028 $outfile = eval($cid);
0029 die $@ if $@;
0030 print STDERR <<EOF;
0031 Firmware(s) $outfile extracted successfully.
0032 Now copy it(them) to either /usr/lib/hotplug/firmware or /lib/firmware
0033 (depending on configuration of firmware hotplug).
0034 EOF
0035 exit(0);
0036 }
0037 }
0038
0039 # If we get here, it wasn't found
0040 print STDERR "Unknown component \"$cid\"\n";
0041 syntax();
0042
0043
0044
0045
0046 # ---------------------------------------------------------------
0047 # Firmware-specific extraction subroutines
0048
0049 sub sp8870 {
0050 my $sourcefile = "tt_Premium_217g.zip";
0051 my $url = "http://www.softwarepatch.pl/9999ccd06a4813cb827dbb0005071c71/$sourcefile";
0052 my $hash = "53970ec17a538945a6d8cb608a7b3899";
0053 my $outfile = "dvb-fe-sp8870.fw";
0054 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
0055
0056 checkstandard();
0057
0058 wgetfile($sourcefile, $url);
0059 unzip($sourcefile, $tmpdir);
0060 verify("$tmpdir/software/OEM/HE/App/boot/SC_MAIN.MC", $hash);
0061 copy("$tmpdir/software/OEM/HE/App/boot/SC_MAIN.MC", $outfile);
0062
0063 $outfile;
0064 }
0065
0066 sub sp887x {
0067 my $sourcefile = "Dvbt1.3.57.6.zip";
0068 my $url = "http://www.avermedia.com/software/$sourcefile";
0069 my $cabfile = "DVBT Net Ver1.3.57.6/disk1/data1.cab";
0070 my $hash = "237938d53a7f834c05c42b894ca68ac3";
0071 my $outfile = "dvb-fe-sp887x.fw";
0072 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
0073
0074 checkstandard();
0075 checkunshield();
0076
0077 wgetfile($sourcefile, $url);
0078 unzip($sourcefile, $tmpdir);
0079 unshield("$tmpdir/$cabfile", $tmpdir);
0080 verify("$tmpdir/ZEnglish/sc_main.mc", $hash);
0081 copy("$tmpdir/ZEnglish/sc_main.mc", $outfile);
0082
0083 $outfile;
0084 }
0085
0086 sub tda10045 {
0087 my $sourcefile = "tt_budget_217g.zip";
0088 my $url = "http://www.technotrend.de/new/217g/$sourcefile";
0089 my $hash = "2105fd5bf37842fbcdfa4bfd58f3594a";
0090 my $outfile = "dvb-fe-tda10045.fw";
0091 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
0092
0093 checkstandard();
0094
0095 wgetfile($sourcefile, $url);
0096 unzip($sourcefile, $tmpdir);
0097 extract("$tmpdir/software/OEM/PCI/App/ttlcdacc.dll", 0x37ef9, 30555, "$tmpdir/fwtmp");
0098 verify("$tmpdir/fwtmp", $hash);
0099 copy("$tmpdir/fwtmp", $outfile);
0100
0101 $outfile;
0102 }
0103
0104 sub tda10046 {
0105 my $sourcefile = "TT_PCI_2.19h_28_11_2006.zip";
0106 my $url = "http://technotrend.com.ua/download/software/219/$sourcefile";
0107 my $hash = "6a7e1e2f2644b162ff0502367553c72d";
0108 my $outfile = "dvb-fe-tda10046.fw";
0109 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
0110
0111 checkstandard();
0112
0113 wgetfile($sourcefile, $url);
0114 unzip($sourcefile, $tmpdir);
0115 extract("$tmpdir/TT_PCI_2.19h_28_11_2006/software/OEM/PCI/App/ttlcdacc.dll", 0x65389, 24478, "$tmpdir/fwtmp");
0116 verify("$tmpdir/fwtmp", $hash);
0117 copy("$tmpdir/fwtmp", $outfile);
0118
0119 $outfile;
0120 }
0121
0122 sub tda10046lifeview {
0123 my $sourcefile = "7%5Cdrv_2.11.02.zip";
0124 my $url = "http://www.lifeview.hk/dbimages/document/$sourcefile";
0125 my $hash = "1ea24dee4eea8fe971686981f34fd2e0";
0126 my $outfile = "dvb-fe-tda10046.fw";
0127 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
0128
0129 checkstandard();
0130
0131 wgetfile($sourcefile, $url);
0132 unzip($sourcefile, $tmpdir);
0133 extract("$tmpdir/LVHybrid.sys", 0x8b088, 24602, "$tmpdir/fwtmp");
0134 verify("$tmpdir/fwtmp", $hash);
0135 copy("$tmpdir/fwtmp", $outfile);
0136
0137 $outfile;
0138 }
0139
0140 sub av7110 {
0141 my $sourcefile = "dvb-ttpci-01.fw-261d";
0142 my $url = "https://linuxtv.org/downloads/firmware/$sourcefile";
0143 my $hash = "603431b6259715a8e88f376a53b64e2f";
0144 my $outfile = "dvb-ttpci-01.fw";
0145
0146 checkstandard();
0147
0148 wgetfile($sourcefile, $url);
0149 verify($sourcefile, $hash);
0150 copy($sourcefile, $outfile);
0151
0152 $outfile;
0153 }
0154
0155 sub dec2000t {
0156 my $sourcefile = "dec217g.exe";
0157 my $url = "http://hauppauge.lightpath.net/de/$sourcefile";
0158 my $hash = "bd86f458cee4a8f0a8ce2d20c66215a9";
0159 my $outfile = "dvb-ttusb-dec-2000t.fw";
0160 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
0161
0162 checkstandard();
0163
0164 wgetfile($sourcefile, $url);
0165 unzip($sourcefile, $tmpdir);
0166 verify("$tmpdir/software/OEM/STB/App/Boot/STB_PC_T.bin", $hash);
0167 copy("$tmpdir/software/OEM/STB/App/Boot/STB_PC_T.bin", $outfile);
0168
0169 $outfile;
0170 }
0171
0172 sub dec2540t {
0173 my $sourcefile = "dec217g.exe";
0174 my $url = "http://hauppauge.lightpath.net/de/$sourcefile";
0175 my $hash = "53e58f4f5b5c2930beee74a7681fed92";
0176 my $outfile = "dvb-ttusb-dec-2540t.fw";
0177 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
0178
0179 checkstandard();
0180
0181 wgetfile($sourcefile, $url);
0182 unzip($sourcefile, $tmpdir);
0183 verify("$tmpdir/software/OEM/STB/App/Boot/STB_PC_X.bin", $hash);
0184 copy("$tmpdir/software/OEM/STB/App/Boot/STB_PC_X.bin", $outfile);
0185
0186 $outfile;
0187 }
0188
0189 sub dec3000s {
0190 my $sourcefile = "dec217g.exe";
0191 my $url = "http://hauppauge.lightpath.net/de/$sourcefile";
0192 my $hash = "b013ececea83f4d6d8d2a29ac7c1b448";
0193 my $outfile = "dvb-ttusb-dec-3000s.fw";
0194 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
0195
0196 checkstandard();
0197
0198 wgetfile($sourcefile, $url);
0199 unzip($sourcefile, $tmpdir);
0200 verify("$tmpdir/software/OEM/STB/App/Boot/STB_PC_S.bin", $hash);
0201 copy("$tmpdir/software/OEM/STB/App/Boot/STB_PC_S.bin", $outfile);
0202
0203 $outfile;
0204 }
0205 sub opera1{
0206 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 0);
0207
0208 checkstandard();
0209 my $fwfile1="dvb-usb-opera1-fpga-01.fw";
0210 my $fwfile2="dvb-usb-opera-01.fw";
0211 extract("2830SCap2.sys", 0x62e8, 55024, "$tmpdir/opera1-fpga.fw");
0212 extract("2830SLoad2.sys",0x3178,0x3685-0x3178,"$tmpdir/fw1part1");
0213 extract("2830SLoad2.sys",0x0980,0x3150-0x0980,"$tmpdir/fw1part2");
0214 delzero("$tmpdir/fw1part1","$tmpdir/fw1part1-1");
0215 delzero("$tmpdir/fw1part2","$tmpdir/fw1part2-1");
0216 verify("$tmpdir/fw1part1-1","5e0909858fdf0b5b09ad48b9fe622e70");
0217 verify("$tmpdir/fw1part2-1","d6e146f321427e931df2c6fcadac37a1");
0218 verify("$tmpdir/opera1-fpga.fw","0f8133f5e9051f5f3c1928f7e5a1b07d");
0219
0220 my $RES1="\x01\x92\x7f\x00\x01\x00";
0221 my $RES0="\x01\x92\x7f\x00\x00\x00";
0222 my $DAT1="\x01\x00\xe6\x00\x01\x00";
0223 my $DAT0="\x01\x00\xe6\x00\x00\x00";
0224 open FW,">$tmpdir/opera.fw";
0225 print FW "$RES1";
0226 print FW "$DAT1";
0227 print FW "$RES1";
0228 print FW "$DAT1";
0229 appendfile(FW,"$tmpdir/fw1part1-1");
0230 print FW "$RES0";
0231 print FW "$DAT0";
0232 print FW "$RES1";
0233 print FW "$DAT1";
0234 appendfile(FW,"$tmpdir/fw1part2-1");
0235 print FW "$RES1";
0236 print FW "$DAT1";
0237 print FW "$RES0";
0238 print FW "$DAT0";
0239 copy ("$tmpdir/opera1-fpga.fw",$fwfile1);
0240 copy ("$tmpdir/opera.fw",$fwfile2);
0241
0242 $fwfile1.",".$fwfile2;
0243 }
0244
0245 sub vp7041 {
0246 my $sourcefile = "2.422.zip";
0247 my $url = "http://www.twinhan.com/files/driver/USB-Ter/$sourcefile";
0248 my $hash = "e88c9372d1f66609a3e7b072c53fbcfe";
0249 my $outfile = "dvb-vp7041-2.422.fw";
0250 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
0251
0252 checkstandard();
0253
0254 wgetfile($sourcefile, $url);
0255 unzip($sourcefile, $tmpdir);
0256 extract("$tmpdir/VisionDTV/Drivers/Win2K&XP/UDTTload.sys", 12503, 3036, "$tmpdir/fwtmp1");
0257 extract("$tmpdir/VisionDTV/Drivers/Win2K&XP/UDTTload.sys", 2207, 10274, "$tmpdir/fwtmp2");
0258
0259 my $CMD = "\000\001\000\222\177\000";
0260 my $PAD = "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000";
0261 my ($FW);
0262 open $FW, ">$tmpdir/fwtmp3";
0263 print $FW "$CMD\001$PAD";
0264 print $FW "$CMD\001$PAD";
0265 appendfile($FW, "$tmpdir/fwtmp1");
0266 print $FW "$CMD\000$PAD";
0267 print $FW "$CMD\001$PAD";
0268 appendfile($FW, "$tmpdir/fwtmp2");
0269 print $FW "$CMD\001$PAD";
0270 print $FW "$CMD\000$PAD";
0271 close($FW);
0272
0273 verify("$tmpdir/fwtmp3", $hash);
0274 copy("$tmpdir/fwtmp3", $outfile);
0275
0276 $outfile;
0277 }
0278
0279 sub vp7049 {
0280 my $fwfile = "dvb-usb-vp7049-0.95.fw";
0281 my $url = "http://ao2.it/sites/default/files/blog/2012/11/06/linux-support-digicom-digitune-s-vp7049-udtt7049/$fwfile";
0282 my $hash = "5609fd295168aea88b25ff43a6f79c36";
0283
0284 checkstandard();
0285
0286 wgetfile($fwfile, $url);
0287 verify($fwfile, $hash);
0288
0289 $fwfile;
0290 }
0291
0292 sub dibusb {
0293 my $url = "https://linuxtv.org/downloads/firmware/dvb-usb-dibusb-5.0.0.11.fw";
0294 my $outfile = "dvb-dibusb-5.0.0.11.fw";
0295 my $hash = "fa490295a527360ca16dcdf3224ca243";
0296
0297 checkstandard();
0298
0299 wgetfile($outfile, $url);
0300 verify($outfile,$hash);
0301
0302 $outfile;
0303 }
0304
0305 sub nxt2002 {
0306 my $sourcefile = "Technisat_DVB-PC_4_4_COMPACT.zip";
0307 my $url = "http://www.bbti.us/download/windows/$sourcefile";
0308 my $hash = "476befae8c7c1bb9648954060b1eec1f";
0309 my $outfile = "dvb-fe-nxt2002.fw";
0310 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
0311
0312 checkstandard();
0313
0314 wgetfile($sourcefile, $url);
0315 unzip($sourcefile, $tmpdir);
0316 verify("$tmpdir/SkyNET.sys", $hash);
0317 extract("$tmpdir/SkyNET.sys", 331624, 5908, $outfile);
0318
0319 $outfile;
0320 }
0321
0322 sub nxt2004 {
0323 my $sourcefile = "AVerTVHD_MCE_A180_Drv_v1.2.2.16.zip";
0324 my $url = "http://www.avermedia-usa.com/support/Drivers/$sourcefile";
0325 my $hash = "111cb885b1e009188346d72acfed024c";
0326 my $outfile = "dvb-fe-nxt2004.fw";
0327 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
0328
0329 checkstandard();
0330
0331 wgetfile($sourcefile, $url);
0332 unzip($sourcefile, $tmpdir);
0333 verify("$tmpdir/3xHybrid.sys", $hash);
0334 extract("$tmpdir/3xHybrid.sys", 465304, 9584, $outfile);
0335
0336 $outfile;
0337 }
0338
0339 sub or51211 {
0340 my $fwfile = "dvb-fe-or51211.fw";
0341 my $url = "https://linuxtv.org/downloads/firmware/$fwfile";
0342 my $hash = "d830949c771a289505bf9eafc225d491";
0343
0344 checkstandard();
0345
0346 wgetfile($fwfile, $url);
0347 verify($fwfile, $hash);
0348
0349 $fwfile;
0350 }
0351
0352 sub cx231xx {
0353 my $fwfile = "v4l-cx231xx-avcore-01.fw";
0354 my $url = "https://linuxtv.org/downloads/firmware/$fwfile";
0355 my $hash = "7d3bb956dc9df0eafded2b56ba57cc42";
0356
0357 checkstandard();
0358
0359 wgetfile($fwfile, $url);
0360 verify($fwfile, $hash);
0361
0362 $fwfile;
0363 }
0364
0365 sub cx18 {
0366 my $url = "https://linuxtv.org/downloads/firmware/";
0367
0368 my %files = (
0369 'v4l-cx23418-apu.fw' => '588f081b562f5c653a3db1ad8f65939a',
0370 'v4l-cx23418-cpu.fw' => 'b6c7ed64bc44b1a6e0840adaeac39d79',
0371 'v4l-cx23418-dig.fw' => '95bc688d3e7599fd5800161e9971cc55',
0372 );
0373
0374 checkstandard();
0375
0376 my $allfiles;
0377 foreach my $fwfile (keys %files) {
0378 wgetfile($fwfile, "$url/$fwfile");
0379 verify($fwfile, $files{$fwfile});
0380 $allfiles .= " $fwfile";
0381 }
0382
0383 $allfiles =~ s/^\s//;
0384
0385 $allfiles;
0386 }
0387
0388 sub mpc718 {
0389 my $archive = 'Yuan MPC718 TV Tuner Card 2.13.10.1016.zip';
0390 my $url = "ftp://ftp.work.acer-euro.com/desktop/aspire_idea510/vista/Drivers/$archive";
0391 my $fwfile = "dvb-cx18-mpc718-mt352.fw";
0392 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
0393
0394 checkstandard();
0395 wgetfile($archive, $url);
0396 unzip($archive, $tmpdir);
0397
0398 my $sourcefile = "$tmpdir/Yuan MPC718 TV Tuner Card 2.13.10.1016/mpc718_32bit/yuanrap.sys";
0399 my $found = 0;
0400
0401 open IN, '<', $sourcefile or die "Couldn't open $sourcefile to extract $fwfile data\n";
0402 binmode IN;
0403 open OUT, '>', $fwfile;
0404 binmode OUT;
0405 {
0406 # Block scope because we change the line terminator variable $/
0407 my $prevlen = 0;
0408 my $currlen;
0409
0410 # Buried in the data segment are 3 runs of almost identical
0411 # register-value pairs that end in 0x5d 0x01 which is a "TUNER GO"
0412 # command for the MT352.
0413 # Pull out the middle run (because it's easy) of register-value
0414 # pairs to make the "firmware" file.
0415
0416 local $/ = "\x5d\x01"; # MT352 "TUNER GO"
0417
0418 while (<IN>) {
0419 $currlen = length($_);
0420 if ($prevlen == $currlen && $currlen <= 64) {
0421 chop; chop; # Get rid of "TUNER GO"
0422 s/^\0\0//; # get rid of leading 00 00 if it's there
0423 printf OUT "$_";
0424 $found = 1;
0425 last;
0426 }
0427 $prevlen = $currlen;
0428 }
0429 }
0430 close OUT;
0431 close IN;
0432 if (!$found) {
0433 unlink $fwfile;
0434 die "Couldn't find valid register-value sequence in $sourcefile for $fwfile\n";
0435 }
0436 $fwfile;
0437 }
0438
0439 sub cx23885 {
0440 my $url = "https://linuxtv.org/downloads/firmware/";
0441
0442 my %files = (
0443 'v4l-cx23885-avcore-01.fw' => 'a9f8f5d901a7fb42f552e1ee6384f3bb',
0444 'v4l-cx23885-enc.fw' => 'a9f8f5d901a7fb42f552e1ee6384f3bb',
0445 );
0446
0447 checkstandard();
0448
0449 my $allfiles;
0450 foreach my $fwfile (keys %files) {
0451 wgetfile($fwfile, "$url/$fwfile");
0452 verify($fwfile, $files{$fwfile});
0453 $allfiles .= " $fwfile";
0454 }
0455
0456 $allfiles =~ s/^\s//;
0457
0458 $allfiles;
0459 }
0460
0461 sub pvrusb2 {
0462 my $url = "https://linuxtv.org/downloads/firmware/";
0463
0464 my %files = (
0465 'v4l-cx25840.fw' => 'dadb79e9904fc8af96e8111d9cb59320',
0466 );
0467
0468 checkstandard();
0469
0470 my $allfiles;
0471 foreach my $fwfile (keys %files) {
0472 wgetfile($fwfile, "$url/$fwfile");
0473 verify($fwfile, $files{$fwfile});
0474 $allfiles .= " $fwfile";
0475 }
0476
0477 $allfiles =~ s/^\s//;
0478
0479 $allfiles;
0480 }
0481
0482 sub or51132_qam {
0483 my $fwfile = "dvb-fe-or51132-qam.fw";
0484 my $url = "https://linuxtv.org/downloads/firmware/$fwfile";
0485 my $hash = "7702e8938612de46ccadfe9b413cb3b5";
0486
0487 checkstandard();
0488
0489 wgetfile($fwfile, $url);
0490 verify($fwfile, $hash);
0491
0492 $fwfile;
0493 }
0494
0495 sub or51132_vsb {
0496 my $fwfile = "dvb-fe-or51132-vsb.fw";
0497 my $url = "https://linuxtv.org/downloads/firmware/$fwfile";
0498 my $hash = "c16208e02f36fc439a557ad4c613364a";
0499
0500 checkstandard();
0501
0502 wgetfile($fwfile, $url);
0503 verify($fwfile, $hash);
0504
0505 $fwfile;
0506 }
0507
0508 sub bluebird {
0509 my $url = "https://linuxtv.org/download/dvb/firmware/dvb-usb-bluebird-01.fw";
0510 my $outfile = "dvb-usb-bluebird-01.fw";
0511 my $hash = "658397cb9eba9101af9031302671f49d";
0512
0513 checkstandard();
0514
0515 wgetfile($outfile, $url);
0516 verify($outfile,$hash);
0517
0518 $outfile;
0519 }
0520
0521 sub af9015 {
0522 my $sourcefile = "download.ashx?file=57";
0523 my $url = "http://www.ite.com.tw/EN/Services/$sourcefile";
0524 my $hash = "e3f08935158038d385ad382442f4bb2d";
0525 my $outfile = "dvb-usb-af9015.fw";
0526 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
0527 my $fwoffset = 0x25690;
0528 my $fwlength = 18725;
0529 my ($chunklength, $buf, $rcount);
0530
0531 checkstandard();
0532
0533 wgetfile($sourcefile, $url);
0534 unzip($sourcefile, $tmpdir);
0535 verify("$tmpdir/Driver/Files/AF15BDA.sys", $hash);
0536
0537 open INFILE, '<', "$tmpdir/Driver/Files/AF15BDA.sys";
0538 open OUTFILE, '>', $outfile;
0539
0540 sysseek(INFILE, $fwoffset, SEEK_SET);
0541 while($fwlength > 0) {
0542 $chunklength = 55;
0543 $chunklength = $fwlength if ($chunklength > $fwlength);
0544 $rcount = sysread(INFILE, $buf, $chunklength);
0545 die "Ran out of data\n" if ($rcount != $chunklength);
0546 syswrite(OUTFILE, $buf);
0547 sysread(INFILE, $buf, 8);
0548 $fwlength -= $rcount + 8;
0549 }
0550
0551 close OUTFILE;
0552 close INFILE;
0553 }
0554
0555 sub ngene {
0556 my $url = "http://www.digitaldevices.de/download/";
0557 my $file1 = "ngene_15.fw";
0558 my $hash1 = "d798d5a757121174f0dbc5f2833c0c85";
0559 my $file2 = "ngene_17.fw";
0560 my $hash2 = "26b687136e127b8ac24b81e0eeafc20b";
0561 my $url2 = "http://l4m-daten.de/downloads/firmware/dvb-s2/linux/all/";
0562 my $file3 = "ngene_18.fw";
0563 my $hash3 = "ebce3ea769a53e3e0b0197c3b3f127e3";
0564
0565 checkstandard();
0566
0567 wgetfile($file1, $url . $file1);
0568 verify($file1, $hash1);
0569
0570 wgetfile($file2, $url . $file2);
0571 verify($file2, $hash2);
0572
0573 wgetfile($file3, $url2 . $file3);
0574 verify($file3, $hash3);
0575
0576 "$file1, $file2, $file3";
0577 }
0578
0579 sub az6027{
0580 my $firmware = "dvb-usb-az6027-03.fw";
0581 my $url = "http://linux.terratec.de/files/TERRATEC_S7/$firmware";
0582
0583 wgetfile($firmware, $url);
0584
0585 $firmware;
0586 }
0587
0588 sub lme2510_lg {
0589 my $sourcefile = "LMEBDA_DVBS.sys";
0590 my $hash = "fc6017ad01e79890a97ec53bea157ed2";
0591 my $outfile = "dvb-usb-lme2510-lg.fw";
0592 my $hasho = "caa065d5fdbd2c09ad57b399bbf55cad";
0593
0594 checkstandard();
0595
0596 verify($sourcefile, $hash);
0597 extract($sourcefile, 4168, 3841, $outfile);
0598 verify($outfile, $hasho);
0599 $outfile;
0600 }
0601
0602 sub lme2510c_s7395 {
0603 my $sourcefile = "US2A0D.sys";
0604 my $hash = "b0155a8083fb822a3bd47bc360e74601";
0605 my $outfile = "dvb-usb-lme2510c-s7395.fw";
0606 my $hasho = "3a3cf1aeebd17b6ddc04cebe131e94cf";
0607
0608 checkstandard();
0609
0610 verify($sourcefile, $hash);
0611 extract($sourcefile, 37248, 3720, $outfile);
0612 verify($outfile, $hasho);
0613 $outfile;
0614 }
0615
0616 sub lme2510c_s7395_old {
0617 my $sourcefile = "LMEBDA_DVBS7395C.sys";
0618 my $hash = "7572ae0eb9cdf91baabd7c0ba9e09b31";
0619 my $outfile = "dvb-usb-lme2510c-s7395.fw";
0620 my $hasho = "90430c5b435eb5c6f88fd44a9d950674";
0621
0622 checkstandard();
0623
0624 verify($sourcefile, $hash);
0625 extract($sourcefile, 4208, 3881, $outfile);
0626 verify($outfile, $hasho);
0627 $outfile;
0628 }
0629
0630 sub drxk {
0631 my $url = "http://l4m-daten.de/files/";
0632 my $zipfile = "DDTuner.zip";
0633 my $hash = "f5a37b9a20a3534997997c0b1382a3e5";
0634 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
0635 my $drvfile = "DDTuner.sys";
0636 my $fwfile = "drxk_a3.mc";
0637
0638 checkstandard();
0639
0640 wgetfile($zipfile, $url . $zipfile);
0641 verify($zipfile, $hash);
0642 unzip($zipfile, $tmpdir);
0643 extract("$tmpdir/$drvfile", 0x14dd8, 15634, "$fwfile");
0644
0645 "$fwfile"
0646 }
0647
0648 sub drxk_hauppauge_hvr930c {
0649 my $url = "http://www.wintvcd.co.uk/drivers/";
0650 my $zipfile = "HVR-9x0_5_10_325_28153_SIGNED.zip";
0651 my $hash = "83ab82e7e9480ec8bf1ae0155ca63c88";
0652 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
0653 my $drvfile = "HVR-900/emOEM.sys";
0654 my $fwfile = "dvb-usb-hauppauge-hvr930c-drxk.fw";
0655
0656 checkstandard();
0657
0658 wgetfile($zipfile, $url . $zipfile);
0659 verify($zipfile, $hash);
0660 unzip($zipfile, $tmpdir);
0661 extract("$tmpdir/$drvfile", 0x117b0, 42692, "$fwfile");
0662
0663 "$fwfile"
0664 }
0665
0666 sub drxk_terratec_h5 {
0667 my $url = "https://linuxtv.org/downloads/firmware/";
0668 my $hash = "19000dada8e2741162ccc50cc91fa7f1";
0669 my $fwfile = "dvb-usb-terratec-h5-drxk.fw";
0670
0671 checkstandard();
0672
0673 wgetfile($fwfile, $url . $fwfile);
0674 verify($fwfile, $hash);
0675
0676 "$fwfile"
0677 }
0678
0679 sub drxk_terratec_htc_stick {
0680 my $url = "http://ftp.terratec.de/Receiver/Cinergy_HTC_Stick/Updates/History/";
0681 my $zipfile = "Cinergy_HTC_Stick_Drv_5.09.1202.00_XP_Vista_7.exe";
0682 my $hash = "6722a2442a05423b781721fbc069ed5e";
0683 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 0);
0684 my $drvfile = "Cinergy HTC Stick/BDA Driver 5.09.1202.00/Windows 32 Bit/emOEM.sys";
0685 my $fwfile = "dvb-usb-terratec-htc-stick-drxk.fw";
0686
0687 checkstandard();
0688
0689 wgetfile($zipfile, $url . $zipfile);
0690 verify($zipfile, $hash);
0691 unzip($zipfile, $tmpdir);
0692 extract("$tmpdir/$drvfile", 0x4e5c0, 42692, "$fwfile");
0693
0694 "$fwfile"
0695 }
0696
0697 sub it9135 {
0698 my $url = "http://www.ite.com.tw/uploads/firmware/v3.25.0.0/";
0699 my $file1 = "dvb-usb-it9135-01.zip";
0700 my $fwfile1 = "dvb-usb-it9135-01.fw";
0701 my $hash1 = "02fcf11174eda84745dae7e61c5ff9ba";
0702 my $file2 = "dvb-usb-it9135-02.zip";
0703 my $fwfile2 = "dvb-usb-it9135-02.fw";
0704 my $hash2 = "d5e1437dc24358578e07999475d4cac9";
0705
0706 checkstandard();
0707
0708 wgetfile($file1, $url . $file1);
0709 unzip($file1, "");
0710 verify("$fwfile1", $hash1);
0711
0712 wgetfile($file2, $url . $file2);
0713 unzip($file2, "");
0714 verify("$fwfile2", $hash2);
0715
0716 "$file1 $file2"
0717 }
0718
0719 sub tda10071 {
0720 my $sourcefile = "PCTV_460e_reference.zip";
0721 my $url = "ftp://ftp.pctvsystems.com/TV/driver/PCTV%2070e%2080e%20100e%20320e%20330e%20800e/";
0722 my $hash = "4403de903bf2593464c8d74bbc200a57";
0723 my $fwfile = "dvb-fe-tda10071.fw";
0724 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
0725
0726 checkstandard();
0727
0728 wgetfile($sourcefile, $url . $sourcefile);
0729 verify($sourcefile, $hash);
0730 unzip($sourcefile, $tmpdir);
0731 extract("$tmpdir/PCTV\ 70e\ 80e\ 100e\ 320e\ 330e\ 800e/32\ bit/emOEM.sys", 0x67d38, 40504, $fwfile);
0732
0733 "$fwfile";
0734 }
0735
0736 sub drxk_pctv {
0737 my $sourcefile = "PCTV_460e_reference.zip";
0738 my $url = "ftp://ftp.pctvsystems.com/TV/driver/PCTV%2070e%2080e%20100e%20320e%20330e%20800e/";
0739 my $hash = "4403de903bf2593464c8d74bbc200a57";
0740 my $fwfile = "dvb-demod-drxk-pctv.fw";
0741 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
0742
0743 checkstandard();
0744
0745 wgetfile($sourcefile, $url . $sourcefile);
0746 verify($sourcefile, $hash);
0747 unzip($sourcefile, $tmpdir);
0748 extract("$tmpdir/PCTV\ 70e\ 80e\ 100e\ 320e\ 330e\ 800e/32\ bit/emOEM.sys", 0x72b80, 42692, $fwfile);
0749
0750 "$fwfile";
0751 }
0752
0753 sub sms1xxx_hcw {
0754 my $url = "http://steventoth.net/linux/sms1xxx/";
0755 my %files = (
0756 'sms1xxx-hcw-55xxx-dvbt-01.fw' => "afb6f9fb9a71d64392e8564ef9577e5a",
0757 'sms1xxx-hcw-55xxx-dvbt-02.fw' => "b44807098ba26e52cbedeadc052ba58f",
0758 'sms1xxx-hcw-55xxx-isdbt-02.fw' => "dae934eeea85225acbd63ce6cfe1c9e4",
0759 );
0760
0761 checkstandard();
0762
0763 my $allfiles;
0764 foreach my $fwfile (keys %files) {
0765 wgetfile($fwfile, "$url/$fwfile");
0766 verify($fwfile, $files{$fwfile});
0767 $allfiles .= " $fwfile";
0768 }
0769
0770 $allfiles =~ s/^\s//;
0771
0772 $allfiles;
0773 }
0774
0775 sub si2165 {
0776 my $sourcefile = "model_111xxx_122xxx_driver_6_0_119_31191_WHQL.zip";
0777 my $url = "http://www.hauppauge.de/files/drivers/";
0778 my $hash = "76633e7c76b0edee47c3ba18ded99336";
0779 my $fwfile = "dvb-demod-si2165.fw";
0780 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
0781
0782 checkstandard();
0783
0784 wgetfile($sourcefile, $url . $sourcefile);
0785 verify($sourcefile, $hash);
0786 unzip($sourcefile, $tmpdir);
0787 extract("$tmpdir/Driver10/Hcw10bda.sys", 0x80788, 0x81E08-0x80788, "$tmpdir/fw1");
0788
0789 delzero("$tmpdir/fw1","$tmpdir/fw1-1");
0790 #verify("$tmpdir/fw1","5e0909858fdf0b5b09ad48b9fe622e70");
0791
0792 my $CRC="\x0A\xCC";
0793 my $BLOCKS_MAIN="\x27";
0794 open FW,">$fwfile";
0795 print FW "\x01\x00"; # just a version id for the driver itself
0796 print FW "\x9A"; # fw version
0797 print FW "\x00"; # padding
0798 print FW "$BLOCKS_MAIN"; # number of blocks of main part
0799 print FW "\x00"; # padding
0800 print FW "$CRC"; # 16bit crc value of main part
0801 appendfile(FW,"$tmpdir/fw1");
0802
0803 "$fwfile";
0804 }
0805
0806 # ---------------------------------------------------------------
0807 # Utilities
0808
0809 sub checkstandard {
0810 if (system("which unzip > /dev/null 2>&1")) {
0811 die "This firmware requires the unzip command - see ftp://ftp.info-zip.org/pub/infozip/UnZip.html\n";
0812 }
0813 if (system("which md5sum > /dev/null 2>&1")) {
0814 die "This firmware requires the md5sum command - see http://www.gnu.org/software/coreutils/\n";
0815 }
0816 if (system("which wget > /dev/null 2>&1")) {
0817 die "This firmware requires the wget command - see http://wget.sunsite.dk/\n";
0818 }
0819 }
0820
0821 sub checkunshield {
0822 if (system("which unshield > /dev/null 2>&1")) {
0823 die "This firmware requires the unshield command - see http://sourceforge.net/projects/synce/\n";
0824 }
0825 }
0826
0827 sub wgetfile {
0828 my ($sourcefile, $url) = @_;
0829
0830 if (! -f $sourcefile) {
0831 system("wget -O \"$sourcefile\" \"$url\"") and die "wget failed - unable to download firmware";
0832 }
0833 }
0834
0835 sub unzip {
0836 my ($sourcefile, $todir) = @_;
0837
0838 $status = system("unzip -q -o -d \"$todir\" \"$sourcefile\" 2>/dev/null" );
0839 if ((($status >> 8) > 2) || (($status & 0xff) != 0)) {
0840 die ("unzip failed - unable to extract firmware");
0841 }
0842 }
0843
0844 sub unshield {
0845 my ($sourcefile, $todir) = @_;
0846
0847 system("unshield x -d \"$todir\" \"$sourcefile\" > /dev/null" ) and die ("unshield failed - unable to extract firmware");
0848 }
0849
0850 sub verify {
0851 my ($filename, $hash) = @_;
0852 my ($testhash);
0853
0854 open(CMD, "md5sum \"$filename\"|");
0855 $testhash = <CMD>;
0856 $testhash =~ /([a-zA-Z0-9]*)/;
0857 $testhash = $1;
0858 close CMD;
0859 die "Hash of extracted file does not match!\n" if ($testhash ne $hash);
0860 }
0861
0862 sub copy {
0863 my ($from, $to) = @_;
0864
0865 system("cp -f \"$from\" \"$to\"") and die ("cp failed");
0866 }
0867
0868 sub extract {
0869 my ($infile, $offset, $length, $outfile) = @_;
0870 my ($chunklength, $buf, $rcount);
0871
0872 open INFILE, "<$infile";
0873 open OUTFILE, ">$outfile";
0874 sysseek(INFILE, $offset, SEEK_SET);
0875 while($length > 0) {
0876 # Calc chunk size
0877 $chunklength = 2048;
0878 $chunklength = $length if ($chunklength > $length);
0879
0880 $rcount = sysread(INFILE, $buf, $chunklength);
0881 die "Ran out of data\n" if ($rcount != $chunklength);
0882 syswrite(OUTFILE, $buf);
0883 $length -= $rcount;
0884 }
0885 close INFILE;
0886 close OUTFILE;
0887 }
0888
0889 sub appendfile {
0890 my ($FH, $infile) = @_;
0891 my ($buf);
0892
0893 open INFILE, "<$infile";
0894 while(1) {
0895 $rcount = sysread(INFILE, $buf, 2048);
0896 last if ($rcount == 0);
0897 print $FH $buf;
0898 }
0899 close(INFILE);
0900 }
0901
0902 sub delzero{
0903 my ($infile,$outfile) =@_;
0904
0905 open INFILE,"<$infile";
0906 open OUTFILE,">$outfile";
0907 while (1){
0908 $rcount=sysread(INFILE,$buf,22);
0909 $len=ord(substr($buf,0,1));
0910 print OUTFILE substr($buf,0,1);
0911 print OUTFILE substr($buf,2,$len+3);
0912 last if ($rcount<1);
0913 printf OUTFILE "%c",0;
0914 #print $len." ".length($buf)."\n";
0915
0916 }
0917 close(INFILE);
0918 close(OUTFILE);
0919 }
0920
0921 sub syntax() {
0922 print STDERR "syntax: get_dvb_firmware <component>\n";
0923 print STDERR "Supported components:\n";
0924 @components = sort @components;
0925 for($i=0; $i < scalar(@components); $i++) {
0926 print STDERR "\t" . $components[$i] . "\n";
0927 }
0928 exit(1);
0929 }