get_dvb_firmware 21 KB

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