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 /;
24 @components = ( "sp8870", "sp887x", "tda10045", "tda10046", "av7110", "dec2000t", "dec2540t", "dec3000s", "vp7041", "dibusb" );
27 syntax() if (scalar(@ARGV) != 1);
31 for($i=0; $i < scalar(@components); $i++) {
32 if ($cid eq $components[$i]) {
33 $outfile = eval($cid);
35 print STDERR "Firmware $outfile extracted successfully. Now copy it to either /lib/firmware or /usr/lib/hotplug/firmware/ (depending on your hotplug version).\n";
40 # If we get here, it wasn't found
41 print STDERR "Unknown component \"$cid\"\n";
47 # ---------------------------------------------------------------
48 # Firmware-specific extraction subroutines
51 my $sourcefile = "tt_Premium_217g.zip";
52 my $url = "http://www.technotrend.de/new/217g/$sourcefile";
53 my $hash = "53970ec17a538945a6d8cb608a7b3899";
54 my $outfile = "dvb-fe-sp8870.fw";
55 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
59 wgetfile($sourcefile, $url);
60 unzip($sourcefile, $tmpdir);
61 verify("$tmpdir/software/OEM/HE/App/boot/SC_MAIN.MC", $hash);
62 copy("$tmpdir/software/OEM/HE/App/boot/SC_MAIN.MC", $outfile);
68 my $sourcefile = "Dvbt1.3.57.6.zip";
69 my $url = "http://www.avermedia.com/software/$sourcefile";
70 my $cabfile = "DVBT Net Ver1.3.57.6/disk1/data1.cab";
71 my $hash = "237938d53a7f834c05c42b894ca68ac3";
72 my $outfile = "dvb-fe-sp887x.fw";
73 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
78 wgetfile($sourcefile, $url);
79 unzip($sourcefile, $tmpdir);
80 unshield("$tmpdir/$cabfile", $tmpdir);
81 verify("$tmpdir/sc_main.mc", $hash);
82 copy("$tmpdir/sc_main.mc", $outfile);
88 my $sourcefile = "tt_budget_217g.zip";
89 my $url = "http://www.technotrend.de/new/217g/$sourcefile";
90 my $hash = "2105fd5bf37842fbcdfa4bfd58f3594a";
91 my $outfile = "dvb-fe-tda10045.fw";
92 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
96 wgetfile($sourcefile, $url);
97 unzip($sourcefile, $tmpdir);
98 extract("$tmpdir/software/OEM/PCI/App/ttlcdacc.dll", 0x37ef9, 30555, "$tmpdir/fwtmp");
99 verify("$tmpdir/fwtmp", $hash);
100 copy("$tmpdir/fwtmp", $outfile);
106 my $sourcefile = "tt_budget_217g.zip";
107 my $url = "http://www.technotrend.de/new/217g/$sourcefile";
108 my $hash = "a25b579e37109af60f4a36c37893957c";
109 my $outfile = "dvb-fe-tda10046.fw";
110 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
114 wgetfile($sourcefile, $url);
115 unzip($sourcefile, $tmpdir);
116 extract("$tmpdir/software/OEM/PCI/App/ttlcdacc.dll", 0x3f731, 24479, "$tmpdir/fwtmp");
117 verify("$tmpdir/fwtmp", $hash);
118 copy("$tmpdir/fwtmp", $outfile);
124 my $sourcefile = "dvb-ttpci-01.fw-261c";
125 my $url = "http://www.linuxtv.org/download/dvb/firmware/$sourcefile";
126 my $hash = "7b263de6b0b92d2347319c65adc7d4fb";
127 my $outfile = "dvb-ttpci-01.fw";
131 wgetfile($sourcefile, $url);
132 verify($sourcefile, $hash);
133 copy($sourcefile, $outfile);
139 my $sourcefile = "dec217g.exe";
140 my $url = "http://hauppauge.lightpath.net/de/$sourcefile";
141 my $hash = "bd86f458cee4a8f0a8ce2d20c66215a9";
142 my $outfile = "dvb-ttusb-dec-2000t.fw";
143 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
147 wgetfile($sourcefile, $url);
148 unzip($sourcefile, $tmpdir);
149 verify("$tmpdir/software/OEM/STB/App/Boot/STB_PC_T.bin", $hash);
150 copy("$tmpdir/software/OEM/STB/App/Boot/STB_PC_T.bin", $outfile);
156 my $sourcefile = "dec217g.exe";
157 my $url = "http://hauppauge.lightpath.net/de/$sourcefile";
158 my $hash = "53e58f4f5b5c2930beee74a7681fed92";
159 my $outfile = "dvb-ttusb-dec-2540t.fw";
160 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
164 wgetfile($sourcefile, $url);
165 unzip($sourcefile, $tmpdir);
166 verify("$tmpdir/software/OEM/STB/App/Boot/STB_PC_X.bin", $hash);
167 copy("$tmpdir/software/OEM/STB/App/Boot/STB_PC_X.bin", $outfile);
173 my $sourcefile = "dec217g.exe";
174 my $url = "http://hauppauge.lightpath.net/de/$sourcefile";
175 my $hash = "b013ececea83f4d6d8d2a29ac7c1b448";
176 my $outfile = "dvb-ttusb-dec-3000s.fw";
177 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
181 wgetfile($sourcefile, $url);
182 unzip($sourcefile, $tmpdir);
183 verify("$tmpdir/software/OEM/STB/App/Boot/STB_PC_S.bin", $hash);
184 copy("$tmpdir/software/OEM/STB/App/Boot/STB_PC_S.bin", $outfile);
190 my $sourcefile = "2.422.zip";
191 my $url = "http://www.twinhan.com/files/driver/USB-Ter/$sourcefile";
192 my $hash = "e88c9372d1f66609a3e7b072c53fbcfe";
193 my $outfile = "dvb-vp7041-2.422.fw";
194 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
198 wgetfile($sourcefile, $url);
199 unzip($sourcefile, $tmpdir);
200 extract("$tmpdir/VisionDTV/Drivers/Win2K&XP/UDTTload.sys", 12503, 3036, "$tmpdir/fwtmp1");
201 extract("$tmpdir/VisionDTV/Drivers/Win2K&XP/UDTTload.sys", 2207, 10274, "$tmpdir/fwtmp2");
203 my $CMD = "\000\001\000\222\177\000";
204 my $PAD = "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000";
206 open $FW, ">$tmpdir/fwtmp3";
207 print $FW "$CMD\001$PAD";
208 print $FW "$CMD\001$PAD";
209 appendfile($FW, "$tmpdir/fwtmp1");
210 print $FW "$CMD\000$PAD";
211 print $FW "$CMD\001$PAD";
212 appendfile($FW, "$tmpdir/fwtmp2");
213 print $FW "$CMD\001$PAD";
214 print $FW "$CMD\000$PAD";
217 verify("$tmpdir/fwtmp3", $hash);
218 copy("$tmpdir/fwtmp3", $outfile);
224 my $url = "http://linuxtv.org/cgi-bin/cvsweb.cgi/dvb-kernel/firmware/dvb-dibusb-5.0.0.11.fw?rev=1.1&content-type=text/plain";
225 my $outfile = "dvb-dibusb-5.0.0.11.fw";
226 my $hash = "fa490295a527360ca16dcdf3224ca243";
230 wgetfile($outfile, $url);
231 verify($outfile,$hash);
236 # ---------------------------------------------------------------
240 if (system("which unzip > /dev/null 2>&1")) {
241 die "This firmware requires the unzip command - see ftp://ftp.info-zip.org/pub/infozip/UnZip.html\n";
243 if (system("which md5sum > /dev/null 2>&1")) {
244 die "This firmware requires the md5sum command - see http://www.gnu.org/software/coreutils/\n";
246 if (system("which wget > /dev/null 2>&1")) {
247 die "This firmware requires the wget command - see http://wget.sunsite.dk/\n";
252 if (system("which unshield > /dev/null 2>&1")) {
253 die "This firmware requires the unshield command - see http://sourceforge.net/projects/synce/\n";
258 my ($sourcefile, $url) = @_;
260 if (! -f $sourcefile) {
261 system("wget -O \"$sourcefile\" \"$url\"") and die "wget failed - unable to download firmware";
266 my ($sourcefile, $todir) = @_;
268 $status = system("unzip -q -o -d \"$todir\" \"$sourcefile\" 2>/dev/null" );
269 if ((($status >> 8) > 2) || (($status & 0xff) != 0)) {
270 die ("unzip failed - unable to extract firmware");
275 my ($sourcefile, $todir) = @_;
277 system("unshield -d \"$todir\" \"$sourcefile\" > /dev/null" ) and die ("unshield failed - unable to extract firmware");
281 my ($filename, $hash) = @_;
284 open(CMD, "md5sum \"$filename\"|");
286 $testhash =~ /([a-zA-Z0-9]*)/;
289 die "Hash of extracted file does not match!\n" if ($testhash ne $hash);
293 my ($from, $to) = @_;
295 system("cp -f \"$from\" \"$to\"") and die ("cp failed");
299 my ($infile, $offset, $length, $outfile) = @_;
300 my ($chunklength, $buf, $rcount);
302 open INFILE, "<$infile";
303 open OUTFILE, ">$outfile";
304 sysseek(INFILE, $offset, SEEK_SET);
308 $chunklength = $length if ($chunklength > $length);
310 $rcount = sysread(INFILE, $buf, $chunklength);
311 die "Ran out of data\n" if ($rcount != $chunklength);
312 syswrite(OUTFILE, $buf);
320 my ($FH, $infile) = @_;
323 open INFILE, "<$infile";
325 $rcount = sysread(INFILE, $buf, 2048);
326 last if ($rcount == 0);
333 print STDERR "syntax: get_dvb_firmware <component>\n";
334 print STDERR "Supported components:\n";
335 for($i=0; $i < scalar(@components); $i++) {
336 print STDERR "\t" . $components[$i] . "\n";