-
Notifications
You must be signed in to change notification settings - Fork 0
/
srec_shift.pl
35 lines (31 loc) · 921 Bytes
/
srec_shift.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
#!/usr/bin/perl
use warnings;
use strict;
# S31510000000862F38C7962FA62FB62FC62FD62F35DC9C
# AABBCCCCCCCCDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDEE
# A - Record Type
# B - Byte Count
# C - Address
# D - Data
# E - Checksum
#
# This script shifts an S-record that targets 0x10000000, to instead target
# 0x8c000000, which is the location of flash when booted from EPROM. This
# allows the linker to arrange things as they need to be when booted from
# flash, but allows the S-record to be written from EPROM.
my $from = 0x10000000;
my $to = 0x8c000000;
while(<>) {
if($_ =~ /S3([0-9A-F]{2})([0-9A-F]{8})([0-9A-F]*)([0-9A-F]{2})/) {
my $len = $1;
my $addr = hex($2) - $from + $to;
my $data = $3;
my @bytes = ( $3 =~ m/../g );
my $checksum = 0;
foreach my $byte (@bytes) {
$checksum = $checksum ^ hex($byte);
}
my $result = sprintf("S3%s%02X%s%02X\n", $len, $addr, $data, $checksum);
print $result;
}
}