Skip to content

Commit

Permalink
[OTA] Add a CLI option to support automatic image apply (#16533)
Browse files Browse the repository at this point in the history
  • Loading branch information
carol-apple authored and pull[bot] committed Apr 6, 2022
1 parent 959b3ca commit 2059716
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ ATWC
AudioOutput
auth
AuthMode
autoApplyImage
autocompletion
autoconnect
autocrlf
Expand Down
1 change: 1 addition & 0 deletions examples/ota-requestor-app/linux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <file path> | If supplied, the OTA image is downloaded to the given fully-qualified file-path. Otherwise, the value defaults to /tmp/test.bin. |
| -u/--userConsentState <granted \| denied \| deferred> | The user consent state for the first QueryImage command. For all subsequent commands, the value of granted will be used. <li> granted: Authorize OTA requestor to download an OTA image <li> denied: Forbid OTA requestor to download an OTA image <li> 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

Expand Down
26 changes: 25 additions & 1 deletion examples/ota-requestor-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class CustomOTARequestorDriver : public DeviceLayer::ExtendedOTARequestorDriver
{
public:
bool CanConsent() override;
void UpdateDownloaded() override;
};

OTARequestor gRequestorCore;
Expand All @@ -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<bool> 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 },
{},
};

Expand All @@ -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 };

Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/app/clusters/ota-requestor/BDXDownloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void BDXDownloader::OnDownloadTimeout()
}
else
{
ChipLogError(BDX, "no download in progress");
ChipLogError(BDX, "No download in progress");
}
}

Expand Down Expand Up @@ -207,7 +207,7 @@ void BDXDownloader::EndDownload(CHIP_ERROR reason)
}
else
{
ChipLogError(BDX, "no download in progress");
ChipLogError(BDX, "No download in progress");
}
}

Expand Down

0 comments on commit 2059716

Please sign in to comment.