get_dvb_firmware 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  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", "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", "it9137",
  30. "drxk_pctv", "drxk_terratec_htc_stick", "sms1xxx_hcw");
  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://www.tt-download.com/download/updates/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 dibusb {
  238. my $url = "http://www.linuxtv.org/downloads/firmware/dvb-usb-dibusb-5.0.0.11.fw";
  239. my $outfile = "dvb-dibusb-5.0.0.11.fw";
  240. my $hash = "fa490295a527360ca16dcdf3224ca243";
  241. checkstandard();
  242. wgetfile($outfile, $url);
  243. verify($outfile,$hash);
  244. $outfile;
  245. }
  246. sub nxt2002 {
  247. my $sourcefile = "Technisat_DVB-PC_4_4_COMPACT.zip";
  248. my $url = "http://www.bbti.us/download/windows/$sourcefile";
  249. my $hash = "476befae8c7c1bb9648954060b1eec1f";
  250. my $outfile = "dvb-fe-nxt2002.fw";
  251. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  252. checkstandard();
  253. wgetfile($sourcefile, $url);
  254. unzip($sourcefile, $tmpdir);
  255. verify("$tmpdir/SkyNET.sys", $hash);
  256. extract("$tmpdir/SkyNET.sys", 331624, 5908, $outfile);
  257. $outfile;
  258. }
  259. sub nxt2004 {
  260. my $sourcefile = "AVerTVHD_MCE_A180_Drv_v1.2.2.16.zip";
  261. my $url = "http://www.avermedia-usa.com/support/Drivers/$sourcefile";
  262. my $hash = "111cb885b1e009188346d72acfed024c";
  263. my $outfile = "dvb-fe-nxt2004.fw";
  264. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  265. checkstandard();
  266. wgetfile($sourcefile, $url);
  267. unzip($sourcefile, $tmpdir);
  268. verify("$tmpdir/3xHybrid.sys", $hash);
  269. extract("$tmpdir/3xHybrid.sys", 465304, 9584, $outfile);
  270. $outfile;
  271. }
  272. sub or51211 {
  273. my $fwfile = "dvb-fe-or51211.fw";
  274. my $url = "http://linuxtv.org/downloads/firmware/$fwfile";
  275. my $hash = "d830949c771a289505bf9eafc225d491";
  276. checkstandard();
  277. wgetfile($fwfile, $url);
  278. verify($fwfile, $hash);
  279. $fwfile;
  280. }
  281. sub cx231xx {
  282. my $fwfile = "v4l-cx231xx-avcore-01.fw";
  283. my $url = "http://linuxtv.org/downloads/firmware/$fwfile";
  284. my $hash = "7d3bb956dc9df0eafded2b56ba57cc42";
  285. checkstandard();
  286. wgetfile($fwfile, $url);
  287. verify($fwfile, $hash);
  288. $fwfile;
  289. }
  290. sub cx18 {
  291. my $url = "http://linuxtv.org/downloads/firmware/";
  292. my %files = (
  293. 'v4l-cx23418-apu.fw' => '588f081b562f5c653a3db1ad8f65939a',
  294. 'v4l-cx23418-cpu.fw' => 'b6c7ed64bc44b1a6e0840adaeac39d79',
  295. 'v4l-cx23418-dig.fw' => '95bc688d3e7599fd5800161e9971cc55',
  296. );
  297. checkstandard();
  298. my $allfiles;
  299. foreach my $fwfile (keys %files) {
  300. wgetfile($fwfile, "$url/$fwfile");
  301. verify($fwfile, $files{$fwfile});
  302. $allfiles .= " $fwfile";
  303. }
  304. $allfiles =~ s/^\s//;
  305. $allfiles;
  306. }
  307. sub mpc718 {
  308. my $archive = 'Yuan MPC718 TV Tuner Card 2.13.10.1016.zip';
  309. my $url = "ftp://ftp.work.acer-euro.com/desktop/aspire_idea510/vista/Drivers/$archive";
  310. my $fwfile = "dvb-cx18-mpc718-mt352.fw";
  311. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  312. checkstandard();
  313. wgetfile($archive, $url);
  314. unzip($archive, $tmpdir);
  315. my $sourcefile = "$tmpdir/Yuan MPC718 TV Tuner Card 2.13.10.1016/mpc718_32bit/yuanrap.sys";
  316. my $found = 0;
  317. open IN, '<', $sourcefile or die "Couldn't open $sourcefile to extract $fwfile data\n";
  318. binmode IN;
  319. open OUT, '>', $fwfile;
  320. binmode OUT;
  321. {
  322. # Block scope because we change the line terminator variable $/
  323. my $prevlen = 0;
  324. my $currlen;
  325. # Buried in the data segment are 3 runs of almost identical
  326. # register-value pairs that end in 0x5d 0x01 which is a "TUNER GO"
  327. # command for the MT352.
  328. # Pull out the middle run (because it's easy) of register-value
  329. # pairs to make the "firmware" file.
  330. local $/ = "\x5d\x01"; # MT352 "TUNER GO"
  331. while (<IN>) {
  332. $currlen = length($_);
  333. if ($prevlen == $currlen && $currlen <= 64) {
  334. chop; chop; # Get rid of "TUNER GO"
  335. s/^\0\0//; # get rid of leading 00 00 if it's there
  336. printf OUT "$_";
  337. $found = 1;
  338. last;
  339. }
  340. $prevlen = $currlen;
  341. }
  342. }
  343. close OUT;
  344. close IN;
  345. if (!$found) {
  346. unlink $fwfile;
  347. die "Couldn't find valid register-value sequence in $sourcefile for $fwfile\n";
  348. }
  349. $fwfile;
  350. }
  351. sub cx23885 {
  352. my $url = "http://linuxtv.org/downloads/firmware/";
  353. my %files = (
  354. 'v4l-cx23885-avcore-01.fw' => 'a9f8f5d901a7fb42f552e1ee6384f3bb',
  355. 'v4l-cx23885-enc.fw' => 'a9f8f5d901a7fb42f552e1ee6384f3bb',
  356. );
  357. checkstandard();
  358. my $allfiles;
  359. foreach my $fwfile (keys %files) {
  360. wgetfile($fwfile, "$url/$fwfile");
  361. verify($fwfile, $files{$fwfile});
  362. $allfiles .= " $fwfile";
  363. }
  364. $allfiles =~ s/^\s//;
  365. $allfiles;
  366. }
  367. sub pvrusb2 {
  368. my $url = "http://linuxtv.org/downloads/firmware/";
  369. my %files = (
  370. 'v4l-cx25840.fw' => 'dadb79e9904fc8af96e8111d9cb59320',
  371. );
  372. checkstandard();
  373. my $allfiles;
  374. foreach my $fwfile (keys %files) {
  375. wgetfile($fwfile, "$url/$fwfile");
  376. verify($fwfile, $files{$fwfile});
  377. $allfiles .= " $fwfile";
  378. }
  379. $allfiles =~ s/^\s//;
  380. $allfiles;
  381. }
  382. sub or51132_qam {
  383. my $fwfile = "dvb-fe-or51132-qam.fw";
  384. my $url = "http://linuxtv.org/downloads/firmware/$fwfile";
  385. my $hash = "7702e8938612de46ccadfe9b413cb3b5";
  386. checkstandard();
  387. wgetfile($fwfile, $url);
  388. verify($fwfile, $hash);
  389. $fwfile;
  390. }
  391. sub or51132_vsb {
  392. my $fwfile = "dvb-fe-or51132-vsb.fw";
  393. my $url = "http://linuxtv.org/downloads/firmware/$fwfile";
  394. my $hash = "c16208e02f36fc439a557ad4c613364a";
  395. checkstandard();
  396. wgetfile($fwfile, $url);
  397. verify($fwfile, $hash);
  398. $fwfile;
  399. }
  400. sub bluebird {
  401. my $url = "http://www.linuxtv.org/download/dvb/firmware/dvb-usb-bluebird-01.fw";
  402. my $outfile = "dvb-usb-bluebird-01.fw";
  403. my $hash = "658397cb9eba9101af9031302671f49d";
  404. checkstandard();
  405. wgetfile($outfile, $url);
  406. verify($outfile,$hash);
  407. $outfile;
  408. }
  409. sub af9015 {
  410. my $sourcefile = "download.ashx?file=57";
  411. my $url = "http://www.ite.com.tw/EN/Services/$sourcefile";
  412. my $hash = "e3f08935158038d385ad382442f4bb2d";
  413. my $outfile = "dvb-usb-af9015.fw";
  414. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  415. my $fwoffset = 0x25690;
  416. my $fwlength = 18725;
  417. my ($chunklength, $buf, $rcount);
  418. checkstandard();
  419. wgetfile($sourcefile, $url);
  420. unzip($sourcefile, $tmpdir);
  421. verify("$tmpdir/Driver/Files/AF15BDA.sys", $hash);
  422. open INFILE, '<', "$tmpdir/Driver/Files/AF15BDA.sys";
  423. open OUTFILE, '>', $outfile;
  424. sysseek(INFILE, $fwoffset, SEEK_SET);
  425. while($fwlength > 0) {
  426. $chunklength = 55;
  427. $chunklength = $fwlength if ($chunklength > $fwlength);
  428. $rcount = sysread(INFILE, $buf, $chunklength);
  429. die "Ran out of data\n" if ($rcount != $chunklength);
  430. syswrite(OUTFILE, $buf);
  431. sysread(INFILE, $buf, 8);
  432. $fwlength -= $rcount + 8;
  433. }
  434. close OUTFILE;
  435. close INFILE;
  436. }
  437. sub ngene {
  438. my $url = "http://www.digitaldevices.de/download/";
  439. my $file1 = "ngene_15.fw";
  440. my $hash1 = "d798d5a757121174f0dbc5f2833c0c85";
  441. my $file2 = "ngene_17.fw";
  442. my $hash2 = "26b687136e127b8ac24b81e0eeafc20b";
  443. my $url2 = "http://l4m-daten.de/downloads/firmware/dvb-s2/linux/all/";
  444. my $file3 = "ngene_18.fw";
  445. my $hash3 = "ebce3ea769a53e3e0b0197c3b3f127e3";
  446. checkstandard();
  447. wgetfile($file1, $url . $file1);
  448. verify($file1, $hash1);
  449. wgetfile($file2, $url . $file2);
  450. verify($file2, $hash2);
  451. wgetfile($file3, $url2 . $file3);
  452. verify($file3, $hash3);
  453. "$file1, $file2, $file3";
  454. }
  455. sub az6027{
  456. my $firmware = "dvb-usb-az6027-03.fw";
  457. my $url = "http://linux.terratec.de/files/TERRATEC_S7/$firmware";
  458. wgetfile($firmware, $url);
  459. $firmware;
  460. }
  461. sub lme2510_lg {
  462. my $sourcefile = "LMEBDA_DVBS.sys";
  463. my $hash = "fc6017ad01e79890a97ec53bea157ed2";
  464. my $outfile = "dvb-usb-lme2510-lg.fw";
  465. my $hasho = "caa065d5fdbd2c09ad57b399bbf55cad";
  466. checkstandard();
  467. verify($sourcefile, $hash);
  468. extract($sourcefile, 4168, 3841, $outfile);
  469. verify($outfile, $hasho);
  470. $outfile;
  471. }
  472. sub lme2510c_s7395 {
  473. my $sourcefile = "US2A0D.sys";
  474. my $hash = "b0155a8083fb822a3bd47bc360e74601";
  475. my $outfile = "dvb-usb-lme2510c-s7395.fw";
  476. my $hasho = "3a3cf1aeebd17b6ddc04cebe131e94cf";
  477. checkstandard();
  478. verify($sourcefile, $hash);
  479. extract($sourcefile, 37248, 3720, $outfile);
  480. verify($outfile, $hasho);
  481. $outfile;
  482. }
  483. sub lme2510c_s7395_old {
  484. my $sourcefile = "LMEBDA_DVBS7395C.sys";
  485. my $hash = "7572ae0eb9cdf91baabd7c0ba9e09b31";
  486. my $outfile = "dvb-usb-lme2510c-s7395.fw";
  487. my $hasho = "90430c5b435eb5c6f88fd44a9d950674";
  488. checkstandard();
  489. verify($sourcefile, $hash);
  490. extract($sourcefile, 4208, 3881, $outfile);
  491. verify($outfile, $hasho);
  492. $outfile;
  493. }
  494. sub drxk {
  495. my $url = "http://l4m-daten.de/files/";
  496. my $zipfile = "DDTuner.zip";
  497. my $hash = "f5a37b9a20a3534997997c0b1382a3e5";
  498. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  499. my $drvfile = "DDTuner.sys";
  500. my $fwfile = "drxk_a3.mc";
  501. checkstandard();
  502. wgetfile($zipfile, $url . $zipfile);
  503. verify($zipfile, $hash);
  504. unzip($zipfile, $tmpdir);
  505. extract("$tmpdir/$drvfile", 0x14dd8, 15634, "$fwfile");
  506. "$fwfile"
  507. }
  508. sub drxk_hauppauge_hvr930c {
  509. my $url = "http://www.wintvcd.co.uk/drivers/";
  510. my $zipfile = "HVR-9x0_5_10_325_28153_SIGNED.zip";
  511. my $hash = "83ab82e7e9480ec8bf1ae0155ca63c88";
  512. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  513. my $drvfile = "HVR-900/emOEM.sys";
  514. my $fwfile = "dvb-usb-hauppauge-hvr930c-drxk.fw";
  515. checkstandard();
  516. wgetfile($zipfile, $url . $zipfile);
  517. verify($zipfile, $hash);
  518. unzip($zipfile, $tmpdir);
  519. extract("$tmpdir/$drvfile", 0x117b0, 42692, "$fwfile");
  520. "$fwfile"
  521. }
  522. sub drxk_terratec_h5 {
  523. my $url = "http://www.linuxtv.org/downloads/firmware/";
  524. my $hash = "19000dada8e2741162ccc50cc91fa7f1";
  525. my $fwfile = "dvb-usb-terratec-h5-drxk.fw";
  526. checkstandard();
  527. wgetfile($fwfile, $url . $fwfile);
  528. verify($fwfile, $hash);
  529. "$fwfile"
  530. }
  531. sub drxk_terratec_htc_stick {
  532. my $url = "http://ftp.terratec.de/Receiver/Cinergy_HTC_Stick/Updates/";
  533. my $zipfile = "Cinergy_HTC_Stick_Drv_5.09.1202.00_XP_Vista_7.exe";
  534. my $hash = "6722a2442a05423b781721fbc069ed5e";
  535. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 0);
  536. my $drvfile = "Cinergy HTC Stick/BDA Driver 5.09.1202.00/Windows 32 Bit/emOEM.sys";
  537. my $fwfile = "dvb-usb-terratec-htc-stick-drxk.fw";
  538. checkstandard();
  539. wgetfile($zipfile, $url . $zipfile);
  540. verify($zipfile, $hash);
  541. unzip($zipfile, $tmpdir);
  542. extract("$tmpdir/$drvfile", 0x4e5c0, 42692, "$fwfile");
  543. "$fwfile"
  544. }
  545. sub it9135 {
  546. my $sourcefile = "dvb-usb-it9135.zip";
  547. my $url = "http://www.ite.com.tw/uploads/firmware/v3.6.0.0/$sourcefile";
  548. my $hash = "1e55f6c8833f1d0ae067c2bb2953e6a9";
  549. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 0);
  550. my $outfile = "dvb-usb-it9135.fw";
  551. my $fwfile1 = "dvb-usb-it9135-01.fw";
  552. my $fwfile2 = "dvb-usb-it9135-02.fw";
  553. checkstandard();
  554. wgetfile($sourcefile, $url);
  555. unzip($sourcefile, $tmpdir);
  556. verify("$tmpdir/$outfile", $hash);
  557. extract("$tmpdir/$outfile", 64, 8128, "$fwfile1");
  558. extract("$tmpdir/$outfile", 12866, 5817, "$fwfile2");
  559. "$fwfile1 $fwfile2"
  560. }
  561. sub it9137 {
  562. my $url = "http://kworld.server261.com/kworld/CD/ITE_TiVme/V1.00/";
  563. my $zipfile = "Driver_V10.323.1.0412.100412.zip";
  564. my $hash = "79b597dc648698ed6820845c0c9d0d37";
  565. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 0);
  566. my $drvfile = "Driver_V10.323.1.0412.100412/Data/x86/IT9135BDA.sys";
  567. my $fwfile = "dvb-usb-it9137-01.fw";
  568. checkstandard();
  569. wgetfile($zipfile, $url . $zipfile);
  570. verify($zipfile, $hash);
  571. unzip($zipfile, $tmpdir);
  572. extract("$tmpdir/$drvfile", 69632, 5731, "$fwfile");
  573. "$fwfile"
  574. }
  575. sub tda10071 {
  576. my $sourcefile = "PCTV_460e_reference.zip";
  577. my $url = "ftp://ftp.pctvsystems.com/TV/driver/PCTV%2070e%2080e%20100e%20320e%20330e%20800e/";
  578. my $hash = "4403de903bf2593464c8d74bbc200a57";
  579. my $fwfile = "dvb-fe-tda10071.fw";
  580. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  581. checkstandard();
  582. wgetfile($sourcefile, $url . $sourcefile);
  583. verify($sourcefile, $hash);
  584. unzip($sourcefile, $tmpdir);
  585. extract("$tmpdir/PCTV\ 70e\ 80e\ 100e\ 320e\ 330e\ 800e/32\ bit/emOEM.sys", 0x67d38, 40504, $fwfile);
  586. "$fwfile";
  587. }
  588. sub drxk_pctv {
  589. my $sourcefile = "PCTV_460e_reference.zip";
  590. my $url = "ftp://ftp.pctvsystems.com/TV/driver/PCTV%2070e%2080e%20100e%20320e%20330e%20800e/";
  591. my $hash = "4403de903bf2593464c8d74bbc200a57";
  592. my $fwfile = "dvb-demod-drxk-pctv.fw";
  593. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  594. checkstandard();
  595. wgetfile($sourcefile, $url . $sourcefile);
  596. verify($sourcefile, $hash);
  597. unzip($sourcefile, $tmpdir);
  598. extract("$tmpdir/PCTV\ 70e\ 80e\ 100e\ 320e\ 330e\ 800e/32\ bit/emOEM.sys", 0x72b80, 42692, $fwfile);
  599. "$fwfile";
  600. }
  601. sub sms1xxx_hcw {
  602. my $url = "http://steventoth.net/linux/sms1xxx/";
  603. my %files = (
  604. 'sms1xxx-hcw-55xxx-dvbt-01.fw' => "afb6f9fb9a71d64392e8564ef9577e5a",
  605. 'sms1xxx-hcw-55xxx-dvbt-02.fw' => "b44807098ba26e52cbedeadc052ba58f",
  606. 'sms1xxx-hcw-55xxx-isdbt-02.fw' => "dae934eeea85225acbd63ce6cfe1c9e4",
  607. );
  608. checkstandard();
  609. my $allfiles;
  610. foreach my $fwfile (keys %files) {
  611. wgetfile($fwfile, "$url/$fwfile");
  612. verify($fwfile, $files{$fwfile});
  613. $allfiles .= " $fwfile";
  614. }
  615. $allfiles =~ s/^\s//;
  616. $allfiles;
  617. }
  618. # ---------------------------------------------------------------
  619. # Utilities
  620. sub checkstandard {
  621. if (system("which unzip > /dev/null 2>&1")) {
  622. die "This firmware requires the unzip command - see ftp://ftp.info-zip.org/pub/infozip/UnZip.html\n";
  623. }
  624. if (system("which md5sum > /dev/null 2>&1")) {
  625. die "This firmware requires the md5sum command - see http://www.gnu.org/software/coreutils/\n";
  626. }
  627. if (system("which wget > /dev/null 2>&1")) {
  628. die "This firmware requires the wget command - see http://wget.sunsite.dk/\n";
  629. }
  630. }
  631. sub checkunshield {
  632. if (system("which unshield > /dev/null 2>&1")) {
  633. die "This firmware requires the unshield command - see http://sourceforge.net/projects/synce/\n";
  634. }
  635. }
  636. sub wgetfile {
  637. my ($sourcefile, $url) = @_;
  638. if (! -f $sourcefile) {
  639. system("wget -O \"$sourcefile\" \"$url\"") and die "wget failed - unable to download firmware";
  640. }
  641. }
  642. sub unzip {
  643. my ($sourcefile, $todir) = @_;
  644. $status = system("unzip -q -o -d \"$todir\" \"$sourcefile\" 2>/dev/null" );
  645. if ((($status >> 8) > 2) || (($status & 0xff) != 0)) {
  646. die ("unzip failed - unable to extract firmware");
  647. }
  648. }
  649. sub unshield {
  650. my ($sourcefile, $todir) = @_;
  651. system("unshield x -d \"$todir\" \"$sourcefile\" > /dev/null" ) and die ("unshield failed - unable to extract firmware");
  652. }
  653. sub verify {
  654. my ($filename, $hash) = @_;
  655. my ($testhash);
  656. open(CMD, "md5sum \"$filename\"|");
  657. $testhash = <CMD>;
  658. $testhash =~ /([a-zA-Z0-9]*)/;
  659. $testhash = $1;
  660. close CMD;
  661. die "Hash of extracted file does not match!\n" if ($testhash ne $hash);
  662. }
  663. sub copy {
  664. my ($from, $to) = @_;
  665. system("cp -f \"$from\" \"$to\"") and die ("cp failed");
  666. }
  667. sub extract {
  668. my ($infile, $offset, $length, $outfile) = @_;
  669. my ($chunklength, $buf, $rcount);
  670. open INFILE, "<$infile";
  671. open OUTFILE, ">$outfile";
  672. sysseek(INFILE, $offset, SEEK_SET);
  673. while($length > 0) {
  674. # Calc chunk size
  675. $chunklength = 2048;
  676. $chunklength = $length if ($chunklength > $length);
  677. $rcount = sysread(INFILE, $buf, $chunklength);
  678. die "Ran out of data\n" if ($rcount != $chunklength);
  679. syswrite(OUTFILE, $buf);
  680. $length -= $rcount;
  681. }
  682. close INFILE;
  683. close OUTFILE;
  684. }
  685. sub appendfile {
  686. my ($FH, $infile) = @_;
  687. my ($buf);
  688. open INFILE, "<$infile";
  689. while(1) {
  690. $rcount = sysread(INFILE, $buf, 2048);
  691. last if ($rcount == 0);
  692. print $FH $buf;
  693. }
  694. close(INFILE);
  695. }
  696. sub delzero{
  697. my ($infile,$outfile) =@_;
  698. open INFILE,"<$infile";
  699. open OUTFILE,">$outfile";
  700. while (1){
  701. $rcount=sysread(INFILE,$buf,22);
  702. $len=ord(substr($buf,0,1));
  703. print OUTFILE substr($buf,0,1);
  704. print OUTFILE substr($buf,2,$len+3);
  705. last if ($rcount<1);
  706. printf OUTFILE "%c",0;
  707. #print $len." ".length($buf)."\n";
  708. }
  709. close(INFILE);
  710. close(OUTFILE);
  711. }
  712. sub syntax() {
  713. print STDERR "syntax: get_dvb_firmware <component>\n";
  714. print STDERR "Supported components:\n";
  715. @components = sort @components;
  716. for($i=0; $i < scalar(@components); $i++) {
  717. print STDERR "\t" . $components[$i] . "\n";
  718. }
  719. exit(1);
  720. }