Merge pull request #101 from marshmellow42/master
[legacy-proxmark3.git] / tools / srecswap.pl
blobfd6f9a944bb07c7c7af9f12e00b5c9ff4347a5f3
1 #!/usr/bin/perl
3 # endian-swap S records; we need this because the JTAG tools we're using
4 # expect the memory image in byte-swapped format
6 # Jonathan Westhues, April 2004
8 if(@ARGV == 0) {
9 die "usage: $0 file-to-endian-swap.s19 > out.s19\n";
12 while(<>) {
13 chomp;
15 if(/^S0/) {
16 next;
18 if(/^S7/) {
19 print "$_\n";
20 next;
23 if(not /^S3(..)(........)(.*)(..)$/) {
24 die "bad S record at line $.\n";
27 $data = $3;
28 $checksum = $4;
30 print "S3$1$2";
31 while($data =~ m#(..)(..)(..)(..)#g) {
32 print "$4$3$2$1";
34 print "$checksum\n";