diff --git a/.github/.wordlist.txt b/.github/.wordlist.txt index 064a278a6c86b2..8a6d2116e2cbb7 100644 --- a/.github/.wordlist.txt +++ b/.github/.wordlist.txt @@ -95,6 +95,7 @@ ATWC AudioOutput auth AuthMode +autoApplyImage autocompletion autoconnect autocrlf diff --git a/examples/ota-requestor-app/linux/README.md b/examples/ota-requestor-app/linux/README.md index f192d94c54b74f..ad610c9a56e870 100644 --- a/examples/ota-requestor-app/linux/README.md +++ b/examples/ota-requestor-app/linux/README.md @@ -23,6 +23,7 @@ following command line options are available for the OTA Requestor application. | -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 | If supplied, the OTA image is downloaded to the given fully-qualified file-path. Otherwise, the value defaults to /tmp/test.bin. | | -u/--userConsentState | The user consent state for the first QueryImage command. For all subsequent commands, the value of granted will be used.
  • granted: Authorize OTA requestor to download an OTA image
  • denied: Forbid OTA requestor to download an OTA image
  • deferred: Defer obtaining user consent | +| -a/--autoApplyImage | If supplied, apply the image immediately after download. Otherwise, the OTA update is complete after image download. | ## Software Image Header diff --git a/examples/ota-requestor-app/linux/main.cpp b/examples/ota-requestor-app/linux/main.cpp index b02cae2c49ac3f..add907124b41c5 100644 --- a/examples/ota-requestor-app/linux/main.cpp +++ b/examples/ota-requestor-app/linux/main.cpp @@ -51,6 +51,7 @@ class CustomOTARequestorDriver : public DeviceLayer::ExtendedOTARequestorDriver { public: bool CanConsent() override; + void UpdateDownloaded() override; }; OTARequestor gRequestorCore; @@ -67,17 +68,20 @@ constexpr uint16_t kOptionUserConsentState = 'u'; constexpr uint16_t kOptionPeriodicQueryTimeout = 'p'; constexpr uint16_t kOptionRequestorCanConsent = 'c'; constexpr uint16_t kOptionOtaDownloadPath = 'f'; +constexpr uint16_t kOptionAutoApplyImage = 'a'; constexpr size_t kMaxFilePathSize = 256; uint32_t gPeriodicQueryTimeoutSec = (24 * 60 * 60); chip::Optional gRequestorCanConsent; static char gOtaDownloadPath[kMaxFilePathSize] = "/tmp/test.bin"; +bool gAutoApplyImage = false; OptionDef cmdLineOptionsDef[] = { { "periodicQueryTimeout", chip::ArgParser::kArgumentRequired, kOptionPeriodicQueryTimeout }, { "requestorCanConsent", chip::ArgParser::kNoArgument, kOptionRequestorCanConsent }, { "otaDownloadPath", chip::ArgParser::kArgumentRequired, kOptionOtaDownloadPath }, { "userConsentState", chip::ArgParser::kArgumentRequired, kOptionUserConsentState }, + { "autoApplyImage", chip::ArgParser::kNoArgument, kOptionAutoApplyImage }, {}, }; @@ -97,7 +101,10 @@ OptionSet cmdLineOptions = { HandleOptions, cmdLineOptionsDef, "PROGRAM OPTIONS" " subsequent commands, the value of granted will be used.\n" " granted: Authorize OTA requestor to download an OTA image\n" " denied: Forbid OTA requestor to download an OTA image\n" - " deferred: Defer obtaining user consent \n" }; + " deferred: Defer obtaining user consent \n" + " -a/--autoApplyImage\n" + " If supplied, apply the image immediately after download.\n" + " Otherwise, the OTA update is complete after image download.\n" }; OptionSet * allOptions[] = { &cmdLineOptions, nullptr }; @@ -106,6 +113,20 @@ bool CustomOTARequestorDriver::CanConsent() return gRequestorCanConsent.ValueOr(DeviceLayer::ExtendedOTARequestorDriver::CanConsent()); } +void CustomOTARequestorDriver::UpdateDownloaded() +{ + if (gAutoApplyImage) + { + // Let the default driver take further action to apply the image + GenericOTARequestorDriver::UpdateDownloaded(); + } + else + { + // Cancelling will put the state back to idle + gRequestorCore.CancelImageUpdate(); + } +} + static void InitOTARequestor(void) { // Set the global instance of the OTA requestor core component @@ -170,6 +191,9 @@ bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier, retval = false; } break; + case kOptionAutoApplyImage: + gAutoApplyImage = true; + break; default: PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", aProgram, aName); retval = false; diff --git a/src/app/clusters/ota-requestor/BDXDownloader.cpp b/src/app/clusters/ota-requestor/BDXDownloader.cpp index 4bf42b151c460d..184fceb2738183 100644 --- a/src/app/clusters/ota-requestor/BDXDownloader.cpp +++ b/src/app/clusters/ota-requestor/BDXDownloader.cpp @@ -174,7 +174,7 @@ void BDXDownloader::OnDownloadTimeout() } else { - ChipLogError(BDX, "no download in progress"); + ChipLogError(BDX, "No download in progress"); } } @@ -207,7 +207,7 @@ void BDXDownloader::EndDownload(CHIP_ERROR reason) } else { - ChipLogError(BDX, "no download in progress"); + ChipLogError(BDX, "No download in progress"); } }