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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [tools/] [bin/] [openmsp430-loader.tcl] - Blame information for rev 35

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

Line No. Rev Author Line
1 2 olivier.gi
#!/usr/bin/tclsh
2
#------------------------------------------------------------------------------
3
# Copyright (C) 2001 Authors
4
#
5
# This source file may be used and distributed without restriction provided
6
# that this copyright statement is not removed from the file and that any
7
# derivative work contains the original copyright notice and the associated
8
# disclaimer.
9
#
10
# This source file is free software; you can redistribute it and/or modify
11
# it under the terms of the GNU Lesser General Public License as published
12
# by the Free Software Foundation; either version 2.1 of the License, or
13
# (at your option) any later version.
14
#
15
# This source is distributed in the hope that it will be useful, but WITHOUT
16
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18
# License for more details.
19
#
20
# You should have received a copy of the GNU Lesser General Public License
21
# along with this source; if not, write to the Free Software Foundation,
22
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23
#
24
#------------------------------------------------------------------------------
25
# 
26
# File Name: openmsp430-loader.tcl
27 14 olivier.gi
#
28
# Author(s):
29
#             - Olivier Girard,    olgirard@gmail.com
30
#
31 2 olivier.gi
#------------------------------------------------------------------------------
32 14 olivier.gi
# $Rev: 35 $
33
# $LastChangedBy: olivier.girard $
34
# $LastChangedDate: 2009-12-29 21:12:19 +0100 (Tue, 29 Dec 2009) $
35
#------------------------------------------------------------------------------
36 2 olivier.gi
 
37
global serial_baudrate
38
global serial_device
39
 
40
###############################################################################
41
#                            PARAMETER CHECK                                  #
42
###############################################################################
43
 
44
proc help {} {
45
    puts ""
46
    puts "USAGE   : openmsp430-loader.tcl \[-device <communication device>\] \[-baudrate <communication speed>\] <elf-file>"
47
    puts ""
48
    puts "Examples: openmsp430-loader.tcl -device /dev/ttyUSB0 -baudrate  9600  leds.elf"
49
    puts "          openmsp430-loader.tcl -device COM2:        -baudrate 38400  ta_uart.elf"
50
    puts ""
51
}
52
 
53
# Default values
54
set serial_device   /dev/ttyUSB0
55
set serial_baudrate 115200
56
set elf_file        -1
57
set bin_file        "[clock clicks].bin"
58
 
59
# Parse arguments
60
for {set i 0} {$i < $argc} {incr i} {
61
    switch -exact -- [lindex $argv $i] {
62
        -device   {set serial_device   [lindex $argv [expr $i+1]]; incr i}
63
        -baudrate {set serial_baudrate [lindex $argv [expr $i+1]]; incr i}
64
        default   {set elf_file        [lindex $argv $i]}
65
    }
66
}
67
 
68
# Make sure arugments were specified
69
if {[string eq $elf_file -1]} {
70
    puts "ERROR: ELF file isn't specified"
71
    help
72
    exit 1
73
}
74
 
75
# Make sure the elf file exists
76
if {![file exists $elf_file]} {
77
    puts "ERROR: Specified ELF file doesn't exist"
78
    help
79
    exit 1
80
}
81
 
82
 
83
###############################################################################
84
#                            SOURCE LIBRARIES                                 #
85
###############################################################################
86
 
87
# Get library path
88
set current_file [info script]
89
if {[file type $current_file]=="link"} {
90
    set current_file [file readlink $current_file]
91
}
92
set lib_path [file dirname $current_file]/../lib/tcl-lib
93
 
94
# Source library
95
source $lib_path/dbg_functions.tcl
96
 
97
 
98
###############################################################################
99
#                  CREATE AND READ BINARY EXECUTABLE FILE                     #
100
###############################################################################
101
 
102
# Generate binary file
103
catch {exec msp430-objcopy -O binary $elf_file $bin_file}
104
 
105
# Read file
106
set fp [open $bin_file r]
107
fconfigure $fp -translation binary
108
binary scan [read $fp] H* hex_data yop
109
close $fp
110
 
111
# Cleanup
112
file delete $bin_file
113
 
114
# Get program size
115
set hex_size  [string length $hex_data]
116
set byte_size [expr $hex_size/2]
117
set word_size [expr $byte_size/2]
118
 
119
# Format data
120
for {set i 0} {$i < $hex_size} {set i [expr $i+4]} {
121
    set hex_msb "[string index $hex_data [expr $i+2]][string index $hex_data [expr $i+3]]"
122
    set hex_lsb "[string index $hex_data [expr $i+0]][string index $hex_data [expr $i+1]]"
123
    lappend DataArray "0x$hex_msb$hex_lsb"
124
}
125
 
126
 
127
###############################################################################
128
#                      LOAD PROGRAM TO OPENMSP430 TARGET                      #
129
###############################################################################
130
 
131
# Connect to target and stop CPU
132
puts -nonewline "Connecting with the openMSP430 ($serial_device, $serial_baudrate\ bps)... "
133
flush stdout
134
if {![GetDevice]} {
135
    puts "failed"
136
    puts "Could not open $serial_device"
137
    puts "Available serial ports are:"
138
    foreach port [dbg_list_uart] {
139
    puts "                             -  $port"
140
    }
141
    exit 1
142
}
143
ExecutePOR_Halt
144
puts "done"
145
set sizes [GetCPU_ID_SIZE]
146 35 olivier.gi
puts "Connected: target device has [lindex $sizes 0]B Program Memory and [lindex $sizes 1]B Data Memory"
147 2 olivier.gi
puts ""
148
 
149 35 olivier.gi
# Load Program Memory
150 2 olivier.gi
set StartAddr [format "0x%04x" [expr 0x10000-$byte_size]]
151 35 olivier.gi
puts -nonewline "Load Program Memory... "
152 2 olivier.gi
flush stdout
153
WriteMemQuick $StartAddr $DataArray
154
puts "done"
155
 
156
# Check Data
157 35 olivier.gi
puts -nonewline "Verify Program Memory... "
158 2 olivier.gi
flush stdout
159
if {[VerifyMem $StartAddr $DataArray]} {
160
    puts "done"
161
} else {
162
    puts "ERROR"
163
}
164
 
165
# Release device
166
ReleaseDevice 0xfffe

powered by: WebSVN 2.1.0

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