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

Subversion Repositories openmsp430

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

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
# 
28
#------------------------------------------------------------------------------
29
 
30
global serial_baudrate
31
global serial_device
32
 
33
###############################################################################
34
#                            PARAMETER CHECK                                  #
35
###############################################################################
36
 
37
proc help {} {
38
    puts ""
39
    puts "USAGE   : openmsp430-loader.tcl \[-device <communication device>\] \[-baudrate <communication speed>\] <elf-file>"
40
    puts ""
41
    puts "Examples: openmsp430-loader.tcl -device /dev/ttyUSB0 -baudrate  9600  leds.elf"
42
    puts "          openmsp430-loader.tcl -device COM2:        -baudrate 38400  ta_uart.elf"
43
    puts ""
44
}
45
 
46
# Default values
47
set serial_device   /dev/ttyUSB0
48
set serial_baudrate 115200
49
set elf_file        -1
50
set bin_file        "[clock clicks].bin"
51
 
52
# Parse arguments
53
for {set i 0} {$i < $argc} {incr i} {
54
    switch -exact -- [lindex $argv $i] {
55
        -device   {set serial_device   [lindex $argv [expr $i+1]]; incr i}
56
        -baudrate {set serial_baudrate [lindex $argv [expr $i+1]]; incr i}
57
        default   {set elf_file        [lindex $argv $i]}
58
    }
59
}
60
 
61
# Make sure arugments were specified
62
if {[string eq $elf_file -1]} {
63
    puts "ERROR: ELF file isn't specified"
64
    help
65
    exit 1
66
}
67
 
68
# Make sure the elf file exists
69
if {![file exists $elf_file]} {
70
    puts "ERROR: Specified ELF file doesn't exist"
71
    help
72
    exit 1
73
}
74
 
75
 
76
###############################################################################
77
#                            SOURCE LIBRARIES                                 #
78
###############################################################################
79
 
80
# Get library path
81
set current_file [info script]
82
if {[file type $current_file]=="link"} {
83
    set current_file [file readlink $current_file]
84
}
85
set lib_path [file dirname $current_file]/../lib/tcl-lib
86
 
87
# Source library
88
source $lib_path/dbg_functions.tcl
89
 
90
 
91
###############################################################################
92
#                  CREATE AND READ BINARY EXECUTABLE FILE                     #
93
###############################################################################
94
 
95
# Generate binary file
96
catch {exec msp430-objcopy -O binary $elf_file $bin_file}
97
 
98
# Read file
99
set fp [open $bin_file r]
100
fconfigure $fp -translation binary
101
binary scan [read $fp] H* hex_data yop
102
close $fp
103
 
104
# Cleanup
105
file delete $bin_file
106
 
107
# Get program size
108
set hex_size  [string length $hex_data]
109
set byte_size [expr $hex_size/2]
110
set word_size [expr $byte_size/2]
111
 
112
# Format data
113
for {set i 0} {$i < $hex_size} {set i [expr $i+4]} {
114
    set hex_msb "[string index $hex_data [expr $i+2]][string index $hex_data [expr $i+3]]"
115
    set hex_lsb "[string index $hex_data [expr $i+0]][string index $hex_data [expr $i+1]]"
116
    lappend DataArray "0x$hex_msb$hex_lsb"
117
}
118
 
119
 
120
###############################################################################
121
#                      LOAD PROGRAM TO OPENMSP430 TARGET                      #
122
###############################################################################
123
 
124
# Connect to target and stop CPU
125
puts -nonewline "Connecting with the openMSP430 ($serial_device, $serial_baudrate\ bps)... "
126
flush stdout
127
if {![GetDevice]} {
128
    puts "failed"
129
    puts "Could not open $serial_device"
130
    puts "Available serial ports are:"
131
    foreach port [dbg_list_uart] {
132
    puts "                             -  $port"
133
    }
134
    exit 1
135
}
136
ExecutePOR_Halt
137
puts "done"
138
set sizes [GetCPU_ID_SIZE]
139
puts "Connected: target device has [lindex $sizes 0]B ROM and [lindex $sizes 1]B RAM"
140
puts ""
141
 
142
# Load ROM
143
set StartAddr [format "0x%04x" [expr 0x10000-$byte_size]]
144
puts -nonewline "Load ROM... "
145
flush stdout
146
WriteMemQuick $StartAddr $DataArray
147
puts "done"
148
 
149
# Check Data
150
puts -nonewline "Verify ROM... "
151
flush stdout
152
if {[VerifyMem $StartAddr $DataArray]} {
153
    puts "done"
154
} else {
155
    puts "ERROR"
156
}
157
 
158
# Release device
159
ReleaseDevice 0xfffe

powered by: WebSVN 2.1.0

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