| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
|  | 21 | use File::Temp qw/ tempdir /; | 
|  | 22 | use IO::Handle; | 
|  | 23 |  | 
|  | 24 | @components = ( "sp8870", "sp887x", "tda10045", "tda10046", "av7110", "dec2000t", | 
| Kirk Lapray | 04a4592 | 2005-11-08 21:35:46 -0800 | [diff] [blame] | 25 | "dec2540t", "dec3000s", "vp7041", "dibusb", "nxt2002", "nxt2004", | 
| Michael Krufky | d8e6acf | 2006-01-09 15:32:42 -0200 | [diff] [blame] | 26 | "or51211", "or51132_qam", "or51132_vsb", "bluebird"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 |  | 
|  | 28 | # Check args | 
|  | 29 | syntax() if (scalar(@ARGV) != 1); | 
|  | 30 | $cid = $ARGV[0]; | 
|  | 31 |  | 
|  | 32 | # Do it! | 
|  | 33 | for ($i=0; $i < scalar(@components); $i++) { | 
|  | 34 | if ($cid eq $components[$i]) { | 
|  | 35 | $outfile = eval($cid); | 
|  | 36 | die $@ if $@; | 
| Ville Skytt\รค | 12e66f6 | 2006-01-09 15:25:38 -0200 | [diff] [blame] | 37 | print STDERR <<EOF; | 
|  | 38 | Firmware $outfile extracted successfully. | 
|  | 39 | Now copy it to either /usr/lib/hotplug/firmware or /lib/firmware | 
|  | 40 | (depending on configuration of firmware hotplug). | 
|  | 41 | EOF | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | exit(0); | 
|  | 43 | } | 
|  | 44 | } | 
|  | 45 |  | 
|  | 46 | # If we get here, it wasn't found | 
|  | 47 | print STDERR "Unknown component \"$cid\"\n"; | 
|  | 48 | syntax(); | 
|  | 49 |  | 
|  | 50 |  | 
|  | 51 |  | 
|  | 52 |  | 
|  | 53 | # --------------------------------------------------------------- | 
|  | 54 | # Firmware-specific extraction subroutines | 
|  | 55 |  | 
|  | 56 | sub sp8870 { | 
|  | 57 | my $sourcefile = "tt_Premium_217g.zip"; | 
|  | 58 | my $url = "http://www.technotrend.de/new/217g/$sourcefile"; | 
|  | 59 | my $hash = "53970ec17a538945a6d8cb608a7b3899"; | 
|  | 60 | my $outfile = "dvb-fe-sp8870.fw"; | 
|  | 61 | my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1); | 
|  | 62 |  | 
|  | 63 | checkstandard(); | 
|  | 64 |  | 
|  | 65 | wgetfile($sourcefile, $url); | 
|  | 66 | unzip($sourcefile, $tmpdir); | 
|  | 67 | verify("$tmpdir/software/OEM/HE/App/boot/SC_MAIN.MC", $hash); | 
|  | 68 | copy("$tmpdir/software/OEM/HE/App/boot/SC_MAIN.MC", $outfile); | 
|  | 69 |  | 
|  | 70 | $outfile; | 
|  | 71 | } | 
|  | 72 |  | 
|  | 73 | sub sp887x { | 
|  | 74 | my $sourcefile = "Dvbt1.3.57.6.zip"; | 
|  | 75 | my $url = "http://www.avermedia.com/software/$sourcefile"; | 
|  | 76 | my $cabfile = "DVBT Net  Ver1.3.57.6/disk1/data1.cab"; | 
|  | 77 | my $hash = "237938d53a7f834c05c42b894ca68ac3"; | 
|  | 78 | my $outfile = "dvb-fe-sp887x.fw"; | 
|  | 79 | my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1); | 
|  | 80 |  | 
|  | 81 | checkstandard(); | 
|  | 82 | checkunshield(); | 
|  | 83 |  | 
|  | 84 | wgetfile($sourcefile, $url); | 
|  | 85 | unzip($sourcefile, $tmpdir); | 
|  | 86 | unshield("$tmpdir/$cabfile", $tmpdir); | 
|  | 87 | verify("$tmpdir/ZEnglish/sc_main.mc", $hash); | 
|  | 88 | copy("$tmpdir/ZEnglish/sc_main.mc", $outfile); | 
|  | 89 |  | 
|  | 90 | $outfile; | 
|  | 91 | } | 
|  | 92 |  | 
|  | 93 | sub tda10045 { | 
|  | 94 | my $sourcefile = "tt_budget_217g.zip"; | 
|  | 95 | my $url = "http://www.technotrend.de/new/217g/$sourcefile"; | 
|  | 96 | my $hash = "2105fd5bf37842fbcdfa4bfd58f3594a"; | 
|  | 97 | my $outfile = "dvb-fe-tda10045.fw"; | 
|  | 98 | my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1); | 
|  | 99 |  | 
|  | 100 | checkstandard(); | 
|  | 101 |  | 
|  | 102 | wgetfile($sourcefile, $url); | 
|  | 103 | unzip($sourcefile, $tmpdir); | 
|  | 104 | extract("$tmpdir/software/OEM/PCI/App/ttlcdacc.dll", 0x37ef9, 30555, "$tmpdir/fwtmp"); | 
|  | 105 | verify("$tmpdir/fwtmp", $hash); | 
|  | 106 | copy("$tmpdir/fwtmp", $outfile); | 
|  | 107 |  | 
|  | 108 | $outfile; | 
|  | 109 | } | 
|  | 110 |  | 
|  | 111 | sub tda10046 { | 
|  | 112 | my $sourcefile = "tt_budget_217g.zip"; | 
|  | 113 | my $url = "http://www.technotrend.de/new/217g/$sourcefile"; | 
| Johannes Stezenbach | 71e3420 | 2005-05-16 21:54:36 -0700 | [diff] [blame] | 114 | my $hash = "6a7e1e2f2644b162ff0502367553c72d"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | my $outfile = "dvb-fe-tda10046.fw"; | 
|  | 116 | my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1); | 
|  | 117 |  | 
|  | 118 | checkstandard(); | 
|  | 119 |  | 
|  | 120 | wgetfile($sourcefile, $url); | 
|  | 121 | unzip($sourcefile, $tmpdir); | 
| Johannes Stezenbach | 71e3420 | 2005-05-16 21:54:36 -0700 | [diff] [blame] | 122 | extract("$tmpdir/software/OEM/PCI/App/ttlcdacc.dll", 0x3f731, 24478, "$tmpdir/fwtmp"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | verify("$tmpdir/fwtmp", $hash); | 
|  | 124 | copy("$tmpdir/fwtmp", $outfile); | 
|  | 125 |  | 
|  | 126 | $outfile; | 
|  | 127 | } | 
|  | 128 |  | 
|  | 129 | sub av7110 { | 
|  | 130 | my $sourcefile = "dvb-ttpci-01.fw-261d"; | 
|  | 131 | my $url = "http://www.linuxtv.org/downloads/firmware/$sourcefile"; | 
|  | 132 | my $hash = "603431b6259715a8e88f376a53b64e2f"; | 
|  | 133 | my $outfile = "dvb-ttpci-01.fw"; | 
|  | 134 |  | 
|  | 135 | checkstandard(); | 
|  | 136 |  | 
|  | 137 | wgetfile($sourcefile, $url); | 
|  | 138 | verify($sourcefile, $hash); | 
|  | 139 | copy($sourcefile, $outfile); | 
|  | 140 |  | 
|  | 141 | $outfile; | 
|  | 142 | } | 
|  | 143 |  | 
|  | 144 | sub dec2000t { | 
|  | 145 | my $sourcefile = "dec217g.exe"; | 
|  | 146 | my $url = "http://hauppauge.lightpath.net/de/$sourcefile"; | 
|  | 147 | my $hash = "bd86f458cee4a8f0a8ce2d20c66215a9"; | 
|  | 148 | my $outfile = "dvb-ttusb-dec-2000t.fw"; | 
|  | 149 | my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1); | 
|  | 150 |  | 
|  | 151 | checkstandard(); | 
|  | 152 |  | 
|  | 153 | wgetfile($sourcefile, $url); | 
|  | 154 | unzip($sourcefile, $tmpdir); | 
|  | 155 | verify("$tmpdir/software/OEM/STB/App/Boot/STB_PC_T.bin", $hash); | 
|  | 156 | copy("$tmpdir/software/OEM/STB/App/Boot/STB_PC_T.bin", $outfile); | 
|  | 157 |  | 
|  | 158 | $outfile; | 
|  | 159 | } | 
|  | 160 |  | 
|  | 161 | sub dec2540t { | 
|  | 162 | my $sourcefile = "dec217g.exe"; | 
|  | 163 | my $url = "http://hauppauge.lightpath.net/de/$sourcefile"; | 
|  | 164 | my $hash = "53e58f4f5b5c2930beee74a7681fed92"; | 
|  | 165 | my $outfile = "dvb-ttusb-dec-2540t.fw"; | 
|  | 166 | my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1); | 
|  | 167 |  | 
|  | 168 | checkstandard(); | 
|  | 169 |  | 
|  | 170 | wgetfile($sourcefile, $url); | 
|  | 171 | unzip($sourcefile, $tmpdir); | 
|  | 172 | verify("$tmpdir/software/OEM/STB/App/Boot/STB_PC_X.bin", $hash); | 
|  | 173 | copy("$tmpdir/software/OEM/STB/App/Boot/STB_PC_X.bin", $outfile); | 
|  | 174 |  | 
|  | 175 | $outfile; | 
|  | 176 | } | 
|  | 177 |  | 
|  | 178 | sub dec3000s { | 
|  | 179 | my $sourcefile = "dec217g.exe"; | 
|  | 180 | my $url = "http://hauppauge.lightpath.net/de/$sourcefile"; | 
|  | 181 | my $hash = "b013ececea83f4d6d8d2a29ac7c1b448"; | 
|  | 182 | my $outfile = "dvb-ttusb-dec-3000s.fw"; | 
|  | 183 | my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1); | 
|  | 184 |  | 
|  | 185 | checkstandard(); | 
|  | 186 |  | 
|  | 187 | wgetfile($sourcefile, $url); | 
|  | 188 | unzip($sourcefile, $tmpdir); | 
|  | 189 | verify("$tmpdir/software/OEM/STB/App/Boot/STB_PC_S.bin", $hash); | 
|  | 190 | copy("$tmpdir/software/OEM/STB/App/Boot/STB_PC_S.bin", $outfile); | 
|  | 191 |  | 
|  | 192 | $outfile; | 
|  | 193 | } | 
|  | 194 |  | 
|  | 195 | sub vp7041 { | 
|  | 196 | my $sourcefile = "2.422.zip"; | 
|  | 197 | my $url = "http://www.twinhan.com/files/driver/USB-Ter/$sourcefile"; | 
|  | 198 | my $hash = "e88c9372d1f66609a3e7b072c53fbcfe"; | 
|  | 199 | my $outfile = "dvb-vp7041-2.422.fw"; | 
|  | 200 | my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1); | 
|  | 201 |  | 
|  | 202 | checkstandard(); | 
|  | 203 |  | 
|  | 204 | wgetfile($sourcefile, $url); | 
|  | 205 | unzip($sourcefile, $tmpdir); | 
|  | 206 | extract("$tmpdir/VisionDTV/Drivers/Win2K&XP/UDTTload.sys", 12503, 3036, "$tmpdir/fwtmp1"); | 
|  | 207 | extract("$tmpdir/VisionDTV/Drivers/Win2K&XP/UDTTload.sys", 2207, 10274, "$tmpdir/fwtmp2"); | 
|  | 208 |  | 
|  | 209 | my $CMD = "\000\001\000\222\177\000"; | 
|  | 210 | my $PAD = "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"; | 
|  | 211 | my ($FW); | 
|  | 212 | open $FW, ">$tmpdir/fwtmp3"; | 
|  | 213 | print $FW "$CMD\001$PAD"; | 
|  | 214 | print $FW "$CMD\001$PAD"; | 
|  | 215 | appendfile($FW, "$tmpdir/fwtmp1"); | 
|  | 216 | print $FW "$CMD\000$PAD"; | 
|  | 217 | print $FW "$CMD\001$PAD"; | 
|  | 218 | appendfile($FW, "$tmpdir/fwtmp2"); | 
|  | 219 | print $FW "$CMD\001$PAD"; | 
|  | 220 | print $FW "$CMD\000$PAD"; | 
|  | 221 | close($FW); | 
|  | 222 |  | 
|  | 223 | verify("$tmpdir/fwtmp3", $hash); | 
|  | 224 | copy("$tmpdir/fwtmp3", $outfile); | 
|  | 225 |  | 
|  | 226 | $outfile; | 
|  | 227 | } | 
|  | 228 |  | 
|  | 229 | sub dibusb { | 
|  | 230 | my $url = "http://www.linuxtv.org/downloads/firmware/dvb-dibusb-5.0.0.11.fw"; | 
|  | 231 | my $outfile = "dvb-dibusb-5.0.0.11.fw"; | 
|  | 232 | my $hash = "fa490295a527360ca16dcdf3224ca243"; | 
|  | 233 |  | 
|  | 234 | checkstandard(); | 
|  | 235 |  | 
|  | 236 | wgetfile($outfile, $url); | 
|  | 237 | verify($outfile,$hash); | 
|  | 238 |  | 
|  | 239 | $outfile; | 
|  | 240 | } | 
|  | 241 |  | 
|  | 242 | sub nxt2002 { | 
|  | 243 | my $sourcefile = "Broadband4PC_4_2_11.zip"; | 
|  | 244 | my $url = "http://www.bbti.us/download/windows/$sourcefile"; | 
|  | 245 | my $hash = "c6d2ea47a8f456d887ada0cfb718ff2a"; | 
|  | 246 | my $outfile = "dvb-fe-nxt2002.fw"; | 
|  | 247 | my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1); | 
|  | 248 |  | 
|  | 249 | checkstandard(); | 
| Michael Krufky | 50c25ff | 2006-01-09 15:25:34 -0200 | [diff] [blame] | 250 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | wgetfile($sourcefile, $url); | 
|  | 252 | unzip($sourcefile, $tmpdir); | 
|  | 253 | verify("$tmpdir/SkyNETU.sys", $hash); | 
|  | 254 | extract("$tmpdir/SkyNETU.sys", 375832, 5908, $outfile); | 
|  | 255 |  | 
|  | 256 | $outfile; | 
|  | 257 | } | 
|  | 258 |  | 
| Kirk Lapray | 04a4592 | 2005-11-08 21:35:46 -0800 | [diff] [blame] | 259 | sub nxt2004 { | 
|  | 260 | my $sourcefile = "AVerTVHD_MCE_A180_Drv_v1.2.2.16.zip"; | 
|  | 261 | my $url = "http://www.aver.com/support/Drivers/$sourcefile"; | 
|  | 262 | my $hash = "111cb885b1e009188346d72acfed024c"; | 
|  | 263 | my $outfile = "dvb-fe-nxt2004.fw"; | 
|  | 264 | my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1); | 
|  | 265 |  | 
|  | 266 | checkstandard(); | 
|  | 267 |  | 
|  | 268 | wgetfile($sourcefile, $url); | 
|  | 269 | unzip($sourcefile, $tmpdir); | 
|  | 270 | verify("$tmpdir/3xHybrid.sys", $hash); | 
|  | 271 | extract("$tmpdir/3xHybrid.sys", 465304, 9584, $outfile); | 
|  | 272 |  | 
|  | 273 | $outfile; | 
|  | 274 | } | 
|  | 275 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | sub or51211 { | 
|  | 277 | my $fwfile = "dvb-fe-or51211.fw"; | 
|  | 278 | my $url = "http://linuxtv.org/downloads/firmware/$fwfile"; | 
|  | 279 | my $hash = "d830949c771a289505bf9eafc225d491"; | 
|  | 280 |  | 
|  | 281 | checkstandard(); | 
|  | 282 |  | 
|  | 283 | wgetfile($fwfile, $url); | 
|  | 284 | verify($fwfile, $hash); | 
|  | 285 |  | 
|  | 286 | $fwfile; | 
|  | 287 | } | 
|  | 288 |  | 
|  | 289 | sub or51132_qam { | 
|  | 290 | my $fwfile = "dvb-fe-or51132-qam.fw"; | 
|  | 291 | my $url = "http://linuxtv.org/downloads/firmware/$fwfile"; | 
|  | 292 | my $hash = "7702e8938612de46ccadfe9b413cb3b5"; | 
|  | 293 |  | 
|  | 294 | checkstandard(); | 
|  | 295 |  | 
|  | 296 | wgetfile($fwfile, $url); | 
|  | 297 | verify($fwfile, $hash); | 
|  | 298 |  | 
|  | 299 | $fwfile; | 
|  | 300 | } | 
|  | 301 |  | 
|  | 302 | sub or51132_vsb { | 
|  | 303 | my $fwfile = "dvb-fe-or51132-vsb.fw"; | 
|  | 304 | my $url = "http://linuxtv.org/downloads/firmware/$fwfile"; | 
|  | 305 | my $hash = "c16208e02f36fc439a557ad4c613364a"; | 
|  | 306 |  | 
|  | 307 | checkstandard(); | 
|  | 308 |  | 
|  | 309 | wgetfile($fwfile, $url); | 
|  | 310 | verify($fwfile, $hash); | 
|  | 311 |  | 
|  | 312 | $fwfile; | 
|  | 313 | } | 
|  | 314 |  | 
| Michael Krufky | d8e6acf | 2006-01-09 15:32:42 -0200 | [diff] [blame] | 315 | sub bluebird { | 
| Michael Krufky | cec4183 | 2006-01-09 18:21:40 -0200 | [diff] [blame] | 316 | my $url = "http://www.linuxtv.org/download/dvb/firmware/dvb-usb-bluebird-01.fw"; | 
| Michael Krufky | d8e6acf | 2006-01-09 15:32:42 -0200 | [diff] [blame] | 317 | my $outfile = "dvb-usb-bluebird-01.fw"; | 
|  | 318 | my $hash = "658397cb9eba9101af9031302671f49d"; | 
|  | 319 |  | 
|  | 320 | checkstandard(); | 
|  | 321 |  | 
|  | 322 | wgetfile($outfile, $url); | 
|  | 323 | verify($outfile,$hash); | 
|  | 324 |  | 
|  | 325 | $outfile; | 
|  | 326 | } | 
|  | 327 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | # --------------------------------------------------------------- | 
|  | 329 | # Utilities | 
|  | 330 |  | 
|  | 331 | sub checkstandard { | 
|  | 332 | if (system("which unzip > /dev/null 2>&1")) { | 
|  | 333 | die "This firmware requires the unzip command - see ftp://ftp.info-zip.org/pub/infozip/UnZip.html\n"; | 
|  | 334 | } | 
|  | 335 | if (system("which md5sum > /dev/null 2>&1")) { | 
|  | 336 | die "This firmware requires the md5sum command - see http://www.gnu.org/software/coreutils/\n"; | 
|  | 337 | } | 
|  | 338 | if (system("which wget > /dev/null 2>&1")) { | 
|  | 339 | die "This firmware requires the wget command - see http://wget.sunsite.dk/\n"; | 
|  | 340 | } | 
|  | 341 | } | 
|  | 342 |  | 
|  | 343 | sub checkunshield { | 
|  | 344 | if (system("which unshield > /dev/null 2>&1")) { | 
|  | 345 | die "This firmware requires the unshield command - see http://sourceforge.net/projects/synce/\n"; | 
|  | 346 | } | 
|  | 347 | } | 
|  | 348 |  | 
|  | 349 | sub wgetfile { | 
|  | 350 | my ($sourcefile, $url) = @_; | 
|  | 351 |  | 
|  | 352 | if (! -f $sourcefile) { | 
|  | 353 | system("wget -O \"$sourcefile\" \"$url\"") and die "wget failed - unable to download firmware"; | 
|  | 354 | } | 
|  | 355 | } | 
|  | 356 |  | 
|  | 357 | sub unzip { | 
|  | 358 | my ($sourcefile, $todir) = @_; | 
|  | 359 |  | 
|  | 360 | $status = system("unzip -q -o -d \"$todir\" \"$sourcefile\" 2>/dev/null" ); | 
|  | 361 | if ((($status >> 8) > 2) || (($status & 0xff) != 0)) { | 
|  | 362 | die ("unzip failed - unable to extract firmware"); | 
|  | 363 | } | 
|  | 364 | } | 
|  | 365 |  | 
|  | 366 | sub unshield { | 
|  | 367 | my ($sourcefile, $todir) = @_; | 
|  | 368 |  | 
|  | 369 | system("unshield x -d \"$todir\" \"$sourcefile\" > /dev/null" ) and die ("unshield failed - unable to extract firmware"); | 
|  | 370 | } | 
|  | 371 |  | 
|  | 372 | sub verify { | 
|  | 373 | my ($filename, $hash) = @_; | 
|  | 374 | my ($testhash); | 
|  | 375 |  | 
|  | 376 | open(CMD, "md5sum \"$filename\"|"); | 
|  | 377 | $testhash = <CMD>; | 
|  | 378 | $testhash =~ /([a-zA-Z0-9]*)/; | 
|  | 379 | $testhash = $1; | 
|  | 380 | close CMD; | 
|  | 381 | die "Hash of extracted file does not match!\n" if ($testhash ne $hash); | 
|  | 382 | } | 
|  | 383 |  | 
|  | 384 | sub copy { | 
|  | 385 | my ($from, $to) = @_; | 
|  | 386 |  | 
|  | 387 | system("cp -f \"$from\" \"$to\"") and die ("cp failed"); | 
|  | 388 | } | 
|  | 389 |  | 
|  | 390 | sub extract { | 
|  | 391 | my ($infile, $offset, $length, $outfile) = @_; | 
|  | 392 | my ($chunklength, $buf, $rcount); | 
|  | 393 |  | 
|  | 394 | open INFILE, "<$infile"; | 
|  | 395 | open OUTFILE, ">$outfile"; | 
|  | 396 | sysseek(INFILE, $offset, SEEK_SET); | 
|  | 397 | while($length > 0) { | 
|  | 398 | # Calc chunk size | 
|  | 399 | $chunklength = 2048; | 
|  | 400 | $chunklength = $length if ($chunklength > $length); | 
|  | 401 |  | 
|  | 402 | $rcount = sysread(INFILE, $buf, $chunklength); | 
|  | 403 | die "Ran out of data\n" if ($rcount != $chunklength); | 
|  | 404 | syswrite(OUTFILE, $buf); | 
|  | 405 | $length -= $rcount; | 
|  | 406 | } | 
|  | 407 | close INFILE; | 
|  | 408 | close OUTFILE; | 
|  | 409 | } | 
|  | 410 |  | 
|  | 411 | sub appendfile { | 
|  | 412 | my ($FH, $infile) = @_; | 
|  | 413 | my ($buf); | 
|  | 414 |  | 
|  | 415 | open INFILE, "<$infile"; | 
|  | 416 | while(1) { | 
|  | 417 | $rcount = sysread(INFILE, $buf, 2048); | 
|  | 418 | last if ($rcount == 0); | 
|  | 419 | print $FH $buf; | 
|  | 420 | } | 
|  | 421 | close(INFILE); | 
|  | 422 | } | 
|  | 423 |  | 
|  | 424 | sub syntax() { | 
|  | 425 | print STDERR "syntax: get_dvb_firmware <component>\n"; | 
|  | 426 | print STDERR "Supported components:\n"; | 
|  | 427 | for($i=0; $i < scalar(@components); $i++) { | 
|  | 428 | print STDERR "\t" . $components[$i] . "\n"; | 
|  | 429 | } | 
|  | 430 | exit(1); | 
|  | 431 | } |