-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflash.sh
163 lines (141 loc) · 3.09 KB
/
flash.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash
#================================================================
# Copyright (C) 2019年08月09日 肖飞 All rights reserved
#
# 文件名称:flash.sh
# 创 建 者:肖飞
# 创建日期:2019年08月09日 星期五 10时59分21秒
# 修改日期:2021年05月21日 星期五 08时59分53秒
# 描 述:
#
#================================================================
opt_string="b:a:efd"
bin_file="build/eva.hex"
load_address="0x8000000"
erase_flash=0
flush_flash=0
debug=0
jlink_script="jlink.script"
#link_if="JTAG"
link_if="SWD"
function process_parameter() {
local arguments="$1"
local optarg="$2"
#echo -e "[$0-$FUNCNAME:$LINENO]arguments:$arguments, optarg:$optarg"
case $arguments in
a)
load_address="$optarg"
echo "load_address:$load_address"
;;
b)
bin_file="$optarg"
echo "bin_file:$bin_file"
;;
e)
erase_flash=1
;;
f)
flush_flash=1
;;
d)
debug=1
;;
*)
;;
esac
}
function opt_parse() {
local args=( "$@" )
local ret=0
local current_opt_index=1
OPTIND=1
OPTERR=0
while getopts $opt_string arguments 2>/dev/null; do
#echo "[$0-$FUNCNAME:$LINENO]\${#args[@]} is ${#args[@]}, \$OPTIND is $OPTIND, \$OPTERR is $OPTERR, \$arguments is $arguments, \$OPTARG is $OPTARG"
OPTERR=0
case $arguments in
"?")
ret=1
break
;;
*)
current_opt_index=$OPTIND
process_parameter "$arguments" "$OPTARG"
;;
esac
done
#echo "[$0-$FUNCNAME:$LINENO]\${#args[@]} is ${#args[@]}, \$OPTIND is $OPTIND, \$OPTERR is $OPTERR, \$arguments is $arguments, \$OPTARG is $OPTARG"
if test ${#args[@]} -gt $((current_opt_index - 1)); then
ret=1
echo -ne "[$0-$FUNCNAME:$LINENO]Usage:$FUNCNAME \"$opt_string\"\n\t"
for((index = $current_opt_index - 1; index < ${#args[@]}; index++)); do
echo -ne " ${args[$index]}"
done
echo
fi
return $ret
}
function gen_jlink_script_erase() {
cat > "$jlink_script" << EOF
power on
Sleep 10
rx 10
unlock kinetis
erase
unlock kinetis
power off
q
EOF
}
function gen_jlink_script_flash() {
cat > "$jlink_script" << EOF
power on
Sleep 10
rx 10
loadbin $bin_file $load_address
rx 10
power off
q
EOF
}
function gen_jlink_script_bootloader() {
cat > "$jlink_script" << EOF
rx 10
r0
r1
q
EOF
}
function gen_jlink_script_debug() {
cat > "$jlink_script" << EOF
power on
Sleep 10
rx 10
rx 10
power off
q
EOF
}
function main() {
opt_parse $@
if [ $? -ne 0 ];then
return
fi
if [ $erase_flash -eq 1 ];then
gen_jlink_script_erase
JLinkExe -Device "STM32F407IGTx" -IF "$link_if" -JTAGConf "-1,-1" -Speed "4000" -CommanderScript "$jlink_script"
rm "$jlink_script"
fi
if [ $flush_flash -eq 1 ];then
gen_jlink_script_flash
JLinkExe -Device "STM32F407IGTx" -IF "$link_if" -JTAGConf "-1,-1" -Speed "4000" -CommanderScript "$jlink_script"
rm "$jlink_script"
fi
if [ $debug -eq 1 ];then
#gen_jlink_script_debug
#JLinkExe -Device "STM32F407IGTx" -IF "$link_if" -JTAGConf "-1,-1" -Speed "4000" -CommanderScript "$jlink_script"
#rm "$jlink_script"
JLinkGDBServer -select USB -device STM32F407IGTx -endian little -if $link_if -speed 4000 -noir -noLocalhostOnly
fi
}
main $@