#!/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 ARMv7-A ports from the generic ARMv7-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_a5 cortex_a7 cortex_a8 cortex_a9 cortex_a12 cortex_a15 cortex_a17" 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 ARMv7-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 for core in ${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 sample_cproject="${destination_directory}/example_build/sample_threadx/.cproject" patch_file "${sample_cproject}" 'value="cortex-a7"' "value=\"cortex-${core_short_lower}\"" patch_file "${sample_cproject}" 'Cortex-A7.NoFPU' "Cortex-${core_short_upper}.NoFPU" tx_cproject="${destination_directory}/example_build/tx/.cproject" patch_file "${tx_cproject}" 'value="cortex-a7"' "value=\"cortex-${core_short_lower}\"" patch_file "${tx_cproject}" 'Cortex-A7.NoFPU' "Cortex-${core_short_upper}.NoFPU" launch="${destination_directory}/example_build/sample_threadx/sample_threadx.launch" patch_file "${launch}" 'Debug Cortex-A7' "Debug Cortex-${core_short_upper}" patch_file "${launch}" 'VE_Cortex_A7x1' "VE_Cortex_${core_short_upper}x1" patch_file "${launch}" 've_cortex_a7x1' "ve_cortex_${core_short_lower}x1" patch_file "${launch}" 'FVP_VE_Cortex-A7x1' "FVP_VE_Cortex-${core_short_upper}x1" fi done done done echo "Done."