Skip to content

Commit

Permalink
Add P6 OTA Requestor App (#14563)
Browse files Browse the repository at this point in the history
* Add P6 ota-requestor app.

* More work on p6 ota app.

* Add new linker script for p6 ota requestor.
Add necessary defines for ota.

* Add anycloud-ota and serial-flash submodules.

* Adding more code to p6 OTA.

* Add factory reset button handling
Fix factory reset bug.

* Move various ota objects to AppTask.

* Fix init bug.

* More p6 ota changes.

* Fix build issues with other p6 apps.

* Add mcuboot config headers.

* Add bootloader hex.

* Format with clang-format and gn format.

* Small improvement to P6 OTA image processor.

* App network commissioning fixes.

* Add ota build scripts.
Add build flag for ota update image.

* Fixup documentation

* Ran gn format

* CI fixes

* Restyling!

* Add DAPLINK to word list.

* More restyling.

* Remove duplicate submodule entry.

* Addressing review issues.

* Add button handling to trigger query-image commands from device.

* Fix for restyle.

* A few more review items.

* More restyle

* Move persistent storage to last 1/4 of flash to leave room for OTA images at start.

* Fix compile issue and add some comments.

* Move NotifyUpdateApplied to after update and reboot.

* Add arg for chip_stack_lock_tracking.

* Delete call to removed function.

* Restyled by clang-format

* Restyled by gn

* Save software version persistently and fix update logic.

* Restyling.

* Fix compile error on other platforms.

* Compile fix for linux fake tests.

* Fix P6 compile after rebase.

* Quick update to README.

* Restyle.

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Sep 12, 2023
1 parent 9b4f8eb commit 9052515
Show file tree
Hide file tree
Showing 43 changed files with 10,384 additions and 27 deletions.
1 change: 1 addition & 0 deletions .github/.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ CY
CYW
DAC
DAP
DAPLINK
DataFrame
DataModelRevision
dataset
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@
[submodule "cyw30739_sdk/tools"]
path = third_party/cyw30739_sdk/repos/btsdk-tools
url = https://github.com/Infineon/btsdk-tools.git
[submodule "third_party/p6/p6_sdk/libs/anycloud-ota"]
path = third_party/p6/p6_sdk/libs/anycloud-ota
url = https://github.com/Infineon/anycloud-ota
[submodule "third_party/mbed-mcu-boot/repo"]
path = third_party/mbed-mcu-boot/repo
url = https://github.com/ATmobica/mcuboot.git
Expand Down
28 changes: 28 additions & 0 deletions examples/ota-requestor-app/p6/.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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.

import("//build_overrides/build.gni")

# The location of the build configuration file.
buildconfig = "${build_root}/config/BUILDCONFIG.gn"

# CHIP uses angle bracket includes.
check_system_includes = true

default_args = {
target_cpu = "arm"
target_os = "freertos"

import("//args.gni")
}
174 changes: 174 additions & 0 deletions examples/ota-requestor-app/p6/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
# 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.

import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")
import("//build_overrides/p6.gni")

import("${build_root}/config/defaults.gni")
import("${p6_sdk_build_root}/p6_executable.gni")
import("${p6_sdk_build_root}/p6_sdk.gni")

assert(current_os == "freertos")

p6_project_dir = "${chip_root}/examples/ota-requestor-app/p6"
examples_plat_dir = "${chip_root}/examples/platform/p6"

declare_args() {
# Dump memory usage at link time.
chip_print_memory_usage = false

# PIN code for PASE session establishment.
setup_pin_code = 20202021

# Monitor & log memory usage at runtime.
enable_heap_monitoring = false

# Build update app
build_update_image = false
}

config("p6_ota_config") {
ldflags = [ "-T/" + rebase_path("src/cy8c6xxa_cm4_dual_ota_int.ld",
"/",
"${p6_project_dir}") ]

ldflags += [ "-Wl,--defsym,MCUBOOT_HEADER_SIZE=0x400,--defsym,MCUBOOT_BOOTLOADER_SIZE=0x18000,--defsym,CY_BOOT_PRIMARY_1_SIZE=0x1C0000" ]

defines = [
"P6_OTA",
"OTA_SUPPORT ",
"OTA_USE_EXTERNAL_FLASH",
"CY_BOOT_USE_EXTERNAL_FLASH",
"MCUBOOT_HEADER_SIZE=0x400",
"MCUBOOT_MAX_IMG_SECTORS=3584",
"CY_BOOT_SCRATCH_SIZE=0x00004000",
"MCUBOOT_BOOTLOADER_SIZE=0x00018000",
"CY_BOOT_BOOTLOADER_SIZE=0x00018000",
"CY_BOOT_PRIMARY_1_START=0x00018000",
"CY_BOOT_PRIMARY_1_SIZE=0x1C0000",
"CY_BOOT_SECONDARY_1_START=0x00000000",
"CY_BOOT_SECONDARY_1_SIZE=0x001C0000",
"CY_FLASH_ERASE_VALUE=0xFF",
"MCUBOOT_IMAGE_NUMBER=1",
"MCUBOOT_SLOT_SIZE=0x1C0000",
"MCUBOOT_SCRATCH_SIZE=0x4000",
"MCUBOOT_SECTOR_SIZE = 512",
"APP_VERSION_MAJOR=1",
"APP_VERSION_MINOR=0",
"APP_VERSION_BUILD=0",
"MCUBOOT_OVERWRITE_ONLY",
"CY_ENABLE_XIP_PROGRAM",
]

if (build_update_image) {
defines += [ "CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION=2" ]
} else {
defines += [ "CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION=1" ]
}
}

# Warning: Don't change the name of this target without also modifying
# third_party/p6/BUILD.gn and third_party/p6/p6_sdk.gn. There are conditionals
# relying on this name.
p6_sdk_sources("ota_requestor_app_sdk_sources") {
include_dirs = [
"${chip_root}/src/platform/P6",
"${p6_project_dir}/include",
"${examples_plat_dir}",
"${p6_project_dir}/config",
"${chip_root}/third_party/p6/p6_sdk/libs/anycloud-ota/source/mcuboot/cy_flash_pal/",
"${chip_root}/third_party/p6/p6_sdk/libs/anycloud-ota/source/mcuboot/cy_flash_pal/mem_config/",
"${chip_root}/third_party/p6/p6_sdk/libs/anycloud-ota/source/mcuboot/cy_flash_pal/include/",
"${chip_root}/third_party/p6/p6_sdk/libs/anycloud-ota/source/mcuboot/cy_flash_pal/include/flash_map_backend/",
"${chip_root}/third_party/p6/p6_sdk/libs/anycloud-ota/source/mcuboot/",
"${chip_root}/third_party/p6/p6_sdk/libs/anycloud-ota/source/mcuboot/sysflash/",
"${chip_root}/third_party/p6/p6_sdk/libs/anycloud-ota/source/mcuboot/bootutil/include",
]

defines = [
"BOARD_ID=${p6_board}",
"P6_LOG_ENABLED=1",
"CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE=${setup_pin_code}",
]

sources = [
"${chip_root}/third_party/p6/p6_sdk/libs/anycloud-ota/source/mcuboot/bootutil/src/bootutil_misc.c",
"${chip_root}/third_party/p6/p6_sdk/libs/anycloud-ota/source/mcuboot/cy_flash_pal/cy_flash_map.c",
"${chip_root}/third_party/p6/p6_sdk/libs/anycloud-ota/source/mcuboot/cy_flash_pal/cy_flash_psoc6.c",
"${chip_root}/third_party/p6/p6_sdk/libs/anycloud-ota/source/mcuboot/cy_flash_pal/cy_smif_psoc6.c",
"${chip_root}/third_party/p6/p6_sdk/libs/anycloud-ota/source/mcuboot/cy_flash_pal/mem_config/mem_config_sfdp.c",
"${p6_project_dir}/include/CHIPProjectConfig.h",
]

public_configs = [
"${chip_root}/third_party/p6:p6_sdk_config",
":p6_ota_config",
]
}

p6_executable("ota_requestor_app") {
include_dirs = []
defines = []
output_name = "chip-p6-ota-requestor-example.out"

sources = [
"${examples_plat_dir}/LEDWidget.cpp",
"${examples_plat_dir}/init_p6Platform.cpp",
"src/AppTask.cpp",
"src/ButtonHandler.cpp",
"src/ZclCallbacks.cpp",
"src/main.cpp",
]

deps = [
":ota_requestor_app_sdk_sources",
"${chip_root}/examples/common/QRCode",
"${chip_root}/examples/ota-requestor-app/ota-requestor-common",
"${chip_root}/src/app/server",
"${chip_root}/src/lib",
"${chip_root}/src/setup_payload",
]

include_dirs += [
"include",
"${examples_plat_dir}",
"${p6_project_dir}/include",
"${chip_root}/examples/ota-requestor-app/ota-requestor-common/include",
]

defines = []

if (enable_heap_monitoring) {
sources += [ "${examples_plat_dir}/MemMonitoring.cpp" ]
defines += [ "HEAP_MONITORING" ]
}

if (chip_print_memory_usage) {
ldflags += [
"-Wl,--print-memory-usage",
"-fstack-usage",
]
}

output_dir = root_out_dir
}

group("p6") {
deps = [ ":ota_requestor_app" ]
}

group("default") {
deps = [ ":p6" ]
}
138 changes: 138 additions & 0 deletions examples/ota-requestor-app/p6/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#CHIP P6 OTA Requestor Example

An example demonstrating the OTA Requestor cluster on a Infineon
CY8CKIT-062S2-43012 board.

<hr>

- [Matter P6 OTA Requestor Example](#chip-p6-ota-requestor-example)
- [Introduction](#introduction)
- [Building](#building)
- [Flashing the Application](#flashing-the-application)
- [Running OTA Update Process](#running-ota-update-process)
- [Notes](#notes)

<hr>

<a name="introduction"></a>

## Introduction

The P6 OTA Requestor example provides a baseline demonstration of a OTA
requestor device, built using Matter and the Infineon Modustoolbox SDK. It can
be controlled by Matter controller over Wi-Fi network.

The P6 device can be commissioned over Bluetooth Low Energy where the device and
the Matter controller will exchange security information with the Rendezvous
procedure. Wi-Fi Network credentials are then provided to the P6 device which
will then join the network.

<a name="building"></a>

## Building

- [Modustoolbox Software](https://www.cypress.com/products/modustoolbox)

Refer to `integrations/docker/images/chip-build-infineon/Dockerfile` or
`scripts/examples/gn_p6_example.sh` for downloading the Software and related
tools.

- Install some additional tools (likely already present for Matter
developers): \$ sudo apt install gcc g++ clang ninja-build python
python3-venv libssl-dev libavahi-client-dev libglib2.0-dev git cmake
python3-pip

- Supported hardware:
[CY8CKIT-062S2-43012](https://www.cypress.com/CY8CKIT-062S2-43012)

* The following applications must be built to demonstrate the OTA process:

- The P6 OTA Requestor App
- The Updated P6 OTA Requestor App (or other app)
- An OTA Provider App (the Linux ota-provider app is used here)
- chip-tool

* Build the P6 OTA Requestor application from the chip root dir:

$ ./examples/ota-requestor-app/examples/ota_base_build.sh

* Build the P6 OTA Update application from the chip root dir:

$ ./examples/ota-requestor-app/examples/ota_update_build.sh

* On a RPi4: Build the Linux OTA Provider application from the chip root dir:

$ ./scripts/examples/gn_build_example.sh examples/ota-provider-app/linux/ out/ota_provider_debug/ chip_config_network_layer_ble=false

* On a RPi4: Build chip-tool:

$ ./scripts/examples/gn_build_example.sh examples/chip-tool/ out/chip-tool/

* Additionally a pre-compiled bootloader must be flashed to the board. This
can be found at:

$ ./examples/ota-requestor-app/p6/matter-psoc6-mcuboot-bootloader.hex

<a name="flashing-the-application"></a>

## Flashing the Application

- Flash the bootloader by first putting the CY8CKIT-062S2-43012 board into
KitProg3 DAPLINK Mode by pressing the `MODE SELECT` button.
`KITPROG3 STATUS` LED will blink to indicate the the board is in the proper
mode. A drive named 'DAPLINK' should be automatically mounted. To flash
drag-and-drop matter-psoc6-mcuboot-bootloader.hex into that drive.

- Put CY8CKIT-062S2-43012 board back into KitProg3 CMSIS-DAP Mode by pressing
the `MODE SELECT` button. `KITPROG3 STATUS` LED is ON confirms board is in
proper mode.

- On the command line:

$ cd ~/connectedhomeip
$ python3 out/ota_requestor_debug/chip-p6-ota-requestor-example.flash.py

<a name="running-ota-update-process"></a>

### Running OTA Update Process

- Make sure the ota-requestor-app is flashed and booting on the
CY8CKIT-062S2-43012.

- Transfer out/ota_requestor_update_debug/chip-p6-ota-requestor-example.bin to
a RPi4.

- On the RPi: In terminal 1 run the Linux ota-provider-app as follows:

$ ./out/ota_provider_debug/chip-ota-provider-app -f chip-p6-ota-requestor-example.bin

- On the RPi: In terminal 2 run the following chip-tool commands

$ ./out/chip-tool/chip-tool pairing ble-wifi 2 "<SSID>" "<PASSWORD>" 20202021 3840

$ ./out/chip-tool/chip-tool pairing onnetwork 1 20202021

$ ./chip-tool accesscontrol write acl '[{"fabricIndex": 1, "privilege": 5, "authMode": 2, "subjects": [112233], "targets": null}, {"fabricIndex": 1, "privilege": 3, "authMode": 2, "subjects": [1, 2], "targets": [{"cluster": null, "endpoint": 0, "deviceType": null}]}]' 1 0

$ ./chip-tool accesscontrol write acl '[{"fabricIndex": 1, "privilege": 5, "authMode": 2, "subjects": [112233], "targets": null}, {"fabricIndex": 1, "privilege": 3, "authMode": 2, "subjects": [1, 2], "targets": [{"cluster": null, "endpoint": 0, "deviceType": null}]}]' 2 0

$ ./chip-tool otasoftwareupdaterequestor write default-ota-providers '[{"fabricIndex": 1, "providerNodeID": 1, "endpoint": 0}]' 2 0

- Press user button 1 on the CY8CKIT-062S2-43012. This will trigger a
query-image call from the board using the default ota provider list written
in the above commands.

- Using a serial emulator reading from the CY8CKIT-062S2-43012, you should
observe the updated application being transferred to the board, written to
flash, and, when completed, booted into.

<a name="notes"></a>

#### Notes

Raspberry Pi 4 BLE connection issues can be avoided by running the following
commands. These power cycle the BlueTooth hardware and disable BR/EDR mode.

$ sudo btmgmt -i hci0 power off
$ sudo btmgmt -i hci0 bredr off
$ sudo btmgmt -i hci0 power on
28 changes: 28 additions & 0 deletions examples/ota-requestor-app/p6/args.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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.

import("//build_overrides/chip.gni")
import("//build_overrides/pigweed.gni")
import("${chip_root}/src/platform/P6/args.gni")

declare_args() {
chip_enable_ota_requestor = true

# Disable lock tracking, since our FreeRTOS configuration does not set
# INCLUDE_xSemaphoreGetMutexHolder
chip_stack_lock_tracking = "none"
}

p6_target_project =
get_label_info(":ota_requestor_app_sdk_sources", "label_no_toolchain")
1 change: 1 addition & 0 deletions examples/ota-requestor-app/p6/build_overrides
Loading

0 comments on commit 9052515

Please sign in to comment.