OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1k_startup/] [sw/] [srec2v.pl] - Blame information for rev 861

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 marcus.erl
#!/usr/bin/perl -w
2
use strict;
3
use IO::File;
4
 
5
# (C) 2003-2007 Willem Jan Hengeveld <itsme@xs4all.nl>
6
# Web: http://www.xs4all.nl/~itsme/
7
#      http://wiki.xda-developers.com/
8
#
9
# $Id$
10
# 
11
# perl script to decode srecord files.
12
# 
13
# specifically written to decode the radio part updates for the 
14
# xda1/ htc-wallaby.
15
#
16
#   perl srec.pl RSUpgrade.cp64 -l 4 -w -o rsu
17
#   perl srec.pl monitor_ul_bs.m0 -o mon
18
 
19
use Getopt::Long;
20
my $outfile="out";
21
my $lenlen=2;
22
my $dowordswap= 0;
23
my $maxgap= 1;
24
GetOptions(
25
    "o=s" => \$outfile,
26
    "l=i" => \$lenlen,
27
    "m=s" => sub { $maxgap= eval($_[1]) },
28
    "w" => \$dowordswap)
29
    or die "Usage: srec [-o=OUTPREFIX] [-l={4|2}] [-w {swap}] [-m=MAXGAP]\n";
30
my %data;
31
 
32
# s-records have the following format:
33
#   "S" + 1 byte  type
34
#   2 hex digits :  length  ( of rest of line - incl address and checksum )
35
#   4,6,8 hex digits address ( for type 1, 2, 3 )
36
#   hex data [ 0..64 bytes ]
37
#   checksum [ 1 byte ]   such that unpack('%8C*', pack('H*', $line))==0xff
38
#            ( or checksum=0xff-sum(otherbytes)
39
#
40
#
41
#   type S0 : version  : char mname[10], byte ver, byte rev, char description[18]
42
#           or usually : 00 00 + 'HDR'
43
#   type S1 : 2 byte address + data
44
#   type S2 : 3 byte address + data
45
#   type S3 : 4 byte address + data
46
#   type S5 : 2 byte count of S1, S2, S3 records transmitted
47
#   type S7 : 4 byte entrypoint address
48
#   type S8 : 3 byte entrypoint address
49
#   type S9 : 2 byte entrypoint address
50
 
51
while (<>) {
52
    my $type= hex(substr($_, 1,1));
53
    my $length= hex(substr($_,2,$lenlen));
54
 
55
    my $adrlen= $type eq "1" ? 4 : $type eq "2" ? 6 :  $type eq "3" ? 8 : 0;
56
    next if (!$adrlen);
57
    my $address= hex(substr($_,2+$lenlen,$adrlen));
58
    my $data= pack("H*", substr($_,2+$lenlen+$adrlen, 2*$length-$adrlen-2));
59
    if ($dowordswap) {
60
        $data= pack('v*', unpack('n*',$data));
61
    }
62
 
63
    $data{$address}= $data;
64
}
65
 
66
#     |---------|...|
67
#                  |-----|
68
#
69
my @addrs= sort { $a <=> $b } keys %data;
70
my $fh;
71
for (0..$#addrs) {
72
    my $startcur= $addrs[$_];
73
 
74
    if ($_>0) {
75
        my $startlast= $addrs[$_-1];
76
        my $endlast= length($data{$startlast})+ $startlast;
77
 
78
        if ($endlast +$maxgap <= $startcur) {
79
            printf("  %08lx-%08lx .. gap .. %08lx\n", $startlast, $endlast, $startcur);
80
 
81
            $fh->close();
82
            undef $fh;
83
        }
84
        elsif ($endlast < $startcur ) {
85
            $fh->seek($startcur-$endlast, SEEK_CUR);
86
        }
87
        elsif ($endlast > $startcur) {
88
            printf("WARNING: overlap found: %08lx-%08lx ~ %08lx\n", $startlast, $endlast, $startcur);
89
            $fh->close();
90
            undef $fh;
91
        }
92
    }
93
 
94
    if (!$fh) {
95
        $fh= IO::File->new(sprintf("%s-%08lx.bin", $outfile, $startcur), "w");
96
        binmode($fh);
97
    }
98
    $fh->print($data{$startcur});
99
}
100
$fh->close();
101
#print map { $data{$_} } sort keys %data;
102
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.