Skip to content

Commit

Permalink
Add support for supplying OTA download file path (#15660)
Browse files Browse the repository at this point in the history
Updated ota_test.sh script to compare the ota binaries to declare success
  • Loading branch information
harsha-rajendran authored and pull[bot] committed Sep 1, 2023
1 parent 5365098 commit 1982418
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 22 deletions.
1 change: 1 addition & 0 deletions .github/.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,7 @@ optionsOverride
orgs
OTA
OTADownloader
otaDownloadPath
otaImageList
OTAImageProcessorDriver
OTAImageProcessorInterface
Expand Down
12 changes: 6 additions & 6 deletions examples/ota-requestor-app/linux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ following command line options are available for the OTA Requestor application.
| --------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| -q/--delayQuery <Time in seconds> | From boot up, the amount of time to wait before triggering the QueryImage command. If none or zero is supplied, QueryImage will not be triggered automatically. At least one provider location must be written to the DefaultOTAProviders attribute. |
| -c/--requestorCanConsent | If supplied, the RequestorCanConsent field of the QueryImage command is set to true. Otherwise, the value is determined by the driver. |
| -f/--otaDownloadPath <file path> | If supplied, the OTA image is downloaded to the given fully-qualified file-path. Otherwise, the value defaults to /tmp/test.bin. |

## Software Image Header

Expand Down Expand Up @@ -86,7 +87,7 @@ Follow instructions
#### Run the OTA Requestor application:

```
out/chip-ota-requestor-app --discriminator ${REQUESTOR_LONG_DISCRIMINATOR} --secured-device-port ${REQUESTOR_UDP_PORT} --KVS ${KVS_STORE_LOCATION} --delayQuery ${TIME_IN_SECONDS}
out/chip-ota-requestor-app --discriminator ${REQUESTOR_LONG_DISCRIMINATOR} --secured-device-port ${REQUESTOR_UDP_PORT} --KVS ${KVS_STORE_LOCATION} --delayQuery ${TIME_IN_SECONDS} --otaDownloadPath ${OTA_FILE_PATH}
```

- `${REQUESTOR_LONG_DISCRIMINATOR}` is the long discriminator specified for
Expand All @@ -101,6 +102,8 @@ out/chip-ota-requestor-app --discriminator ${REQUESTOR_LONG_DISCRIMINATOR} --sec
the value used by the OTA Provider application.
- `${TIME_IN_SECONDS}` is the amount of time to wait before triggering the
QueryImage command specified by the DefaultOTAProviders attribute
- `${OTA_FILE_PATH}` is the fully-qualified path for the OTA file download
location

#### Commission the OTA Requestor application

Expand Down Expand Up @@ -212,7 +215,7 @@ scripts/examples/gn_build_example.sh examples/ota-requestor-app/linux/ out chip_
**Run the OTA Requestor application**

```
out/chip-ota-requestor-app --discriminator 18 --secured-device-port 5560 --KVS /tmp/chip_kvs_requestor --delayQuery 30
out/chip-ota-requestor-app --discriminator 18 --secured-device-port 5560 --KVS /tmp/chip_kvs_requestor --delayQuery 30 --otaDownloadPath /tmp/test.bin
```

#### In terminal 3:
Expand Down Expand Up @@ -257,7 +260,7 @@ specified below:

```
scripts/examples/gn_build_example.sh examples/ota-requestor-app/linux/ out chip_config_network_layer_ble=false
out/chip-ota-requestor-app --discriminator 18 --secured-device-port 5560 --KVS /tmp/chip_kvs_requestor
out/chip-ota-requestor-app --discriminator 18 --secured-device-port 5560 --KVS /tmp/chip_kvs_requestor --otaDownloadPath /tmp/test.bin
```

**Commission to the first fabric**
Expand Down Expand Up @@ -297,6 +300,3 @@ out/chip-tool otasoftwareupdaterequestor read default-ota-providers 0x858 0 --co
```

## Limitations

- Stores the downloaded file in the directory this reference app is launched
from
16 changes: 12 additions & 4 deletions examples/ota-requestor-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,17 @@ void OnStartDelayTimerHandler(Layer * systemLayer, void * appState);

constexpr uint16_t kOptionDelayQuery = 'q';
constexpr uint16_t kOptionRequestorCanConsent = 'c';
constexpr uint16_t kOptionOtaDownloadPath = 'f';
constexpr size_t kMaxFilePathSize = 256;

uint16_t delayQueryTimeInSec = 0;
chip::Optional<bool> gRequestorCanConsent;
static char gOtaDownloadPath[kMaxFilePathSize] = "/tmp/test.bin";

OptionDef cmdLineOptionsDef[] = {
{ "delayQuery", chip::ArgParser::kArgumentRequired, kOptionDelayQuery },
{ "requestorCanConsent", chip::ArgParser::kNoArgument, kOptionRequestorCanConsent },
{ "otaDownloadPath", chip::ArgParser::kArgumentRequired, kOptionOtaDownloadPath },
{},
};

Expand All @@ -73,7 +77,10 @@ OptionSet cmdLineOptions = { HandleOptions, cmdLineOptionsDef, "PROGRAM OPTIONS"
"least one provider location must be written to the DefaultOTAProviders attribute.\n"
" -c/--requestorCanConsent\n"
" If supplied, the RequestorCanConsent field of the QueryImage command is set to true.\n"
" Otherwise, the value is determined by the driver.\n " };
" Otherwise, the value is determined by the driver.\n "
" -f/--otaDownloadPath <file path>\n"
" If supplied, the OTA image is downloaded to the given fully-qualified file-path.\n"
" Otherwise, the value defaults to /tmp/test.bin.\n " };

OptionSet * allOptions[] = { &cmdLineOptions, nullptr };

Expand All @@ -87,10 +94,8 @@ static void InitOTARequestor(void)

// WARNING: this is probably not realistic to know such details of the image or to even have an OTADownloader instantiated at
// the beginning of program execution. We're using hardcoded values here for now since this is a reference application.
// TODO: instatiate and initialize these values when QueryImageResponse tells us an image is available
// TODO: add API for OTARequestor to pass QueryImageResponse info to the application to use for OTADownloader init
OTAImageProcessorParams ipParams;
ipParams.imageFile = CharSpan("test.txt");
ipParams.imageFile = CharSpan::fromCharString(gOtaDownloadPath);
gImageProcessor.SetOTAImageProcessorParams(ipParams);
gImageProcessor.SetOTADownloader(&gDownloader);

Expand All @@ -110,6 +115,9 @@ bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier,
case kOptionRequestorCanConsent:
gRequestorCanConsent.SetValue(true);
break;
case kOptionOtaDownloadPath:
chip::Platform::CopyString(gOtaDownloadPath, aValue);
break;
default:
PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", aProgram, aName);
retval = false;
Expand Down
28 changes: 16 additions & 12 deletions scripts/tests/ota_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,30 @@
PASSCODE=${1:-20202021}
DISCRIMINATOR=${2:-42}
UDP_PORT=${3:-5560}
OTA_DOWNLOAD_PATH=${4:-"/tmp/test.bin"}

pkill chip-ota-provider-app
pkill chip-ota-requestor-app
FIRMWARE_BIN="my-firmware.bin"
FIRMWARE_OTA="my-firmware.ota"

OTA_PROVIDER_APP="chip-ota-provider-app"
OTA_REQUESTOR_APP="chip-ota-requestor-app"

killall -e "$OTA_PROVIDER_APP" "$OTA_REQUESTOR_APP"
rm -f "$FIRMWARE_OTA" "$FIRMWARE_BIN" "$OTA_DOWNLOAD_PATH"

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

touch my-firmware.bin
echo "Test" >"$FIRMWARE_BIN"

rm /tmp/chip_*

./src/app/ota_image_tool.py create -v 0xDEAD -p 0xBEEF -vn 1 -vs "1.0" -da sha256 my-firmware.bin my-firmware.ota
./src/app/ota_image_tool.py create -v 0xDEAD -p 0xBEEF -vn 1 -vs "1.0" -da sha256 "$FIRMWARE_BIN" "$FIRMWARE_OTA"

if [ ! -f "my-firmware.ota" ]; then
if [ ! -f "$FIRMWARE_OTA" ]; then
exit 1
fi

./out/ota_provider_debug/chip-ota-provider-app -f my-firmware.ota | tee /tmp/ota/provider-log.txt &
provider_pid=$!
./out/ota_provider_debug/"$OTA_PROVIDER_APP" -f "$FIRMWARE_OTA" | tee /tmp/ota/provider-log.txt &

echo "Commissioning Provider"

Expand All @@ -33,8 +39,7 @@ fi

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

stdbuf -o0 ./out/ota_requestor_debug/chip-ota-requestor-app --discriminator "$DISCRIMINATOR" --secured-device-port "$UDP_PORT" --KVS /tmp/chip_kvs_requestor | tee /tmp/ota/requestor-log.txt &
requestor_pid=$!
stdbuf -o0 ./out/ota_requestor_debug/"$OTA_REQUESTOR_APP" --discriminator "$DISCRIMINATOR" --secured-device-port "$UDP_PORT" --KVS /tmp/chip_kvs_requestor --otaDownloadPath "$OTA_DOWNLOAD_PATH" | tee /tmp/ota/requestor-log.txt &

echo "Commissioning Requestor"

Expand All @@ -54,10 +59,9 @@ timeout 30 grep -q "OTA image downloaded to" <(tail -n0 -f /tmp/ota/requestor-lo

echo "Exiting, logs are in tmp/ota/"

kill "$provider_pid"
kill "$requestor_pid"
killall -e "$OTA_PROVIDER_APP" "$OTA_REQUESTOR_APP"

if grep "OTA image downloaded to" /tmp/ota/requestor-log.txt; then
if cmp "$OTA_DOWNLOAD_PATH" "$FIRMWARE_BIN"; then
echo Test passed && exit 0
else
echo Test failed && exit 1
Expand Down

0 comments on commit 1982418

Please sign in to comment.