Skip to content

Commit

Permalink
Added GSL_TS_CFG.h conversion utility
Browse files Browse the repository at this point in the history
  • Loading branch information
onitake committed Feb 4, 2016
1 parent 1e6f030 commit a02128d
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tools/untscfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,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();

0 comments on commit a02128d

Please sign in to comment.