forked from onitake/gsl-firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuntscfg
executable file
·47 lines (40 loc) · 1.01 KB
/
untscfg
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
#!/usr/bin/perl
use strict;
use warnings;
use IO::File;
sub usage() {
print STDERR "Usage: untscfg GSL_TS_CFG.h gsl_ts.fw\n";
print STDERR "Converts the GSL_TS_CFG.h from a Silead Windows driver package into legacy binary format.\n";
-1;
}
my $tscffile = $ARGV[0] or exit usage;
my $fwfile = $ARGV[1] or exit usage;
my $unscrambled = '';
do {
my $in = IO::File->new($tscffile, 'r') or die "Can't open $tscffile: $!";
$in->binmode();
local $/;
$unscrambled = <$in>;
defined $unscrambled or die "Can't read firmware: $!";
$in->close();
};
my $out = IO::File->new($fwfile, 'w') or die "Can't open $fwfile: $!";
my $cfg = 0;
for my $line (split /\n/, $unscrambled) {
if ($cfg and $line =~ /};/) {
$cfg = 0;
}
if ($line =~ /TS_CFG_DATA/) {
$cfg = 1;
}
if ($cfg) {
$line =~ s/\s//g;
$line = lc($line);
if ($line =~ /{0x([0-9a-f]+),0x([0-9a-f]+)},/) {
my $address = hex($1);
my $data = hex($2);
print $out pack('(LL)<', $address, $data) or die "Can't write to output: $!";;
}
}
}
$out->close();