aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichel Jaouen <michel.jaouen@st.com>2020-07-11 19:02:46 +0200
committerMichel Jaouen <michel.jaouen@st.com>2020-07-21 12:02:34 +0200
commitdcc1ef71eebdaa02d03f304993e3f8327ba63758 (patch)
tree0f006d7e4d935e9a6cbb8bb51add8129f6c991ba
parente1e5eeac3f22e83e16cfccb720df2dd862d4ae50 (diff)
downloadtrusted-firmware-m-feature-ux-buildsystem.tar.gz
Platform: stm32l5xx: Create a dedicated stm_tool.pyfeature-ux-buildsystem
Since tfm relies on mcuboot upstream, the imgtool stm specific function used for computing the stm32l5xx board programming settings is not available on mcuboot upstream. stm_tool.py implements the computing of board programming settings. Change-Id: I49059d543806dab198bd18e85be18cf057b82b89 Signed-off-by: Michel Jaouen <michel.jaouen@st.com>
-rwxr-xr-xplatform/ext/target/stm/stm32l5xx/boards/scripts/postbuild.sh24
-rw-r--r--platform/ext/target/stm/stm32l5xx/boards/scripts/stm_tool.py87
-rw-r--r--platform/ext/target/stm/stm32l5xx/nucleo_l552ze_q.cmake9
-rw-r--r--platform/ext/target/stm/stm32l5xx/stm32l562e_dk.cmake11
4 files changed, 102 insertions, 29 deletions
diff --git a/platform/ext/target/stm/stm32l5xx/boards/scripts/postbuild.sh b/platform/ext/target/stm/stm32l5xx/boards/scripts/postbuild.sh
index 01d39bf19..605fd0017 100755
--- a/platform/ext/target/stm/stm32l5xx/boards/scripts/postbuild.sh
+++ b/platform/ext/target/stm/stm32l5xx/boards/scripts/postbuild.sh
@@ -25,7 +25,7 @@ updatesh=$projectdir/TFM_UPDATE.sh
basedir=$projectdir
echo preprocess bl2 file
arm-none-eabi-gcc -E -P -xc -I$projectdir -o$preprocess_bl2_file $bl2_file_to_preprocess
-imgtool=$basedir"/scripts/imgtool.py"
+stm_tool=$basedir"/scripts/stm_tool.py"
#determine/check python version command
cmd="python3"
$cmd --version &> /dev/null
@@ -45,7 +45,7 @@ if [ $ret != 0 ]; then
fi
fi
-command=$cmd" "$imgtool" flash --layout "$preprocess_bl2_file" -b secbootadd0 -m RE_BL2_BOOT_ADDRESS -d 0x80 -s 0 "$regressionsh
+command=$cmd" "$stm_tool" flash --layout "$preprocess_bl2_file" -b secbootadd0 -m RE_BL2_BOOT_ADDRESS -d 0x80 -s 0 "$regressionsh
$command >> $projectdir"/output.txt"
ret=$?
if [ $ret != 0 ]; then
@@ -54,7 +54,7 @@ echo $command
exit 1
fi
-command=$cmd" "$imgtool" flash --layout "$preprocess_bl2_file" -b boot -m RE_BL2_PERSO_ADDRESS -s 0 "$updatesh
+command=$cmd" "$stm_tool" flash --layout "$preprocess_bl2_file" -b boot -m RE_BL2_PERSO_ADDRESS -s 0 "$updatesh
$command >> $projectdir"/output.txt"
ret=$?
if [ $ret != 0 ]; then
@@ -63,7 +63,7 @@ echo $command
exit 1
fi
-command=$cmd" "$imgtool" flash --layout "$preprocess_bl2_file" -b slot0 -m RE_IMAGE_FLASH_ADDRESS_SECURE -s 0 "$updatesh
+command=$cmd" "$stm_tool" flash --layout "$preprocess_bl2_file" -b slot0 -m RE_IMAGE_FLASH_ADDRESS_SECURE -s 0 "$updatesh
$command >> $projectdir"/output.txt"
ret=$?
if [ $ret != 0 ]; then
@@ -73,7 +73,7 @@ exit 1
fi
echo $updatebat" updated"
-command=$cmd" "$imgtool" flash --layout "$preprocess_bl2_file" -b slot1 -m RE_IMAGE_FLASH_ADDRESS_NON_SECURE -s 0 "$updatesh
+command=$cmd" "$stm_tool" flash --layout "$preprocess_bl2_file" -b slot1 -m RE_IMAGE_FLASH_ADDRESS_NON_SECURE -s 0 "$updatesh
$command >> $projectdir"/output.txt"
ret=$?
if [ $ret != 0 ]; then
@@ -82,7 +82,7 @@ echo $command
exit 1
fi
echo $updatebat" updated"
-command=$cmd" "$imgtool" flash --layout "$preprocess_bl2_file" -b slot2 -m RE_IMAGE_FLASH_SECURE_UPDATE -s 0 "$updatesh
+command=$cmd" "$stm_tool" flash --layout "$preprocess_bl2_file" -b slot2 -m RE_IMAGE_FLASH_SECURE_UPDATE -s 0 "$updatesh
$command >> $projectdir"/output.txt"
ret=$?
if [ $ret != 0 ]; then
@@ -91,7 +91,7 @@ echo $command
exit 1
fi
echo $updatebat" updated"
-command=$cmd" "$imgtool" flash --layout "$preprocess_bl2_file" -b slot3 -m RE_IMAGE_FLASH_NON_SECURE_UPDATE -s 0 "$updatesh
+command=$cmd" "$stm_tool" flash --layout "$preprocess_bl2_file" -b slot3 -m RE_IMAGE_FLASH_NON_SECURE_UPDATE -s 0 "$updatesh
$command >> $projectdir"/output.txt"
ret=$?
if [ $ret != 0 ]; then
@@ -100,7 +100,7 @@ echo $command
exit 1
fi
echo $updatebat" updated"
-command=$cmd" "$imgtool" flash --layout "$preprocess_bl2_file" -b scratch -m RE_IMAGE_FLASH_SCRATCH -s 0 "$updatesh
+command=$cmd" "$stm_tool" flash --layout "$preprocess_bl2_file" -b scratch -m RE_IMAGE_FLASH_SCRATCH -s 0 "$updatesh
$command >> $projectdir"/output.txt"
ret=$?
if [ $ret != 0 ]; then
@@ -109,7 +109,7 @@ echo $command
exit 1
fi
echo $updatebat" updated"
-command=$cmd" "$imgtool" flash --layout "$preprocess_bl2_file" -b nvcounter -m RE_IMAGE_FLASH_NV_COUNTERS -s 0 "$updatesh
+command=$cmd" "$stm_tool" flash --layout "$preprocess_bl2_file" -b nvcounter -m RE_IMAGE_FLASH_NV_COUNTERS -s 0 "$updatesh
$command >> $projectdir"/output.txt"
ret=$?
if [ $ret != 0 ]; then
@@ -118,7 +118,7 @@ echo $command
exit 1
fi
echo $updatebat" updated"
-command=$cmd" "$imgtool" flash --layout "$preprocess_bl2_file" -b sst -m RE_IMAGE_FLASH_NV_PS -s 0 "$updatesh
+command=$cmd" "$stm_tool" flash --layout "$preprocess_bl2_file" -b sst -m RE_IMAGE_FLASH_NV_PS -s 0 "$updatesh
$command >> $projectdir"/output.txt"
ret=$?
if [ $ret != 0 ]; then
@@ -127,7 +127,7 @@ echo $command
exit 1
fi
echo $updatebat" updated"
-command=$cmd" "$imgtool" flash --layout "$preprocess_bl2_file" -b its -m RE_IMAGE_FLASH_NV_ITS -s 0 "$updatesh
+command=$cmd" "$stm_tool" flash --layout "$preprocess_bl2_file" -b its -m RE_IMAGE_FLASH_NV_ITS -s 0 "$updatesh
$command >> $projectdir"/output.txt"
ret=$?
if [ $ret != 0 ]; then
@@ -136,7 +136,7 @@ echo $command
exit 1
fi
echo $updatebat" updated"
-command=$cmd" "$imgtool" flash --layout "$preprocess_bl2_file" -b unused -m RE_IMAGE_FLASH_UNUSED -s 0 "$updatesh
+command=$cmd" "$stm_tool" flash --layout "$preprocess_bl2_file" -b unused -m RE_IMAGE_FLASH_UNUSED -s 0 "$updatesh
$command >> $projectdir"/output.txt"
ret=$?
if [ $ret != 0 ]; then
diff --git a/platform/ext/target/stm/stm32l5xx/boards/scripts/stm_tool.py b/platform/ext/target/stm/stm32l5xx/boards/scripts/stm_tool.py
new file mode 100644
index 000000000..6295ed8b7
--- /dev/null
+++ b/platform/ext/target/stm/stm32l5xx/boards/scripts/stm_tool.py
@@ -0,0 +1,87 @@
+#! /usr/bin/env python3
+#
+# Copyright 2017 Linaro Limited
+# Copyright (c) 2018-2019, Arm Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from __future__ import print_function
+import os
+import re
+import argparse
+
+import sys
+import macro_parser
+import fileinput
+
+
+def do_flash(args):
+ image_value_re = re.compile(r"^\s*"+args.macro+"\s*=\s*(.*)")
+ value = macro_parser.evaluate_macro(args.layout, image_value_re, 0, 1,
+ True)
+ if args.setting == 1:
+ begin_line="set "+args.begin
+ else:
+ begin_line=args.begin
+
+ for line in fileinput.input(args.infile, inplace=True):
+ if line.startswith(begin_line):
+ if args.division:
+ value = int(value/int(args.division))
+ if args.phexa == 0:
+ line = begin_line+"="+str(value)+"\n"
+ else:
+ line = begin_line+"="+hex(value)+"\n"
+ sys.stdout.write(line)
+
+subcmds = {
+ 'flash': do_flash, }
+
+
+def intparse(text):
+ """Parse a command line argument as an integer.
+
+ Accepts 0x and other prefixes to allow other bases to be used."""
+ return int(text, 0)
+
+def args():
+ parser = argparse.ArgumentParser()
+ subs = parser.add_subparsers(help='subcommand help', dest='subcmd')
+
+
+ flash = subs.add_parser('flash', help='modify flash script')
+ flash.add_argument("infile")
+ flash.add_argument('-l', '--layout', required=True,
+ help='Location of the file that contains preprocessed macros')
+ flash.add_argument('-m', '--macro', required =True,
+ help='macro symbol string to grep in preprocessed file')
+ flash.add_argument('-b', '--begin', required=True,
+ help='begin of line to replace ')
+ flash.add_argument('-s', '--setting',type=intparse,required=False,default=0,
+ help='search for window batch set variable')
+ flash.add_argument('-d', '--division',
+ required=False,type=intparse,default=0,
+ help='search for window batch set variable')
+ flash.add_argument('-p', '--phexa',
+ required=False,type=intparse,default=1,
+ help='print value in hexa')
+
+ args = parser.parse_args()
+ if args.subcmd is None:
+ print('Must specify a subcommand', file=sys.stderr)
+ sys.exit(1)
+
+ subcmds[args.subcmd](args)
+
+if __name__ == '__main__':
+ args()
diff --git a/platform/ext/target/stm/stm32l5xx/nucleo_l552ze_q.cmake b/platform/ext/target/stm/stm32l5xx/nucleo_l552ze_q.cmake
index d501d9da0..a8f2daf5e 100644
--- a/platform/ext/target/stm/stm32l5xx/nucleo_l552ze_q.cmake
+++ b/platform/ext/target/stm/stm32l5xx/nucleo_l552ze_q.cmake
@@ -133,16 +133,9 @@ if (NOT ${MCUBOOT_UPGRADE_STRATEGY} STREQUAL "OVERWRITE_ONLY")
endif()
#install files reuqired for flashing and performing regression
install(FILES
- ${PLATFORM_DIR}/../../bl2/ext/mcuboot/scripts/imgtool.py
+ ${PLATFORM_DIR}/target/stm/stm32l5xx/boards/scripts/stm_tool.py
${PLATFORM_DIR}/../../bl2/ext/mcuboot/scripts/macro_parser.py
DESTINATION ./scripts/ )
-install(FILES
- ${PLATFORM_DIR}/../../bl2/ext/mcuboot/scripts/imgtool_lib/image.py
- ${PLATFORM_DIR}/../../bl2/ext/mcuboot/scripts/imgtool_lib/boot_record.py
- ${PLATFORM_DIR}/../../bl2/ext/mcuboot/scripts/imgtool_lib/keys.py
- ${PLATFORM_DIR}/../../bl2/ext/mcuboot/scripts/imgtool_lib/version.py
- ${PLATFORM_DIR}/../../bl2/ext/mcuboot/scripts/imgtool_lib/__init__.py
- DESTINATION ./scripts/imgtool_lib )
install(FILES ${PLATFORM_DIR}/target/stm/stm32l5xx/boards/stm32l562e_dk/flash_layout.h
${PLATFORM_DIR}/target/stm/stm32l5xx/boards/stm32l562e_dk/region_defs.h
DESTINATION ./ )
diff --git a/platform/ext/target/stm/stm32l5xx/stm32l562e_dk.cmake b/platform/ext/target/stm/stm32l5xx/stm32l562e_dk.cmake
index eb069c48f..7856e81fc 100644
--- a/platform/ext/target/stm/stm32l5xx/stm32l562e_dk.cmake
+++ b/platform/ext/target/stm/stm32l5xx/stm32l562e_dk.cmake
@@ -130,18 +130,11 @@ if (NOT ${MCUBOOT_UPGRADE_STRATEGY} STREQUAL "OVERWRITE_ONLY")
message(WARNING "OVERWRITE ONLY upgrade strategy is preferred on target '${TARGET_PLATFORM}'. Your choice was overriden.")
set(MCUBOOT_UPGRADE_STRATEGY "OVERWRITE_ONLY")
endif()
-#install files reuqired for flashing and performing regression
+#install files required for flashing and performing regression
install(FILES
- ${PLATFORM_DIR}/../../bl2/ext/mcuboot/scripts/imgtool.py
+ ${PLATFORM_DIR}/target/stm/stm32l5xx/boards/scripts/stm_tool.py
${PLATFORM_DIR}/../../bl2/ext/mcuboot/scripts/macro_parser.py
DESTINATION ./scripts/ )
-install(FILES
- ${PLATFORM_DIR}/../../bl2/ext/mcuboot/scripts/imgtool_lib/image.py
- ${PLATFORM_DIR}/../../bl2/ext/mcuboot/scripts/imgtool_lib/boot_record.py
- ${PLATFORM_DIR}/../../bl2/ext/mcuboot/scripts/imgtool_lib/keys.py
- ${PLATFORM_DIR}/../../bl2/ext/mcuboot/scripts/imgtool_lib/version.py
- ${PLATFORM_DIR}/../../bl2/ext/mcuboot/scripts/imgtool_lib/__init__.py
- DESTINATION ./scripts/imgtool_lib )
install(FILES ${PLATFORM_DIR}/target/stm/stm32l5xx/boards/stm32l562e_dk/flash_layout.h
${PLATFORM_DIR}/target/stm/stm32l5xx/boards/stm32l562e_dk/region_defs.h
DESTINATION ./ )