Skip to content

Commit

Permalink
Make telink compile in the vscode image using build_example.py (#9535)
Browse files Browse the repository at this point in the history
* Remove need for TELINK_TOOLCHAIN in the exampels build script.

Since #9163, this environment variable is not used anymore.

* Make telink build in vscode image, update vscode image to export more useful build variables

* Update unit test for build commands

* Remove telink example script, use unified build script

* Add TELINK_ZEPHYR_BASE in the telink docker image

* Restyle fixes

* Ensure cmd is initialized in telink

* Ensure cmd is initialized in telink

* Ensure cmd is initialized in telink

* Fix order of environment validation

* Fix build documentation for telink: output path and requirement for bootstrap

* allow for telink gen, fix up all platform commands constants

* Fix more placeholders in the scripts unit test
  • Loading branch information
andy31415 authored Sep 10, 2021
1 parent 7b60fed commit 5d2654a
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 79 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/examples-telink.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@ jobs:
uses: actions/checkout@v2
with:
submodules: true
- name: Build example Telink Lighting App on TLSR9518ADK80D
run: scripts/examples/telink_example.sh lighting-app tlsr9518adk80d
- name: Build example Telink Lighting App
run: |
./scripts/run_in_build_env.sh \
"./scripts/build/build_examples.py --no-log-timestamps --platform telink --app light build"
3 changes: 2 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@
"host",
"nrf",
"qpg",
"infineon"
"infineon",
"telink"
],
"default": "build"
},
Expand Down
12 changes: 10 additions & 2 deletions examples/lighting-app/telink/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,21 @@
here `${CHIP_BASE}` is directory which contains CHIP repo files **!!!Pay
attention that OUTPUT_DIR should conatins ABSOLUTE path to output dir**
1. Bootstrap the build environment:
```
source ./scripts/bootstrap.sh
```
1. Run build script:
```
cd /root/chip/scripts/examples && ./telink_example.sh lighting-app tlsr9518adk80d
./scripts/build/build_examples.py --app light --platform telink build
```
1. Exit docker container and collect build artifacts. Firmware binary would be
located in
**\${CHIP_BASE}/examples/lighting-app/telink/build/tlsr9518adk80d/zephyr/zephyr.bin**
**\${CHIP_BASE}/out/telink-tlsr9518adk80d-light/zephyr/zephyr.bin**
## Flash
Expand Down
1 change: 1 addition & 0 deletions integrations/docker/images/chip-build-telink/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ RUN apt update \
&& python3 -m pip install -U pip \
&& pip3 install --user -r ${ZEPHYR_PROJECT_DIR}/zephyr/scripts/requirements.txt

ENV TELINK_ZEPHYR_BASE=${ZEPHYR_PROJECT_DIR}/zephyr
ENV ZEPHYR_BASE=${ZEPHYR_PROJECT_DIR}/zephyr
1 change: 1 addition & 0 deletions integrations/docker/images/chip-build-vscode/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ ENV MBED_OS_PATH=/opt/mbed-os/
ENV OPENOCD_PATH=/opt/openocd/
ENV PW_ENVIRONMENT_ROOT=/home/vscode/pigweed/env
ENV TELINK_ZEPHYR_BASE=/opt/telink/zephyrproject/zephyr
ENV TELINK_ZEPHYR_SDK_DIR=/opt/telink/zephyr-sdk-0.13.0
ENV CY_TOOLS_PATHS="/opt/ModusToolbox/tools_2.3"
ENV TIZEN_HOME /opt/tizen_sdk
2 changes: 1 addition & 1 deletion integrations/docker/images/chip-build/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.3
0.5.4
29 changes: 15 additions & 14 deletions scripts/build/builders/telink.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,25 @@ def __init__(self,
def generate(self):

if not os.path.exists(self.output_dir):
cmd = 'export ZEPHYR_BASE="$TELINK_ZEPHYR_BASE"\n'

if not self._runner.dry_run:

# Check Zephyr base
# Zephyr base
if 'TELINK_ZEPHYR_BASE' not in os.environ:
raise Exception(
"Telink builds require TELINK_ZEPHYR_BASE to be set")

# Check Telink toolchain
if 'TELINK_TOOLCHAIN_PATH' not in os.environ:
raise Exception(
"Telink requires TELINK_TOOLCHAIN_PATH to be set")

cmd = '''
source "$TELINK_ZEPHYR_BASE/zephyr-env.sh";
export ZEPHYR_TOOLCHAIN_VARIANT=cross-compile;
export CROSS_COMPILE=$TELINK_TOOLCHAIN_PATH/riscv32-elf-;
west build -d {outdir} -b {board} {sourcedir}
# TODO: remove once variable in all images
cmd = ''
if 'ZEPHYR_BASE' not in os.environ:
raise Exception(
"Telink builds require TELINK_ZEPHYR_BASE or ZEPHYR_BASE to be set")

# TODO: TELINK_ZEPHYR_SDK_DIR should be used for compilation and
# NOT hardcoding of zephyr-sdk-0.13.0
cmd += '''
export ZEPHYR_TOOLCHAIN_VARIANT=zephyr
export ZEPHYR_SDK_INSTALL_DIR="$ZEPHYR_BASE/../../zephyr-sdk-0.13.0"
source "$ZEPHYR_BASE/zephyr-env.sh";
west build --cmake-only -d {outdir} -b {board} {sourcedir}
'''.format(
outdir=shlex.quote(
self.output_dir), board=self.board.GnArgName(), sourcedir=shlex.quote(
Expand Down
29 changes: 15 additions & 14 deletions scripts/build/expected_all_platform_commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ west build --cmake-only -d {out}/nrf-nrf52840-shell -b nrf52840dk_nrf52840 {root
# Generating nrf-nrf52840-pump
bash -c 'source "$ZEPHYR_BASE/zephyr-env.sh";
export GNUARMEMB_TOOLCHAIN_PATH="$PW_PIGWEED_CIPD_INSTALL_DIR";
west build --cmake-only -d /OUTPUT/DIR/nrf-nrf52840-pump -b nrf52840dk_nrf52840 /TEST/BUILD/ROOT/examples/pump-app/nrfconnect'
west build --cmake-only -d {out}/nrf-nrf52840-pump -b nrf52840dk_nrf52840 {root}/examples/pump-app/nrfconnect'

# Generating nrf-nrf52840-pump_controller
bash -c 'source "$ZEPHYR_BASE/zephyr-env.sh";
export GNUARMEMB_TOOLCHAIN_PATH="$PW_PIGWEED_CIPD_INSTALL_DIR";
west build --cmake-only -d /OUTPUT/DIR/nrf-nrf52840-pump_controller -b nrf52840dk_nrf52840 /TEST/BUILD/ROOT/examples/pump-controller-app/nrfconnect'
west build --cmake-only -d {out}/nrf-nrf52840-pump_controller -b nrf52840dk_nrf52840 {root}/examples/pump-controller-app/nrfconnect'

# Generating nrf-nrf5340-light
bash -c 'source "$ZEPHYR_BASE/zephyr-env.sh";
Expand All @@ -97,12 +97,12 @@ west build --cmake-only -d {out}/nrf-nrf5340-shell -b nrf5340dk_nrf5340_cpuapp {
# Generating nrf-nrf5340-pump
bash -c 'source "$ZEPHYR_BASE/zephyr-env.sh";
export GNUARMEMB_TOOLCHAIN_PATH="$PW_PIGWEED_CIPD_INSTALL_DIR";
west build --cmake-only -d /OUTPUT/DIR/nrf-nrf5340-pump -b nrf5340dk_nrf5340_cpuapp /TEST/BUILD/ROOT/examples/pump-app/nrfconnect'
west build --cmake-only -d {out}/nrf-nrf5340-pump -b nrf5340dk_nrf5340_cpuapp {root}/examples/pump-app/nrfconnect'

# Generating nrf-nrf5340-pump_controller
bash -c 'source "$ZEPHYR_BASE/zephyr-env.sh";
export GNUARMEMB_TOOLCHAIN_PATH="$PW_PIGWEED_CIPD_INSTALL_DIR";
west build --cmake-only -d /OUTPUT/DIR/nrf-nrf5340-pump_controller -b nrf5340dk_nrf5340_cpuapp /TEST/BUILD/ROOT/examples/pump-controller-app/nrfconnect'
west build --cmake-only -d {out}/nrf-nrf5340-pump_controller -b nrf5340dk_nrf5340_cpuapp {root}/examples/pump-controller-app/nrfconnect'

# Generating android-arm-chip_tool
gn gen --check --fail-on-unused-args {out}/android-arm-chip_tool '--args=target_os="android" target_cpu="arm" android_ndk_root="TEST_ANDROID_NDK_HOME" android_sdk_root="TEST_ANDROID_HOME" chip_use_clusters_for_ip_commissioning="true"'
Expand All @@ -123,13 +123,14 @@ gn gen --check --fail-on-unused-args {out}/android-x64-chip_tool '--args=target_
bash -c 'yes | TEST_ANDROID_HOME/tools/bin/sdkmanager --licenses >/dev/null'

# Generating infineon-p6board-lock
gn gen --check --fail-on-unused-args --root=/TEST/BUILD/ROOT/examples/lock-app/p6 '--args=p6_board="CY8CKIT-062S2-43012"' /OUTPUT/DIR/infineon-p6board-lock
gn gen --check --fail-on-unused-args --root={root}/examples/lock-app/p6 '--args=p6_board="CY8CKIT-062S2-43012"' {out}/infineon-p6board-lock

# Generating telink-tlsr9518adk80d-light
bash -c 'source "$TELINK_ZEPHYR_BASE/zephyr-env.sh";
export ZEPHYR_TOOLCHAIN_VARIANT=cross-compile;
export CROSS_COMPILE=$TELINK_TOOLCHAIN_PATH/riscv32-elf-;
west build -d {out}/telink-tlsr9518adk80d-light -b tlsr9518adk80d {root}/examples/lighting-app/telink'
bash -c 'export ZEPHYR_BASE="$TELINK_ZEPHYR_BASE"
export ZEPHYR_TOOLCHAIN_VARIANT=zephyr
export ZEPHYR_SDK_INSTALL_DIR="$ZEPHYR_BASE/../../zephyr-sdk-0.13.0"
source "$ZEPHYR_BASE/zephyr-env.sh";
west build --cmake-only -d {out}/telink-tlsr9518adk80d-light -b tlsr9518adk80d {root}/examples/lighting-app/telink'

# Building {real_platform}-native-all_clusters
ninja -C {out}/{real_platform}-native-all_clusters
Expand Down Expand Up @@ -183,10 +184,10 @@ ninja -C {out}/nrf-nrf52840-lock
ninja -C {out}/nrf-nrf52840-shell

# Building nrf-nrf52840-pump
ninja -C /OUTPUT/DIR/nrf-nrf52840-pump
ninja -C {out}/nrf-nrf52840-pump

# Building nrf-nrf52840-pump_controller
ninja -C /OUTPUT/DIR/nrf-nrf52840-pump_controller
ninja -C {out}/nrf-nrf52840-pump_controller

# Building nrf-nrf5340-light
ninja -C {out}/nrf-nrf5340-light
Expand All @@ -198,10 +199,10 @@ ninja -C {out}/nrf-nrf5340-lock
ninja -C {out}/nrf-nrf5340-shell

# Building nrf-nrf5340-pump
ninja -C /OUTPUT/DIR/nrf-nrf5340-pump
ninja -C {out}/nrf-nrf5340-pump

# Building nrf-nrf5340-pump_controller
ninja -C /OUTPUT/DIR/nrf-nrf5340-pump_controller
ninja -C {out}/nrf-nrf5340-pump_controller

# Building JNI android-arm-chip_tool
ninja -C {out}/android-arm-chip_tool
Expand Down Expand Up @@ -249,7 +250,7 @@ cp {out}/android-x64-chip_tool/lib/jni/x86_64/libc++_shared.so {root}/src/androi
{root}/src/android/CHIPTool/gradlew -p {root}/src/android/CHIPTool -PchipSdkJarDir={out}/android-x64-chip_tool/lib -PbuildDir={out}/android-x64-chip_tool build

# Building infineon-p6board-lock
ninja -C /OUTPUT/DIR/infineon-p6board-lock
ninja -C {out}/infineon-p6board-lock

# Building telink-tlsr9518adk80d-light
ninja -C {out}/telink-tlsr9518adk80d-light
Expand Down
45 changes: 0 additions & 45 deletions scripts/examples/telink_example.sh

This file was deleted.

0 comments on commit 5d2654a

Please sign in to comment.