get_dvb_firmware 19 KB

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