Skip to content

Commit 1172906

Browse files
Damian-Nordicpull[bot]
authored andcommitted
[nrfconnect] Automatically build OTA image (#13640)
1. Add certain software configuration, such as vendor ID, product ID etc, to Kconfig. 2. Use values of the Kconfig variables in existing CHIP project configuration. 3. Add two more Kconfig variables: OTA_IMAGE_BUILD and OTA_IMAGE_EXTRA_ARGS. The first one enables building OTA image file using the ota_image_tool.py script, and the second one allows to pass some extra arguments to that script.
1 parent 2db8182 commit 1172906

File tree

5 files changed

+147
-0
lines changed

5 files changed

+147
-0
lines changed

config/nrfconnect/chip-module/CMakeLists.txt

+13
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
if (CONFIG_CHIP)
2929

3030
include(ExternalProject)
31+
include(../../zephyr/ota-image.cmake)
3132
include(../../zephyr/zephyr-util.cmake)
3233

3334
# ==============================================================================
@@ -267,4 +268,16 @@ target_link_libraries(chip INTERFACE -Wl,--start-group ${CHIP_LIBRARIES} -Wl,--e
267268

268269
add_dependencies(chip chip-gn)
269270

271+
# ==============================================================================
272+
# Define 'chip-ota-image' target for building CHIP OTA image
273+
# ==============================================================================
274+
275+
if (CONFIG_CHIP_OTA_IMAGE_BUILD)
276+
chip_ota_image(chip-ota-image
277+
INPUT_FILES ${PROJECT_BINARY_DIR}/app_update.bin
278+
OUTPUT_FILE ${PROJECT_BINARY_DIR}/matter_ota.bin
279+
)
280+
add_dependencies(chip-ota-image mcuboot_sign_target)
281+
endif()
282+
270283
endif() # CONFIG_CHIP

config/nrfconnect/chip-module/Kconfig

+5
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,8 @@ config CHIP_OTA_REQUESTOR_BUFFER_SIZE
4242
help
4343
Configures size of the buffer used by OTA Requestor when downloading and
4444
writing a new firmware image to flash.
45+
46+
# See config/zephyr/Kconfig for full definition
47+
config CHIP_OTA_IMAGE_BUILD
48+
bool
49+
depends on SIGN_IMAGES

config/zephyr/Kconfig

+49
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,43 @@ menuconfig CHIP
3434

3535
if CHIP
3636

37+
config CHIP_DEVICE_VENDOR_ID
38+
int "Device vendor ID"
39+
default 9050 # 0x235A
40+
range 0 65535
41+
help
42+
Identifier of the device manufacturer, assigned by Connectivity Standards
43+
Alliance. It is used in various CHIP areas, such as the Basic Information
44+
cluster or OTA (Over-the-air update) image header.
45+
46+
config CHIP_DEVICE_PRODUCT_ID
47+
int "Device product ID"
48+
default 0
49+
range 0 65535
50+
help
51+
Identifier of the product, assigned by the device manufacturer. It is used
52+
in various CHIP areas, such as the Basic Information cluster or OTA
53+
(Over-the-air update) image header.
54+
55+
config CHIP_DEVICE_SOFTWARE_VERSION
56+
int "Device software version"
57+
default 0
58+
range 0 4294967295
59+
help
60+
A number identifying the software version. It is used in various CHIP
61+
areas, such as the Basic Information cluster or OTA (Over-the-air update)
62+
image header. Note that due to the rollback protection a device will only
63+
accept a software update whose version is greater than the current one.
64+
65+
config CHIP_DEVICE_SOFTWARE_VERSION_STRING
66+
string "Device software version string"
67+
default "prerelease"
68+
help
69+
A string between 1 and 64 characters that provides a user-friendly
70+
description of the numeric software version specified in
71+
CHIP_DEVICE_SOFTWARE_VERSION. It is used in various CHIP areas, such as
72+
the Basic Information cluster or OTA (Over-the-air update) image header.
73+
3774
config CHIP_PROJECT_CONFIG
3875
string "Project configuration file for CHIP"
3976
help
@@ -131,6 +168,18 @@ config APP_LINK_WITH_CHIP
131168
Add Connected Home over IP header files to the 'app' include path
132169
and link the 'app' with Connected Home over IP libraries.
133170

171+
config CHIP_OTA_IMAGE_BUILD
172+
bool "Generate OTA image"
173+
help
174+
Enable building OTA (Over-the-air update) image.
175+
176+
config CHIP_OTA_IMAGE_EXTRA_ARGS
177+
string "OTA image creator extra arguments"
178+
depends on CHIP_OTA_IMAGE_BUILD
179+
help
180+
This option allows one to pass optional arguments to the
181+
ota_image_tool.py script, used for building OTA image.
182+
134183
module = MATTER
135184
module-str = Matter
136185
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"

config/zephyr/ota-image.cmake

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#
2+
# Copyright (c) 2021 Project CHIP Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
find_package(Python3 REQUIRED)
18+
19+
#
20+
# Create CMake target for building Matter OTA (Over-the-air update) image.
21+
# Required arguments:
22+
# INPUT_FILES file1, [file2...] - binary files which Matter OTA image will be composed of
23+
# OUTPUT_FILE file - where to store newly created Matter OTA image
24+
#
25+
function(chip_ota_image TARGET_NAME)
26+
cmake_parse_arguments(ARG "" "OUTPUT_FILE" "INPUT_FILES" ${ARGN})
27+
28+
if (NOT ARG_INPUT_FILES OR NOT ARG_OUTPUT_FILE)
29+
message(FATAL_ERROR "Both INPUT_FILES and OUTPUT_FILE arguments must be specified")
30+
endif()
31+
32+
# Prepare ota_image_tool.py argument list
33+
set(OTA_ARGS
34+
"--vendor-id"
35+
${CONFIG_CHIP_DEVICE_VENDOR_ID}
36+
"--product-id"
37+
${CONFIG_CHIP_DEVICE_PRODUCT_ID}
38+
"--version"
39+
${CONFIG_CHIP_DEVICE_SOFTWARE_VERSION}
40+
"--version-str"
41+
${CONFIG_CHIP_DEVICE_SOFTWARE_VERSION_STRING}
42+
"--digest-algorithm"
43+
"sha256"
44+
)
45+
46+
separate_arguments(OTA_EXTRA_ARGS NATIVE_COMMAND "${CHIP_OTA_IMAGE_EXTRA_ARGS}")
47+
48+
list(APPEND OTA_ARGS ${OTA_EXTRA_ARGS})
49+
list(APPEND OTA_ARGS ${ARG_INPUT_FILES})
50+
list(APPEND OTA_ARGS ${ARG_OUTPUT_FILE})
51+
52+
# Convert the argument list to multi-line string
53+
string(REPLACE ";" "\n" OTA_ARGS "${OTA_ARGS}")
54+
55+
# Pass the argument list via file to avoid hitting Windows command-line length limit
56+
file(GENERATE
57+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/args-ota-image.tmp
58+
CONTENT ${OTA_ARGS}
59+
)
60+
61+
add_custom_target(${TARGET_NAME} ALL
62+
COMMAND ${Python3_EXECUTABLE} ${CHIP_ROOT}/src/app/ota_image_tool.py create @${CMAKE_CURRENT_BINARY_DIR}/args-ota-image.tmp
63+
)
64+
endfunction()

src/platform/nrfconnect/CHIPDevicePlatformConfig.h

+16
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@
2727

2828
// ==================== Platform Adaptations ====================
2929

30+
#ifndef CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID
31+
#define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID CONFIG_CHIP_DEVICE_VENDOR_ID
32+
#endif
33+
34+
#ifndef CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID
35+
#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID CONFIG_CHIP_DEVICE_PRODUCT_ID
36+
#endif
37+
38+
#ifndef CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION
39+
#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION CONFIG_CHIP_DEVICE_SOFTWARE_VERSION
40+
#endif
41+
42+
#ifndef CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING
43+
#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING CONFIG_CHIP_DEVICE_SOFTWARE_VERSION_STRING
44+
#endif
45+
3046
#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION 0
3147
#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP 0
3248

0 commit comments

Comments
 (0)