Skip to content

Commit 96fb1e0

Browse files
Jerry-ESPwqx6
andauthored
ESP32: Add OTA function for thread border router device (#37099)
* esp32: add thread border router ota function * Update the implementation of some APIs * restyled update * add thread br ota file generate and fix some issue * fix restyled error * Update src/platform/ESP32/OTAImageProcessorImpl.cpp Co-authored-by: Wang Qixiang <43193572+wqx6@users.noreply.github.com> --------- Co-authored-by: Wang Qixiang <43193572+wqx6@users.noreply.github.com>
1 parent 0be4b00 commit 96fb1e0

File tree

10 files changed

+550
-22
lines changed

10 files changed

+550
-22
lines changed

config/esp32/components/chip/CMakeLists.txt

+17-8
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ endif()
345345

346346
set(args_gn "${CMAKE_CURRENT_BINARY_DIR}/args.gn")
347347
add_custom_command(OUTPUT "${args_gn}"
348-
COMMAND ${python}
349-
${CMAKE_CURRENT_LIST_DIR}/create_args_gn.py
348+
COMMAND ${python}
349+
${CMAKE_CURRENT_LIST_DIR}/create_args_gn.py
350350
"${CMAKE_BINARY_DIR}"
351351
"${idf_path}"
352352
"${CMAKE_CURRENT_LIST_DIR}/chip.c"
@@ -468,10 +468,19 @@ endif()
468468

469469
# Build Matter OTA image
470470
if (CONFIG_CHIP_OTA_IMAGE_BUILD)
471-
chip_ota_image(chip-ota-image
472-
INPUT_FILES ${BUILD_DIR}/${CMAKE_PROJECT_NAME}.bin
473-
OUTPUT_FILE ${BUILD_DIR}/${CMAKE_PROJECT_NAME}-ota.bin
474-
)
475-
# Adding dependecy as app target so that this runs after images are ready
476-
add_dependencies(chip-ota-image app)
471+
if (CONFIG_OPENTHREAD_BORDER_ROUTER AND CONFIG_AUTO_UPDATE_RCP)
472+
chip_ota_image(chip-ota-image
473+
INPUT_FILES ${BUILD_DIR}/ota_with_rcp_image
474+
OUTPUT_FILE ${BUILD_DIR}/ota_with_rcp_image-ota.bin
475+
)
476+
# Adding dependecy as app target so that this runs after images are ready
477+
add_dependencies(chip-ota-image gen_ota_image)
478+
else()
479+
chip_ota_image(chip-ota-image
480+
INPUT_FILES ${BUILD_DIR}/${CMAKE_PROJECT_NAME}.bin
481+
OUTPUT_FILE ${BUILD_DIR}/${CMAKE_PROJECT_NAME}-ota.bin
482+
)
483+
# Adding dependecy as app target so that this runs after images are ready
484+
add_dependencies(chip-ota-image app)
485+
endif()
477486
endif()

config/esp32/components/chip/idf_component.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dependencies:
2626
- if: "target != esp32h2"
2727

2828
espressif/esp_rcp_update:
29-
version: "1.2.0"
29+
version: "~1.3.0"
3030
rules:
3131
- if: "idf_version >=5.0"
3232

examples/thread-br-app/esp32/README.md

+13-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ guides to get started.
1111

1212
---
1313

14-
- [OpenThread Border Router Board](#openthread-border-router-board)
15-
- [OpenThread RCP](#openthread-rcp)
16-
- [OpenThread CLI](#openthread-cli)
17-
- [Setup Thread Network](#setup-thread-network)
18-
- [Commissioning Thread End Devices](#commissioning-thread-end-devices)
14+
- [Matter ESP32 Thread Border Router Example](#matter-esp32-thread-border-router-example)
15+
- [OpenThread Border Router Board](#openthread-border-router-board)
16+
- [OpenThread RCP](#openthread-rcp)
17+
- [OpenThread CLI](#openthread-cli)
18+
- [Setup Thread Network](#setup-thread-network)
19+
- [Commissioning Thread End Devices](#commissioning-thread-end-devices)
20+
- [Generate OTA Firmware For BR](#generate-ota-firmware-for-br)
1921

2022
---
2123

@@ -92,3 +94,9 @@ the Thread network.
9294
```
9395
./chip-tool pairing ble-wifi 2 hex:<dataset_tlvs> <pincode> <discriminator>
9496
```
97+
98+
### Generate OTA Firmware For BR
99+
100+
After enable the option `CONFIG_CREATE_OTA_IMAGE_WITH_RCP_FW` and
101+
`CONFIG_CHIP_OTA_IMAGE_BUILD` in menuconfig, will generate OTA image with rcp
102+
firmware, named `ota_with_rcp_image_ota.bin` in build folder.

examples/thread-br-app/esp32/partitions.csv

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
nvs, data, nvs, , 0xC000,
44
otadata, data, ota, , 0x2000,
55
phy_init, data, phy, , 0x1000,
6-
ota_0, app, ota_0, , 1800K,
7-
ota_1, app, ota_1, , 1800K,
8-
rcp_fw, data, spiffs, , 300K,
6+
ota_0, app, ota_0, , 1600k,
7+
ota_1, app, ota_1, , 1600k,
8+
rcp_fw, data, spiffs, , 640k,

examples/thread-br-app/esp32/sdkconfig.defaults

+21-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
3131
CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=7200
3232
CONFIG_ESP_MAIN_TASK_STACK_SIZE=5120
3333
CONFIG_ESP_TIMER_TASK_STACK_SIZE=5120
34+
CONFIG_CHIP_TASK_STACK_SIZE=9216
3435

3536
# USB console for Thread border board
3637
CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y
@@ -69,9 +70,27 @@ CONFIG_THREAD_NETWORK_COMMISSIONING_DRIVER=n
6970

7071
# Auto update RCP firmware
7172
CONFIG_AUTO_UPDATE_RCP=y
73+
CONFIG_ENABLE_OTA_REQUESTOR=y
74+
CONFIG_CREATE_OTA_IMAGE_WITH_RCP_FW=y
7275

7376
# Use platform mDNS
7477
CONFIG_USE_MINIMAL_MDNS=n
7578

76-
# Enable Matter shell
77-
CONFIG_ENABLE_CHIP_SHELL=y
79+
# Reduce flash size
80+
CONFIG_ENABLE_CHIP_SHELL=n
81+
CONFIG_OPENTHREAD_CLI=n
82+
CONFIG_NEWLIB_NANO_FORMAT=y
83+
84+
CONFIG_NIMBLE_MAX_CONNECTIONS=1
85+
CONFIG_BTDM_CTRL_BLE_MAX_CONN=1
86+
CONFIG_BT_NIMBLE_ROLE_CENTRAL=n
87+
CONFIG_BT_NIMBLE_ROLE_OBSERVER=n
88+
89+
CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE=1024
90+
91+
CONFIG_LOG_DEFAULT_LEVEL_ERROR=y
92+
93+
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
94+
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y
95+
CONFIG_COMPILER_OPTIMIZATION_CHECKS_SILENT=y
96+
CONFIG_ESP_ERR_TO_NAME_LOOKUP=n

examples/thread-br-app/thread-br-common/thread-br-app.matter

+172
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,160 @@ cluster BasicInformation = 40 {
496496
command MfgSpecificPing(): DefaultSuccess = 0;
497497
}
498498

499+
/** Provides an interface for providing OTA software updates */
500+
cluster OtaSoftwareUpdateProvider = 41 {
501+
revision 1; // NOTE: Default/not specifically set
502+
503+
enum ApplyUpdateActionEnum : enum8 {
504+
kProceed = 0;
505+
kAwaitNextAction = 1;
506+
kDiscontinue = 2;
507+
}
508+
509+
enum DownloadProtocolEnum : enum8 {
510+
kBDXSynchronous = 0;
511+
kBDXAsynchronous = 1;
512+
kHTTPS = 2;
513+
kVendorSpecific = 3;
514+
}
515+
516+
enum StatusEnum : enum8 {
517+
kUpdateAvailable = 0;
518+
kBusy = 1;
519+
kNotAvailable = 2;
520+
kDownloadProtocolNotSupported = 3;
521+
}
522+
523+
readonly attribute command_id generatedCommandList[] = 65528;
524+
readonly attribute command_id acceptedCommandList[] = 65529;
525+
readonly attribute event_id eventList[] = 65530;
526+
readonly attribute attrib_id attributeList[] = 65531;
527+
readonly attribute bitmap32 featureMap = 65532;
528+
readonly attribute int16u clusterRevision = 65533;
529+
530+
request struct QueryImageRequest {
531+
vendor_id vendorID = 0;
532+
int16u productID = 1;
533+
int32u softwareVersion = 2;
534+
DownloadProtocolEnum protocolsSupported[] = 3;
535+
optional int16u hardwareVersion = 4;
536+
optional char_string<2> location = 5;
537+
optional boolean requestorCanConsent = 6;
538+
optional octet_string<512> metadataForProvider = 7;
539+
}
540+
541+
response struct QueryImageResponse = 1 {
542+
StatusEnum status = 0;
543+
optional int32u delayedActionTime = 1;
544+
optional char_string<256> imageURI = 2;
545+
optional int32u softwareVersion = 3;
546+
optional char_string<64> softwareVersionString = 4;
547+
optional octet_string<32> updateToken = 5;
548+
optional boolean userConsentNeeded = 6;
549+
optional octet_string<512> metadataForRequestor = 7;
550+
}
551+
552+
request struct ApplyUpdateRequestRequest {
553+
octet_string<32> updateToken = 0;
554+
int32u newVersion = 1;
555+
}
556+
557+
response struct ApplyUpdateResponse = 3 {
558+
ApplyUpdateActionEnum action = 0;
559+
int32u delayedActionTime = 1;
560+
}
561+
562+
request struct NotifyUpdateAppliedRequest {
563+
octet_string<32> updateToken = 0;
564+
int32u softwareVersion = 1;
565+
}
566+
567+
/** Determine availability of a new Software Image */
568+
command QueryImage(QueryImageRequest): QueryImageResponse = 0;
569+
/** Determine next action to take for a downloaded Software Image */
570+
command ApplyUpdateRequest(ApplyUpdateRequestRequest): ApplyUpdateResponse = 2;
571+
/** Notify OTA Provider that an update was applied */
572+
command NotifyUpdateApplied(NotifyUpdateAppliedRequest): DefaultSuccess = 4;
573+
}
574+
575+
/** Provides an interface for downloading and applying OTA software updates */
576+
cluster OtaSoftwareUpdateRequestor = 42 {
577+
revision 1; // NOTE: Default/not specifically set
578+
579+
enum AnnouncementReasonEnum : enum8 {
580+
kSimpleAnnouncement = 0;
581+
kUpdateAvailable = 1;
582+
kUrgentUpdateAvailable = 2;
583+
}
584+
585+
enum ChangeReasonEnum : enum8 {
586+
kUnknown = 0;
587+
kSuccess = 1;
588+
kFailure = 2;
589+
kTimeOut = 3;
590+
kDelayByProvider = 4;
591+
}
592+
593+
enum UpdateStateEnum : enum8 {
594+
kUnknown = 0;
595+
kIdle = 1;
596+
kQuerying = 2;
597+
kDelayedOnQuery = 3;
598+
kDownloading = 4;
599+
kApplying = 5;
600+
kDelayedOnApply = 6;
601+
kRollingBack = 7;
602+
kDelayedOnUserConsent = 8;
603+
}
604+
605+
fabric_scoped struct ProviderLocation {
606+
node_id providerNodeID = 1;
607+
endpoint_no endpoint = 2;
608+
fabric_idx fabricIndex = 254;
609+
}
610+
611+
info event StateTransition = 0 {
612+
UpdateStateEnum previousState = 0;
613+
UpdateStateEnum newState = 1;
614+
ChangeReasonEnum reason = 2;
615+
nullable int32u targetSoftwareVersion = 3;
616+
}
617+
618+
critical event VersionApplied = 1 {
619+
int32u softwareVersion = 0;
620+
int16u productID = 1;
621+
}
622+
623+
info event DownloadError = 2 {
624+
int32u softwareVersion = 0;
625+
int64u bytesDownloaded = 1;
626+
nullable int8u progressPercent = 2;
627+
nullable int64s platformCode = 3;
628+
}
629+
630+
attribute access(write: administer) ProviderLocation defaultOTAProviders[] = 0;
631+
readonly attribute boolean updatePossible = 1;
632+
readonly attribute UpdateStateEnum updateState = 2;
633+
readonly attribute nullable int8u updateStateProgress = 3;
634+
readonly attribute command_id generatedCommandList[] = 65528;
635+
readonly attribute command_id acceptedCommandList[] = 65529;
636+
readonly attribute event_id eventList[] = 65530;
637+
readonly attribute attrib_id attributeList[] = 65531;
638+
readonly attribute bitmap32 featureMap = 65532;
639+
readonly attribute int16u clusterRevision = 65533;
640+
641+
request struct AnnounceOTAProviderRequest {
642+
node_id providerNodeID = 0;
643+
vendor_id vendorID = 1;
644+
AnnouncementReasonEnum announcementReason = 2;
645+
optional octet_string<512> metadataForNode = 3;
646+
endpoint_no endpoint = 4;
647+
}
648+
649+
/** Announce the presence of an OTA Provider */
650+
command AnnounceOTAProvider(AnnounceOTAProviderRequest): DefaultSuccess = 0;
651+
}
652+
499653
/** This cluster is used to manage global aspects of the Commissioning flow. */
500654
cluster GeneralCommissioning = 48 {
501655
revision 1; // NOTE: Default/not specifically set
@@ -1426,6 +1580,7 @@ cluster ThreadBorderRouterManagement = 1106 {
14261580
endpoint 0 {
14271581
device type ma_rootdevice = 22, version 1;
14281582

1583+
binding cluster OtaSoftwareUpdateProvider;
14291584

14301585
server cluster Descriptor {
14311586
callback attribute deviceTypeList;
@@ -1481,6 +1636,23 @@ endpoint 0 {
14811636
ram attribute clusterRevision default = 3;
14821637
}
14831638

1639+
server cluster OtaSoftwareUpdateRequestor {
1640+
emits event StateTransition;
1641+
emits event VersionApplied;
1642+
emits event DownloadError;
1643+
callback attribute defaultOTAProviders;
1644+
ram attribute updatePossible default = true;
1645+
ram attribute updateState default = 0;
1646+
ram attribute updateStateProgress;
1647+
callback attribute generatedCommandList;
1648+
callback attribute acceptedCommandList;
1649+
callback attribute attributeList;
1650+
ram attribute featureMap default = 0;
1651+
ram attribute clusterRevision default = 1;
1652+
1653+
handle command AnnounceOTAProvider;
1654+
}
1655+
14841656
server cluster GeneralCommissioning {
14851657
ram attribute breadcrumb default = 0x0000000000000000;
14861658
callback attribute basicCommissioningInfo;

0 commit comments

Comments
 (0)