1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
#!/usr/bin/perl
# DVB firmware extractor
#
# (c) 2004 Andrew de Quincey
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
use File::Temp qw/ tempdir /;
use IO::Handle;
@components = ( "sp8870", "sp887x", "tda10045", "tda10046",
"tda10046lifeview", "av7110", "dec2000t", "dec2540t",
"dec3000s", "vp7041", "dibusb", "nxt2002", "nxt2004",
"or51211", "or51132_qam", "or51132_vsb", "bluebird",
"opera1", "cx231xx", "cx18", "cx23885", "pvrusb2", "mpc718",
"af9015");
# Check args
syntax() if (scalar(@ARGV) != 1);
$cid = $ARGV[0];
# Do it!
for ($i=0; $i < scalar(@components); $i++) {
if ($cid eq $components[$i]) {
$outfile = eval($cid);
die $@ if $@;
print STDERR <<EOF;
Firmware(s) $outfile extracted successfully.
Now copy it(they) to either /usr/lib/hotplug/firmware or /lib/firmware
(depending on configuration of firmware hotplug).
EOF
exit(0);
}
}
# If we get here, it wasn't found
print STDERR "Unknown component \"$cid\"\n";
syntax();
sub tda10046 {
my $sourcefile = "TT_PCI_2.19h_28_11_2006.zip";
my $url = "http://studio/$sourcefile";
my $hash = "6a7e1e2f2644b162ff0502367553c72d";
my $outfile = "dvb-fe-tda10046.fw";
my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
checkstandard();
wgetfile($sourcefile, $url);
unzip($sourcefile, $tmpdir);
extract("$tmpdir/TT_PCI_2.19h_28_11_2006/software/OEM/PCI/App/ttlcdacc.dll", 0x65389, 24478, "$tmpdir/fwtmp");
#verify("$tmpdir/fwtmp", $hash);
copy("$tmpdir/fwtmp", $outfile);
$outfile;
}
# ---------------------------------------------------------------
# Utilities
sub checkstandard {
if (system("which unzip > /dev/null 2>&1")) {
die "This firmware requires the unzip command - see ftp://ftp.info-zip.org/pub/infozip/UnZip.html\n";
}
if (system("which md5sum > /dev/null 2>&1")) {
die "This firmware requires the md5sum command - see http://www.gnu.org/software/coreutils/\n";
}
if (system("which wget > /dev/null 2>&1")) {
die "This firmware requires the wget command - see http://wget.sunsite.dk/\n";
}
}
sub checkunshield {
if (system("which unshield > /dev/null 2>&1")) {
die "This firmware requires the unshield command - see http://sourceforge.net/projects/synce/\n";
}
}
sub wgetfile {
my ($sourcefile, $url) = @_;
if (! -f $sourcefile) {
system("wget -O \"$sourcefile\" \"$url\"") and die "wget failed - unable to download firmware";
}
}
sub unzip {
my ($sourcefile, $todir) = @_;
$status = system("unzip -q -o -d \"$todir\" \"$sourcefile\" 2>/dev/null" );
if ((($status >> 8) > 2) || (($status & 0xff) != 0)) {
die ("unzip failed - unable to extract firmware");
}
}
sub unshield {
my ($sourcefile, $todir) = @_;
system("unshield x -d \"$todir\" \"$sourcefile\" > /dev/null" ) and die ("unshield failed - unable to extract firmware");
}
sub verify {
my ($filename, $hash) = @_;
my ($testhash);
open(CMD, "md5sum \"$filename\"|");
$testhash = <CMD>;
$testhash =~ /([a-zA-Z0-9]*)/;
$testhash = $1;
close CMD;
die "Hash of extracted file does not match!\n" if ($testhash ne $hash);
}
sub copy {
my ($from, $to) = @_;
system("cp -f \"$from\" \"$to\"") and die ("cp failed");
}
sub extract {
my ($infile, $offset, $length, $outfile) = @_;
my ($chunklength, $buf, $rcount);
open INFILE, "<$infile";
open OUTFILE, ">$outfile";
sysseek(INFILE, $offset, SEEK_SET);
while($length > 0) {
# Calc chunk size
$chunklength = 2048;
$chunklength = $length if ($chunklength > $length);
$rcount = sysread(INFILE, $buf, $chunklength);
die "Ran out of data\n" if ($rcount != $chunklength);
syswrite(OUTFILE, $buf);
$length -= $rcount;
}
close INFILE;
close OUTFILE;
}
sub appendfile {
my ($FH, $infile) = @_;
my ($buf);
open INFILE, "<$infile";
while(1) {
$rcount = sysread(INFILE, $buf, 2048);
last if ($rcount == 0);
print $FH $buf;
}
close(INFILE);
}
sub delzero{
my ($infile,$outfile) =@_;
open INFILE,"<$infile";
open OUTFILE,">$outfile";
while (1){
$rcount=sysread(INFILE,$buf,22);
$len=ord(substr($buf,0,1));
print OUTFILE substr($buf,0,1);
print OUTFILE substr($buf,2,$len+3);
last if ($rcount<1);
printf OUTFILE "%c",0;
#print $len." ".length($buf)."\n";
}
close(INFILE);
close(OUTFILE);
}
sub syntax() {
print STDERR "syntax: get_dvb_firmware <component>\n";
print STDERR "Supported components:\n";
for($i=0; $i < scalar(@components); $i++) {
print STDERR "\t" . $components[$i] . "\n";
}
exit(1);
}
|