11#! /bin/sh -
22set -o nounset# Treat unset variables as an error
3+ # set -o xtrace # Print command traces before executing command.
34
45STM32CP_CLI=
56ADDRESS=0x8000000
@@ -13,7 +14,7 @@ OPTS=""
1314usage () {
1415echo " ############################################################"
1516echo " ##"
16- echo " ##$( basename" $0 " ) <protocol> <file_path> [OPTIONS]"
17+ echo " ##$( basename" $0 " ) <protocol> <file_path><offset> [OPTIONS]"
1718echo " ##"
1819echo " ## protocol:"
1920echo " ## 0: SWD"
@@ -22,6 +23,7 @@ usage() {
2223echo " ## Note: prefix it by 1 to erase all sectors."
2324echo " ## Ex: 10 erase all sectors using SWD interface."
2425echo " ## file_path: file path name to be downloaded: (bin, hex)"
26+ echo " ## offset: offset to add to$ADDRESS "
2527echo " ## Options:"
2628echo " ## For SWD and DFU: no mandatory options"
2729echo " ## For Serial: <com_port>"
@@ -92,14 +94,17 @@ case "${UNAME_OS}" in
9294 ;;
9395esac
9496
95- if [$# -lt 2 ]; then
97+ if [$# -lt 3 ]; then
9698echo " Not enough arguments!"
9799 usage 2
98100fi
99101
100102# Parse options
101103PROTOCOL=$1
102104FILEPATH=$2
105+ OFFSET=$3
106+ ADDRESS=$( printf" 0x%x" $(( ADDRESS+ OFFSET)) )
107+
103108# Protocol $1
104109# 1x: Erase all sectors
105110if [" $1 " -ge 10 ]; then
@@ -114,19 +119,19 @@ case $PROTOCOL in
114119 0)
115120 PORT=" SWD"
116121 MODE=" mode=UR"
117- shift 2
122+ shift 3
118123 ;;
119124 1)
120- if [$# -lt 3 ]; then
125+ if [$# -lt 4 ]; then
121126 usage 3
122127else
123- PORT=$3
124- shift 3
128+ PORT=$4
129+ shift 4
125130fi
126131 ;;
127132 2)
128133 PORT=" USB1"
129- shift 2
134+ shift 3
130135 ;;
131136* )
132137echo " Protocol unknown!"