summaryrefslogtreecommitdiff
path: root/ports_arch/ARMv8-A/update.sh
diff options
context:
space:
mode:
Diffstat (limited to 'ports_arch/ARMv8-A/update.sh')
-rwxr-xr-xports_arch/ARMv8-A/update.sh191
1 files changed, 191 insertions, 0 deletions
diff --git a/ports_arch/ARMv8-A/update.sh b/ports_arch/ARMv8-A/update.sh
new file mode 100755
index 00000000..4084d33f
--- /dev/null
+++ b/ports_arch/ARMv8-A/update.sh
@@ -0,0 +1,191 @@
+#!/bin/bash
+##############################################################################
+# Copyright (C) 2026 Eclipse ThreadX contributors
+#
+# This program and the accompanying materials are made available under the
+# terms of the MIT License which is available at
+# https://opensource.org/licenses/MIT.
+#
+# AI Disclosure: This file was largely AI-generated by Claude Code (Opus 5).
+# The AI-generated portions may be considered public domain (CC0-1.0)
+# and not subject to the project's licence. The human contributor has
+# reviewed and verified that the code is correct.
+#
+# SPDX-License-Identifier: MIT and CC0-1.0
+##############################################################################
+
+# Update the ARMv8-A ports from the generic ARMv8-A port, generating ports and
+# examples from the common files. This is a port of update.ps1 beside it, which
+# needs PowerShell and so could only be run on Windows. The two are kept
+# equivalent: same cores, same compilers, same copy sets and the same patches.
+#
+# To update the ThreadX ports for the source tree:
+# ./update.sh --port-sets tx --copy-common-files --copy-port-files \
+# --copy-example --patch-files
+#
+# To update the ThreadX ports for the test tree:
+# ./update.sh --port-sets tx --copy-common-files --copy-port-files \
+# --copy-example --copy-validation-test --copy-regression-test \
+# --patch-files
+#
+# --copy-example, --copy-validation-test and --copy-regression-test are
+# accepted and ignored, exactly as in update.ps1, where they are declared as
+# parameters but never consulted. They are kept so that both scripts take the
+# same command line.
+
+set -eu
+
+cd "$(dirname "$(realpath "$0")")"
+
+cores="cortex_a34 cortex_a35 cortex_a53 cortex_a55 cortex_a57 cortex_a65 cortex_a65ae \
+ cortex_a72 cortex_a73 cortex_a75 cortex_a76 cortex_a76ae cortex_a77"
+
+# Cortex-A78 ships as an SMP port only: ports_smp/cortex_a78_smp exists but
+# ports/cortex_a78 does not. Listing it separately keeps the generator from
+# creating a ThreadX port that the tree has never had.
+cores_smp_only="cortex_a78"
+
+compilers="ac6 gnu"
+
+port_sets=""
+copy_common_files=0
+copy_port_files=0
+patch_files=0
+
+usage() {
+ sed -n '22,35p' "$0"
+ exit "${1:-1}"
+}
+
+while [ "$#" -gt 0 ]; do
+ case "$1" in
+ --port-sets)
+ [ "$#" -ge 2 ] || { echo "Error: --port-sets needs a value" >&2; exit 1; }
+ port_sets="$(printf '%s' "$2" | tr ',' ' ')"
+ shift 2
+ ;;
+ --copy-common-files) copy_common_files=1; shift ;;
+ --copy-port-files) copy_port_files=1; shift ;;
+ --patch-files) patch_files=1; shift ;;
+ # Accepted and ignored, as in update.ps1.
+ --copy-example|--copy-validation-test|--copy-regression-test) shift ;;
+ -h|--help) usage 0 ;;
+ *) echo "Error: unknown option '$1'" >&2; usage ;;
+ esac
+done
+
+if [ -z "${port_sets}" ]; then
+ echo "Error: --port-sets is required" >&2
+ usage
+fi
+
+for port_set in ${port_sets}; do
+ case "${port_set}" in
+ tx|tx_smp|txm|txm_smp) ;;
+ *) echo "Error: invalid port set '${port_set}'" >&2; exit 1 ;;
+ esac
+done
+
+echo "Update the ARMv8-A ports"
+
+# Copy the contents of a directory over a destination, creating what is missing
+# and overwriting what is not. This mirrors Copy-Item -Recurse -Force, which
+# merges into the destination rather than replacing it.
+copy_files() {
+ source_dir="$1"
+ destination_directory="$2"
+
+ if [ -d "${source_dir}" ]; then
+ cp -Rf "${source_dir}/." "${destination_directory}/"
+ fi
+}
+
+# Replace every occurrence of a literal string in a file, leaving the file
+# alone when it does not exist. Only the files named in the patch list below
+# are ever touched.
+patch_file() {
+ path="$1"
+ original="$2"
+ substitute="$3"
+
+ [ -f "${path}" ] || return 0
+
+ original_escaped="$(printf '%s' "${original}" | sed -e 's/[][\.*^$/&]/\\&/g')"
+ substitute_escaped="$(printf '%s' "${substitute}" | sed -e 's/[\/&]/\\&/g')"
+ sed -i "s/${original_escaped}/${substitute_escaped}/g" "${path}"
+}
+
+for port_set in ${port_sets}; do
+ case "${port_set}" in
+ tx_smp) port_set_cores="${cores} ${cores_smp_only}" ;;
+ *) port_set_cores="${cores}" ;;
+ esac
+
+ for core in ${port_set_cores}; do
+ case "${port_set}" in
+ tx) core_directory="../../ports/${core}" ;;
+ tx_smp) core_directory="../../ports_smp/${core}_smp" ;;
+ txm) core_directory="../../ports_module/${core}" ;;
+ txm_smp) core_directory="../../ports_module_smp/${core}_smp" ;;
+ esac
+
+ core_short="${core#cortex_}"
+ core_short_lower="$(printf '%s' "${core_short}" | tr '[:upper:]' '[:lower:]')"
+ core_short_upper="$(printf '%s' "${core_short}" | tr '[:lower:]' '[:upper:]')"
+
+ for compiler in ${compilers}; do
+ destination_directory="${core_directory}/${compiler}"
+ mkdir -p "${destination_directory}"
+
+ if [ "${copy_common_files}" -eq 1 ]; then
+ copy_files "threadx/common" "${destination_directory}"
+ fi
+
+ if [ "${copy_port_files}" -eq 1 ]; then
+ copy_files "threadx/ports/${compiler}" "${destination_directory}"
+ fi
+
+ if [ "${port_set}" = "tx_smp" ]; then
+ if [ "${copy_common_files}" -eq 1 ]; then
+ copy_files "threadx_smp/common" "${destination_directory}"
+ fi
+ if [ "${copy_port_files}" -eq 1 ]; then
+ copy_files "threadx_smp/ports/${compiler}" "${destination_directory}"
+ fi
+ fi
+
+ if [ "${patch_files}" -eq 1 ]; then
+ neon='Cortex-A35.AArch64.ARMv8.Neon.Crypto'
+
+ sample_cproject="${destination_directory}/example_build/sample_threadx/.cproject"
+ patch_file "${sample_cproject}" 'value="cortex-a35"' "value=\"cortex-${core_short_lower}\""
+ patch_file "${sample_cproject}" "${neon}" "Cortex-${core_short_upper}.AArch64.ARMv8.Neon.Crypto"
+
+ tx_cproject="${destination_directory}/example_build/tx/.cproject"
+ patch_file "${tx_cproject}" 'value="cortex-a35"' "value=\"cortex-${core_short_lower}\""
+ patch_file "${tx_cproject}" "${neon}" "Cortex-${core_short_upper}.AArch64.ARMv8.Neon.Crypto"
+
+ launch="${destination_directory}/example_build/sample_threadx/sample_threadx.launch"
+ patch_file "${launch}" 'Debug Cortex-A35' "Debug Cortex-${core_short_upper}"
+ for count in 1 2 4; do
+ patch_file "${launch}" "Base_A35x${count}" "Base_${core_short_upper}x${count}"
+ # The config database taxonomy id is spelt in lower case in
+ # the launch files, so the search string must be too. It
+ # used to read base_A35x, which matched nothing and left
+ # every port pointing at the A35 platform. The ARMv7-A
+ # generator gets this right, which is why its ports carry a
+ # per-core ve_cortex_a<n>x1 id.
+ patch_file "${launch}" "base_a35x${count}" "base_${core_short_lower}x${count}"
+ patch_file "${launch}" "FVP_Base_Cortex-A35x${count}" "FVP_Base_Cortex-${core_short_upper}x${count}"
+ # The SMP launch files name the activity "Cortex-A35x4 SMP"
+ # rather than "Debug Cortex-A35", so the rule above does not
+ # reach them. Match the " SMP" suffix so this cannot also
+ # rewrite the FVP model name handled on the line above.
+ patch_file "${launch}" "Cortex-A35x${count} SMP" "Cortex-${core_short_upper}x${count} SMP"
+ done
+ fi
+ done
+ done
+done
+
+echo "Done."