|
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | 15 | import sys |
16 | | -from os.path import join |
| 16 | +from platform import system |
| 17 | +from os import makedirs |
| 18 | +from os.path import isdir, join |
17 | 19 |
|
18 | 20 | from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Builder, Default, |
19 | 21 | DefaultEnvironment) |
|
184 | 186 | env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE") |
185 | 187 | ] |
186 | 188 |
|
187 | | -elif upload_protocol.startswith("nrfjprog"): |
| 189 | +elif upload_protocol == "nrfjprog": |
188 | 190 | env.Replace( |
189 | 191 | UPLOADER="nrfjprog", |
190 | 192 | UPLOADERFLAGS=[ |
191 | 193 | "--chiperase", |
192 | | - "-r" |
| 194 | + "--reset" |
193 | 195 | ], |
194 | 196 | UPLOADCMD="$UPLOADER $UPLOADERFLAGS --program $SOURCE" |
195 | 197 | ) |
196 | 198 | upload_actions = [env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")] |
197 | 199 |
|
| 200 | +elif upload_protocol.startswith("jlink"): |
| 201 | + |
| 202 | + def _jlink_cmd_script(env, source): |
| 203 | + build_dir = env.subst("$BUILD_DIR") |
| 204 | + if not isdir(build_dir): |
| 205 | + makedirs(build_dir) |
| 206 | + script_path = join(build_dir, "upload.jlink") |
| 207 | + commands = ["h", "loadbin %s,0x0" % source, "r", "q"] |
| 208 | + with open(script_path, "w") as fp: |
| 209 | + fp.write("\n".join(commands)) |
| 210 | + return script_path |
| 211 | + |
| 212 | + env.Replace( |
| 213 | + __jlink_cmd_script=_jlink_cmd_script, |
| 214 | + UPLOADER="JLink.exe" if system() == "Windows" else "JLinkExe", |
| 215 | + UPLOADERFLAGS=[ |
| 216 | + "-device", env.BoardConfig().get("debug", {}).get("jlink_device"), |
| 217 | + "-speed", "4000", |
| 218 | + "-if", ("jtag" if upload_protocol == "jlink-jtag" else "swd"), |
| 219 | + "-autoconnect", "1" |
| 220 | + ], |
| 221 | + UPLOADCMD="$UPLOADER $UPLOADERFLAGS -CommanderScript ${__jlink_cmd_script(__env__, SOURCE)}" |
| 222 | + ) |
| 223 | + upload_actions = [env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")] |
| 224 | + |
198 | 225 | elif upload_protocol in debug_tools: |
199 | 226 | env.Replace( |
200 | 227 | UPLOADER="openocd", |
|
0 commit comments