Skip to content

Commit

Permalink
Refactor ncs build script
Browse files Browse the repository at this point in the history
Refactor ncs build script to reduce build time and align with
ot building calls.

Signed-off-by: Maciej Baczmanski <[email protected]>
  • Loading branch information
maciejbaczmanski committed Sep 4, 2024
1 parent 89a78e6 commit 70a0539
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 81 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
157 changes: 76 additions & 81 deletions script/make-firmware.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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[@]}")
Expand All @@ -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[@]}")
Expand All @@ -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)
Expand Down Expand Up @@ -426,14 +427,8 @@ main()
nrfutil_setup
;;
esac
case "${platform}" in
ncs*)
build_ncs
;;
*)
build "$@"
;;
esac

build "$@"
done

}
Expand Down

0 comments on commit 70a0539

Please sign in to comment.