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:

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.

Revision:
19:169aab9047bd
Parent:
18:5f7667d63a27
Child:
21:253e7da56ff9
--- a/SWUpdate.cpp	Sat Oct 11 17:27:46 2014 +0000
+++ b/SWUpdate.cpp	Mon Jan 19 13:33:47 2015 +0000
@@ -27,9 +27,15 @@
 
 static HTTPResult HTTPErrorCode;
 
-static bool PassesIntegrityCheck(const char * fname, int cksum, int fsize)
+typedef enum {
+    ok,
+    no_file,
+    bad_crc
+} Integrity_t;
+
+static Integrity_t PassesIntegrityCheck(const char * fname, int cksum, int fsize)
 {
-    int res = false;    // assume things go wrong...
+    Integrity_t res = bad_crc;    // assume things go wrong...
     int newCksum = 0;
     int newFSize = 0;
     FILE *fh = fopen(fname, "rb");
@@ -44,9 +50,10 @@
         fclose(fh);
         INFO("      Check(...,%d,%d)", newCksum, newFSize);
         if (newCksum == cksum && newFSize == fsize)
-            res = true;
+            res = ok;
     } else {
         WARN("failed to open %s.", fname);
+        res = no_file;
     }
     return res;
 }
@@ -186,7 +193,11 @@
                 HTTPFile latest(fwfn);
                 HTTPErrorCode = http.get(fqurl, &latest);
                 if (HTTPErrorCode == HTTP_OK) {
-                    if (PassesIntegrityCheck(fwfn, cksum, fsize)) {
+                    Integrity_t t = PassesIntegrityCheck(fwfn, cksum, fsize);
+                    if (t == no_file) {
+                        ERR("  *** No space on file system. ***");
+                        result |= SWUP_NO_SPACE;
+                    } else if (t == ok) {
                         if (!RemoveOtherBinFiles(nameroot, latest_ver)) {
                             ERR("  *** Failed to remove old version(s). ***");
                             result |= SWUP_OLD_STUCK;
@@ -211,7 +222,7 @@
                             WARN("Failed to update local version info in %s.", verfn);
                             result |= SWUP_VWRITE_FAILED;
                         }
-                    } else {
+                    } else /* t == bad_crc */ {
                         WARN("New file {%s} did not pass integrity check.", fwfn);
                         result |= SWUP_INTEGRITY_FAILED;
                     }