aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichel Jaouen <michel.jaouen@st.com>2021-04-20 17:50:34 +0200
committerAnton Komlev <Anton.Komlev@arm.com>2021-05-06 00:34:55 +0200
commit1a9eab2d1a66b77a7b29854176f38ecaab20416a (patch)
treef4d8d7047a51aeaa14d000656509aa441f2834aa
parent01a497c2c03f95a11aab48714b5fb3a907195f5b (diff)
downloadtrusted-firmware-m-1a9eab2d1a66b77a7b29854176f38ecaab20416a.tar.gz
platform: stm: Add options for programming board
Add optional parameter for scripts regression.sh and TFM_UPDATE.sh (board serial number). Create script TFM_BIN2HEX.sh for mass storage programming. Change-Id: I0d746fbdf44dbcd25f55cfca46f37a7ab324629a Signed-off-by: Michel Jaouen <michel.jaouen@st.com>
-rw-r--r--platform/ext/target/stm/common/stm32l5xx/CMakeLists.txt2
-rw-r--r--platform/ext/target/stm/common/stm32l5xx/boards/scripts/TFM_BIN2HEX.sh121
-rwxr-xr-xplatform/ext/target/stm/common/stm32l5xx/boards/scripts/TFM_UPDATE.sh8
-rw-r--r--platform/ext/target/stm/common/stm32l5xx/boards/scripts/bin2hex.py114
-rw-r--r--platform/ext/target/stm/common/stm32l5xx/boards/scripts/postbuild.sh29
-rwxr-xr-xplatform/ext/target/stm/common/stm32l5xx/boards/scripts/regression.sh8
6 files changed, 277 insertions, 5 deletions
diff --git a/platform/ext/target/stm/common/stm32l5xx/CMakeLists.txt b/platform/ext/target/stm/common/stm32l5xx/CMakeLists.txt
index c1b63f0a54..b556ce2286 100644
--- a/platform/ext/target/stm/common/stm32l5xx/CMakeLists.txt
+++ b/platform/ext/target/stm/common/stm32l5xx/CMakeLists.txt
@@ -194,6 +194,7 @@ endif()
install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/boards/scripts/stm_tool.py
+ ${CMAKE_CURRENT_SOURCE_DIR}/boards/scripts/bin2hex.py
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../bl2/ext/mcuboot/scripts/macro_parser.py
DESTINATION ${CMAKE_BINARY_DIR}/scripts/ )
@@ -208,6 +209,7 @@ endif()
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/boards/scripts/regression.sh
${PREPROCESSOR_FILE}
${CMAKE_CURRENT_SOURCE_DIR}/boards/scripts/TFM_UPDATE.sh
+ ${CMAKE_CURRENT_SOURCE_DIR}/boards/scripts/TFM_BIN2HEX.sh
${CMAKE_CURRENT_SOURCE_DIR}/boards/scripts/postbuild.sh
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
DESTINATION ${CMAKE_BINARY_DIR} )
diff --git a/platform/ext/target/stm/common/stm32l5xx/boards/scripts/TFM_BIN2HEX.sh b/platform/ext/target/stm/common/stm32l5xx/boards/scripts/TFM_BIN2HEX.sh
new file mode 100644
index 0000000000..d9b8b1a4dc
--- /dev/null
+++ b/platform/ext/target/stm/common/stm32l5xx/boards/scripts/TFM_BIN2HEX.sh
@@ -0,0 +1,121 @@
+#!/bin/bash -
+#******************************************************************************
+# * @attention
+# *
+# * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
+# * All rights reserved.</center></h2>
+# *
+# * This software component is licensed by ST under BSD 3-Clause license,
+# * the "License"; You may not use this file except in compliance with the
+# * License. You may obtain a copy of the License at:
+# * opensource.org/licenses/BSD-3-Clause
+# *
+# ******************************************************************************
+
+echo "TFM BIN2HEX started"
+disk=d
+if [ $# -eq 1 ]; then
+disk="$1"
+fi
+disk_option="/"$disk
+
+# Absolute path to this script
+SCRIPT=$(readlink -f $0)
+# Absolute path this script
+SCRIPTPATH=`dirname $SCRIPT`
+BINPATH="$SCRIPTPATH/bin"
+
+
+echo "Write TFM_Appli Secure"
+# part ot be updated according to flash_layout.h
+slot0=
+slot1=
+boot=
+unused=
+#since drag an drop is not supporting flash secure alias, address is conververted to non secure flash alias
+let image_s=$slot0-0x4000000
+image_s=`printf 0x%x $image_s`
+let image_ns=$slot1-0x4000000
+image_ns=`printf 0x%x $image_ns`
+let bl2=$boot-0x4000000
+bl2=`printf 0x%x $bl2`
+printf "disk "$disk_option", hex addresses: "$bl2", "$image_s", "$image_ns
+python scripts/bin2hex.py --offset=$image_s $BINPATH/tfm_s_signed.bin $BINPATH/tfm_s_signed.hex
+python scripts/bin2hex.py --offset=$image_ns $BINPATH/tfm_ns_signed.bin $BINPATH/tfm_ns_signed.hex
+python scripts/bin2hex.py --offset=$bl2 $BINPATH/bl2.bin $BINPATH/bl2.hex
+if [ ! -f $disk_option/DETAILS.TXT ]; then
+ echo "disk not present"
+ exit 1
+fi
+# cleaning 1st bank is ok for now.
+echo "Cleaning 1st bank"
+#create a file with 0 to clean up internal 1st bank : NVM, ITS and PS area
+# must be clean
+dd if=/dev/zero of=$BINPATH/clean.bin bs=1K count=256
+python scripts/bin2hex.py --offset=0x8000000 $BINPATH/clean.bin $BINPATH/clean.hex
+cp $BINPATH/clean.hex $disk_option
+while [ -f $disk_option/clean.hex ];
+do
+ sleep 0.1
+done
+sleep 5
+while [ ! -f $disk_option/DETAILS.TXT ]
+do
+ sleep 0.1
+done
+if [ -f $disk_option/failed.txt ]; then
+ echo " tfm_s_signed.hex not written"
+ cat $disk-option/failed.txt
+ exit 1
+fi
+#write secure image
+echo "Write Secure Image"
+cp $BINPATH/tfm_s_signed.hex $disk_option
+while [ -f $disk_option/tfm_s_signed.hex ];
+do
+ sleep 0.1
+done
+sleep 5
+while [ ! -f $disk_option/DETAILS.TXT ]
+do
+ sleep 0.1
+done
+if [ -f $disk_option/failed.txt ]; then
+ echo " tfm_s_signed.hex not written"
+ cat $disk-option/failed.txt
+ exit 1
+fi
+#write non secure image
+echo "Write non secure image"
+cp $BINPATH/tfm_ns_signed.hex $disk_option
+while [ -f $disk_option/tfm_ns_signed.hex ];
+do
+ sleep 0.1
+done
+sleep 5
+while [ ! -f $disk_option/DETAILS.TXT ]
+do
+ sleep 0.1
+done
+if [ -f $disk_option/failed.txt ]; then
+ echo "tfm_ns_signed.hex not written"
+ cat $disk_option/failed.txt
+ exit 1
+fi
+#write bl2 image
+echo "Write bl2 Image"
+cp $BINPATH/bl2.hex $disk_option
+while [ -f $disk_option/tfm_ns_signed.hex ];
+do
+ sleep 0.1
+done
+sleep 5
+while [ ! -f $disk_option/DETAILS.TXT ]
+do
+ sleep 0.1
+done
+if [ -f $disk_option/failed.txt ]; then
+ echo "bl2.hex not written"
+ cat $disk_option/failed.txt
+ exit 1
+fi
diff --git a/platform/ext/target/stm/common/stm32l5xx/boards/scripts/TFM_UPDATE.sh b/platform/ext/target/stm/common/stm32l5xx/boards/scripts/TFM_UPDATE.sh
index 99472e707e..8edc8ca93f 100755
--- a/platform/ext/target/stm/common/stm32l5xx/boards/scripts/TFM_UPDATE.sh
+++ b/platform/ext/target/stm/common/stm32l5xx/boards/scripts/TFM_UPDATE.sh
@@ -13,6 +13,10 @@
# ******************************************************************************
echo "TFM UPDATE started"
+sn_option=""
+if [ $# -eq 1 ]; then
+sn_option="sn=$1"
+fi
# Absolute path to this script
SCRIPT=$(readlink -f $0)
# Absolute path this script
@@ -21,8 +25,8 @@ BINPATH="$SCRIPTPATH/bin"
PATH="/C/Program Files/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin/":$PATH
stm32programmercli="STM32_Programmer_CLI"
external_loader="C:\PROGRA~1\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\ExternalLoader\MX25LM51245G_STM32L562E-DK.stldr"
-connect_no_reset="-c port=SWD mode=UR -el $external_loader"
-connect="-c port=SWD mode=UR --hardRst -el $external_loader"
+connect_no_reset="-c port=SWD "$sn_option" mode=UR -el $external_loader"
+connect="-c port=SWD "$sn_option" mode=UR --hardRst -el $external_loader"
echo "Write TFM_Appli Secure"
# part ot be updated according to flash_layout.h
diff --git a/platform/ext/target/stm/common/stm32l5xx/boards/scripts/bin2hex.py b/platform/ext/target/stm/common/stm32l5xx/boards/scripts/bin2hex.py
new file mode 100644
index 0000000000..2098e33878
--- /dev/null
+++ b/platform/ext/target/stm/common/stm32l5xx/boards/scripts/bin2hex.py
@@ -0,0 +1,114 @@
+#!/usr/bin/python
+# Copyright (c) 2008-2018 Alexander Belchenko
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms,
+# with or without modification, are permitted provided
+# that the following conditions are met:
+#
+# * Redistributions of source code must retain
+# the above copyright notice, this list of conditions
+# and the following disclaimer.
+# * Redistributions in binary form must reproduce
+# the above copyright notice, this list of conditions
+# and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# * Neither the name of the author nor the names
+# of its contributors may be used to endorse
+# or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+'''Intel HEX file format bin2hex convertor utility.'''
+
+VERSION = '2.3.0'
+
+if __name__ == '__main__':
+ import getopt
+ import os
+ import sys
+
+ usage = '''Bin2Hex convertor utility.
+Usage:
+ python bin2hex.py [options] INFILE [OUTFILE]
+
+Arguments:
+ INFILE name of bin file for processing.
+ Use '-' for reading from stdin.
+
+ OUTFILE name of output file. If omitted then output
+ will be writing to stdout.
+
+Options:
+ -h, --help this help message.
+ -v, --version version info.
+ --offset=N offset for loading bin file (default: 0).
+'''
+
+ offset = 0
+
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], "hv",
+ ["help", "version", "offset="])
+
+ for o, a in opts:
+ if o in ("-h", "--help"):
+ print(usage)
+ sys.exit(0)
+ elif o in ("-v", "--version"):
+ print(VERSION)
+ sys.exit(0)
+ elif o in ("--offset"):
+ base = 10
+ if a[:2].lower() == '0x':
+ base = 16
+ try:
+ offset = int(a, base)
+ except:
+ raise getopt.GetoptError('Bad offset value')
+
+ if not args:
+ raise getopt.GetoptError('Input file is not specified')
+
+ if len(args) > 2:
+ raise getopt.GetoptError('Too many arguments')
+
+ except getopt.GetoptError:
+ msg = sys.exc_info()[1] # current exception
+ txt = 'ERROR: '+str(msg) # that's required to get not-so-dumb result from 2to3 tool
+ print(txt)
+ print(usage)
+ sys.exit(2)
+
+ from intelhex import compat
+
+ fin = args[0]
+ if fin == '-':
+ # read from stdin
+ fin = compat.get_binary_stdin()
+ elif not os.path.isfile(fin):
+ txt = "ERROR: File not found: %s" % fin # that's required to get not-so-dumb result from 2to3 tool
+ print(txt)
+ sys.exit(1)
+
+ if len(args) == 2:
+ fout = args[1]
+ else:
+ # write to stdout
+ fout = sys.stdout # compat.get_binary_stdout()
+
+ from intelhex import bin2hex
+ sys.exit(bin2hex(fin, fout, offset))
diff --git a/platform/ext/target/stm/common/stm32l5xx/boards/scripts/postbuild.sh b/platform/ext/target/stm/common/stm32l5xx/boards/scripts/postbuild.sh
index f4cee4e7a9..0291f5749d 100644
--- a/platform/ext/target/stm/common/stm32l5xx/boards/scripts/postbuild.sh
+++ b/platform/ext/target/stm/common/stm32l5xx/boards/scripts/postbuild.sh
@@ -22,7 +22,7 @@ bl2_file_to_preprocess=$projectdir/image_macros_to_preprocess_bl2.c
preprocess_bl2_file=$projectdir/image_macros_preprocessed_bl2.c
regressionsh=$projectdir/regression.sh
updatesh=$projectdir/TFM_UPDATE.sh
-
+bin2hexsh=$projectdir/TFM_BIN2HEX.sh
basedir=$projectdir
echo preprocess bl2 file
preprocess $projectdir $bl2_file_to_preprocess $preprocess_bl2_file
@@ -145,3 +145,30 @@ echo "postbuild.sh failed"
echo $command
exit 1
fi
+command=$cmd" "$stm_tool" flash --layout "$preprocess_bl2_file" -b boot -m RE_BL2_PERSO_ADDRESS -s 0 "$bin2hexsh
+$command >> $projectdir"/output.txt"
+ret=$?
+if [ $ret != 0 ]; then
+echo "postbuild.sh failed"
+echo $command
+exit 1
+fi
+
+command=$cmd" "$stm_tool" flash --layout "$preprocess_bl2_file" -b slot0 -m RE_IMAGE_FLASH_ADDRESS_SECURE -s 0 "$bin2hexsh
+$command >> $projectdir"/output.txt"
+ret=$?
+if [ $ret != 0 ]; then
+echo "postbuild.sh failed"
+echo $command
+exit 1
+fi
+
+echo $updatebat" updated"
+command=$cmd" "$stm_tool" flash --layout "$preprocess_bl2_file" -b slot1 -m RE_IMAGE_FLASH_ADDRESS_NON_SECURE -s 0 "$bin2hexsh
+$command >> $projectdir"/output.txt"
+ret=$?
+if [ $ret != 0 ]; then
+echo "postbuild.sh failed"
+echo $command
+exit 1
+fi
diff --git a/platform/ext/target/stm/common/stm32l5xx/boards/scripts/regression.sh b/platform/ext/target/stm/common/stm32l5xx/boards/scripts/regression.sh
index a51aac75a6..034b5c1440 100755
--- a/platform/ext/target/stm/common/stm32l5xx/boards/scripts/regression.sh
+++ b/platform/ext/target/stm/common/stm32l5xx/boards/scripts/regression.sh
@@ -13,12 +13,16 @@
# ******************************************************************************
echo "regression script started"
+sn_option=""
+if [ $# -eq 1 ]; then
+sn_option="sn=$1"
+fi
PATH="/C/Program Files/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin/":$PATH
stm32programmercli="STM32_Programmer_CLI"
# remove write protection
secbootadd0=0x180030
-connect="-c port=SWD mode=UR --hardRst"
-connect_no_reset="-c port=SWD mode=HotPlug"
+connect="-c port=SWD "$sn_option" mode=UR --hardRst"
+connect_no_reset="-c port=SWD "$sn_option" mode=HotPlug"
rdp_0="-ob RDP=0xAA TZEN=1"
remove_bank1_protect="-ob SECWM1_PSTRT=127 SECWM1_PEND=0 WRP1A_PSTRT=127 WRP1A_PEND=0 WRP1B_PSTRT=127 WRP1B_PEND=0"
remove_bank2_protect="-ob SECWM2_PSTRT=127 SECWM2_PEND=0 WRP2A_PSTRT=127 WRP2A_PEND=0 WRP2B_PSTRT=127 WRP2B_PEND=0"