diff --git a/config/nrfconnect/chip-module/CMakeLists.txt b/config/nrfconnect/chip-module/CMakeLists.txt index 857bf65ed0e21f..791098ba5d518e 100644 --- a/config/nrfconnect/chip-module/CMakeLists.txt +++ b/config/nrfconnect/chip-module/CMakeLists.txt @@ -28,6 +28,7 @@ if (CONFIG_CHIP) include(ExternalProject) +include(../../zephyr/ota-image.cmake) include(../../zephyr/zephyr-util.cmake) # ============================================================================== @@ -267,4 +268,16 @@ target_link_libraries(chip INTERFACE -Wl,--start-group ${CHIP_LIBRARIES} -Wl,--e add_dependencies(chip chip-gn) +# ============================================================================== +# Define 'chip-ota-image' target for building CHIP OTA image +# ============================================================================== + +if (CONFIG_CHIP_OTA_IMAGE_BUILD) + chip_ota_image(chip-ota-image + INPUT_FILES ${PROJECT_BINARY_DIR}/app_update.bin + OUTPUT_FILE ${PROJECT_BINARY_DIR}/matter_ota.bin + ) + add_dependencies(chip-ota-image mcuboot_sign_target) +endif() + endif() # CONFIG_CHIP diff --git a/config/nrfconnect/chip-module/Kconfig b/config/nrfconnect/chip-module/Kconfig index 38dcd3bb3845ac..6aecc3d070be2f 100644 --- a/config/nrfconnect/chip-module/Kconfig +++ b/config/nrfconnect/chip-module/Kconfig @@ -42,3 +42,8 @@ config CHIP_OTA_REQUESTOR_BUFFER_SIZE help Configures size of the buffer used by OTA Requestor when downloading and writing a new firmware image to flash. + +# See config/zephyr/Kconfig for full definition +config CHIP_OTA_IMAGE_BUILD + bool + depends on SIGN_IMAGES diff --git a/config/zephyr/Kconfig b/config/zephyr/Kconfig index e3c7bdfd0a6810..8ace731baac543 100644 --- a/config/zephyr/Kconfig +++ b/config/zephyr/Kconfig @@ -34,6 +34,43 @@ menuconfig CHIP if CHIP +config CHIP_DEVICE_VENDOR_ID + int "Device vendor ID" + default 9050 # 0x235A + range 0 65535 + help + Identifier of the device manufacturer, assigned by Connectivity Standards + Alliance. It is used in various CHIP areas, such as the Basic Information + cluster or OTA (Over-the-air update) image header. + +config CHIP_DEVICE_PRODUCT_ID + int "Device product ID" + default 0 + range 0 65535 + help + Identifier of the product, assigned by the device manufacturer. It is used + in various CHIP areas, such as the Basic Information cluster or OTA + (Over-the-air update) image header. + +config CHIP_DEVICE_SOFTWARE_VERSION + int "Device software version" + default 0 + range 0 4294967295 + help + A number identifying the software version. It is used in various CHIP + areas, such as the Basic Information cluster or OTA (Over-the-air update) + image header. Note that due to the rollback protection a device will only + accept a software update whose version is greater than the current one. + +config CHIP_DEVICE_SOFTWARE_VERSION_STRING + string "Device software version string" + default "prerelease" + help + A string between 1 and 64 characters that provides a user-friendly + description of the numeric software version specified in + CHIP_DEVICE_SOFTWARE_VERSION. It is used in various CHIP areas, such as + the Basic Information cluster or OTA (Over-the-air update) image header. + config CHIP_PROJECT_CONFIG string "Project configuration file for CHIP" help @@ -131,6 +168,18 @@ config APP_LINK_WITH_CHIP Add Connected Home over IP header files to the 'app' include path and link the 'app' with Connected Home over IP libraries. +config CHIP_OTA_IMAGE_BUILD + bool "Generate OTA image" + help + Enable building OTA (Over-the-air update) image. + +config CHIP_OTA_IMAGE_EXTRA_ARGS + string "OTA image creator extra arguments" + depends on CHIP_OTA_IMAGE_BUILD + help + This option allows one to pass optional arguments to the + ota_image_tool.py script, used for building OTA image. + module = MATTER module-str = Matter source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config" diff --git a/config/zephyr/ota-image.cmake b/config/zephyr/ota-image.cmake new file mode 100644 index 00000000000000..e6a86092056a74 --- /dev/null +++ b/config/zephyr/ota-image.cmake @@ -0,0 +1,64 @@ +# +# Copyright (c) 2021 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +find_package(Python3 REQUIRED) + +# +# Create CMake target for building Matter OTA (Over-the-air update) image. +# Required arguments: +# INPUT_FILES file1, [file2...] - binary files which Matter OTA image will be composed of +# OUTPUT_FILE file - where to store newly created Matter OTA image +# +function(chip_ota_image TARGET_NAME) + cmake_parse_arguments(ARG "" "OUTPUT_FILE" "INPUT_FILES" ${ARGN}) + + if (NOT ARG_INPUT_FILES OR NOT ARG_OUTPUT_FILE) + message(FATAL_ERROR "Both INPUT_FILES and OUTPUT_FILE arguments must be specified") + endif() + + # Prepare ota_image_tool.py argument list + set(OTA_ARGS + "--vendor-id" + ${CONFIG_CHIP_DEVICE_VENDOR_ID} + "--product-id" + ${CONFIG_CHIP_DEVICE_PRODUCT_ID} + "--version" + ${CONFIG_CHIP_DEVICE_SOFTWARE_VERSION} + "--version-str" + ${CONFIG_CHIP_DEVICE_SOFTWARE_VERSION_STRING} + "--digest-algorithm" + "sha256" + ) + + separate_arguments(OTA_EXTRA_ARGS NATIVE_COMMAND "${CHIP_OTA_IMAGE_EXTRA_ARGS}") + + list(APPEND OTA_ARGS ${OTA_EXTRA_ARGS}) + list(APPEND OTA_ARGS ${ARG_INPUT_FILES}) + list(APPEND OTA_ARGS ${ARG_OUTPUT_FILE}) + + # Convert the argument list to multi-line string + string(REPLACE ";" "\n" OTA_ARGS "${OTA_ARGS}") + + # Pass the argument list via file to avoid hitting Windows command-line length limit + file(GENERATE + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/args-ota-image.tmp + CONTENT ${OTA_ARGS} + ) + + add_custom_target(${TARGET_NAME} ALL + COMMAND ${Python3_EXECUTABLE} ${CHIP_ROOT}/src/app/ota_image_tool.py create @${CMAKE_CURRENT_BINARY_DIR}/args-ota-image.tmp + ) +endfunction() diff --git a/src/platform/nrfconnect/CHIPDevicePlatformConfig.h b/src/platform/nrfconnect/CHIPDevicePlatformConfig.h index 70e2179206b138..60baa9424f4784 100644 --- a/src/platform/nrfconnect/CHIPDevicePlatformConfig.h +++ b/src/platform/nrfconnect/CHIPDevicePlatformConfig.h @@ -27,6 +27,22 @@ // ==================== Platform Adaptations ==================== +#ifndef CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID +#define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID CONFIG_CHIP_DEVICE_VENDOR_ID +#endif + +#ifndef CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID +#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID CONFIG_CHIP_DEVICE_PRODUCT_ID +#endif + +#ifndef CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION +#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION CONFIG_CHIP_DEVICE_SOFTWARE_VERSION +#endif + +#ifndef CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING +#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING CONFIG_CHIP_DEVICE_SOFTWARE_VERSION_STRING +#endif + #define CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION 0 #define CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP 0