uml: this patch went upstream
[openwrt.git] / package / uboot-ifxmips / files / gct
1 #!/usr/bin/perl
2 my $aline;
3 my $lineid;
4 my $length;
5 my $address;
6 my @bytes;
7 my $addstr;
8 my $chsum=0;
9 my $count=0;
10 my $firstime=1;
11 my $i;
12 my $currentaddr;
13 my $tmp;
14 my $holder="";
15 my $loadaddr;
16
17 if(@ARGV < 2){
18 print "\n not enough arguments";
19 print "\n Syntax: ./program_SDRAM input output\n";
20 }
21
22 open(INFILE1, "<$ARGV[0]") || die("\ninput open fail\n");
23 open(INFILE2, "<$ARGV[1]") || die("\ninput open fail\n");
24 open(OUTFILE, ">$ARGV[2]") || die("\nOutput file open fail\n");
25
26 $i=0;
27 while ($line = <INFILE1>){
28 if($line=~/\w/){
29 if($line!~/[;#\*]/){
30 if($i eq 0){
31 printf OUTFILE ("33333333");
32 }
33 chomp($line);
34 $line=~s/\t//;
35 @array=split(/ +/,$line);
36 $j=0;
37 while(@array[$j]!~/\w/)
38 {
39 $j=$j+1;
40
41 }
42 $addr=@array[$j];
43 $regval=@array[$j+1];
44 $addr=~s/0x//;
45 $regval=~s/0x//;
46 printf OUTFILE ("%08x%08x",hex($addr),hex($regval));
47 $i=$i+1;
48 if($i eq 8)
49 {
50 $i=0;
51 printf OUTFILE ("\n");
52 }
53
54 }
55 }
56
57 }
58
59 while($i lt 8 && $i gt 0){
60 printf OUTFILE "00"x8;
61 $i=$i+1;
62 }
63 if($i eq 8){
64 printf OUTFILE ("\n");
65 }
66
67 while($aline=<INFILE2>){
68 $aline=uc($aline);
69 chomp($aline);
70 next if(($aline=~/^S0/) || ($aline=~/^S7/));
71 ($lineid, $length, $address, @bytes) = unpack"A2A2A8"."A2"x300, $aline;
72 $length = hex($length);
73 $address = hex($address);
74 $length -=5;
75 $i=0;
76
77 while($length>0){
78 if($firstime==1){
79 $addstr = sprintf("%x", $address);
80 $addstr = "0"x(8-length($addstr)).$addstr;
81 print OUTFILE $addstr;
82 addchsum($addstr);
83 $firstime=0;
84 $currentaddr=$address;
85 $loadaddr = $addstr;
86 }
87 else{
88 if($count==64){
89 $addstr = sprintf("%x", $currentaddr);
90 $addstr = "0"x(8-length($addstr)).$addstr;
91 print OUTFILE $addstr;
92 addchsum($addstr);
93 $count=0;
94 }
95 }
96 while($count<64){
97 $bytes[$i]=~tr/ABCDEF/abcdef/;
98 print OUTFILE "$bytes[$i]";
99 addchsum($bytes[$i]);
100 $i++;
101 $count++;
102 $length--;
103 last if($length==0);
104 }
105 if($count==64){
106 print OUTFILE "\n";
107 #print OUTFILE "\r";
108 $currentaddr+=64;
109 }
110 }
111 }
112 if($count != 64){
113 $tmp = "00";
114 for($i=0;$i<(64-$count);$i++){
115 print OUTFILE "00";
116 addchsum($tmp);
117 }
118 print OUTFILE "\n";
119 #print OUTFILE "\r";
120 }
121
122
123 print OUTFILE "11"x4;
124 use integer;
125 $chsum=$chsum & 0xffffffff;
126 $chsum = sprintf("%X", $chsum);
127 $chsum = "0"x(8-length($chsum)).$chsum;
128 $chsum =~tr/ABCDEF/abcdef/;
129 print OUTFILE $chsum;
130 print OUTFILE "00"x60;
131 print OUTFILE "\n";
132 #print OUTFILE "\r";
133
134 print OUTFILE "99"x4;
135 print OUTFILE $loadaddr;
136 print OUTFILE "00"x60;
137 print OUTFILE "\n";
138 #print OUTFILE "\r";
139
140
141 close OUTFILE;
142 #END of Program
143
144
145
146 sub addchsum{
147 my $cc=$_[0];
148 $holder=$holder.$cc;
149 if(length($holder)==8){
150 $holder = hex($holder);
151 $chsum+=$holder;
152 $holder="";
153 }
154 }
155 #END
156
157
This page took 0.059931 seconds and 5 git commands to generate.