uml: improve PTRACE_SYSEMU checking
[pv_ops_mirror.git] / Documentation / dvb / get_dvb_firmware
blob4820366b6ae899667cf0589b789661d990eda7cc
1 #!/usr/bin/perl
2 # DVB firmware extractor
4 # (c) 2004 Andrew de Quincey
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.
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
15 # GNU General Public License for more details.
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.
21 use File::Temp qw/ tempdir /;
22 use IO::Handle;
24 @components = ( "sp8870", "sp887x", "tda10045", "tda10046",
25 "tda10046lifeview", "av7110", "dec2000t", "dec2540t",
26 "dec3000s", "vp7041", "dibusb", "nxt2002", "nxt2004",
27 "or51211", "or51132_qam", "or51132_vsb", "bluebird");
29 # Check args
30 syntax() if (scalar(@ARGV) != 1);
31 $cid = $ARGV[0];
33 # Do it!
34 for ($i=0; $i < scalar(@components); $i++) {
35 if ($cid eq $components[$i]) {
36 $outfile = eval($cid);
37 die $@ if $@;
38 print STDERR <<EOF;
39 Firmware $outfile extracted successfully.
40 Now copy it to either /usr/lib/hotplug/firmware or /lib/firmware
41 (depending on configuration of firmware hotplug).
42 EOF
43 exit(0);
47 # If we get here, it wasn't found
48 print STDERR "Unknown component \"$cid\"\n";
49 syntax();
54 # ---------------------------------------------------------------
55 # Firmware-specific extraction subroutines
57 sub sp8870 {
58 my $sourcefile = "tt_Premium_217g.zip";
59 my $url = "http://www.technotrend.de/new/217g/$sourcefile";
60 my $hash = "53970ec17a538945a6d8cb608a7b3899";
61 my $outfile = "dvb-fe-sp8870.fw";
62 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
64 checkstandard();
66 wgetfile($sourcefile, $url);
67 unzip($sourcefile, $tmpdir);
68 verify("$tmpdir/software/OEM/HE/App/boot/SC_MAIN.MC", $hash);
69 copy("$tmpdir/software/OEM/HE/App/boot/SC_MAIN.MC", $outfile);
71 $outfile;
74 sub sp887x {
75 my $sourcefile = "Dvbt1.3.57.6.zip";
76 my $url = "http://www.avermedia.com/software/$sourcefile";
77 my $cabfile = "DVBT Net Ver1.3.57.6/disk1/data1.cab";
78 my $hash = "237938d53a7f834c05c42b894ca68ac3";
79 my $outfile = "dvb-fe-sp887x.fw";
80 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
82 checkstandard();
83 checkunshield();
85 wgetfile($sourcefile, $url);
86 unzip($sourcefile, $tmpdir);
87 unshield("$tmpdir/$cabfile", $tmpdir);
88 verify("$tmpdir/ZEnglish/sc_main.mc", $hash);
89 copy("$tmpdir/ZEnglish/sc_main.mc", $outfile);
91 $outfile;
94 sub tda10045 {
95 my $sourcefile = "tt_budget_217g.zip";
96 my $url = "http://www.technotrend.de/new/217g/$sourcefile";
97 my $hash = "2105fd5bf37842fbcdfa4bfd58f3594a";
98 my $outfile = "dvb-fe-tda10045.fw";
99 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
101 checkstandard();
103 wgetfile($sourcefile, $url);
104 unzip($sourcefile, $tmpdir);
105 extract("$tmpdir/software/OEM/PCI/App/ttlcdacc.dll", 0x37ef9, 30555, "$tmpdir/fwtmp");
106 verify("$tmpdir/fwtmp", $hash);
107 copy("$tmpdir/fwtmp", $outfile);
109 $outfile;
112 sub tda10046 {
113 my $sourcefile = "tt_budget_217g.zip";
114 my $url = "http://www.technotrend.de/new/217g/$sourcefile";
115 my $hash = "6a7e1e2f2644b162ff0502367553c72d";
116 my $outfile = "dvb-fe-tda10046.fw";
117 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
119 checkstandard();
121 wgetfile($sourcefile, $url);
122 unzip($sourcefile, $tmpdir);
123 extract("$tmpdir/software/OEM/PCI/App/ttlcdacc.dll", 0x3f731, 24478, "$tmpdir/fwtmp");
124 verify("$tmpdir/fwtmp", $hash);
125 copy("$tmpdir/fwtmp", $outfile);
127 $outfile;
130 sub tda10046lifeview {
131 my $sourcefile = "Drv_2.11.02.zip";
132 my $url = "http://www.lifeview.com.tw/drivers/pci_card/FlyDVB-T/$sourcefile";
133 my $hash = "1ea24dee4eea8fe971686981f34fd2e0";
134 my $outfile = "dvb-fe-tda10046.fw";
135 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
137 checkstandard();
139 wgetfile($sourcefile, $url);
140 unzip($sourcefile, $tmpdir);
141 extract("$tmpdir/LVHybrid.sys", 0x8b088, 24602, "$tmpdir/fwtmp");
142 verify("$tmpdir/fwtmp", $hash);
143 copy("$tmpdir/fwtmp", $outfile);
145 $outfile;
148 sub av7110 {
149 my $sourcefile = "dvb-ttpci-01.fw-261d";
150 my $url = "http://www.linuxtv.org/downloads/firmware/$sourcefile";
151 my $hash = "603431b6259715a8e88f376a53b64e2f";
152 my $outfile = "dvb-ttpci-01.fw";
154 checkstandard();
156 wgetfile($sourcefile, $url);
157 verify($sourcefile, $hash);
158 copy($sourcefile, $outfile);
160 $outfile;
163 sub dec2000t {
164 my $sourcefile = "dec217g.exe";
165 my $url = "http://hauppauge.lightpath.net/de/$sourcefile";
166 my $hash = "bd86f458cee4a8f0a8ce2d20c66215a9";
167 my $outfile = "dvb-ttusb-dec-2000t.fw";
168 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
170 checkstandard();
172 wgetfile($sourcefile, $url);
173 unzip($sourcefile, $tmpdir);
174 verify("$tmpdir/software/OEM/STB/App/Boot/STB_PC_T.bin", $hash);
175 copy("$tmpdir/software/OEM/STB/App/Boot/STB_PC_T.bin", $outfile);
177 $outfile;
180 sub dec2540t {
181 my $sourcefile = "dec217g.exe";
182 my $url = "http://hauppauge.lightpath.net/de/$sourcefile";
183 my $hash = "53e58f4f5b5c2930beee74a7681fed92";
184 my $outfile = "dvb-ttusb-dec-2540t.fw";
185 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
187 checkstandard();
189 wgetfile($sourcefile, $url);
190 unzip($sourcefile, $tmpdir);
191 verify("$tmpdir/software/OEM/STB/App/Boot/STB_PC_X.bin", $hash);
192 copy("$tmpdir/software/OEM/STB/App/Boot/STB_PC_X.bin", $outfile);
194 $outfile;
197 sub dec3000s {
198 my $sourcefile = "dec217g.exe";
199 my $url = "http://hauppauge.lightpath.net/de/$sourcefile";
200 my $hash = "b013ececea83f4d6d8d2a29ac7c1b448";
201 my $outfile = "dvb-ttusb-dec-3000s.fw";
202 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
204 checkstandard();
206 wgetfile($sourcefile, $url);
207 unzip($sourcefile, $tmpdir);
208 verify("$tmpdir/software/OEM/STB/App/Boot/STB_PC_S.bin", $hash);
209 copy("$tmpdir/software/OEM/STB/App/Boot/STB_PC_S.bin", $outfile);
211 $outfile;
214 sub vp7041 {
215 my $sourcefile = "2.422.zip";
216 my $url = "http://www.twinhan.com/files/driver/USB-Ter/$sourcefile";
217 my $hash = "e88c9372d1f66609a3e7b072c53fbcfe";
218 my $outfile = "dvb-vp7041-2.422.fw";
219 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
221 checkstandard();
223 wgetfile($sourcefile, $url);
224 unzip($sourcefile, $tmpdir);
225 extract("$tmpdir/VisionDTV/Drivers/Win2K&XP/UDTTload.sys", 12503, 3036, "$tmpdir/fwtmp1");
226 extract("$tmpdir/VisionDTV/Drivers/Win2K&XP/UDTTload.sys", 2207, 10274, "$tmpdir/fwtmp2");
228 my $CMD = "\000\001\000\222\177\000";
229 my $PAD = "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000";
230 my ($FW);
231 open $FW, ">$tmpdir/fwtmp3";
232 print $FW "$CMD\001$PAD";
233 print $FW "$CMD\001$PAD";
234 appendfile($FW, "$tmpdir/fwtmp1");
235 print $FW "$CMD\000$PAD";
236 print $FW "$CMD\001$PAD";
237 appendfile($FW, "$tmpdir/fwtmp2");
238 print $FW "$CMD\001$PAD";
239 print $FW "$CMD\000$PAD";
240 close($FW);
242 verify("$tmpdir/fwtmp3", $hash);
243 copy("$tmpdir/fwtmp3", $outfile);
245 $outfile;
248 sub dibusb {
249 my $url = "http://www.linuxtv.org/downloads/firmware/dvb-usb-dibusb-5.0.0.11.fw";
250 my $outfile = "dvb-dibusb-5.0.0.11.fw";
251 my $hash = "fa490295a527360ca16dcdf3224ca243";
253 checkstandard();
255 wgetfile($outfile, $url);
256 verify($outfile,$hash);
258 $outfile;
261 sub nxt2002 {
262 my $sourcefile = "Technisat_DVB-PC_4_4_COMPACT.zip";
263 my $url = "http://www.bbti.us/download/windows/$sourcefile";
264 my $hash = "476befae8c7c1bb9648954060b1eec1f";
265 my $outfile = "dvb-fe-nxt2002.fw";
266 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
268 checkstandard();
270 wgetfile($sourcefile, $url);
271 unzip($sourcefile, $tmpdir);
272 verify("$tmpdir/SkyNET.sys", $hash);
273 extract("$tmpdir/SkyNET.sys", 331624, 5908, $outfile);
275 $outfile;
278 sub nxt2004 {
279 my $sourcefile = "AVerTVHD_MCE_A180_Drv_v1.2.2.16.zip";
280 my $url = "http://www.aver.com/support/Drivers/$sourcefile";
281 my $hash = "111cb885b1e009188346d72acfed024c";
282 my $outfile = "dvb-fe-nxt2004.fw";
283 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
285 checkstandard();
287 wgetfile($sourcefile, $url);
288 unzip($sourcefile, $tmpdir);
289 verify("$tmpdir/3xHybrid.sys", $hash);
290 extract("$tmpdir/3xHybrid.sys", 465304, 9584, $outfile);
292 $outfile;
295 sub or51211 {
296 my $fwfile = "dvb-fe-or51211.fw";
297 my $url = "http://linuxtv.org/downloads/firmware/$fwfile";
298 my $hash = "d830949c771a289505bf9eafc225d491";
300 checkstandard();
302 wgetfile($fwfile, $url);
303 verify($fwfile, $hash);
305 $fwfile;
308 sub or51132_qam {
309 my $fwfile = "dvb-fe-or51132-qam.fw";
310 my $url = "http://linuxtv.org/downloads/firmware/$fwfile";
311 my $hash = "7702e8938612de46ccadfe9b413cb3b5";
313 checkstandard();
315 wgetfile($fwfile, $url);
316 verify($fwfile, $hash);
318 $fwfile;
321 sub or51132_vsb {
322 my $fwfile = "dvb-fe-or51132-vsb.fw";
323 my $url = "http://linuxtv.org/downloads/firmware/$fwfile";
324 my $hash = "c16208e02f36fc439a557ad4c613364a";
326 checkstandard();
328 wgetfile($fwfile, $url);
329 verify($fwfile, $hash);
331 $fwfile;
334 sub bluebird {
335 my $url = "http://www.linuxtv.org/download/dvb/firmware/dvb-usb-bluebird-01.fw";
336 my $outfile = "dvb-usb-bluebird-01.fw";
337 my $hash = "658397cb9eba9101af9031302671f49d";
339 checkstandard();
341 wgetfile($outfile, $url);
342 verify($outfile,$hash);
344 $outfile;
347 # ---------------------------------------------------------------
348 # Utilities
350 sub checkstandard {
351 if (system("which unzip > /dev/null 2>&1")) {
352 die "This firmware requires the unzip command - see ftp://ftp.info-zip.org/pub/infozip/UnZip.html\n";
354 if (system("which md5sum > /dev/null 2>&1")) {
355 die "This firmware requires the md5sum command - see http://www.gnu.org/software/coreutils/\n";
357 if (system("which wget > /dev/null 2>&1")) {
358 die "This firmware requires the wget command - see http://wget.sunsite.dk/\n";
362 sub checkunshield {
363 if (system("which unshield > /dev/null 2>&1")) {
364 die "This firmware requires the unshield command - see http://sourceforge.net/projects/synce/\n";
368 sub wgetfile {
369 my ($sourcefile, $url) = @_;
371 if (! -f $sourcefile) {
372 system("wget -O \"$sourcefile\" \"$url\"") and die "wget failed - unable to download firmware";
376 sub unzip {
377 my ($sourcefile, $todir) = @_;
379 $status = system("unzip -q -o -d \"$todir\" \"$sourcefile\" 2>/dev/null" );
380 if ((($status >> 8) > 2) || (($status & 0xff) != 0)) {
381 die ("unzip failed - unable to extract firmware");
385 sub unshield {
386 my ($sourcefile, $todir) = @_;
388 system("unshield x -d \"$todir\" \"$sourcefile\" > /dev/null" ) and die ("unshield failed - unable to extract firmware");
391 sub verify {
392 my ($filename, $hash) = @_;
393 my ($testhash);
395 open(CMD, "md5sum \"$filename\"|");
396 $testhash = <CMD>;
397 $testhash =~ /([a-zA-Z0-9]*)/;
398 $testhash = $1;
399 close CMD;
400 die "Hash of extracted file does not match!\n" if ($testhash ne $hash);
403 sub copy {
404 my ($from, $to) = @_;
406 system("cp -f \"$from\" \"$to\"") and die ("cp failed");
409 sub extract {
410 my ($infile, $offset, $length, $outfile) = @_;
411 my ($chunklength, $buf, $rcount);
413 open INFILE, "<$infile";
414 open OUTFILE, ">$outfile";
415 sysseek(INFILE, $offset, SEEK_SET);
416 while($length > 0) {
417 # Calc chunk size
418 $chunklength = 2048;
419 $chunklength = $length if ($chunklength > $length);
421 $rcount = sysread(INFILE, $buf, $chunklength);
422 die "Ran out of data\n" if ($rcount != $chunklength);
423 syswrite(OUTFILE, $buf);
424 $length -= $rcount;
426 close INFILE;
427 close OUTFILE;
430 sub appendfile {
431 my ($FH, $infile) = @_;
432 my ($buf);
434 open INFILE, "<$infile";
435 while(1) {
436 $rcount = sysread(INFILE, $buf, 2048);
437 last if ($rcount == 0);
438 print $FH $buf;
440 close(INFILE);
443 sub syntax() {
444 print STDERR "syntax: get_dvb_firmware <component>\n";
445 print STDERR "Supported components:\n";
446 for($i=0; $i < scalar(@components); $i++) {
447 print STDERR "\t" . $components[$i] . "\n";
449 exit(1);