3 # Copyright (C) 2013-2014 Czech Technical University in Prague
6 # - Michal Horn <hornmich@fel.cvut.cz>
8 # This document contains proprietary information belonging to Czech
9 # Technical University in Prague. Passing on and copying of this
10 # document, and communication of its contents is not permitted
11 # without prior written authorization.
13 # File : loadopenocd.sh.py
15 # Wrapper script for downloading binary code via OpenOCD
18 # http://rtime.felk.cvut.cz/hw/index.php/TMS570LS3137#OpenOCD_setup_and_Flashing
21 echo "TMS570LS3137 loader script v0.1.0-dev (2014-09-02)"
22 echo "Licensed under GNU GPL v2"
23 echo "Downloads a compiled binary file to the Texas Instruments TMS570LS3137 MCU."
24 echo "-h display this help"
25 echo "-d destination selector <sdram|flash>"
26 echo "-b halt after download completed"
27 echo "-s path to the binary file to be downloaded to the MCU"
29 echo "example: ./load.sh -d flash -b -s ./bin/foo.out"
35 LOAD_PATH=$(dirname $(which $0))
36 FLASH_MEMORY_SIZE=3145728 #3MB
37 SDRAM_MEMORY_SIZE=8388608 #8MB
38 MEMORY_SIZE=$FLASH_MEMORY_SIZE
40 while getopts "hd:bs:" flag
43 h) show_help; exit 0;;
45 sdram) DESTINATION="SDRAM";;
46 flash) DESTINATION="FLASH";;
47 *) echo "unknown destination"; exit 1;;
55 if [ $DESTINATION == "0" ]
57 echo "No destination specified."
59 elif [ $DESTINATION == "SDRAM" ]
61 MEMORY_SIZE=$SDRAM_MEMORY_SIZE
66 echo "No source binary file specified."
71 echo "Source binary file does not exists."
75 SIZE=`size -d $SOURCE | awk 'NR==2 {print $1}'`
77 echo >&2 "Checking binary file size..."
78 if [ "$SIZE" -ge "$MEMORY_SIZE" ]
80 echo "The output binary file si bigger than the capacity of the memory."
81 echo >&2 " [failed] - binary size: $SIZE, memory cize: $MEMORY_SIZE"
85 echo >&2 " [OK] - binary size: $SIZE"
89 CFG_FILE=$LOAD_PATH/openocd.cfg
91 CFG_FILE=$LOAD_PATH/openocd-halt-immediatelly.cfg
94 echo >&2 "Checking existence of $CFG_FILE file..."
97 echo "OpenOCD configuration file not found."
98 echo >&2 " [failed] - file $CFG_FILE not found."
102 echo >&2 "Looking for OpenOCD executable..."
103 OPENOCD_PATH=`command -v openocd || { echo "OpenOCD executable not found."; echo >&2 " [failed] - Could not find OpenOCD."; exit 3; }`
104 echo >&2 " [OK] - $OPENOCD_PATH"
106 if [ $DESTINATION == "FLASH" ]
108 echo "Downloading binary file..."
109 echo >&2 "Downloading binary file..."
110 CMD="openocd -f $CFG_FILE --command \"program $SOURCE\" --command \"exit\""
112 openocd -f $CFG_FILE --command "program $SOURCE" --command "exit"
114 echo "SDRAM download not yet implemented."