From d140d5c87751603278f2483523993ee81922e7be Mon Sep 17 00:00:00 2001 From: Alex Tsitsiura Date: Tue, 17 Oct 2023 19:05:40 +0300 Subject: [PATCH] [Telink] Fix DFU target build & add to CI (#29754) * [Telink] Fix DFU target build conflict * [Telink] Fix app path in CI --------- Co-authored-by: Andrei Litvin --- .github/workflows/examples-telink.yaml | 8 ++++---- config/telink/chip-module/CMakeLists.txt | 11 ++++++++--- scripts/build/build/targets.py | 1 + scripts/build/builders/telink.py | 5 +++++ .../build/testdata/all_targets_linux_x64.txt | 2 +- src/platform/telink/OTAUtil.cpp | 17 +++++++++-------- 6 files changed, 28 insertions(+), 16 deletions(-) diff --git a/.github/workflows/examples-telink.yaml b/.github/workflows/examples-telink.yaml index 04fcdb33aac8ac..76537d15e037e5 100644 --- a/.github/workflows/examples-telink.yaml +++ b/.github/workflows/examples-telink.yaml @@ -148,13 +148,13 @@ jobs: - name: clean out build output run: rm -rf ./out - - name: Build example Telink (B92) Lock App + - name: Build example Telink (B92) Lock App with DFU run: | ./scripts/run_in_build_env.sh \ - "./scripts/build/build_examples.py --target 'telink-tlsr9528a-lock' build" + "./scripts/build/build_examples.py --target 'telink-tlsr9528a-lock-dfu' build" .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ - telink tlsr9528a lock-app \ - out/telink-tlsr9528a-lock/zephyr/zephyr.elf \ + telink tlsr9528a lock-app-dfu \ + out/telink-tlsr9528a-lock-dfu/zephyr/zephyr.elf \ /tmp/bloat_reports/ - name: clean out build output diff --git a/config/telink/chip-module/CMakeLists.txt b/config/telink/chip-module/CMakeLists.txt index 323bc55d6a1a1c..6a1a2393b8627a 100644 --- a/config/telink/chip-module/CMakeLists.txt +++ b/config/telink/chip-module/CMakeLists.txt @@ -173,28 +173,33 @@ dt_nodelabel(dts_partition_path NODELABEL "boot_partition") dt_reg_size(mcuboot_size PATH ${dts_partition_path}) math(EXPR boot_blocks "${mcuboot_size} / ${BLOCK_SIZE}" OUTPUT_FORMAT DECIMAL) -if (CONFIG_CHIP_OTA_IMAGE_BUILD) +if (CONFIG_BOOTLOADER_MCUBOOT) add_custom_target(build_mcuboot ALL COMMAND west build -b ${BOARD} -d build_mcuboot ${ZEPHYR_BASE}/../bootloader/mcuboot/boot/zephyr -- -DOVERLAY_CONFIG=${GLOBAL_BOOTLOADER_CONF_OVERLAY_FILE} -DDTC_OVERLAY_FILE="${GLOBAL_DTC_OVERLAY_FILE};${USB_BOOT_DTC_OVERLAY_FILE}" + COMMAND + cp ${PROJECT_BINARY_DIR}/../modules/chip-module/build_mcuboot/zephyr/zephyr.bin ${PROJECT_BINARY_DIR}/zephyr.mcuboot.bin ) add_custom_target(merge_mcuboot ALL COMMAND - dd if=${PROJECT_BINARY_DIR}/../modules/chip-module/build_mcuboot/zephyr/zephyr.bin of=${PROJECT_BINARY_DIR}/zephyr.bin + dd if=${PROJECT_BINARY_DIR}/zephyr.mcuboot.bin of=${PROJECT_BINARY_DIR}/zephyr.bin COMMAND dd if=${PROJECT_BINARY_DIR}/zephyr.signed.bin of=${PROJECT_BINARY_DIR}/zephyr.bin bs=${BLOCK_SIZE} seek=${boot_blocks} ) + add_dependencies(merge_mcuboot ${ZEPHYR_FINAL_EXECUTABLE}) + +if (CONFIG_CHIP_OTA_IMAGE_BUILD) chip_ota_image(chip-ota-image INPUT_FILES ${PROJECT_BINARY_DIR}/zephyr.signed.bin OUTPUT_FILE ${PROJECT_BINARY_DIR}/zephyr-ota.bin ) - add_dependencies(merge_mcuboot ${ZEPHYR_FINAL_EXECUTABLE}) add_dependencies(chip-ota-image ${ZEPHYR_FINAL_EXECUTABLE}) endif() +endif() # get code-partition factory_partition address dt_nodelabel(dts_partition_path NODELABEL "factory_partition") diff --git a/scripts/build/build/targets.py b/scripts/build/build/targets.py index 6d755495b50969..fb5e92fb38ca0f 100755 --- a/scripts/build/build/targets.py +++ b/scripts/build/build/targets.py @@ -720,6 +720,7 @@ def BuildTelinkTarget(): ]) target.AppendModifier('ota', enable_ota=True) + target.AppendModifier('dfu', enable_dfu=True) target.AppendModifier('shell', enable_shell=True) target.AppendModifier('rpc', enable_rpcs=True) target.AppendModifier('factory-data', enable_factory_data=True) diff --git a/scripts/build/builders/telink.py b/scripts/build/builders/telink.py index 39bdbe9675a2ad..0aa6ac68940eec 100644 --- a/scripts/build/builders/telink.py +++ b/scripts/build/builders/telink.py @@ -137,6 +137,7 @@ def __init__(self, app: TelinkApp = TelinkApp, board: TelinkBoard = TelinkBoard, enable_ota: bool = False, + enable_dfu: bool = False, enable_shell: bool = False, enable_rpcs: bool = False, enable_factory_data: bool = False, @@ -145,6 +146,7 @@ def __init__(self, self.app = app self.board = board self.enable_ota = enable_ota + self.enable_dfu = enable_dfu self.enable_shell = enable_shell self.enable_rpcs = enable_rpcs self.enable_factory_data = enable_factory_data @@ -172,6 +174,9 @@ def generate(self): if self.enable_ota: flags.append("-DCONFIG_CHIP_OTA_REQUESTOR=y") + if self.enable_dfu: + flags.append("-DCONFIG_BOOTLOADER_MCUBOOT=y") + if self.enable_shell: flags.append("-DCONFIG_CHIP_LIB_SHELL=y") diff --git a/scripts/build/testdata/all_targets_linux_x64.txt b/scripts/build/testdata/all_targets_linux_x64.txt index c325aa52fb57d9..7ed9c674b978f3 100644 --- a/scripts/build/testdata/all_targets_linux_x64.txt +++ b/scripts/build/testdata/all_targets_linux_x64.txt @@ -22,5 +22,5 @@ nrf-native-posix-64-tests qpg-qpg6105-{lock,light,shell,persistent-storage} stm32-stm32wb5mm-dk-light tizen-arm-{all-clusters,all-clusters-minimal,chip-tool,light,tests}[-no-ble][-no-thread][-no-wifi][-asan][-ubsan] -telink-{tlsr9518adk80d,tlsr9528a}-{air-quality-sensor,all-clusters,all-clusters-minimal,bridge,contact-sensor,light,light-switch,lock,ota-requestor,pump,pump-controller,resource-monitoring,shell,smoke-co-alarm,temperature-measurement,thermostat,window-covering}[-ota][-shell][-rpc][-factory-data][-4mb] +telink-{tlsr9518adk80d,tlsr9528a}-{air-quality-sensor,all-clusters,all-clusters-minimal,bridge,contact-sensor,light,light-switch,lock,ota-requestor,pump,pump-controller,resource-monitoring,shell,smoke-co-alarm,temperature-measurement,thermostat,window-covering}[-ota][-dfu][-shell][-rpc][-factory-data][-4mb] openiotsdk-{shell,lock}[-mbedtls][-psa] diff --git a/src/platform/telink/OTAUtil.cpp b/src/platform/telink/OTAUtil.cpp index e63920d0adc555..b13c4abf3f72c5 100755 --- a/src/platform/telink/OTAUtil.cpp +++ b/src/platform/telink/OTAUtil.cpp @@ -21,14 +21,15 @@ #include #include #include + +using namespace chip; +using namespace chip::DeviceLayer; #endif -#if CONFIG_BOOTLOADER_MCUBOOT #include -#endif +#include -using namespace chip; -using namespace chip::DeviceLayer; +LOG_MODULE_DECLARE(app, CONFIG_CHIP_APP_LOG_LEVEL); #ifdef CONFIG_CHIP_OTA_REQUESTOR @@ -59,14 +60,14 @@ void OtaConfirmNewImage() { if (mcuboot_swap_type() == BOOT_SWAP_TYPE_REVERT) { - CHIP_ERROR err = System::MapErrorZephyr(boot_write_img_confirmed()); - if (CHIP_NO_ERROR == err) + int img_confirmation = boot_write_img_confirmed(); + if (img_confirmation) { - ChipLogProgress(SoftwareUpdate, "New firmware image confirmed"); + LOG_ERR("Image not confirmed %d. Will be reverted!", img_confirmation); } else { - ChipLogError(SoftwareUpdate, "Failed to confirm firmware image, it will be reverted on the next boot"); + LOG_INF("Image confirmed"); } } }