From 4bacbe648f032c298bbebb35ec28f8f518833f16 Mon Sep 17 00:00:00 2001 From: enriquezgarc Date: Thu, 24 Oct 2024 15:54:43 +0200 Subject: [PATCH] ports/psoc6: Added bsp assets version control mechanism. Signed-off-by: enriquezgarc --- .../boards/CY8CKIT-062S2-AI/bsp-deps.json | 34 ++++++++ .../boards/CY8CPROTO-062-4343W/bsp-deps.json | 34 ++++++++ .../boards/CY8CPROTO-063-BLE/bsp-deps.json | 34 ++++++++ ports/psoc6/mtb-libs/makefile_mtb.mk | 2 + ports/psoc6/mtb-libs/mtb_bsp_set_deps_ver.sh | 81 +++++++++++++++++++ 5 files changed, 185 insertions(+) create mode 100644 ports/psoc6/boards/CY8CKIT-062S2-AI/bsp-deps.json create mode 100644 ports/psoc6/boards/CY8CPROTO-062-4343W/bsp-deps.json create mode 100644 ports/psoc6/boards/CY8CPROTO-063-BLE/bsp-deps.json create mode 100755 ports/psoc6/mtb-libs/mtb_bsp_set_deps_ver.sh diff --git a/ports/psoc6/boards/CY8CKIT-062S2-AI/bsp-deps.json b/ports/psoc6/boards/CY8CKIT-062S2-AI/bsp-deps.json new file mode 100644 index 000000000000..5768a7c1365d --- /dev/null +++ b/ports/psoc6/boards/CY8CKIT-062S2-AI/bsp-deps.json @@ -0,0 +1,34 @@ +[ + { + "asset-name": "cat1cm0p", + "locked-commit": "release-v1.7.0" + }, + { + "asset-name": "cmsis", + "locked-commit": "release-v5.8.1" + }, + { + "asset-name": "core-lib", + "locked-commit": "release-v1.4.2" + }, + { + "asset-name": "core-make", + "locked-commit": "release-v3.3.1" + }, + { + "asset-name": "device-db", + "locked-commit": "release-v4.18.0" + }, + { + "asset-name": "mtb-hal-cat1", + "locked-commit": "release-v2.6.1" + }, + { + "asset-name": "mtb-pdl-cat1", + "locked-commit": "release-v3.12.0" + }, + { + "asset-name": "recipe-make-cat1a", + "locked-commit": "release-v2.2.1" + } +] \ No newline at end of file diff --git a/ports/psoc6/boards/CY8CPROTO-062-4343W/bsp-deps.json b/ports/psoc6/boards/CY8CPROTO-062-4343W/bsp-deps.json new file mode 100644 index 000000000000..5768a7c1365d --- /dev/null +++ b/ports/psoc6/boards/CY8CPROTO-062-4343W/bsp-deps.json @@ -0,0 +1,34 @@ +[ + { + "asset-name": "cat1cm0p", + "locked-commit": "release-v1.7.0" + }, + { + "asset-name": "cmsis", + "locked-commit": "release-v5.8.1" + }, + { + "asset-name": "core-lib", + "locked-commit": "release-v1.4.2" + }, + { + "asset-name": "core-make", + "locked-commit": "release-v3.3.1" + }, + { + "asset-name": "device-db", + "locked-commit": "release-v4.18.0" + }, + { + "asset-name": "mtb-hal-cat1", + "locked-commit": "release-v2.6.1" + }, + { + "asset-name": "mtb-pdl-cat1", + "locked-commit": "release-v3.12.0" + }, + { + "asset-name": "recipe-make-cat1a", + "locked-commit": "release-v2.2.1" + } +] \ No newline at end of file diff --git a/ports/psoc6/boards/CY8CPROTO-063-BLE/bsp-deps.json b/ports/psoc6/boards/CY8CPROTO-063-BLE/bsp-deps.json new file mode 100644 index 000000000000..5768a7c1365d --- /dev/null +++ b/ports/psoc6/boards/CY8CPROTO-063-BLE/bsp-deps.json @@ -0,0 +1,34 @@ +[ + { + "asset-name": "cat1cm0p", + "locked-commit": "release-v1.7.0" + }, + { + "asset-name": "cmsis", + "locked-commit": "release-v5.8.1" + }, + { + "asset-name": "core-lib", + "locked-commit": "release-v1.4.2" + }, + { + "asset-name": "core-make", + "locked-commit": "release-v3.3.1" + }, + { + "asset-name": "device-db", + "locked-commit": "release-v4.18.0" + }, + { + "asset-name": "mtb-hal-cat1", + "locked-commit": "release-v2.6.1" + }, + { + "asset-name": "mtb-pdl-cat1", + "locked-commit": "release-v3.12.0" + }, + { + "asset-name": "recipe-make-cat1a", + "locked-commit": "release-v2.2.1" + } +] \ No newline at end of file diff --git a/ports/psoc6/mtb-libs/makefile_mtb.mk b/ports/psoc6/mtb-libs/makefile_mtb.mk index 45e95517ccb3..45076bba99dc 100644 --- a/ports/psoc6/mtb-libs/makefile_mtb.mk +++ b/ports/psoc6/mtb-libs/makefile_mtb.mk @@ -49,6 +49,8 @@ mtb_config_deps: $(info Configuring ModusToolbox dependencies ...) $(info mtb_deps_dir : $(MTB_LIBS_DIR)/deps/$(MTB_DEPS_DIRS)/) $(Q) $(foreach DIR, $(MTB_DEPS_DIRS), $(shell cp -r $(MTB_LIBS_DIR)/deps/$(DIR)/. $(MTB_LIBS_DIR)/deps)) + $(info mtb_bsp_deps_dir : Updating dependencies for $(BOARD) ...) + $(Q) bash $(MTB_LIBS_DIR)/mtb_bsp_set_deps_ver.sh $(BOARD) mtb_get_libs: mtb_config_deps $(info ) diff --git a/ports/psoc6/mtb-libs/mtb_bsp_set_deps_ver.sh b/ports/psoc6/mtb-libs/mtb_bsp_set_deps_ver.sh new file mode 100755 index 000000000000..86fdf26d87c2 --- /dev/null +++ b/ports/psoc6/mtb-libs/mtb_bsp_set_deps_ver.sh @@ -0,0 +1,81 @@ +#!/usr/bin/bash + +# This script will be use to set the dependencies version in the bsps deps/ folder. + +# Why we need this script? +# -------------------------------- +# The ModusTooolbox sets a fix version for the bsp repo sources, but the version of the dependencies +# are not fixed. They are handled by the manifest system instead. +# As we are not keeping these bsps under version control, but we retrieve them when initializing +# the project, we will always get the latest version of the bsp dependencies (according to the manifest configuration). +# We donĀ“t want libraries to be updated without our knowledge, so we will set the dependencies version with this script. + +# Move to the directory where the script is located +cd "$(dirname "$0")" + +board=$1 +# Pass "-d" as the second argument to enable debug mode +debug=$2 + +json_file_default_name="bsp-deps.json" +json_file="../boards/$board/$json_file_default_name" +bsp_deps_dir="bsps/TARGET_APP_$board/deps" + +if [ ! -f "$json_file" ]; then + echo "JSON file not found: $json_file" + exit 1 +fi + +# Read the JSON file line by line +while IFS= read -r line; do + # Extract the asset-name + if [[ $line =~ \"asset-name\":\ \"([^\"]+)\" ]]; then + asset_name="${BASH_REMATCH[1]}" + fi + + # Extract the locked-commit + if [[ $line =~ \"locked-commit\":\ \"([^\"]+)\" ]]; then + locked_commit="${BASH_REMATCH[1]}" + + # Print the extracted values if -d flag is passed + if [ "$debug" == "-d" ]; then + echo "Asset Name: $asset_name" + echo "Locked Commit: $locked_commit" + echo "-------------------------" + fi + + # Iterate over each file in the BSP_DEPS_DIR directory + for file in "$bsp_deps_dir"/*; do + if [ -f "$file" ]; then + # Get the file name without the extension + filename=$(basename -- "$file") + filename="${filename%.*}" + + # Check if the file name matches the asset name + if [ "$filename" == "$asset_name" ]; then + + if [ "$debug" == "-d" ]; then + echo "Match found: $file matches asset name $asset_name" + fi + + # Read the content of the .mtbx file + content=$(cat "$file") + + # Replace the version pattern with the locked-commit value + updated_content=$(echo "$content" | sed -E "s/release-v[0-9]+\.[0-9]+\.[0-9]+/$locked_commit/g") + + # Write the updated content back to the .mtbx file + echo "$updated_content" > "$file" + + echo "Updated $file with locked commit $locked_commit" + else + if [ "$debug" == "-d" ]; then + echo "No match: $file does not match asset name $asset_name" + fi + fi + fi + done + fi +done < "$json_file" + +exit 0 \ No newline at end of file