get_dvb_firmware 23 KB

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