get_dvb_firmware 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  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. # Check args
  28. syntax() if (scalar(@ARGV) != 1);
  29. $cid = $ARGV[0];
  30. # Do it!
  31. for ($i=0; $i < scalar(@components); $i++) {
  32. if ($cid eq $components[$i]) {
  33. $outfile = eval($cid);
  34. die $@ if $@;
  35. print STDERR <<EOF;
  36. Firmware(s) $outfile extracted successfully.
  37. Now copy it(they) to either /usr/lib/hotplug/firmware or /lib/firmware
  38. (depending on configuration of firmware hotplug).
  39. EOF
  40. exit(0);
  41. }
  42. }
  43. # If we get here, it wasn't found
  44. print STDERR "Unknown component \"$cid\"\n";
  45. syntax();
  46. # ---------------------------------------------------------------
  47. # Firmware-specific extraction subroutines
  48. sub sp8870 {
  49. my $sourcefile = "tt_Premium_217g.zip";
  50. my $url = "http://www.softwarepatch.pl/9999ccd06a4813cb827dbb0005071c71/$sourcefile";
  51. my $hash = "53970ec17a538945a6d8cb608a7b3899";
  52. my $outfile = "dvb-fe-sp8870.fw";
  53. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  54. checkstandard();
  55. wgetfile($sourcefile, $url);
  56. unzip($sourcefile, $tmpdir);
  57. verify("$tmpdir/software/OEM/HE/App/boot/SC_MAIN.MC", $hash);
  58. copy("$tmpdir/software/OEM/HE/App/boot/SC_MAIN.MC", $outfile);
  59. $outfile;
  60. }
  61. sub sp887x {
  62. my $sourcefile = "Dvbt1.3.57.6.zip";
  63. my $url = "http://www.avermedia.com/software/$sourcefile";
  64. my $cabfile = "DVBT Net Ver1.3.57.6/disk1/data1.cab";
  65. my $hash = "237938d53a7f834c05c42b894ca68ac3";
  66. my $outfile = "dvb-fe-sp887x.fw";
  67. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  68. checkstandard();
  69. checkunshield();
  70. wgetfile($sourcefile, $url);
  71. unzip($sourcefile, $tmpdir);
  72. unshield("$tmpdir/$cabfile", $tmpdir);
  73. verify("$tmpdir/ZEnglish/sc_main.mc", $hash);
  74. copy("$tmpdir/ZEnglish/sc_main.mc", $outfile);
  75. $outfile;
  76. }
  77. sub tda10045 {
  78. my $sourcefile = "tt_budget_217g.zip";
  79. my $url = "http://www.technotrend.de/new/217g/$sourcefile";
  80. my $hash = "2105fd5bf37842fbcdfa4bfd58f3594a";
  81. my $outfile = "dvb-fe-tda10045.fw";
  82. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  83. checkstandard();
  84. wgetfile($sourcefile, $url);
  85. unzip($sourcefile, $tmpdir);
  86. extract("$tmpdir/software/OEM/PCI/App/ttlcdacc.dll", 0x37ef9, 30555, "$tmpdir/fwtmp");
  87. verify("$tmpdir/fwtmp", $hash);
  88. copy("$tmpdir/fwtmp", $outfile);
  89. $outfile;
  90. }
  91. sub tda10046 {
  92. my $sourcefile = "TT_PCI_2.19h_28_11_2006.zip";
  93. my $url = "http://www.tt-download.com/download/updates/219/$sourcefile";
  94. my $hash = "6a7e1e2f2644b162ff0502367553c72d";
  95. my $outfile = "dvb-fe-tda10046.fw";
  96. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  97. checkstandard();
  98. wgetfile($sourcefile, $url);
  99. unzip($sourcefile, $tmpdir);
  100. extract("$tmpdir/TT_PCI_2.19h_28_11_2006/software/OEM/PCI/App/ttlcdacc.dll", 0x65389, 24478, "$tmpdir/fwtmp");
  101. verify("$tmpdir/fwtmp", $hash);
  102. copy("$tmpdir/fwtmp", $outfile);
  103. $outfile;
  104. }
  105. sub tda10046lifeview {
  106. my $sourcefile = "7%5Cdrv_2.11.02.zip";
  107. my $url = "http://www.lifeview.hk/dbimages/document/$sourcefile";
  108. my $hash = "1ea24dee4eea8fe971686981f34fd2e0";
  109. my $outfile = "dvb-fe-tda10046.fw";
  110. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  111. checkstandard();
  112. wgetfile($sourcefile, $url);
  113. unzip($sourcefile, $tmpdir);
  114. extract("$tmpdir/LVHybrid.sys", 0x8b088, 24602, "$tmpdir/fwtmp");
  115. verify("$tmpdir/fwtmp", $hash);
  116. copy("$tmpdir/fwtmp", $outfile);
  117. $outfile;
  118. }
  119. sub av7110 {
  120. my $sourcefile = "dvb-ttpci-01.fw-261d";
  121. my $url = "http://www.linuxtv.org/downloads/firmware/$sourcefile";
  122. my $hash = "603431b6259715a8e88f376a53b64e2f";
  123. my $outfile = "dvb-ttpci-01.fw";
  124. checkstandard();
  125. wgetfile($sourcefile, $url);
  126. verify($sourcefile, $hash);
  127. copy($sourcefile, $outfile);
  128. $outfile;
  129. }
  130. sub dec2000t {
  131. my $sourcefile = "dec217g.exe";
  132. my $url = "http://hauppauge.lightpath.net/de/$sourcefile";
  133. my $hash = "bd86f458cee4a8f0a8ce2d20c66215a9";
  134. my $outfile = "dvb-ttusb-dec-2000t.fw";
  135. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  136. checkstandard();
  137. wgetfile($sourcefile, $url);
  138. unzip($sourcefile, $tmpdir);
  139. verify("$tmpdir/software/OEM/STB/App/Boot/STB_PC_T.bin", $hash);
  140. copy("$tmpdir/software/OEM/STB/App/Boot/STB_PC_T.bin", $outfile);
  141. $outfile;
  142. }
  143. sub dec2540t {
  144. my $sourcefile = "dec217g.exe";
  145. my $url = "http://hauppauge.lightpath.net/de/$sourcefile";
  146. my $hash = "53e58f4f5b5c2930beee74a7681fed92";
  147. my $outfile = "dvb-ttusb-dec-2540t.fw";
  148. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  149. checkstandard();
  150. wgetfile($sourcefile, $url);
  151. unzip($sourcefile, $tmpdir);
  152. verify("$tmpdir/software/OEM/STB/App/Boot/STB_PC_X.bin", $hash);
  153. copy("$tmpdir/software/OEM/STB/App/Boot/STB_PC_X.bin", $outfile);
  154. $outfile;
  155. }
  156. sub dec3000s {
  157. my $sourcefile = "dec217g.exe";
  158. my $url = "http://hauppauge.lightpath.net/de/$sourcefile";
  159. my $hash = "b013ececea83f4d6d8d2a29ac7c1b448";
  160. my $outfile = "dvb-ttusb-dec-3000s.fw";
  161. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  162. checkstandard();
  163. wgetfile($sourcefile, $url);
  164. unzip($sourcefile, $tmpdir);
  165. verify("$tmpdir/software/OEM/STB/App/Boot/STB_PC_S.bin", $hash);
  166. copy("$tmpdir/software/OEM/STB/App/Boot/STB_PC_S.bin", $outfile);
  167. $outfile;
  168. }
  169. sub opera1{
  170. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 0);
  171. checkstandard();
  172. my $fwfile1="dvb-usb-opera1-fpga-01.fw";
  173. my $fwfile2="dvb-usb-opera-01.fw";
  174. extract("2830SCap2.sys", 0x62e8, 55024, "$tmpdir/opera1-fpga.fw");
  175. extract("2830SLoad2.sys",0x3178,0x3685-0x3178,"$tmpdir/fw1part1");
  176. extract("2830SLoad2.sys",0x0980,0x3150-0x0980,"$tmpdir/fw1part2");
  177. delzero("$tmpdir/fw1part1","$tmpdir/fw1part1-1");
  178. delzero("$tmpdir/fw1part2","$tmpdir/fw1part2-1");
  179. verify("$tmpdir/fw1part1-1","5e0909858fdf0b5b09ad48b9fe622e70");
  180. verify("$tmpdir/fw1part2-1","d6e146f321427e931df2c6fcadac37a1");
  181. verify("$tmpdir/opera1-fpga.fw","0f8133f5e9051f5f3c1928f7e5a1b07d");
  182. my $RES1="\x01\x92\x7f\x00\x01\x00";
  183. my $RES0="\x01\x92\x7f\x00\x00\x00";
  184. my $DAT1="\x01\x00\xe6\x00\x01\x00";
  185. my $DAT0="\x01\x00\xe6\x00\x00\x00";
  186. open FW,">$tmpdir/opera.fw";
  187. print FW "$RES1";
  188. print FW "$DAT1";
  189. print FW "$RES1";
  190. print FW "$DAT1";
  191. appendfile(FW,"$tmpdir/fw1part1-1");
  192. print FW "$RES0";
  193. print FW "$DAT0";
  194. print FW "$RES1";
  195. print FW "$DAT1";
  196. appendfile(FW,"$tmpdir/fw1part2-1");
  197. print FW "$RES1";
  198. print FW "$DAT1";
  199. print FW "$RES0";
  200. print FW "$DAT0";
  201. copy ("$tmpdir/opera1-fpga.fw",$fwfile1);
  202. copy ("$tmpdir/opera.fw",$fwfile2);
  203. $fwfile1.",".$fwfile2;
  204. }
  205. sub vp7041 {
  206. my $sourcefile = "2.422.zip";
  207. my $url = "http://www.twinhan.com/files/driver/USB-Ter/$sourcefile";
  208. my $hash = "e88c9372d1f66609a3e7b072c53fbcfe";
  209. my $outfile = "dvb-vp7041-2.422.fw";
  210. my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
  211. checkstandard();
  212. wgetfile($sourcefile, $url);
  213. unzip($sourcefile, $tmpdir);
  214. extract("$tmpdir/VisionDTV/Drivers/Win2K&XP/UDTTload.sys", 12503, 3036, "$tmpdir/fwtmp1");
  215. extract("$tmpdir/VisionDTV/Drivers/Win2K&XP/UDTTload.sys", 2207, 10274, "$tmpdir/fwtmp2");
  216. my $CMD = "\000\001\000\222\177\000";
  217. my $PAD = "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000";
  218. my ($FW);
  219. open $FW, ">$tmpdir/fwtmp3";
  220. print $FW "$CMD\001$PAD";
  221. print $FW "$CMD\001$PAD";
  222. appendfile($FW, "$tmpdir/fwtmp1");
  223. print $FW "$CMD\000$PAD";
  224. print $FW "$CMD\001$PAD";
  225. appendfile($FW, "$tmpdir/fwtmp2");
  226. print $FW "$CMD\001$PAD";
  227. print $FW "$CMD\000$PAD";
  228. close($FW);
  229. verify("$tmpdir/fwtmp3", $hash);
  230. copy("$tmpdir/fwtmp3", $outfile);
  231. $outfile;
  232. }
  233. sub dibusb {
  234. my $url = "http://www.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 = "http://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 = "http://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 = "http://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 = "http://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 = "http://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 = "http://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 = "http://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 = "http://www.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. # ---------------------------------------------------------------
  406. # Utilities
  407. sub checkstandard {
  408. if (system("which unzip > /dev/null 2>&1")) {
  409. die "This firmware requires the unzip command - see ftp://ftp.info-zip.org/pub/infozip/UnZip.html\n";
  410. }
  411. if (system("which md5sum > /dev/null 2>&1")) {
  412. die "This firmware requires the md5sum command - see http://www.gnu.org/software/coreutils/\n";
  413. }
  414. if (system("which wget > /dev/null 2>&1")) {
  415. die "This firmware requires the wget command - see http://wget.sunsite.dk/\n";
  416. }
  417. }
  418. sub checkunshield {
  419. if (system("which unshield > /dev/null 2>&1")) {
  420. die "This firmware requires the unshield command - see http://sourceforge.net/projects/synce/\n";
  421. }
  422. }
  423. sub wgetfile {
  424. my ($sourcefile, $url) = @_;
  425. if (! -f $sourcefile) {
  426. system("wget -O \"$sourcefile\" \"$url\"") and die "wget failed - unable to download firmware";
  427. }
  428. }
  429. sub unzip {
  430. my ($sourcefile, $todir) = @_;
  431. $status = system("unzip -q -o -d \"$todir\" \"$sourcefile\" 2>/dev/null" );
  432. if ((($status >> 8) > 2) || (($status & 0xff) != 0)) {
  433. die ("unzip failed - unable to extract firmware");
  434. }
  435. }
  436. sub unshield {
  437. my ($sourcefile, $todir) = @_;
  438. system("unshield x -d \"$todir\" \"$sourcefile\" > /dev/null" ) and die ("unshield failed - unable to extract firmware");
  439. }
  440. sub verify {
  441. my ($filename, $hash) = @_;
  442. my ($testhash);
  443. open(CMD, "md5sum \"$filename\"|");
  444. $testhash = <CMD>;
  445. $testhash =~ /([a-zA-Z0-9]*)/;
  446. $testhash = $1;
  447. close CMD;
  448. die "Hash of extracted file does not match!\n" if ($testhash ne $hash);
  449. }
  450. sub copy {
  451. my ($from, $to) = @_;
  452. system("cp -f \"$from\" \"$to\"") and die ("cp failed");
  453. }
  454. sub extract {
  455. my ($infile, $offset, $length, $outfile) = @_;
  456. my ($chunklength, $buf, $rcount);
  457. open INFILE, "<$infile";
  458. open OUTFILE, ">$outfile";
  459. sysseek(INFILE, $offset, SEEK_SET);
  460. while($length > 0) {
  461. # Calc chunk size
  462. $chunklength = 2048;
  463. $chunklength = $length if ($chunklength > $length);
  464. $rcount = sysread(INFILE, $buf, $chunklength);
  465. die "Ran out of data\n" if ($rcount != $chunklength);
  466. syswrite(OUTFILE, $buf);
  467. $length -= $rcount;
  468. }
  469. close INFILE;
  470. close OUTFILE;
  471. }
  472. sub appendfile {
  473. my ($FH, $infile) = @_;
  474. my ($buf);
  475. open INFILE, "<$infile";
  476. while(1) {
  477. $rcount = sysread(INFILE, $buf, 2048);
  478. last if ($rcount == 0);
  479. print $FH $buf;
  480. }
  481. close(INFILE);
  482. }
  483. sub delzero{
  484. my ($infile,$outfile) =@_;
  485. open INFILE,"<$infile";
  486. open OUTFILE,">$outfile";
  487. while (1){
  488. $rcount=sysread(INFILE,$buf,22);
  489. $len=ord(substr($buf,0,1));
  490. print OUTFILE substr($buf,0,1);
  491. print OUTFILE substr($buf,2,$len+3);
  492. last if ($rcount<1);
  493. printf OUTFILE "%c",0;
  494. #print $len." ".length($buf)."\n";
  495. }
  496. close(INFILE);
  497. close(OUTFILE);
  498. }
  499. sub syntax() {
  500. print STDERR "syntax: get_dvb_firmware <component>\n";
  501. print STDERR "Supported components:\n";
  502. for($i=0; $i < scalar(@components); $i++) {
  503. print STDERR "\t" . $components[$i] . "\n";
  504. }
  505. exit(1);
  506. }