-
Notifications
You must be signed in to change notification settings - Fork 0
/
out2hex.pl
executable file
·78 lines (61 loc) · 1.75 KB
/
out2hex.pl
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
#!/usr/bin/perl -w
use File::Basename;
if (defined($ENV{CCS_UTILS_DIR})) {
$CCS_TOOLS = $ENV{CCS_UTILS_DIR} . '/../tools/compiler/c2000_6.1.0/bin';
} else {
$CCS_TOOLS = '/opt/ti/ccsv5/tools/compiler/c2000_6.1.0/bin';
}
$print_addr = defined($ENV{PRINT_ADDR});
sub out2hex {
my ($f) = @_;
my $l;
my @a;
my ($i, $k);
my $csum;
my $skip = 0;
open F, "<$f";
<F>; # skip start \x02 char
while ($l = <F>) {
chomp $l;
if ($l =~ /^\$A([0-9a-f]+)/) {
chop $l;
$addr = hex($1);
$skip = ($entry_addr == 0 && $addr >= 0x3d7800 && $addr < 0x3f8000);
printf OUT "\$A%06s\n", $1 unless $skip;
} elsif ("$l" =~ /^[0-9A-F]{2} /) {
@a = split / /, lc($l);
printf OUT "\$A%06x\n", $addr if ($addr == 0);
for ($i = 0; $i <= $#a; $i+=2, $wc++) {
printf OUT "%04x ", $addr if ($print_addr && !$skip);
printf OUT "%s%s\n", $a[$i], $a[$i+1] unless $skip;
$addr++;
}
}
}
close F;
}
my ($entry) = grep(/Entry Point:/, `$CCS_TOOLS/ofd2000 --obj_display=none,header $ARGV[0]`);
chomp $entry;
$entry =~ s/\s*Entry Point:\s+0x[0]{2}?([0-9a-f]+)\s*$/$1/;
$entry_addr = hex($entry);
system("$CCS_TOOLS/hex2000 -a -memwidth 16 -romwidth 16 ".$ARGV[0]);
my $hexfile = basename($ARGV[0]);
$hexfile =~ s/\.([a-z]+)$//;
my @ascii;
# Get ascii-files
opendir D, dirname($ARGV[0]);
while (readdir D) {
push @ascii, $_ if ($_ =~ /$hexfile\.a[0-9]+/);
}
closedir D;
@ascii = sort @ascii;
$wc = 0;
$addr = 0;
open OUT, ">$hexfile.hex";
for ($i = 0; $i <= $#ascii; $i++) {
out2hex $ascii[$i];
unlink $ascii[$i];
}
printf OUT "\$E$entry\n";
close OUT;
printf "Wordcount: %d\n", $wc;