Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32: Add OTA function for thread border router device #37099

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions config/esp32/components/chip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ endif()

set(args_gn "${CMAKE_CURRENT_BINARY_DIR}/args.gn")
add_custom_command(OUTPUT "${args_gn}"
COMMAND ${python}
${CMAKE_CURRENT_LIST_DIR}/create_args_gn.py
COMMAND ${python}
${CMAKE_CURRENT_LIST_DIR}/create_args_gn.py
"${CMAKE_BINARY_DIR}"
"${idf_path}"
"${CMAKE_CURRENT_LIST_DIR}/chip.c"
Expand Down Expand Up @@ -468,10 +468,19 @@ endif()

# Build Matter OTA image
if (CONFIG_CHIP_OTA_IMAGE_BUILD)
chip_ota_image(chip-ota-image
INPUT_FILES ${BUILD_DIR}/${CMAKE_PROJECT_NAME}.bin
OUTPUT_FILE ${BUILD_DIR}/${CMAKE_PROJECT_NAME}-ota.bin
)
# Adding dependecy as app target so that this runs after images are ready
add_dependencies(chip-ota-image app)
if (CONFIG_OPENTHREAD_BORDER_ROUTER AND CONFIG_AUTO_UPDATE_RCP)
chip_ota_image(chip-ota-image
INPUT_FILES ${BUILD_DIR}/ota_with_rcp_image
OUTPUT_FILE ${BUILD_DIR}/ota_with_rcp_image-ota.bin
)
# Adding dependecy as app target so that this runs after images are ready
add_dependencies(chip-ota-image gen_ota_image)
else()
chip_ota_image(chip-ota-image
INPUT_FILES ${BUILD_DIR}/${CMAKE_PROJECT_NAME}.bin
OUTPUT_FILE ${BUILD_DIR}/${CMAKE_PROJECT_NAME}-ota.bin
)
# Adding dependecy as app target so that this runs after images are ready
add_dependencies(chip-ota-image app)
endif()
endif()
2 changes: 1 addition & 1 deletion config/esp32/components/chip/idf_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies:
- if: "target != esp32h2"

espressif/esp_rcp_update:
version: "1.2.0"
version: "~1.3.0"
rules:
- if: "idf_version >=5.0"

Expand Down
18 changes: 13 additions & 5 deletions examples/thread-br-app/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ guides to get started.

---

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

---

Expand Down Expand Up @@ -92,3 +94,9 @@ the Thread network.
```
./chip-tool pairing ble-wifi 2 hex:<dataset_tlvs> <pincode> <discriminator>
```

### Generate OTA Firmware For BR

After enable the option `CONFIG_CREATE_OTA_IMAGE_WITH_RCP_FW` and
`CONFIG_CHIP_OTA_IMAGE_BUILD` in menuconfig, will generate OTA image with rcp
firmware, named `ota_with_rcp_image_ota.bin` in build folder.
6 changes: 3 additions & 3 deletions examples/thread-br-app/esp32/partitions.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
nvs, data, nvs, , 0xC000,
otadata, data, ota, , 0x2000,
phy_init, data, phy, , 0x1000,
ota_0, app, ota_0, , 1800K,
ota_1, app, ota_1, , 1800K,
rcp_fw, data, spiffs, , 300K,
ota_0, app, ota_0, , 1600k,
ota_1, app, ota_1, , 1600k,
rcp_fw, data, spiffs, , 640k,
23 changes: 21 additions & 2 deletions examples/thread-br-app/esp32/sdkconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=7200
CONFIG_ESP_MAIN_TASK_STACK_SIZE=5120
CONFIG_ESP_TIMER_TASK_STACK_SIZE=5120
CONFIG_CHIP_TASK_STACK_SIZE=9216

# USB console for Thread border board
CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y
Expand Down Expand Up @@ -69,9 +70,27 @@ CONFIG_THREAD_NETWORK_COMMISSIONING_DRIVER=n

# Auto update RCP firmware
CONFIG_AUTO_UPDATE_RCP=y
CONFIG_ENABLE_OTA_REQUESTOR=y
CONFIG_CREATE_OTA_IMAGE_WITH_RCP_FW=y

# Use platform mDNS
CONFIG_USE_MINIMAL_MDNS=n

# Enable Matter shell
CONFIG_ENABLE_CHIP_SHELL=y
# Reduce flash size
CONFIG_ENABLE_CHIP_SHELL=n
CONFIG_OPENTHREAD_CLI=n
CONFIG_NEWLIB_NANO_FORMAT=y

CONFIG_NIMBLE_MAX_CONNECTIONS=1
CONFIG_BTDM_CTRL_BLE_MAX_CONN=1
CONFIG_BT_NIMBLE_ROLE_CENTRAL=n
CONFIG_BT_NIMBLE_ROLE_OBSERVER=n

CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE=1024

CONFIG_LOG_DEFAULT_LEVEL_ERROR=y

CONFIG_COMPILER_OPTIMIZATION_SIZE=y
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y
CONFIG_COMPILER_OPTIMIZATION_CHECKS_SILENT=y
CONFIG_ESP_ERR_TO_NAME_LOOKUP=n
172 changes: 172 additions & 0 deletions examples/thread-br-app/thread-br-common/thread-br-app.matter
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,160 @@ cluster BasicInformation = 40 {
command MfgSpecificPing(): DefaultSuccess = 0;
}

/** Provides an interface for providing OTA software updates */
cluster OtaSoftwareUpdateProvider = 41 {
revision 1; // NOTE: Default/not specifically set

enum ApplyUpdateActionEnum : enum8 {
kProceed = 0;
kAwaitNextAction = 1;
kDiscontinue = 2;
}

enum DownloadProtocolEnum : enum8 {
kBDXSynchronous = 0;
kBDXAsynchronous = 1;
kHTTPS = 2;
kVendorSpecific = 3;
}

enum StatusEnum : enum8 {
kUpdateAvailable = 0;
kBusy = 1;
kNotAvailable = 2;
kDownloadProtocolNotSupported = 3;
}

readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
readonly attribute event_id eventList[] = 65530;
readonly attribute attrib_id attributeList[] = 65531;
readonly attribute bitmap32 featureMap = 65532;
readonly attribute int16u clusterRevision = 65533;

request struct QueryImageRequest {
vendor_id vendorID = 0;
int16u productID = 1;
int32u softwareVersion = 2;
DownloadProtocolEnum protocolsSupported[] = 3;
optional int16u hardwareVersion = 4;
optional char_string<2> location = 5;
optional boolean requestorCanConsent = 6;
optional octet_string<512> metadataForProvider = 7;
}

response struct QueryImageResponse = 1 {
StatusEnum status = 0;
optional int32u delayedActionTime = 1;
optional char_string<256> imageURI = 2;
optional int32u softwareVersion = 3;
optional char_string<64> softwareVersionString = 4;
optional octet_string<32> updateToken = 5;
optional boolean userConsentNeeded = 6;
optional octet_string<512> metadataForRequestor = 7;
}

request struct ApplyUpdateRequestRequest {
octet_string<32> updateToken = 0;
int32u newVersion = 1;
}

response struct ApplyUpdateResponse = 3 {
ApplyUpdateActionEnum action = 0;
int32u delayedActionTime = 1;
}

request struct NotifyUpdateAppliedRequest {
octet_string<32> updateToken = 0;
int32u softwareVersion = 1;
}

/** Determine availability of a new Software Image */
command QueryImage(QueryImageRequest): QueryImageResponse = 0;
/** Determine next action to take for a downloaded Software Image */
command ApplyUpdateRequest(ApplyUpdateRequestRequest): ApplyUpdateResponse = 2;
/** Notify OTA Provider that an update was applied */
command NotifyUpdateApplied(NotifyUpdateAppliedRequest): DefaultSuccess = 4;
}

/** Provides an interface for downloading and applying OTA software updates */
cluster OtaSoftwareUpdateRequestor = 42 {
revision 1; // NOTE: Default/not specifically set

enum AnnouncementReasonEnum : enum8 {
kSimpleAnnouncement = 0;
kUpdateAvailable = 1;
kUrgentUpdateAvailable = 2;
}

enum ChangeReasonEnum : enum8 {
kUnknown = 0;
kSuccess = 1;
kFailure = 2;
kTimeOut = 3;
kDelayByProvider = 4;
}

enum UpdateStateEnum : enum8 {
kUnknown = 0;
kIdle = 1;
kQuerying = 2;
kDelayedOnQuery = 3;
kDownloading = 4;
kApplying = 5;
kDelayedOnApply = 6;
kRollingBack = 7;
kDelayedOnUserConsent = 8;
}

fabric_scoped struct ProviderLocation {
node_id providerNodeID = 1;
endpoint_no endpoint = 2;
fabric_idx fabricIndex = 254;
}

info event StateTransition = 0 {
UpdateStateEnum previousState = 0;
UpdateStateEnum newState = 1;
ChangeReasonEnum reason = 2;
nullable int32u targetSoftwareVersion = 3;
}

critical event VersionApplied = 1 {
int32u softwareVersion = 0;
int16u productID = 1;
}

info event DownloadError = 2 {
int32u softwareVersion = 0;
int64u bytesDownloaded = 1;
nullable int8u progressPercent = 2;
nullable int64s platformCode = 3;
}

attribute access(write: administer) ProviderLocation defaultOTAProviders[] = 0;
readonly attribute boolean updatePossible = 1;
readonly attribute UpdateStateEnum updateState = 2;
readonly attribute nullable int8u updateStateProgress = 3;
readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
readonly attribute event_id eventList[] = 65530;
readonly attribute attrib_id attributeList[] = 65531;
readonly attribute bitmap32 featureMap = 65532;
readonly attribute int16u clusterRevision = 65533;

request struct AnnounceOTAProviderRequest {
node_id providerNodeID = 0;
vendor_id vendorID = 1;
AnnouncementReasonEnum announcementReason = 2;
optional octet_string<512> metadataForNode = 3;
endpoint_no endpoint = 4;
}

/** Announce the presence of an OTA Provider */
command AnnounceOTAProvider(AnnounceOTAProviderRequest): DefaultSuccess = 0;
}

/** This cluster is used to manage global aspects of the Commissioning flow. */
cluster GeneralCommissioning = 48 {
revision 1; // NOTE: Default/not specifically set
Expand Down Expand Up @@ -1426,6 +1580,7 @@ cluster ThreadBorderRouterManagement = 1106 {
endpoint 0 {
device type ma_rootdevice = 22, version 1;

binding cluster OtaSoftwareUpdateProvider;

server cluster Descriptor {
callback attribute deviceTypeList;
Expand Down Expand Up @@ -1481,6 +1636,23 @@ endpoint 0 {
ram attribute clusterRevision default = 3;
}

server cluster OtaSoftwareUpdateRequestor {
emits event StateTransition;
emits event VersionApplied;
emits event DownloadError;
callback attribute defaultOTAProviders;
ram attribute updatePossible default = true;
ram attribute updateState default = 0;
ram attribute updateStateProgress;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute attributeList;
ram attribute featureMap default = 0;
ram attribute clusterRevision default = 1;

handle command AnnounceOTAProvider;
}

server cluster GeneralCommissioning {
ram attribute breadcrumb default = 0x0000000000000000;
callback attribute basicCommissioningInfo;
Expand Down
Loading
Loading