1#!/usr/bin/env bash
2#******************************************************************************
3#  * @attention
4#  *
5#  * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
6#  * All rights reserved.</center></h2>
7#  *
8#  * This software component is licensed by ST under BSD 3-Clause license,
9#  * the "License"; You may not use this file except in compliance with the
10#  * License. You may obtain a copy of the License at:
11#  *                        opensource.org/licenses/BSD-3-Clause
12#  *
13#  ******************************************************************************
14
15echo "TFM UPDATE started"
16sn_option=""
17if [ $# -eq 1 ]; then
18sn_option="sn=$1"
19fi
20# Absolute path to this script
21SCRIPT=$(readlink -f $0)
22# Absolute path this script
23SCRIPTPATH=`dirname $SCRIPT`
24BINPATH="$SCRIPTPATH/bin"
25PATH="/C/Program Files/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin/":$PATH
26stm32programmercli="STM32_Programmer_CLI"
27# part ot be updated according to flash_layout.h
28slot0=
29slot1=
30slot2=
31slot3=
32its=
33sst=
34scratch=
35nvcounter=
36boot=
37nvmcnt=
38prov=
39unused=
40encrypted=
41#select external flash according to slot2 value
42u5=0x70000000
43l5=0x90000000
44slot_s=$slot0
45slot_ns=$slot1
46#when image are encrypted, image are not installed in place (mcuboot installs the image from download slot)
47if [ $encrypted == "0x1" ]; then
48slot_s=$slot2
49slot_ns=$slot3
50fi
51if [ $slot2 == $u5 ]; then
52external_loader="-el C:\PROGRA~1\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\ExternalLoader\MX25LM51245G_STM32U585I-IOT02A.stldr"
53fi
54if [ $slot2 == $l5 ]; then
55external_loader="-el C:\PROGRA~1\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\ExternalLoader\MX25LM51245G_STM32L562E-DK.stldr"
56fi
57connect_no_reset="-c port=SWD "$sn_option" mode=UR $external_loader"
58connect="-c port=SWD "$sn_option" mode=UR --hardRst $external_loader"
59
60echo "Write TFM_Appli Secure"
61# part ot be updated according to flash_layout.h
62
63$stm32programmercli $connect -d $BINPATH/tfm_s_signed.bin $slot_s -v
64echo "TFM_Appli Secure Written"
65echo "Write TFM_Appli NonSecure"
66$stm32programmercli $connect -d $BINPATH/tfm_ns_signed.bin $slot_ns -v
67echo "TFM_Appli NonSecure Written"
68echo "Write TFM_SBSFU_Boot"
69$stm32programmercli $connect -d $BINPATH/bl2.bin $boot -v
70echo "TFM_SBSFU_Boot Written"
71echo "TFM_UPDATE Done"