1# Copyright (c) 2020, Linaro. All rights reserved.
2# Copyright (c) 2020, Arm Limited. All rights reserved.
3# Copyright 2020-2023 NXP. All rights reserved.
4# SPDX-License-Identifier: BSD-3-Clause
5
6import os
7import platform
8
9# Move to the TFM build folder
10os.chdir('../../../../../../build/bin')
11
12# Define JLink configuration script file
13FILE = "flash.jlink"
14
15# Remove previous flash.jlink script file
16if os.path.isfile(FILE):
17    if platform.system() == 'Windows':
18        os.system('del /f /q ' + FILE)
19    else:
20        os.system('rm -rf ' + FILE)
21
22# Write the JLink configuration into flash.jlink script
23os.system('echo r >> ' + FILE)                      # reset the target
24os.system('echo erase  >> ' + FILE)                 # erase the flash memory
25os.system('echo loadfile tfm_s.hex >> ' + FILE)     # flash the secure image into target
26os.system('echo loadfile tfm_ns.hex  >> ' + FILE)   # flash the non-secure image into target
27os.system('echo r >> ' + FILE)                      # reset the target
28os.system('echo go >> ' + FILE)                     # run the program
29os.system('echo exit >> ' + FILE)                   # exit the JLinkCommander
30
31# Upload the configuration from flash.jlink script into the target device
32if platform.system() == 'Windows':
33    os.system('JLink -device lpc55s69 -if swd -speed 2000 -autoconnect 1 -commanderscript ' + FILE)
34
35else:
36    os.system('JLinkExe -device lpc55s69 -if swd -speed 2000 -autoconnect 1 -commanderscript ' +FILE)
37