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

[ota] decouple ota from build #96

Merged
merged 4 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
75 changes: 75 additions & 0 deletions doc/matter/MatterOTA_guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Matter OTA Guide for AmebaZ2

Follow this guide to carry out Matter standard Over the Air Software Update

## Prerequisites

Build Linux ota-provider-app

cd connectedhomeip
source scripts/activate.sh
./scripts/examples/gn_build_example.sh examples/ota-provider-app/linux/ ota-provider

## Generating the OTA Image

When building the OTA firmware, ensure that `CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION` and `CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING` is higher than that of the current image.
step0035 marked this conversation as resolved.
Show resolved Hide resolved

In `GCC-Release/ameba_firmware.json`, update the **serial** value to a higher number than that of current image.

After building the firmware, use the `ota_image_tool.py` to generate the OTA image. This tool will add Matter OTA header to the firmware image.

python3 ota_image_tool.py create -v <VENDORID> -p <PRODUCTID> -vn <VERSION> -vs <VERSIONSTRING> -da <DIGESTALGO> <path to firmware> <output ota image>

For example

cd ambz2_matter/tools/matter/ota
python3 ota_image_tool.py create -v 0x8888 -p 0x9999 -vn 2 -vs 2.0 -da sha256 ../../../project/realtek_amebaz2_v0_example/GCC-RELEASE/application_is/Debug/bin/firmware_is.bin ota_image.bin

Ensure that the `VERSION` and `VERSIONSTRING` matches your `CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION` and `CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING` respectively.

To check your OTA image

python3 ota_image_tool.py show <ota image>

Once you have ensured that the ITA image is correct, copy the output OTA image to the directory of the ota-provider built from the previous step.
step0035 marked this conversation as resolved.
Show resolved Hide resolved

cp ota_image.bin <path to the ota-provider directory>

## Executing the OTA

#### Terminal 1 (Linux ota-provider-app)

cd connectedhomeip/ota-provider
./chip-ota-provider-app -f ota_image.bin

#### Terminal 2 (chip-tool):

Pair the device on NodeID=1, pair the ota-provider-app on NodeID=2.

./chip-tool ble-wifi 1 <SSID> <PASSWORD> 20202021 3840
./chip-tool pairing onnetwork 2 20202021

Set the ota-provider to be the default-otaprovider of the device.

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

Configure the ACL of the ota-provider-app to allow access for device.

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

Announce the ota-provider-app to the device to start the OTA process.

./chip-tool otasoftwareupdaterequestor announce-otaprovider 2 0 0 0 1 0

## Expected Outcome

- The ota-provider-app will transfer the ota image by blocks of 1024 bytes.
- After completion, device will send an `ApplyUpdateRequest` to the ota-provider-app, who will send back an `ApplyUpdateResponse`.
- Upon receiving the `ApplyUpdateResponse`, the device will countdown 10 seconds before rebooting.
- If the OTA is successful, the device will reboot into the new image and will send a `NotifyUpdateApplied` to the ota-provider-app.

## Common Mistakes

- VendorID and ProductID of the new OTA image does not match the ones in the Basic Information cluster, causing OTA to fail.
step0035 marked this conversation as resolved.
Show resolved Hide resolved
- Version of the new OTA image is not higher than the current image's version. OTA will only be allowed to execute if new image is newer than the current image.
- OTA process completed, but device still reboots into old image instead of the new image. Check if you have updated the **Serial** field in `ameba_firmware.json`.
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ OS := $(shell uname)

LDSCRIPT := ./rtl8710c_ram_matter.ld

# Matter OTA header information
VENDORID := 0xDEAD
PRODUCTID := 0xBEEF
VERSION := 0
VERSIONSTRING := 0.0
DIGESTALGO := sha256

# Initialize target name and target object files
# -------------------------------------------------------------------

Expand Down Expand Up @@ -826,8 +819,6 @@ endif
$(ELF2BIN) convert amebaz2_firmware_is.json FIRMWARE secure_bit=0
$(CHKSUM) $(BIN_DIR)/firmware_is.bin
$(ELF2BIN) combine $(BIN_DIR)/flash_is.bin PTAB=partition.bin,BOOT=$(BOOT_BIN_DIR)/bootloader.bin,FW1=$(BIN_DIR)/firmware_is.bin
python3 $(AMEBAZ2_MATTER_TOOLDIR)/ota/ota_image_tool.py create -v $(VENDORID) -p $(PRODUCTID) -vn $(VERSION) -vs $(VERSIONSTRING) -da $(DIGESTALGO) $(BIN_DIR)/firmware_is.bin $(BIN_DIR)/MATTER_OTA_FIRMWARE.bin
python3 $(AMEBAZ2_MATTER_TOOLDIR)/ota/ota_image_tool.py show $(BIN_DIR)/MATTER_OTA_FIRMWARE.bin

# Generate build info
# -------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion tools/matter/ota/ota_image_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import struct
import sys
from enum import IntEnum
from tlv import TLVReader, TLVWriter, uint # noqa: E402
from tlv import TLVReader, TLVWriter, uint # noqa: E402 isort:skip
step0035 marked this conversation as resolved.
Show resolved Hide resolved

HEADER_MAGIC = 0x1BEEF11E
FIXED_HEADER_FORMAT = '<IQI'
Expand Down
13 changes: 5 additions & 8 deletions tools/matter/ota/tlv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
#


from __future__ import absolute_import
from __future__ import print_function
from __future__ import absolute_import, print_function

import struct
from collections import OrderedDict
Expand Down Expand Up @@ -680,13 +679,11 @@ def _get(self, tlv, decodings, out):
if "profileTag" in list(decoding.keys()):
out[decoding["profileTag"]] = decoding["value"]
elif "tag" in list(decoding.keys()):
if decoding["tag"] is not None:
out[decoding["tag"]] = decoding["value"]
if isinstance(out, Mapping):
tag = decoding["tag"] if decoding["tag"] is not None else "Any"
out[tag] = decoding["value"]
else:
if isinstance(out, Mapping):
out["Any"] = decoding["value"]
elif isinstance(out, Sequence):
out.append(decoding["value"])
out.append(decoding["value"])
else:
raise ValueError("Attempt to decode unsupported TLV tag")

Expand Down