From d13a85969210fef2fa11e7544dd536b50b2071d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Baczma=C5=84ski?= Date: Wed, 11 Sep 2024 16:24:02 +0200 Subject: [PATCH] Refactor ncs build script (#86) Refactor ncs build script to reduce build time and align with ot building calls. Signed-off-by: Maciej Baczmanski --- ...i-1_1.conf => overlay-ot-cli-ftd-1.1.conf} | 0 ...i-1_2.conf => overlay-ot-cli-ftd-1.2.conf} | 0 ...i-1_3.conf => overlay-ot-cli-ftd-1.3.conf} | 0 ...i-1_4.conf => overlay-ot-cli-ftd-1.4.conf} | 0 ...y-rcp-1_2.conf => overlay-ot-rcp-1.2.conf} | 0 ...y-rcp-1_3.conf => overlay-ot-rcp-1.3.conf} | 0 ...y-rcp-1_4.conf => overlay-ot-rcp-1.4.conf} | 0 script/make-firmware.bash | 157 +++++++++--------- 8 files changed, 76 insertions(+), 81 deletions(-) rename config/ncs/{overlay-cli-1_1.conf => overlay-ot-cli-ftd-1.1.conf} (100%) rename config/ncs/{overlay-cli-1_2.conf => overlay-ot-cli-ftd-1.2.conf} (100%) rename config/ncs/{overlay-cli-1_3.conf => overlay-ot-cli-ftd-1.3.conf} (100%) rename config/ncs/{overlay-cli-1_4.conf => overlay-ot-cli-ftd-1.4.conf} (100%) rename config/ncs/{overlay-rcp-1_2.conf => overlay-ot-rcp-1.2.conf} (100%) rename config/ncs/{overlay-rcp-1_3.conf => overlay-ot-rcp-1.3.conf} (100%) rename config/ncs/{overlay-rcp-1_4.conf => overlay-ot-rcp-1.4.conf} (100%) diff --git a/config/ncs/overlay-cli-1_1.conf b/config/ncs/overlay-ot-cli-ftd-1.1.conf similarity index 100% rename from config/ncs/overlay-cli-1_1.conf rename to config/ncs/overlay-ot-cli-ftd-1.1.conf diff --git a/config/ncs/overlay-cli-1_2.conf b/config/ncs/overlay-ot-cli-ftd-1.2.conf similarity index 100% rename from config/ncs/overlay-cli-1_2.conf rename to config/ncs/overlay-ot-cli-ftd-1.2.conf diff --git a/config/ncs/overlay-cli-1_3.conf b/config/ncs/overlay-ot-cli-ftd-1.3.conf similarity index 100% rename from config/ncs/overlay-cli-1_3.conf rename to config/ncs/overlay-ot-cli-ftd-1.3.conf diff --git a/config/ncs/overlay-cli-1_4.conf b/config/ncs/overlay-ot-cli-ftd-1.4.conf similarity index 100% rename from config/ncs/overlay-cli-1_4.conf rename to config/ncs/overlay-ot-cli-ftd-1.4.conf diff --git a/config/ncs/overlay-rcp-1_2.conf b/config/ncs/overlay-ot-rcp-1.2.conf similarity index 100% rename from config/ncs/overlay-rcp-1_2.conf rename to config/ncs/overlay-ot-rcp-1.2.conf diff --git a/config/ncs/overlay-rcp-1_3.conf b/config/ncs/overlay-ot-rcp-1.3.conf similarity index 100% rename from config/ncs/overlay-rcp-1_3.conf rename to config/ncs/overlay-ot-rcp-1.3.conf diff --git a/config/ncs/overlay-rcp-1_4.conf b/config/ncs/overlay-ot-rcp-1.4.conf similarity index 100% rename from config/ncs/overlay-rcp-1_4.conf rename to config/ncs/overlay-ot-rcp-1.4.conf diff --git a/script/make-firmware.bash b/script/make-firmware.bash index ccbb0b5..fcd463e 100755 --- a/script/make-firmware.bash +++ b/script/make-firmware.bash @@ -272,6 +272,70 @@ nrfutil_setup() fi } +deploy_ncs() +{ + local commit_hash + commit_hash=$(<"${script_dir}"'/../config/ncs/sdk-nrf-commit') + + sudo apt install --no-install-recommends git cmake ninja-build gperf \ + ccache dfu-util device-tree-compiler wget \ + python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \ + make gcc gcc-multilib g++-multilib libsdl2-dev + pip3 install --user west + mkdir -p "${script_dir}"/../ncs + cd "${script_dir}"/../ncs + unset ZEPHYR_BASE + west init -m https://github.com/nrfconnect/sdk-nrf --mr main || true + cd nrf + git fetch origin + git reset --hard "$commit_hash" || die "ERROR: unable to checkout the specified sdk-nrf commit." + west update -n -o=--depth=1 + cd .. + pip3 install --user -r zephyr/scripts/requirements.txt + pip3 install --user -r nrf/scripts/requirements.txt + pip3 install --user -r bootloader/mcuboot/scripts/requirements.txt + + # shellcheck disable=SC1091 + source zephyr/zephyr-env.sh + west config manifest.path nrf +} + +build_ncs() +{ + mkdir -p "$OUTPUT_ROOT" + deploy_ncs + cd nrf + + thread_version=${thread_version?} + local timestamp=$(date +%Y%m%d) + local commit_id=$(git rev-parse --short HEAD) + + # variant is a list of entries: "app:sample_name" + local variants + case "${thread_version}" in + 1.1) + variants=("ot-cli-ftd:cli") + ;; + *) + variants=("ot-cli-ftd:cli" "ot-rcp:coprocessor") + ;; + + esac + + for variant in "${variants[@]}"; do + local app=$(echo $variant | cut -d':' -f1) + local sample_name=$(echo $variant | cut -d':' -f2) + local sample_path="samples/openthread/${sample_name}" + local sample_config="${script_dir}/../config/ncs/overlay-${app}-${thread_version}.conf" + local build_path="/tmp/ncs_${app}_${thread_version}" + local hex_path="${build_path}/${sample_name}/zephyr/zephyr.hex" + + west build -d "${build_path}" -b nrf52840dongle/nrf52840 -p always "${sample_path}" --sysbuild -- -DOVERLAY_CONFIG="${sample_config}" + + distribute "${hex_path}" "${app}" "${thread_version}" "${timestamp}" "${commit_id}" + done +} + build() { if [ "${REFERENCE_RELEASE_TYPE?}" = "1.2" ]; then @@ -287,6 +351,10 @@ build() thread_version=1.2 build_type="USB_trans" build_ot "${build_1_2_options[@]}" "$@" thread_version=1.1 build_type="USB_trans" build_ot "${build_1_1_env[@]}" "$@" ;; + ncs) + thread_version=1.2 build_ncs + thread_version=1.1 build_ncs + ;; esac elif [ "${REFERENCE_RELEASE_TYPE}" = "1.3" ]; then options=("${build_1_3_options_common[@]}") @@ -303,6 +371,9 @@ build() build_script_flags=("--skip-silabs-apps") thread_version=1.3 build_ot "-DBOARD=brd4166a" "${options[@]}" "$@" ;; + ncs) + thread_version=1.3 build_ncs + ;; esac elif [ "${REFERENCE_RELEASE_TYPE}" = "1.4" ]; then options=("${build_1_4_options_common[@]}") @@ -319,85 +390,15 @@ build() build_script_flags=("--skip-silabs-apps") thread_version=1.4 build_ot "-DBOARD=brd4166a" "${options[@]}" "$@" ;; + ncs) + thread_version=1.4 build_ncs + ;; esac else die "Error: REFERENCE_RELEASE_TYPE = ${REFERENCE_RELEASE_TYPE} is unsupported" fi } -deploy_ncs() -{ - local commit_hash - commit_hash=$(<"${script_dir}"'/../config/ncs/sdk-nrf-commit') - - sudo apt install --no-install-recommends git cmake ninja-build gperf \ - ccache dfu-util device-tree-compiler wget \ - python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \ - make gcc gcc-multilib g++-multilib libsdl2-dev - pip3 install --user west - mkdir -p "${script_dir}"/../ncs - cd "${script_dir}"/../ncs - unset ZEPHYR_BASE - west init -m https://github.com/nrfconnect/sdk-nrf --mr main || true - cd nrf - git fetch origin - git reset --hard "$commit_hash" || die "ERROR: unable to checkout the specified sdk-nrf commit." - west update -n -o=--depth=1 - cd .. - pip3 install --user -r zephyr/scripts/requirements.txt - pip3 install --user -r nrf/scripts/requirements.txt - pip3 install --user -r bootloader/mcuboot/scripts/requirements.txt - - # shellcheck disable=SC1091 - source zephyr/zephyr-env.sh - west config manifest.path nrf -} - -package_ncs() -{ - # Get build info - local commit_id - local timestamp - commit_id=$(git rev-parse --short HEAD) - timestamp=$(date +%Y%m%d) - - distribute "/tmp/ncs_cli_1_1/cli/zephyr/zephyr.hex" "ot-cli-ftd" "1.1" "${timestamp}" "${commit_id}" - distribute "/tmp/ncs_cli_1_2/cli/zephyr/zephyr.hex" "ot-cli-ftd" "1.2" "${timestamp}" "${commit_id}" - distribute "/tmp/ncs_rcp_1_2/coprocessor/zephyr/zephyr.hex" "ot-rcp" "1.2" "${timestamp}" "${commit_id}" - distribute "/tmp/ncs_cli_1_3/cli/zephyr/zephyr.hex" "ot-cli-ftd" "1.3" "${timestamp}" "${commit_id}" - distribute "/tmp/ncs_rcp_1_3/coprocessor/zephyr/zephyr.hex" "ot-rcp" "1.3" "${timestamp}" "${commit_id}" - distribute "/tmp/ncs_cli_1_4/cli/zephyr/zephyr.hex" "ot-cli-ftd" "1.4" "${timestamp}" "${commit_id}" - distribute "/tmp/ncs_rcp_1_4/coprocessor/zephyr/zephyr.hex" "ot-rcp" "1.4" "${timestamp}" "${commit_id}" -} - -build_ncs() -{ - mkdir -p "$OUTPUT_ROOT" - deploy_ncs - - # Build folder | nrf-sdk sample | Sample configuration - local cli_1_1=("/tmp/ncs_cli_1_1" "samples/openthread/cli/" "${script_dir}/../config/ncs/overlay-cli-1_1.conf") - local cli_1_2=("/tmp/ncs_cli_1_2" "samples/openthread/cli/" "${script_dir}/../config/ncs/overlay-cli-1_2.conf") - local rcp_1_2=("/tmp/ncs_rcp_1_2" "samples/openthread/coprocessor/" "${script_dir}/../config/ncs/overlay-rcp-1_2.conf") - local cli_1_3=("/tmp/ncs_cli_1_3" "samples/openthread/cli/" "${script_dir}/../config/ncs/overlay-cli-1_3.conf") - local rcp_1_3=("/tmp/ncs_rcp_1_3" "samples/openthread/coprocessor/" "${script_dir}/../config/ncs/overlay-rcp-1_3.conf") - local cli_1_4=("/tmp/ncs_cli_1_4" "samples/openthread/cli/" "${script_dir}/../config/ncs/overlay-cli-1_4.conf") - local rcp_1_4=("/tmp/ncs_rcp_1_4" "samples/openthread/coprocessor/" "${script_dir}/../config/ncs/overlay-rcp-1_4.conf") - - local variants=(cli_1_1[@] cli_1_2[@] rcp_1_2[@] cli_1_3[@] rcp_1_3[@] cli_1_4[@] rcp_1_4[@]) - - cd nrf - for variant in "${variants[@]}"; do - west build -d "${!variant:0:1}" -b nrf52840dongle/nrf52840 -p always "${!variant:1:1}" --sysbuild -- -DOVERLAY_CONFIG="${!variant:2:1}" - done - - package_ncs "ot-cli-ftd" "1.1" - package_ncs "ot-cli-ftd" "1.2" - package_ncs "ot-rcp" "1.2" - package_ncs "ot-cli-ftd" "1.3" - package_ncs "ot-rcp" "1.3" -} - main() { readonly OT_PLATFORMS=(nrf52840 efr32mg12 ncs) @@ -426,14 +427,8 @@ main() nrfutil_setup ;; esac - case "${platform}" in - ncs*) - build_ncs - ;; - *) - build "$@" - ;; - esac + + build "$@" done }