Software Update via Ethernet - the mbed application can pull down an updated application binary from a web server and activate that binary. This library works only with the LPC1768, as it relies on the magic-chip boot-loader mechanism.
Dependents: WattEye X10Svr PUB_SWUpdate
Success!! With this library, a network connection, and a web server hosting a new binary image, you can update the mbed firmware over the air (FOTA) - well, at least via Ethernet so far.
As of March 2015, it has been tested with the following mbed official libraries:
- mbed v95, v85 thru v89
- mbed-rtos v64, v32 thru v44
- EthernetInterface v47, v41 thru v43
And a custom derivation:
- HTTPClient v33, v32, which includes a custom HTTPFile.
Part of the update process involves checking the integrity of the downloaded binary file, for both a checksum and the program (file) size. To create this additional information, a small perl script is used (the important part is only 20 lines of code). See the documentation in the header file.
After the new binary is successfully downloaded, the checksum and the size are evaluated and if correct, then the old binary file is removed (this is the only way to cause the new binary to activate).
The mbed can then be automatically reset to activate the new image, or this may be deferred in case there is some other process necessary for an orderly restart.
Details are in the SWUpdate header file, and PUB_SWUpdate is a publicly accessible demonstration program for this library.
Diff: SWUpdate.cpp
- Revision:
- 27:3d3089b8212d
- Parent:
- 26:f2bb6061dcb3
- Child:
- 29:f67a7f54c173
--- a/SWUpdate.cpp Mon May 07 19:56:00 2018 +0000 +++ b/SWUpdate.cpp Sun Jul 14 01:40:36 2019 +0000 @@ -36,18 +36,19 @@ "OK", // SWUP_OK = 0x00, ///< Software Update succeeded as planned. "Same version", // SWUP_SAME_VER = 0x01, ///< Online version is the same as the installed version. "Get bin error", // SWUP_HTTP_BIN = 0x02, ///< HTTP get returned an error while trying to fetch the bin file. - "Old file stuck", // SWUP_OLD_STUCK = 0x04, ///< Old file could not be removed. - "Old vers stuck", // SWUP_VER_STUCK = 0x08, ///< Old version number could not be updated. - "Ver write fail", // SWUP_VWRITE_FAILED = 0x10, ///< Can't open for write the version tracking file. - "Integrity fail", // SWUP_INTEGRITY_FAILED = 0x20, ///< Integrity check of downloaded file failed. - "Get ver fail", // SWUP_HTTP_VER = 0x40, ///< HTTP get returned an error while trying to fetch the version file. - "Filesys full", // SWUP_NO_SPACE = 0x80, ///< No space on file system for new version. + "Old file stuck", // SWUP_OLD_STUCK = 0x03, ///< Old file could not be removed. + "Old vers stuck", // SWUP_VER_STUCK = 0x04, ///< Old version number could not be updated. + "Ver write fail", // SWUP_VWRITE_FAILED = 0x05, ///< Can't open for write the version tracking file. + "Integrity fail", // SWUP_INTEGRITY_FAILED = 0x06, ///< Integrity check of downloaded file failed. + "Get ver fail", // SWUP_HTTP_VER = 0x07, ///< HTTP get returned an error while trying to fetch the version file. + "Filesys full", // SWUP_NO_SPACE = 0x08, ///< No space on file system for new version. + "Does not exist", // SWUP_NO_FILE = 0x09, ///< Specified file does not exist }; -const char * SoftwareUpdateGetHTTPErrorMsg(HTTPResult r) +const char * SoftwareUpdateGetHTTPErrorMsg(SWUpdate_T r) { const char * p = "invalid result code"; - if (r <= SWUP_NO_SPACE) + if (r <= SWUP_NO_FILE) p = SWErrorMsg[r]; return p; } @@ -221,7 +222,7 @@ char fqurl[SW_MAX_URL]; // fully qualified url char fwfn[SW_MAX_FQFN]; char nameroot[7]; - uint16_t result = SWUP_OK; // starting out quite optimistic, for all the things that can go wrong + SWUpdate_T result = SWUP_OK; // starting out quite optimistic, for all the things that can go wrong char buf[50]; // long enough for 3 comma separated numbers... INFO("SoftwareUpdate(%s , %s)", url, name); @@ -255,11 +256,11 @@ Integrity_t t = PassesIntegrityCheck(fwfn, cksum, fsize); if (t == no_file) { ERR(" *** No space on file system. ***"); - result |= SWUP_NO_SPACE; + result = SWUP_NO_SPACE; } else if (t == ok) { if (!RemoveOtherBinFiles(nameroot, latest_ver)) { ERR(" *** Failed to remove old version(s). ***"); - result |= SWUP_OLD_STUCK; + result = SWUP_OLD_STUCK; } INFO("Updating stored version number."); if (SetSoftwareVersionNumber(name, latest_ver, cksum, fsize)) { @@ -272,24 +273,29 @@ } else { // failed ERR("Failed to update stored version number."); - result |= SWUP_VWRITE_FAILED; + result = SWUP_VWRITE_FAILED; } } else /* t == bad_crc */ { WARN("New file {%s} did not pass integrity check.", fwfn); - result |= SWUP_INTEGRITY_FAILED; + result = SWUP_INTEGRITY_FAILED; } } else { WARN("Failed to download lastest firmware."); - result |= SWUP_HTTP_BIN; + result = SWUP_HTTP_BIN; } } else { INFO("Online version is same as installed version."); - result |= SWUP_SAME_VER; + result = SWUP_SAME_VER; } } } else { + int ec = http.getHTTPResponseCode(); WARN("Failed accessing {%s}. Extended Error Code = %d", fqurl, HTTPErrorCode); - result |= SWUP_HTTP_VER; + WARN(" HTTP Response Code %d", ec); + if (ec == 404) + result = SWUP_NO_FILE; + else + result = SWUP_HTTP_VER; } - return (SWUpdate_T)result; + return result; }