get_dvb_firmware 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942
  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. use File::Temp qw/ tempdir /;
  21. use IO::Handle;
  22. @components = ( "sp8870", "sp887x", "tda10045", "tda10046",
  23. "tda10046lifeview", "av7110", "dec2000t", "dec2540t",
  24. "dec3000s", "vp7041", "vp7049", "dibusb", "nxt2002", "nxt2004",
  25. "or51211", "or51132_qam", "or51132_vsb", "bluebird",
  26. "opera1", "cx231xx", "cx18", "cx23885", "pvrusb2", "mpc718",
  27. "af9015", "ngene", "az6027", "lme2510_lg", "lme2510c_s7395",
  28. "lme2510c_s7395_old", "drxk", "drxk_terratec_h5",
  29. "drxk_hauppauge_hvr930c", "tda10071", "it9135", "drxk_pctv",
  30. "drxk_terratec_htc_stick", "sms1xxx_hcw", "si2165");
  31. # Check args
  32. syntax() if (scalar(@ARGV) != 1);
  33. $cid = $ARGV[0];
  34. # Do it!
  35. for ($i=0; $i < scalar(@components); $i++) {
  36. if ($cid eq $components[$i]) {
  37. $outfile = eval($cid);
  38. die $@ if $@;
  39. print STDERR <<EOF;
  40. Firmware(s) $outfile extracted successfully.
  41. Now copy it(them) to either /usr/lib/hotplug/firmware or /lib/firmware
  42. (depending on configuration of firmware hotplug).
  43. EOF
  44. exit(0);
  45. }
  46. }
  47. # If we get here, it wasn't found
  48. print STDERR "Unknown component \"$cid\"\n";
  49. syntax();
  50. # ---------------------------------------------------------------
  51. # Firmware-specific extraction subroutines
  52. sub sp8870 {
  53. my $sourcefile = "tt_Premium_217g.zip";
  54. my $url = "http://www.softwarepatch.pl/9999ccd06a4813cb827dbb0005071c71/$sourcefile";
  55. my $hash = "53970ec17a538945a6d8cb608a7b3899";
  56. my $outfile = "dvb-fe-sp8870.fw";
  57. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  58. checkstandard();
  59. wgetfile($sourcefile, $url);
  60. unzip($sourcefile, $tmpdir);
  61. verify("$tmpdir/software/OEM/HE/App/boot/SC_MAIN.MC", $hash);
  62. copy("$tmpdir/software/OEM/HE/App/boot/SC_MAIN.MC", $outfile);
  63. $outfile;
  64. }
  65. sub sp887x {
  66. my $sourcefile = "Dvbt1.3.57.6.zip";
  67. my $url = "http://www.avermedia.com/software/$sourcefile";
  68. my $cabfile = "DVBT Net Ver1.3.57.6/disk1/data1.cab";
  69. my $hash = "237938d53a7f834c05c42b894ca68ac3";
  70. my $outfile = "dvb-fe-sp887x.fw";
  71. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  72. checkstandard();
  73. checkunshield();
  74. wgetfile($sourcefile, $url);
  75. unzip($sourcefile, $tmpdir);
  76. unshield("$tmpdir/$cabfile", $tmpdir);
  77. verify("$tmpdir/ZEnglish/sc_main.mc", $hash);
  78. copy("$tmpdir/ZEnglish/sc_main.mc", $outfile);
  79. $outfile;
  80. }
  81. sub tda10045 {
  82. my $sourcefile = "tt_budget_217g.zip";
  83. my $url = "http://www.technotrend.de/new/217g/$sourcefile";
  84. my $hash = "2105fd5bf37842fbcdfa4bfd58f3594a";
  85. my $outfile = "dvb-fe-tda10045.fw";
  86. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  87. checkstandard();
  88. wgetfile($sourcefile, $url);
  89. unzip($sourcefile, $tmpdir);
  90. extract("$tmpdir/software/OEM/PCI/App/ttlcdacc.dll", 0x37ef9, 30555, "$tmpdir/fwtmp");
  91. verify("$tmpdir/fwtmp", $hash);
  92. copy("$tmpdir/fwtmp", $outfile);
  93. $outfile;
  94. }
  95. sub tda10046 {
  96. my $sourcefile = "TT_PCI_2.19h_28_11_2006.zip";
  97. my $url = "http://technotrend.com.ua/download/software/219/$sourcefile";
  98. my $hash = "6a7e1e2f2644b162ff0502367553c72d";
  99. my $outfile = "dvb-fe-tda10046.fw";
  100. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  101. checkstandard();
  102. wgetfile($sourcefile, $url);
  103. unzip($sourcefile, $tmpdir);
  104. extract("$tmpdir/TT_PCI_2.19h_28_11_2006/software/OEM/PCI/App/ttlcdacc.dll", 0x65389, 24478, "$tmpdir/fwtmp");
  105. verify("$tmpdir/fwtmp", $hash);
  106. copy("$tmpdir/fwtmp", $outfile);
  107. $outfile;
  108. }
  109. sub tda10046lifeview {
  110. my $sourcefile = "7%5Cdrv_2.11.02.zip";
  111. my $url = "http://www.lifeview.hk/dbimages/document/$sourcefile";
  112. my $hash = "1ea24dee4eea8fe971686981f34fd2e0";
  113. my $outfile = "dvb-fe-tda10046.fw";
  114. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  115. checkstandard();
  116. wgetfile($sourcefile, $url);
  117. unzip($sourcefile, $tmpdir);
  118. extract("$tmpdir/LVHybrid.sys", 0x8b088, 24602, "$tmpdir/fwtmp");
  119. verify("$tmpdir/fwtmp", $hash);
  120. copy("$tmpdir/fwtmp", $outfile);
  121. $outfile;
  122. }
  123. sub av7110 {
  124. my $sourcefile = "dvb-ttpci-01.fw-261d";
  125. my $url = "http://www.linuxtv.org/downloads/firmware/$sourcefile";
  126. my $hash = "603431b6259715a8e88f376a53b64e2f";
  127. my $outfile = "dvb-ttpci-01.fw";
  128. checkstandard();
  129. wgetfile($sourcefile, $url);
  130. verify($sourcefile, $hash);
  131. copy($sourcefile, $outfile);
  132. $outfile;
  133. }
  134. sub dec2000t {
  135. my $sourcefile = "dec217g.exe";
  136. my $url = "http://hauppauge.lightpath.net/de/$sourcefile";
  137. my $hash = "bd86f458cee4a8f0a8ce2d20c66215a9";
  138. my $outfile = "dvb-ttusb-dec-2000t.fw";
  139. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  140. checkstandard();
  141. wgetfile($sourcefile, $url);
  142. unzip($sourcefile, $tmpdir);
  143. verify("$tmpdir/software/OEM/STB/App/Boot/STB_PC_T.bin", $hash);
  144. copy("$tmpdir/software/OEM/STB/App/Boot/STB_PC_T.bin", $outfile);
  145. $outfile;
  146. }
  147. sub dec2540t {
  148. my $sourcefile = "dec217g.exe";
  149. my $url = "http://hauppauge.lightpath.net/de/$sourcefile";
  150. my $hash = "53e58f4f5b5c2930beee74a7681fed92";
  151. my $outfile = "dvb-ttusb-dec-2540t.fw";
  152. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  153. checkstandard();
  154. wgetfile($sourcefile, $url);
  155. unzip($sourcefile, $tmpdir);
  156. verify("$tmpdir/software/OEM/STB/App/Boot/STB_PC_X.bin", $hash);
  157. copy("$tmpdir/software/OEM/STB/App/Boot/STB_PC_X.bin", $outfile);
  158. $outfile;
  159. }
  160. sub dec3000s {
  161. my $sourcefile = "dec217g.exe";
  162. my $url = "http://hauppauge.lightpath.net/de/$sourcefile";
  163. my $hash = "b013ececea83f4d6d8d2a29ac7c1b448";
  164. my $outfile = "dvb-ttusb-dec-3000s.fw";
  165. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  166. checkstandard();
  167. wgetfile($sourcefile, $url);
  168. unzip($sourcefile, $tmpdir);
  169. verify("$tmpdir/software/OEM/STB/App/Boot/STB_PC_S.bin", $hash);
  170. copy("$tmpdir/software/OEM/STB/App/Boot/STB_PC_S.bin", $outfile);
  171. $outfile;
  172. }
  173. sub opera1{
  174. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 0);
  175. checkstandard();
  176. my $fwfile1="dvb-usb-opera1-fpga-01.fw";
  177. my $fwfile2="dvb-usb-opera-01.fw";
  178. extract("2830SCap2.sys", 0x62e8, 55024, "$tmpdir/opera1-fpga.fw");
  179. extract("2830SLoad2.sys",0x3178,0x3685-0x3178,"$tmpdir/fw1part1");
  180. extract("2830SLoad2.sys",0x0980,0x3150-0x0980,"$tmpdir/fw1part2");
  181. delzero("$tmpdir/fw1part1","$tmpdir/fw1part1-1");
  182. delzero("$tmpdir/fw1part2","$tmpdir/fw1part2-1");
  183. verify("$tmpdir/fw1part1-1","5e0909858fdf0b5b09ad48b9fe622e70");
  184. verify("$tmpdir/fw1part2-1","d6e146f321427e931df2c6fcadac37a1");
  185. verify("$tmpdir/opera1-fpga.fw","0f8133f5e9051f5f3c1928f7e5a1b07d");
  186. my $RES1="\x01\x92\x7f\x00\x01\x00";
  187. my $RES0="\x01\x92\x7f\x00\x00\x00";
  188. my $DAT1="\x01\x00\xe6\x00\x01\x00";
  189. my $DAT0="\x01\x00\xe6\x00\x00\x00";
  190. open FW,">$tmpdir/opera.fw";
  191. print FW "$RES1";
  192. print FW "$DAT1";
  193. print FW "$RES1";
  194. print FW "$DAT1";
  195. appendfile(FW,"$tmpdir/fw1part1-1");
  196. print FW "$RES0";
  197. print FW "$DAT0";
  198. print FW "$RES1";
  199. print FW "$DAT1";
  200. appendfile(FW,"$tmpdir/fw1part2-1");
  201. print FW "$RES1";
  202. print FW "$DAT1";
  203. print FW "$RES0";
  204. print FW "$DAT0";
  205. copy ("$tmpdir/opera1-fpga.fw",$fwfile1);
  206. copy ("$tmpdir/opera.fw",$fwfile2);
  207. $fwfile1.",".$fwfile2;
  208. }
  209. sub vp7041 {
  210. my $sourcefile = "2.422.zip";
  211. my $url = "http://www.twinhan.com/files/driver/USB-Ter/$sourcefile";
  212. my $hash = "e88c9372d1f66609a3e7b072c53fbcfe";
  213. my $outfile = "dvb-vp7041-2.422.fw";
  214. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  215. checkstandard();
  216. wgetfile($sourcefile, $url);
  217. unzip($sourcefile, $tmpdir);
  218. extract("$tmpdir/VisionDTV/Drivers/Win2K&XP/UDTTload.sys", 12503, 3036, "$tmpdir/fwtmp1");
  219. extract("$tmpdir/VisionDTV/Drivers/Win2K&XP/UDTTload.sys", 2207, 10274, "$tmpdir/fwtmp2");
  220. my $CMD = "\000\001\000\222\177\000";
  221. my $PAD = "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000";
  222. my ($FW);
  223. open $FW, ">$tmpdir/fwtmp3";
  224. print $FW "$CMD\001$PAD";
  225. print $FW "$CMD\001$PAD";
  226. appendfile($FW, "$tmpdir/fwtmp1");
  227. print $FW "$CMD\000$PAD";
  228. print $FW "$CMD\001$PAD";
  229. appendfile($FW, "$tmpdir/fwtmp2");
  230. print $FW "$CMD\001$PAD";
  231. print $FW "$CMD\000$PAD";
  232. close($FW);
  233. verify("$tmpdir/fwtmp3", $hash);
  234. copy("$tmpdir/fwtmp3", $outfile);
  235. $outfile;
  236. }
  237. sub vp7049 {
  238. my $fwfile = "dvb-usb-vp7049-0.95.fw";
  239. my $url = "http://ao2.it/sites/default/files/blog/2012/11/06/linux-support-digicom-digitune-s-vp7049-udtt7049/$fwfile";
  240. my $hash = "5609fd295168aea88b25ff43a6f79c36";
  241. checkstandard();
  242. wgetfile($fwfile, $url);
  243. verify($fwfile, $hash);
  244. $fwfile;
  245. }
  246. sub dibusb {
  247. my $url = "http://www.linuxtv.org/downloads/firmware/dvb-usb-dibusb-5.0.0.11.fw";
  248. my $outfile = "dvb-dibusb-5.0.0.11.fw";
  249. my $hash = "fa490295a527360ca16dcdf3224ca243";
  250. checkstandard();
  251. wgetfile($outfile, $url);
  252. verify($outfile,$hash);
  253. $outfile;
  254. }
  255. sub nxt2002 {
  256. my $sourcefile = "Technisat_DVB-PC_4_4_COMPACT.zip";
  257. my $url = "http://www.bbti.us/download/windows/$sourcefile";
  258. my $hash = "476befae8c7c1bb9648954060b1eec1f";
  259. my $outfile = "dvb-fe-nxt2002.fw";
  260. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  261. checkstandard();
  262. wgetfile($sourcefile, $url);
  263. unzip($sourcefile, $tmpdir);
  264. verify("$tmpdir/SkyNET.sys", $hash);
  265. extract("$tmpdir/SkyNET.sys", 331624, 5908, $outfile);
  266. $outfile;
  267. }
  268. sub nxt2004 {
  269. my $sourcefile = "AVerTVHD_MCE_A180_Drv_v1.2.2.16.zip";
  270. my $url = "http://www.avermedia-usa.com/support/Drivers/$sourcefile";
  271. my $hash = "111cb885b1e009188346d72acfed024c";
  272. my $outfile = "dvb-fe-nxt2004.fw";
  273. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  274. checkstandard();
  275. wgetfile($sourcefile, $url);
  276. unzip($sourcefile, $tmpdir);
  277. verify("$tmpdir/3xHybrid.sys", $hash);
  278. extract("$tmpdir/3xHybrid.sys", 465304, 9584, $outfile);
  279. $outfile;
  280. }
  281. sub or51211 {
  282. my $fwfile = "dvb-fe-or51211.fw";
  283. my $url = "http://linuxtv.org/downloads/firmware/$fwfile";
  284. my $hash = "d830949c771a289505bf9eafc225d491";
  285. checkstandard();
  286. wgetfile($fwfile, $url);
  287. verify($fwfile, $hash);
  288. $fwfile;
  289. }
  290. sub cx231xx {
  291. my $fwfile = "v4l-cx231xx-avcore-01.fw";
  292. my $url = "http://linuxtv.org/downloads/firmware/$fwfile";
  293. my $hash = "7d3bb956dc9df0eafded2b56ba57cc42";
  294. checkstandard();
  295. wgetfile($fwfile, $url);
  296. verify($fwfile, $hash);
  297. $fwfile;
  298. }
  299. sub cx18 {
  300. my $url = "http://linuxtv.org/downloads/firmware/";
  301. my %files = (
  302. 'v4l-cx23418-apu.fw' => '588f081b562f5c653a3db1ad8f65939a',
  303. 'v4l-cx23418-cpu.fw' => 'b6c7ed64bc44b1a6e0840adaeac39d79',
  304. 'v4l-cx23418-dig.fw' => '95bc688d3e7599fd5800161e9971cc55',
  305. );
  306. checkstandard();
  307. my $allfiles;
  308. foreach my $fwfile (keys %files) {
  309. wgetfile($fwfile, "$url/$fwfile");
  310. verify($fwfile, $files{$fwfile});
  311. $allfiles .= " $fwfile";
  312. }
  313. $allfiles =~ s/^\s//;
  314. $allfiles;
  315. }
  316. sub mpc718 {
  317. my $archive = 'Yuan MPC718 TV Tuner Card 2.13.10.1016.zip';
  318. my $url = "ftp://ftp.work.acer-euro.com/desktop/aspire_idea510/vista/Drivers/$archive";
  319. my $fwfile = "dvb-cx18-mpc718-mt352.fw";
  320. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  321. checkstandard();
  322. wgetfile($archive, $url);
  323. unzip($archive, $tmpdir);
  324. my $sourcefile = "$tmpdir/Yuan MPC718 TV Tuner Card 2.13.10.1016/mpc718_32bit/yuanrap.sys";
  325. my $found = 0;
  326. open IN, '<', $sourcefile or die "Couldn't open $sourcefile to extract $fwfile data\n";
  327. binmode IN;
  328. open OUT, '>', $fwfile;
  329. binmode OUT;
  330. {
  331. # Block scope because we change the line terminator variable $/
  332. my $prevlen = 0;
  333. my $currlen;
  334. # Buried in the data segment are 3 runs of almost identical
  335. # register-value pairs that end in 0x5d 0x01 which is a "TUNER GO"
  336. # command for the MT352.
  337. # Pull out the middle run (because it's easy) of register-value
  338. # pairs to make the "firmware" file.
  339. local $/ = "\x5d\x01"; # MT352 "TUNER GO"
  340. while (<IN>) {
  341. $currlen = length($_);
  342. if ($prevlen == $currlen && $currlen <= 64) {
  343. chop; chop; # Get rid of "TUNER GO"
  344. s/^\0\0//; # get rid of leading 00 00 if it's there
  345. printf OUT "$_";
  346. $found = 1;
  347. last;
  348. }
  349. $prevlen = $currlen;
  350. }
  351. }
  352. close OUT;
  353. close IN;
  354. if (!$found) {
  355. unlink $fwfile;
  356. die "Couldn't find valid register-value sequence in $sourcefile for $fwfile\n";
  357. }
  358. $fwfile;
  359. }
  360. sub cx23885 {
  361. my $url = "http://linuxtv.org/downloads/firmware/";
  362. my %files = (
  363. 'v4l-cx23885-avcore-01.fw' => 'a9f8f5d901a7fb42f552e1ee6384f3bb',
  364. 'v4l-cx23885-enc.fw' => 'a9f8f5d901a7fb42f552e1ee6384f3bb',
  365. );
  366. checkstandard();
  367. my $allfiles;
  368. foreach my $fwfile (keys %files) {
  369. wgetfile($fwfile, "$url/$fwfile");
  370. verify($fwfile, $files{$fwfile});
  371. $allfiles .= " $fwfile";
  372. }
  373. $allfiles =~ s/^\s//;
  374. $allfiles;
  375. }
  376. sub pvrusb2 {
  377. my $url = "http://linuxtv.org/downloads/firmware/";
  378. my %files = (
  379. 'v4l-cx25840.fw' => 'dadb79e9904fc8af96e8111d9cb59320',
  380. );
  381. checkstandard();
  382. my $allfiles;
  383. foreach my $fwfile (keys %files) {
  384. wgetfile($fwfile, "$url/$fwfile");
  385. verify($fwfile, $files{$fwfile});
  386. $allfiles .= " $fwfile";
  387. }
  388. $allfiles =~ s/^\s//;
  389. $allfiles;
  390. }
  391. sub or51132_qam {
  392. my $fwfile = "dvb-fe-or51132-qam.fw";
  393. my $url = "http://linuxtv.org/downloads/firmware/$fwfile";
  394. my $hash = "7702e8938612de46ccadfe9b413cb3b5";
  395. checkstandard();
  396. wgetfile($fwfile, $url);
  397. verify($fwfile, $hash);
  398. $fwfile;
  399. }
  400. sub or51132_vsb {
  401. my $fwfile = "dvb-fe-or51132-vsb.fw";
  402. my $url = "http://linuxtv.org/downloads/firmware/$fwfile";
  403. my $hash = "c16208e02f36fc439a557ad4c613364a";
  404. checkstandard();
  405. wgetfile($fwfile, $url);
  406. verify($fwfile, $hash);
  407. $fwfile;
  408. }
  409. sub bluebird {
  410. my $url = "http://www.linuxtv.org/download/dvb/firmware/dvb-usb-bluebird-01.fw";
  411. my $outfile = "dvb-usb-bluebird-01.fw";
  412. my $hash = "658397cb9eba9101af9031302671f49d";
  413. checkstandard();
  414. wgetfile($outfile, $url);
  415. verify($outfile,$hash);
  416. $outfile;
  417. }
  418. sub af9015 {
  419. my $sourcefile = "download.ashx?file=57";
  420. my $url = "http://www.ite.com.tw/EN/Services/$sourcefile";
  421. my $hash = "e3f08935158038d385ad382442f4bb2d";
  422. my $outfile = "dvb-usb-af9015.fw";
  423. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  424. my $fwoffset = 0x25690;
  425. my $fwlength = 18725;
  426. my ($chunklength, $buf, $rcount);
  427. checkstandard();
  428. wgetfile($sourcefile, $url);
  429. unzip($sourcefile, $tmpdir);
  430. verify("$tmpdir/Driver/Files/AF15BDA.sys", $hash);
  431. open INFILE, '<', "$tmpdir/Driver/Files/AF15BDA.sys";
  432. open OUTFILE, '>', $outfile;
  433. sysseek(INFILE, $fwoffset, SEEK_SET);
  434. while($fwlength > 0) {
  435. $chunklength = 55;
  436. $chunklength = $fwlength if ($chunklength > $fwlength);
  437. $rcount = sysread(INFILE, $buf, $chunklength);
  438. die "Ran out of data\n" if ($rcount != $chunklength);
  439. syswrite(OUTFILE, $buf);
  440. sysread(INFILE, $buf, 8);
  441. $fwlength -= $rcount + 8;
  442. }
  443. close OUTFILE;
  444. close INFILE;
  445. }
  446. sub ngene {
  447. my $url = "http://www.digitaldevices.de/download/";
  448. my $file1 = "ngene_15.fw";
  449. my $hash1 = "d798d5a757121174f0dbc5f2833c0c85";
  450. my $file2 = "ngene_17.fw";
  451. my $hash2 = "26b687136e127b8ac24b81e0eeafc20b";
  452. my $url2 = "http://l4m-daten.de/downloads/firmware/dvb-s2/linux/all/";
  453. my $file3 = "ngene_18.fw";
  454. my $hash3 = "ebce3ea769a53e3e0b0197c3b3f127e3";
  455. checkstandard();
  456. wgetfile($file1, $url . $file1);
  457. verify($file1, $hash1);
  458. wgetfile($file2, $url . $file2);
  459. verify($file2, $hash2);
  460. wgetfile($file3, $url2 . $file3);
  461. verify($file3, $hash3);
  462. "$file1, $file2, $file3";
  463. }
  464. sub az6027{
  465. my $firmware = "dvb-usb-az6027-03.fw";
  466. my $url = "http://linux.terratec.de/files/TERRATEC_S7/$firmware";
  467. wgetfile($firmware, $url);
  468. $firmware;
  469. }
  470. sub lme2510_lg {
  471. my $sourcefile = "LMEBDA_DVBS.sys";
  472. my $hash = "fc6017ad01e79890a97ec53bea157ed2";
  473. my $outfile = "dvb-usb-lme2510-lg.fw";
  474. my $hasho = "caa065d5fdbd2c09ad57b399bbf55cad";
  475. checkstandard();
  476. verify($sourcefile, $hash);
  477. extract($sourcefile, 4168, 3841, $outfile);
  478. verify($outfile, $hasho);
  479. $outfile;
  480. }
  481. sub lme2510c_s7395 {
  482. my $sourcefile = "US2A0D.sys";
  483. my $hash = "b0155a8083fb822a3bd47bc360e74601";
  484. my $outfile = "dvb-usb-lme2510c-s7395.fw";
  485. my $hasho = "3a3cf1aeebd17b6ddc04cebe131e94cf";
  486. checkstandard();
  487. verify($sourcefile, $hash);
  488. extract($sourcefile, 37248, 3720, $outfile);
  489. verify($outfile, $hasho);
  490. $outfile;
  491. }
  492. sub lme2510c_s7395_old {
  493. my $sourcefile = "LMEBDA_DVBS7395C.sys";
  494. my $hash = "7572ae0eb9cdf91baabd7c0ba9e09b31";
  495. my $outfile = "dvb-usb-lme2510c-s7395.fw";
  496. my $hasho = "90430c5b435eb5c6f88fd44a9d950674";
  497. checkstandard();
  498. verify($sourcefile, $hash);
  499. extract($sourcefile, 4208, 3881, $outfile);
  500. verify($outfile, $hasho);
  501. $outfile;
  502. }
  503. sub drxk {
  504. my $url = "http://l4m-daten.de/files/";
  505. my $zipfile = "DDTuner.zip";
  506. my $hash = "f5a37b9a20a3534997997c0b1382a3e5";
  507. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  508. my $drvfile = "DDTuner.sys";
  509. my $fwfile = "drxk_a3.mc";
  510. checkstandard();
  511. wgetfile($zipfile, $url . $zipfile);
  512. verify($zipfile, $hash);
  513. unzip($zipfile, $tmpdir);
  514. extract("$tmpdir/$drvfile", 0x14dd8, 15634, "$fwfile");
  515. "$fwfile"
  516. }
  517. sub drxk_hauppauge_hvr930c {
  518. my $url = "http://www.wintvcd.co.uk/drivers/";
  519. my $zipfile = "HVR-9x0_5_10_325_28153_SIGNED.zip";
  520. my $hash = "83ab82e7e9480ec8bf1ae0155ca63c88";
  521. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  522. my $drvfile = "HVR-900/emOEM.sys";
  523. my $fwfile = "dvb-usb-hauppauge-hvr930c-drxk.fw";
  524. checkstandard();
  525. wgetfile($zipfile, $url . $zipfile);
  526. verify($zipfile, $hash);
  527. unzip($zipfile, $tmpdir);
  528. extract("$tmpdir/$drvfile", 0x117b0, 42692, "$fwfile");
  529. "$fwfile"
  530. }
  531. sub drxk_terratec_h5 {
  532. my $url = "http://www.linuxtv.org/downloads/firmware/";
  533. my $hash = "19000dada8e2741162ccc50cc91fa7f1";
  534. my $fwfile = "dvb-usb-terratec-h5-drxk.fw";
  535. checkstandard();
  536. wgetfile($fwfile, $url . $fwfile);
  537. verify($fwfile, $hash);
  538. "$fwfile"
  539. }
  540. sub drxk_terratec_htc_stick {
  541. my $url = "http://ftp.terratec.de/Receiver/Cinergy_HTC_Stick/Updates/History/";
  542. my $zipfile = "Cinergy_HTC_Stick_Drv_5.09.1202.00_XP_Vista_7.exe";
  543. my $hash = "6722a2442a05423b781721fbc069ed5e";
  544. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 0);
  545. my $drvfile = "Cinergy HTC Stick/BDA Driver 5.09.1202.00/Windows 32 Bit/emOEM.sys";
  546. my $fwfile = "dvb-usb-terratec-htc-stick-drxk.fw";
  547. checkstandard();
  548. wgetfile($zipfile, $url . $zipfile);
  549. verify($zipfile, $hash);
  550. unzip($zipfile, $tmpdir);
  551. extract("$tmpdir/$drvfile", 0x4e5c0, 42692, "$fwfile");
  552. "$fwfile"
  553. }
  554. sub it9135 {
  555. my $url = "http://www.ite.com.tw/uploads/firmware/v3.25.0.0/";
  556. my $file1 = "dvb-usb-it9135-01.zip";
  557. my $fwfile1 = "dvb-usb-it9135-01.fw";
  558. my $hash1 = "02fcf11174eda84745dae7e61c5ff9ba";
  559. my $file2 = "dvb-usb-it9135-02.zip";
  560. my $fwfile2 = "dvb-usb-it9135-02.fw";
  561. my $hash2 = "d5e1437dc24358578e07999475d4cac9";
  562. checkstandard();
  563. wgetfile($file1, $url . $file1);
  564. unzip($file1, "");
  565. verify("$fwfile1", $hash1);
  566. wgetfile($file2, $url . $file2);
  567. unzip($file2, "");
  568. verify("$fwfile2", $hash2);
  569. "$file1 $file2"
  570. }
  571. sub tda10071 {
  572. my $sourcefile = "PCTV_460e_reference.zip";
  573. my $url = "ftp://ftp.pctvsystems.com/TV/driver/PCTV%2070e%2080e%20100e%20320e%20330e%20800e/";
  574. my $hash = "4403de903bf2593464c8d74bbc200a57";
  575. my $fwfile = "dvb-fe-tda10071.fw";
  576. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  577. checkstandard();
  578. wgetfile($sourcefile, $url . $sourcefile);
  579. verify($sourcefile, $hash);
  580. unzip($sourcefile, $tmpdir);
  581. extract("$tmpdir/PCTV\ 70e\ 80e\ 100e\ 320e\ 330e\ 800e/32\ bit/emOEM.sys", 0x67d38, 40504, $fwfile);
  582. "$fwfile";
  583. }
  584. sub drxk_pctv {
  585. my $sourcefile = "PCTV_460e_reference.zip";
  586. my $url = "ftp://ftp.pctvsystems.com/TV/driver/PCTV%2070e%2080e%20100e%20320e%20330e%20800e/";
  587. my $hash = "4403de903bf2593464c8d74bbc200a57";
  588. my $fwfile = "dvb-demod-drxk-pctv.fw";
  589. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  590. checkstandard();
  591. wgetfile($sourcefile, $url . $sourcefile);
  592. verify($sourcefile, $hash);
  593. unzip($sourcefile, $tmpdir);
  594. extract("$tmpdir/PCTV\ 70e\ 80e\ 100e\ 320e\ 330e\ 800e/32\ bit/emOEM.sys", 0x72b80, 42692, $fwfile);
  595. "$fwfile";
  596. }
  597. sub sms1xxx_hcw {
  598. my $url = "http://steventoth.net/linux/sms1xxx/";
  599. my %files = (
  600. 'sms1xxx-hcw-55xxx-dvbt-01.fw' => "afb6f9fb9a71d64392e8564ef9577e5a",
  601. 'sms1xxx-hcw-55xxx-dvbt-02.fw' => "b44807098ba26e52cbedeadc052ba58f",
  602. 'sms1xxx-hcw-55xxx-isdbt-02.fw' => "dae934eeea85225acbd63ce6cfe1c9e4",
  603. );
  604. checkstandard();
  605. my $allfiles;
  606. foreach my $fwfile (keys %files) {
  607. wgetfile($fwfile, "$url/$fwfile");
  608. verify($fwfile, $files{$fwfile});
  609. $allfiles .= " $fwfile";
  610. }
  611. $allfiles =~ s/^\s//;
  612. $allfiles;
  613. }
  614. sub si2165 {
  615. my $sourcefile = "model_111xxx_122xxx_driver_6_0_119_31191_WHQL.zip";
  616. my $url = "http://www.hauppauge.de/files/drivers/";
  617. my $hash = "76633e7c76b0edee47c3ba18ded99336";
  618. my $fwfile = "dvb-demod-si2165.fw";
  619. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  620. checkstandard();
  621. wgetfile($sourcefile, $url . $sourcefile);
  622. verify($sourcefile, $hash);
  623. unzip($sourcefile, $tmpdir);
  624. extract("$tmpdir/Driver10/Hcw10bda.sys", 0x80788, 0x81E08-0x80788, "$tmpdir/fw1");
  625. delzero("$tmpdir/fw1","$tmpdir/fw1-1");
  626. #verify("$tmpdir/fw1","5e0909858fdf0b5b09ad48b9fe622e70");
  627. my $CRC="\x0A\xCC";
  628. my $BLOCKS_MAIN="\x27";
  629. open FW,">$fwfile";
  630. print FW "\x01\x00"; # just a version id for the driver itself
  631. print FW "\x9A"; # fw version
  632. print FW "\x00"; # padding
  633. print FW "$BLOCKS_MAIN"; # number of blocks of main part
  634. print FW "\x00"; # padding
  635. print FW "$CRC"; # 16bit crc value of main part
  636. appendfile(FW,"$tmpdir/fw1");
  637. "$fwfile";
  638. }
  639. # ---------------------------------------------------------------
  640. # Utilities
  641. sub checkstandard {
  642. if (system("which unzip > /dev/null 2>&1")) {
  643. die "This firmware requires the unzip command - see ftp://ftp.info-zip.org/pub/infozip/UnZip.html\n";
  644. }
  645. if (system("which md5sum > /dev/null 2>&1")) {
  646. die "This firmware requires the md5sum command - see http://www.gnu.org/software/coreutils/\n";
  647. }
  648. if (system("which wget > /dev/null 2>&1")) {
  649. die "This firmware requires the wget command - see http://wget.sunsite.dk/\n";
  650. }
  651. }
  652. sub checkunshield {
  653. if (system("which unshield > /dev/null 2>&1")) {
  654. die "This firmware requires the unshield command - see http://sourceforge.net/projects/synce/\n";
  655. }
  656. }
  657. sub wgetfile {
  658. my ($sourcefile, $url) = @_;
  659. if (! -f $sourcefile) {
  660. system("wget -O \"$sourcefile\" \"$url\"") and die "wget failed - unable to download firmware";
  661. }
  662. }
  663. sub unzip {
  664. my ($sourcefile, $todir) = @_;
  665. $status = system("unzip -q -o -d \"$todir\" \"$sourcefile\" 2>/dev/null" );
  666. if ((($status >> 8) > 2) || (($status & 0xff) != 0)) {
  667. die ("unzip failed - unable to extract firmware");
  668. }
  669. }
  670. sub unshield {
  671. my ($sourcefile, $todir) = @_;
  672. system("unshield x -d \"$todir\" \"$sourcefile\" > /dev/null" ) and die ("unshield failed - unable to extract firmware");
  673. }
  674. sub verify {
  675. my ($filename, $hash) = @_;
  676. my ($testhash);
  677. open(CMD, "md5sum \"$filename\"|");
  678. $testhash = <CMD>;
  679. $testhash =~ /([a-zA-Z0-9]*)/;
  680. $testhash = $1;
  681. close CMD;
  682. die "Hash of extracted file does not match!\n" if ($testhash ne $hash);
  683. }
  684. sub copy {
  685. my ($from, $to) = @_;
  686. system("cp -f \"$from\" \"$to\"") and die ("cp failed");
  687. }
  688. sub extract {
  689. my ($infile, $offset, $length, $outfile) = @_;
  690. my ($chunklength, $buf, $rcount);
  691. open INFILE, "<$infile";
  692. open OUTFILE, ">$outfile";
  693. sysseek(INFILE, $offset, SEEK_SET);
  694. while($length > 0) {
  695. # Calc chunk size
  696. $chunklength = 2048;
  697. $chunklength = $length if ($chunklength > $length);
  698. $rcount = sysread(INFILE, $buf, $chunklength);
  699. die "Ran out of data\n" if ($rcount != $chunklength);
  700. syswrite(OUTFILE, $buf);
  701. $length -= $rcount;
  702. }
  703. close INFILE;
  704. close OUTFILE;
  705. }
  706. sub appendfile {
  707. my ($FH, $infile) = @_;
  708. my ($buf);
  709. open INFILE, "<$infile";
  710. while(1) {
  711. $rcount = sysread(INFILE, $buf, 2048);
  712. last if ($rcount == 0);
  713. print $FH $buf;
  714. }
  715. close(INFILE);
  716. }
  717. sub delzero{
  718. my ($infile,$outfile) =@_;
  719. open INFILE,"<$infile";
  720. open OUTFILE,">$outfile";
  721. while (1){
  722. $rcount=sysread(INFILE,$buf,22);
  723. $len=ord(substr($buf,0,1));
  724. print OUTFILE substr($buf,0,1);
  725. print OUTFILE substr($buf,2,$len+3);
  726. last if ($rcount<1);
  727. printf OUTFILE "%c",0;
  728. #print $len." ".length($buf)."\n";
  729. }
  730. close(INFILE);
  731. close(OUTFILE);
  732. }
  733. sub syntax() {
  734. print STDERR "syntax: get_dvb_firmware <component>\n";
  735. print STDERR "Supported components:\n";
  736. @components = sort @components;
  737. for($i=0; $i < scalar(@components); $i++) {
  738. print STDERR "\t" . $components[$i] . "\n";
  739. }
  740. exit(1);
  741. }