3 # Copyright (C) 2013-2014 Czech Technical University in Prague
6 # - Michal Horn <hornmich@fel.cvut.cz>
8 # Permission is hereby granted, free of charge, to any person
9 # obtaining a copy of this software and associated documentation
10 # files (the "Software"), to deal in the Software without
11 # restriction, including without limitation the rights to use,
12 # copy, modify, merge, publish, distribute, sublicense, and/or sell
13 # copies of the Software, and to permit persons to whom the
14 # Software is furnished to do so, subject to the following
17 # The above copyright notice and this permission notice shall be
18 # included in all copies or substantial portions of the Software.
20 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22 # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 # OTHER DEALINGS IN THE SOFTWARE.
29 # File : loadopenocd.sh.py
31 # Wrapper script for downloading binary code via OpenOCD
34 # http://rtime.felk.cvut.cz/hw/index.php/TMS570LS3137#OpenOCD_setup_and_Flashing
37 echo "TMS570LS3137 loader script v0.1.0-dev (2014-09-02)"
38 echo "Licensed under GNU GPL v2"
39 echo "Downloads a compiled binary file to the Texas Instruments TMS570LS3137 MCU."
40 echo "-h display this help"
41 echo "-d destination selector <sdram|flash>"
42 echo "-b halt after download completed"
43 echo "-s path to the binary file to be downloaded to the MCU"
45 echo "example: ./load.sh -d flash -b -s ./bin/foo.out"
51 LOAD_PATH=$(dirname $(which $0))
52 FLASH_MEMORY_SIZE=3145728 #3MB
53 SDRAM_MEMORY_SIZE=8388608 #8MB
54 MEMORY_SIZE=$FLASH_MEMORY_SIZE
56 while getopts "hd:bs:" flag
59 h) show_help; exit 0;;
61 sdram) DESTINATION="SDRAM";;
62 flash) DESTINATION="FLASH";;
63 *) echo "unknown destination"; exit 1;;
71 if [ $DESTINATION == "0" ]
73 echo "No destination specified."
75 elif [ $DESTINATION == "SDRAM" ]
77 MEMORY_SIZE=$SDRAM_MEMORY_SIZE
82 echo "No source binary file specified."
87 echo "Source binary file does not exists."
91 SIZE=`size -d $SOURCE | awk 'NR==2 {print $1}'`
93 echo >&2 "Checking binary file size..."
94 if [ "$SIZE" -ge "$MEMORY_SIZE" ]
96 echo "The output binary file si bigger than the capacity of the memory."
97 echo >&2 " [failed] - binary size: $SIZE, memory cize: $MEMORY_SIZE"
101 echo >&2 " [OK] - binary size: $SIZE"
105 CFG_FILE=$LOAD_PATH/openocd.cfg
107 CFG_FILE=$LOAD_PATH/openocd-halt-immediatelly.cfg
110 echo >&2 "Checking existence of $CFG_FILE file..."
111 if [ ! -f $CFG_FILE ]
113 echo "OpenOCD configuration file not found."
114 echo >&2 " [failed] - file $CFG_FILE not found."
118 echo >&2 "Looking for OpenOCD executable..."
119 OPENOCD_PATH=`command -v openocd || { echo "OpenOCD executable not found."; echo >&2 " [failed] - Could not find OpenOCD."; exit 3; }`
120 echo >&2 " [OK] - $OPENOCD_PATH"
122 if [ $DESTINATION == "FLASH" ]
124 echo "Downloading binary file..."
125 echo >&2 "Downloading binary file..."
126 CMD="openocd -f $CFG_FILE --command \"program $SOURCE\" --command \"exit\""
128 openocd -f $CFG_FILE --command "program $SOURCE" --command "exit"
130 echo "SDRAM download not yet implemented."