get_dvb_firmware 25 KB

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