comparison packages/hal/arm/aeb/current/src/flash_cksum.tcl @ 76:435cced73e2f ecos-v1_3_1-release

eCos v1.3.1 merged from eCos master repository on 2000-03-27-23:22:51-BST
author jlarmour
date Tue, 28 Mar 2000 14:10:45 +0000
parents
children 2085233a121a
comparison
equal deleted inserted replaced
75:41bf073c0c32 76:435cced73e2f
1 #!/bin/sh
2 # the next line restarts using tclsh \
3 exec tclsh "$0" ${1+"$@"}
4
5 #===============================================================================
6 #
7 # flash_cksum.tcl
8 #
9 # Compute the checksum for a AEB-1 flash module
10 #
11 #===============================================================================
12 #####COPYRIGHTBEGIN####
13 #
14 # -------------------------------------------
15 # The contents of this file are subject to the Red Hat eCos Public License
16 # Version 1.1 (the "License"); you may not use this file except in
17 # compliance with the License. You may obtain a copy of the License at
18 # http://www.redhat.com/
19 #
20 # Software distributed under the License is distributed on an "AS IS"
21 # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
22 # License for the specific language governing rights and limitations under
23 # the License.
24 #
25 # The Original Code is eCos - Embedded Configurable Operating System,
26 # released September 30, 1998.
27 #
28 # The Initial Developer of the Original Code is Red Hat.
29 # Portions created by Red Hat are
30 # Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
31 # All Rights Reserved.
32 # -------------------------------------------
33 #
34 #####COPYRIGHTEND####
35 #===============================================================================
36 ######DESCRIPTIONBEGIN####
37 #
38 # Author(s): gthomas
39 # Contact(s): gthomas
40 # Date: 1999/01/06
41 # Version: 0.01 $RcsVersion$
42 # Purpose: Compute the checksum for a FLASH ROM module.
43 # Description:
44 # Requires: A working Tcl interpreter, V8.0 or later.
45 # Provides: Command line operation only.
46 # Inputs:
47 # Side FX:
48 # Outputs:
49 # See also: 'Notes' which describes the process of creating the GDB stubs
50 # module.
51 # Known bugs:
52 # Usage:
53 #
54 #####DESCRIPTIONEND####
55 #===============================================================================
56
57 #
58 # This ckecksum is the 32-bit XOR of all 32 bit words in the file.
59 # The output of the program is a single number, suitable for use in
60 # a Makefile/script used to create an AEB-1 module for FLASH ROM.
61 #
62
63 proc checksum { name } {
64
65 set status [ catch {
66 set fd [open $name "r"]
67 fconfigure $fd -translation binary
68 set data [read $fd]
69 close $fd
70 } message]
71
72 if { $status != 0 } {
73 puts "Unable to read file $name: $message"
74 exit 1
75 }
76
77 set sum 0
78 set length [string length $data]
79 for { set i 0 } { $i < $length } { incr i 4 } {
80 # Fetch the next 32 bit word. The funky tests are to handle the case
81 # of zero bytes.
82 set char0 [string index $data [expr $i + 0]]
83 if { "$char0" != "" } {
84 scan $char0 "%c" ascii0
85 } else {
86 set ascii0 0
87 }
88 set char1 [string index $data [expr $i + 1]]
89 if { "$char1" != "" } {
90 scan $char1 "%c" ascii1
91 } else {
92 set ascii1 0
93 }
94 set char2 [string index $data [expr $i + 2]]
95 if { "$char2" != "" } {
96 scan $char2 "%c" ascii2
97 } else {
98 set ascii2 0
99 }
100 set char3 [string index $data [expr $i + 3]]
101 if { "$char3" != "" } {
102 scan $char3 "%c" ascii3
103 } else {
104 set ascii3 0
105 }
106 set word [expr $ascii0 << 24]
107 set word [expr $word | [expr $ascii1 << 16]]
108 set word [expr $word | [expr $ascii2 << 8]]
109 set word [expr $word | $ascii3]
110 set sum [expr $sum ^ $word]
111 # puts "sum: [format %8.8X $sum], word: [format %8.8X $word]"
112 }
113
114 return $sum
115 }
116
117 proc bswap { native } {
118 set byte0 [expr [expr $native >> 24] & 255]
119 set byte1 [expr [expr $native >> 16] & 255]
120 set byte2 [expr [expr $native >> 8] & 255]
121 set byte3 [expr [expr $native >> 0] & 255]
122 set swapped [expr $byte3 << 24]
123 set swapped [expr $swapped | [expr $byte2 << 16]]
124 set swapped [expr $swapped | [expr $byte1 << 8]]
125 set swapped [expr $swapped | [expr $byte0 << 0]]
126 # puts "native: [format %8.8X $native], swapped: [format %8.8X $swapped]"
127 return $swapped
128 }
129
130 global tcl_platform
131 set byteOrder $tcl_platform(byteOrder)
132 # puts "platform byte order = $byteOrder"
133
134 # Parse command line arguments
135 set argc 0
136 array set args { }
137 foreach arg $argv {
138 set args([incr argc]) $arg
139 }
140
141 if { "$argc" != "1" } {
142 puts "usage: flash_cksum <file>"
143 exit 1
144 }
145
146 set cksum [checksum $args(1)]
147
148 # if { "$byteOrder" == "littleEndian" } {
149 # puts "Swap bytes!"
150 set cksum [bswap $cksum]
151 # }
152
153 puts "[format 0x%8.8X $cksum]"
154