Skip to content

Commit 42a7b0a

Browse files
authored
[Mbed] Add OTA-requestor-app and DFU support (project-chip#12616)
* Add Mbed OTA requestor app Add Mbed MCUboot to third_party Add Mbed bootloader application Add build applicaiton with bootloader option to mbed_example.sh script Improve mbed launch tasks in launch.json Move capsense lib including to common cmake file Update mbed-os-posix-socket module * Add debug Mbed bootloader option to launch.json * Mbed MCUboot update
1 parent 1ccf850 commit 42a7b0a

File tree

34 files changed

+2296
-34
lines changed

34 files changed

+2296
-34
lines changed

.github/.wordlist.txt

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ alloc
4343
Ameba
4444
amebad
4545
amebaiot
46+
announcementReason
4647
AnnounceOTAProvider
4748
APIs
4849
apk
@@ -783,6 +784,7 @@ pre
783784
preprocessor
784785
Presetup
785786
prj
787+
providerNodeId
786788
ProductID
787789
ProductLabel
788790
ProductName

.github/workflows/examples-mbed.yaml

+10-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ concurrency:
2626
jobs:
2727
mbedos:
2828
name: Mbed OS examples building
29-
timeout-minutes: 70
29+
timeout-minutes: 80
3030

3131
env:
3232
BUILD_TYPE: mbedos
@@ -110,6 +110,15 @@ jobs:
110110
mbed $APP_TARGET+$APP_PROFILE shell \
111111
examples/shell/mbed/build-CY8CPROTO_062_4343W/release/chip-mbed-shell-example.elf \
112112
/tmp/bloat_reports/
113+
114+
- name: Build ota-requestor-app example
115+
timeout-minutes: 10
116+
run: |
117+
scripts/examples/mbed_example.sh -a=ota-requestor-app -b=$APP_TARGET -p=$APP_PROFILE
118+
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
119+
mbed $APP_TARGET+$APP_PROFILE shell \
120+
examples/ota-requestor-app/mbed/build-CY8CPROTO_062_4343W/release/chip-mbed-ota-requestor-app-example.elf \
121+
/tmp/bloat_reports/
113122
114123
- name: Build unit tests
115124
timeout-minutes: 10

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,6 @@
181181
[submodule "cyw30739_sdk/tools"]
182182
path = third_party/cyw30739_sdk/repos/btsdk-tools
183183
url = https://github.com/Infineon/btsdk-tools.git
184+
[submodule "third_party/mbed-mcu-boot/repo"]
185+
path = third_party/mbed-mcu-boot/repo
186+
url = https://github.com/ATmobica/mcuboot.git

.vscode/launch.json

+63-2
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@
264264
"configFiles": ["${input:mbedTarget}.tcl"],
265265
"overrideLaunchCommands": [
266266
"monitor reset halt",
267-
"monitor program {./build-${input:mbedTarget}/${input:mbedFlashProfile}/chip-mbed-unit-tests}",
267+
"monitor program {./build-${input:mbedTarget}/${input:mbedFlashProfile}/chip-mbed-unit-tests.hex}",
268268
"monitor reset run",
269269
"quit"
270270
],
@@ -289,6 +289,66 @@
289289
"quit"
290290
],
291291
"showDevDebugOutput": false // When set to true, displays output of GDB.
292+
},
293+
294+
{
295+
"name": "Debug Mbed bootloader",
296+
"type": "cortex-debug",
297+
"request": "launch",
298+
"cwd": "${workspaceRoot}/examples/platform/mbed/bootloader",
299+
"executable": "./build-${input:mbedTarget}/${input:mbedDebugProfile}/chip-mbed-bootloader.elf",
300+
"armToolchainPath": "${env:PW_ENVIRONMENT_ROOT}/cipd/pigweed/bin/", // Pigweed environment bootstraping required
301+
"servertype": "openocd",
302+
"openocdPath": "${env:OPENOCD_PATH/bin}",
303+
"searchDir": [
304+
"${workspaceRoot}/config/mbed/scripts",
305+
"${env:OPENOCD_PATH}/scripts"
306+
],
307+
"configFiles": ["${input:mbedTarget}.tcl"],
308+
"overrideLaunchCommands": [
309+
"-enable-pretty-printing",
310+
"monitor program {./build-${input:mbedTarget}/${input:mbedDebugProfile}/chip-mbed-bootloader.hex}",
311+
"monitor reset run",
312+
"monitor sleep 200",
313+
"monitor psoc6 reset_halt sysresetreq"
314+
],
315+
"numberOfProcessors": 2,
316+
"targetProcessor": 1, // Set to 0 for the CM0+, set to 1 for the CM4
317+
"overrideRestartCommands": [
318+
"monitor reset init",
319+
"monitor reset run",
320+
"monitor sleep 200",
321+
"monitor psoc6 reset_halt sysresetreq"
322+
],
323+
"runToMain": true, // if true, program will halt at main. Not used for a restart
324+
"showDevDebugOutput": false // When set to true, displays output of GDB.
325+
},
326+
327+
{
328+
"name": "Debug Mbed bootloader [remote]",
329+
"type": "cortex-debug",
330+
"request": "launch",
331+
"cwd": "${workspaceRoot}/examples/platform/mbed/bootloader",
332+
"executable": "./build-${input:mbedTarget}/${input:mbedDebugProfile}/chip-mbed-bootloader.elf",
333+
"armToolchainPath": "${env:PW_ENVIRONMENT_ROOT}/cipd/pigweed/bin/", // Pigweed environment bootstraping required
334+
"servertype": "external",
335+
"gdbTarget": "host.docker.internal:3334", //port 3333 for the CM0+, 3334 for the CM4
336+
"overrideLaunchCommands": [
337+
"-enable-pretty-printing",
338+
"monitor reset halt",
339+
"load ./build-${input:mbedTarget}/${input:mbedDebugProfile}/chip-mbed-bootloader.hex",
340+
"monitor reset run",
341+
"monitor sleep 200",
342+
"monitor psoc6 reset_halt sysresetreq"
343+
],
344+
"overrideRestartCommands": [
345+
"monitor reset init",
346+
"monitor reset run",
347+
"monitor sleep 200",
348+
"monitor psoc6 reset_halt sysresetreq"
349+
],
350+
"runToMain": true, // if true, program will halt at main. Not used for a restart
351+
"showDevDebugOutput": false // When set to true, displays output of GDB.
292352
}
293353
],
294354
"inputs": [
@@ -315,7 +375,8 @@
315375
"lighting-app",
316376
"pigweed-app",
317377
"all-clusters-app",
318-
"shell"
378+
"shell",
379+
"ota-requestor-app"
319380
],
320381
"default": "lock-app"
321382
},

.vscode/tasks.json

+13-4
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@
142142
"-c=${input:mbedCommand}",
143143
"-a=${input:mbedApp}",
144144
"-b=${input:mbedTarget}",
145-
"-p=${input:mbedProfile}"
145+
"-p=${input:mbedProfile}",
146+
"-T=${input:mbedAppType}"
146147
],
147148
"group": "build",
148149
"problemMatcher": {
@@ -200,7 +201,8 @@
200201
"lighting-app",
201202
"pigweed-app",
202203
"all-clusters-app",
203-
"shell"
204+
"shell",
205+
"ota-requestor-app"
204206
],
205207
"default": "lock-app"
206208
},
@@ -215,8 +217,15 @@
215217
"type": "pickString",
216218
"id": "mbedProfile",
217219
"description": "What mbed profile do you want to use?",
218-
"options": ["develop", "release", "debug"],
219-
"default": "develop"
220+
"options": ["release", "develop", "debug"],
221+
"default": "release"
222+
},
223+
{
224+
"type": "pickString",
225+
"id": "mbedAppType",
226+
"description": "What mbed application type do you want to use?",
227+
"options": ["simple", "boot", "upgrade"],
228+
"default": "simple"
220229
},
221230
{
222231
"type": "promptString",

config/mbed/CMakeLists.txt

+71
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ if (CONFIG_CHIP_PW_RPC)
279279
chip_gn_arg_bool ("chip_build_pw_rpc_lighting_proto" CONFIG_CHIP_PW_RPC_LIGHTING_PROTO)
280280
chip_gn_arg_bool ("chip_build_pw_rpc_locking_proto" CONFIG_CHIP_PW_RPC_LOCKING_PROTO)
281281
endif(CONFIG_CHIP_PW_RPC)
282+
if (CONFIG_CHIP_OTA_REQUESTOR)
283+
chip_gn_arg_bool ("chip_enable_ota_requestor" CONFIG_CHIP_OTA_REQUESTOR)
284+
endif(CONFIG_CHIP_OTA_REQUESTOR)
285+
282286

283287
file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/args.gn CONTENT ${CHIP_GN_ARGS})
284288

@@ -325,6 +329,12 @@ list(APPEND CHIP_INCLUDES)
325329
# CHIP defines
326330
list(APPEND CHIP_DEFINES)
327331

332+
# Target specific configuration
333+
if("capsense" IN_LIST MBED_TARGET_LABELS)
334+
add_subdirectory(${CHIP_ROOT}/third_party/mbed-os-cypress-capsense-button/repo ${CMAKE_BINARY_DIR}/capsense_build)
335+
target_link_libraries(${APP_TARGET} capsense)
336+
endif()
337+
328338
list(APPEND CHIP_INCLUDES
329339
${CHIP_ROOT}/config/mbed/mbedtls
330340
)
@@ -442,6 +452,67 @@ endif(CONFIG_CHIP_PW_RPC_LOCKING_PROTO)
442452

443453
endif(CONFIG_CHIP_PW_RPC)
444454

455+
if (CONFIG_CHIP_OTA_REQUESTOR)
456+
target_include_directories(${APP_TARGET} PRIVATE
457+
${CHIP_ROOT}/zzz_generated/ota-requestor-app
458+
${CHIP_ROOT}/src/app/clusters/ota-requestor
459+
${CHIP_ROOT}/src/platform
460+
${CHIP_ROOT}/src/platform/mbed
461+
${CHIP_ROOT}/src/include/platform
462+
)
463+
464+
target_sources(${APP_TARGET} PRIVATE
465+
${CHIP_ROOT}/zzz_generated/ota-requestor-app/zap-generated/callback-stub.cpp
466+
${CHIP_ROOT}/zzz_generated/ota-requestor-app/zap-generated/CHIPClusters.cpp
467+
${CHIP_ROOT}/zzz_generated/ota-requestor-app/zap-generated/IMClusterCommandHandler.cpp
468+
469+
${CHIP_ROOT}/src/app/clusters/ota-requestor/OTARequestor.cpp
470+
${CHIP_ROOT}/src/app/clusters/ota-requestor/BDXDownloader.cpp
471+
${CHIP_ROOT}/src/app/clusters/ota-requestor/ota-requestor-server.cpp
472+
473+
${CHIP_ROOT}/src/platform/mbed/OTAImageProcessorImpl.cpp
474+
)
475+
476+
list(APPEND CHIP_DEFINES
477+
CHIP_OTA_REQUESTOR=1
478+
)
479+
endif(CONFIG_CHIP_OTA_REQUESTOR)
480+
481+
if(BOOT_ENABLED)
482+
add_subdirectory(${MCUBOOT_PATH}/boot/bootutil/ ${CMAKE_BINARY_DIR}/mbed_mcu_boot_util_build)
483+
add_subdirectory(${MCUBOOT_PATH}/boot/mbed/ ${CMAKE_BINARY_DIR}/mbed_mcu_boot_build)
484+
485+
target_include_directories(${APP_TARGET} PRIVATE
486+
${MCUBOOT_PATH}/boot/mbed/include
487+
)
488+
489+
target_sources(${APP_TARGET} PRIVATE
490+
${CHIP_ROOT}/examples/platform/mbed/bootloader/default_bd.cpp
491+
)
492+
493+
target_include_directories(bootutil PUBLIC
494+
${CHIP_ROOT}/config/mbed/mbedtls
495+
)
496+
497+
target_link_libraries(${APP_TARGET} mbed-mcuboot bootutil)
498+
499+
file(READ ${APP_PATH}/mbed_app.json mbedAppJson)
500+
string(JSON PRIMARY_SLOT_ADDRESS GET "${mbedAppJson}" target_overrides ${MBED_TARGET} mcuboot.primary-slot-address)
501+
string(JSON HEADER_SIZE GET "${mbedAppJson}" target_overrides ${MBED_TARGET} mcuboot.header-size)
502+
string(JSON SLOT_SIZE GET "${mbedAppJson}" target_overrides ${MBED_TARGET} mcuboot.slot-size)
503+
math(EXPR APP_START "${PRIMARY_SLOT_ADDRESS} + ${HEADER_SIZE}" OUTPUT_FORMAT HEXADECIMAL)
504+
math(EXPR APP_SIZE "${SLOT_SIZE} - 2 * ${HEADER_SIZE}" OUTPUT_FORMAT HEXADECIMAL)
505+
target_compile_definitions(mbed-core
506+
INTERFACE
507+
"-DMBED_APP_START=${APP_START}"
508+
"-DMBED_APP_SIZE=${APP_SIZE}"
509+
)
510+
511+
list(APPEND CHIP_DEFINES
512+
BOOT_ENABLED=1
513+
)
514+
endif()
515+
445516

446517
target_include_directories(${APP_TARGET} PRIVATE
447518
${CHIP_INCLUDES}

examples/all-clusters-app/mbed/README.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ example ported to the mbed-os platform.
111111
- **by using generic vscode task**:
112112

113113
```
114-
Command Palette (F1) => Run Task... => Run Mbed Application => build => all-clusters-app => (board name) => (build profile)`
114+
Command Palette (F1) => Run Task... => Run Mbed Application => build => all-clusters-app => (board name) => (build profile) => (build type)
115115
```
116116

117117
- **by calling explicitly building script:**
118118

119119
```
120-
${MATTER_ROOT}/scripts/examples/mbed_example.sh -c=build -a=all-clusters-app -b=<board name> -p=<build profile>
120+
${MATTER_ROOT}/scripts/examples/mbed_example.sh -c=build -a=all-clusters-app -b=<board name> -p=<build profile> -T=<build type>
121121
```
122122

123123
Both approaches are limited to supported evaluation boards which are listed in
@@ -127,6 +127,16 @@ Mbed OS defines three building profiles: _develop, debug_ and _release_. For
127127
more details please visit
128128
[ARM Mbed OS build profiles](https://os.mbed.com/docs/mbed-os/latest/program-setup/build-profiles-and-rules.html).
129129

130+
There are also three types of built application: _simple, boot_ and _upgrade_:
131+
132+
- **simple** - standalone application, mainly for developing and testing
133+
purpose (all building profiles are supported)
134+
- **boot** - signed application + bootloader, it supports booting process and
135+
can be use for firmware update (only _release_ building profiles is
136+
supported)
137+
- **update** - signed application, application image can be used for firmware
138+
update (only _release_ building profiles is supported)
139+
130140
When using the building script, it is possible expand the list of acceptable
131141
targets; this may be useful for rapid testing of a new mbed-targets.
132142

examples/lighting-app/mbed/CMakeLists.txt

-5
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,6 @@ if(MBED_TARGET STREQUAL "CY8CPROTO_062_4343W")
110110
target_link_libraries(${APP_TARGET} mbed-cy-psoc6-common-network)
111111
endif()
112112

113-
if("capsense" IN_LIST MBED_TARGET_LABELS)
114-
add_subdirectory(${CHIP_ROOT}/third_party/mbed-os-cypress-capsense-button/repo ./capsense_build)
115-
target_link_libraries(${APP_TARGET} capsense)
116-
endif()
117-
118113
mbed_set_post_build(${APP_TARGET})
119114

120115
option(VERBOSE_BUILD "Have a verbose build process")

examples/lighting-app/mbed/README.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,13 @@ example ported to the mbed-os platform.
124124
- **by using generic vscode task**:
125125

126126
```
127-
Command Palette (F1) => Run Task... => Run Mbed Application => build => lighting-app => (board name) => (build profile)
127+
Command Palette (F1) => Run Task... => Run Mbed Application => build => lighting-app => (board name) => (build profile) => (build type)
128128
```
129129

130130
- **by calling explicitly building script:**
131131

132132
```
133-
${MATTER_ROOT}/scripts/examples/mbed_example.sh -c=build -a=lighting-app -b=<board name> -p=<build profile>
133+
${MATTER_ROOT}/scripts/examples/mbed_example.sh -c=build -a=lighting-app -b=<board name> -p=<build profile> -T=<build type>
134134
```
135135

136136
Both approaches are limited to supported evaluation boards which are listed in
@@ -140,6 +140,16 @@ Mbed OS defines three building profiles: _develop, debug_ and _release_. For
140140
more details please visit
141141
[ARM Mbed OS build profiles](https://os.mbed.com/docs/mbed-os/latest/program-setup/build-profiles-and-rules.html).
142142

143+
There are also three types of built application: _simple, boot_ and _upgrade_:
144+
145+
- **simple** - standalone application, mainly for developing and testing
146+
purpose (all building profiles are supported)
147+
- **boot** - signed application + bootloader, it supports booting process and
148+
can be use for firmware update (only _release_ building profiles is
149+
supported)
150+
- **update** - signed application, application image can be used for firmware
151+
update (only _release_ building profiles is supported)
152+
143153
When using the building script, it is possible expand the list of acceptable
144154
targets; this may be useful for rapid testing of a new mbed-targets.
145155

examples/lock-app/mbed/CMakeLists.txt

-5
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,6 @@ if(MBED_TARGET STREQUAL "CY8CPROTO_062_4343W")
102102
target_link_libraries(${APP_TARGET} mbed-cy-psoc6-common-network)
103103
endif()
104104

105-
if("capsense" IN_LIST MBED_TARGET_LABELS)
106-
add_subdirectory(${CHIP_ROOT}/third_party/mbed-os-cypress-capsense-button/repo ./capsense_build)
107-
target_link_libraries(${APP_TARGET} capsense)
108-
endif()
109-
110105
mbed_set_post_build(${APP_TARGET})
111106

112107
option(VERBOSE_BUILD "Have a verbose build process")

examples/lock-app/mbed/README.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ ported to the mbed-os platform.
114114
- **by using generic vscode task**:
115115

116116
```
117-
Command Palette (F1) => Run Task... => Run Mbed Application => build => lock-app => (board name) => (build profile)
117+
Command Palette (F1) => Run Task... => Run Mbed Application => build => lock-app => (board name) => (build profile) => (build type)
118118
```
119119

120120
- **by calling explicitly building script:**
121121

122122
```
123-
${MATTER_ROOT}/scripts/examples/mbed_example.sh -c=build -a=lock-app -b=<board name> -p=<build profile>
123+
${MATTER_ROOT}/scripts/examples/mbed_example.sh -c=build -a=lock-app -b=<board name> -p=<build profile> -T=<build type>
124124
```
125125

126126
Both approaches are limited to supported evaluation boards which are listed in
@@ -130,6 +130,16 @@ Mbed OS defines three building profiles: _develop, debug_ and _release_. For
130130
more details please visit
131131
[ARM Mbed OS build profiles](https://os.mbed.com/docs/mbed-os/latest/program-setup/build-profiles-and-rules.html).
132132

133+
There are also three types of built application: _simple, boot_ and _upgrade_:
134+
135+
- **simple** - standalone application, mainly for developing and testing
136+
purpose (all building profiles are supported)
137+
- **boot** - signed application + bootloader, it supports booting process and
138+
can be use for firmware update (only _release_ building profiles is
139+
supported)
140+
- **update** - signed application, application image can be used for firmware
141+
update (only _release_ building profiles is supported)
142+
133143
When using the building script, it is possible expand the list of acceptable
134144
targets; this may be useful for rapid testing of a new mbed-targets.
135145

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build-*/
2+
mcuboot

0 commit comments

Comments
 (0)