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.

Committer:
WiredHome
Date:
Sat Jun 14 18:27:48 2014 +0000
Revision:
6:6025fddc1af9
Parent:
5:e10f18e9b93a
Child:
9:73067ef14c30
More updates to the docs for doxygen.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WiredHome 4:1a3656ae80dc 1 /// Firmware Over The Air (FOTA) Update.
WiredHome 4:1a3656ae80dc 2 ///
WiredHome 0:e221363f7942 3 #include "mbed.h"
WiredHome 0:e221363f7942 4
WiredHome 5:e10f18e9b93a 5 /** \file
WiredHome 5:e10f18e9b93a 6 Software Update header file
WiredHome 5:e10f18e9b93a 7 */
WiredHome 0:e221363f7942 8 #ifndef SWUPDATE_H
WiredHome 0:e221363f7942 9 #define SWUPDATE_H
WiredHome 0:e221363f7942 10
WiredHome 1:208de08b1a19 11 /// After downloading, the user can choose what happens next.
WiredHome 0:e221363f7942 12 typedef enum {
WiredHome 6:6025fddc1af9 13 DEFER_REBOOT, ///< Do not reboot to activate the new firmware.
WiredHome 6:6025fddc1af9 14 AUTO_REBOOT ///< Automatically reboot to activate the new firmware.
WiredHome 0:e221363f7942 15 } Reboot_T;
WiredHome 0:e221363f7942 16
WiredHome 1:208de08b1a19 17 /// This API performs some processing to see if a web server
WiredHome 1:208de08b1a19 18 /// has an updated version of software. If it does, then it
WiredHome 1:208de08b1a19 19 /// will try to download it. If that succeeds, then it can
WiredHome 1:208de08b1a19 20 /// optionally reboot to activate the new software.
WiredHome 1:208de08b1a19 21 ///
WiredHome 3:c69fff55fc60 22 /// The files on the web server are as follows:
WiredHome 3:c69fff55fc60 23 /// @li myprog.bin - The actual binary file. The name is unimportant, but
WiredHome 3:c69fff55fc60 24 /// this is the binary file that was generated from the sources.
WiredHome 3:c69fff55fc60 25 /// @li myprog.txt - A corresponding text file. The root name must match
WiredHome 3:c69fff55fc60 26 /// that of the binary file.
WiredHome 3:c69fff55fc60 27 ///
WiredHome 3:c69fff55fc60 28 /// The myprog.txt file shall have 3 comma-separated numbers in it.
WiredHome 3:c69fff55fc60 29 /// version,checksum,filesize (ex: "21,41384,107996")
WiredHome 3:c69fff55fc60 30 ///
WiredHome 3:c69fff55fc60 31 /// @li version is a simple number. If the number is different than
WiredHome 3:c69fff55fc60 32 /// what is stored on the local file system, then the program
WiredHome 3:c69fff55fc60 33 /// will be updated (even if the server number is lower).
WiredHome 3:c69fff55fc60 34 /// @li checksum is the decimal representation of a simple 16-bit checksum.
WiredHome 3:c69fff55fc60 35 /// @li filesize is the decimal representation of the size of the file.
WiredHome 3:c69fff55fc60 36 ///
WiredHome 3:c69fff55fc60 37 /// You can create the server "myprog.txt" file with this perl script (not
WiredHome 3:c69fff55fc60 38 /// every detail is shown, but it should be easy to figure out).
WiredHome 6:6025fddc1af9 39 /// @code
WiredHome 3:c69fff55fc60 40 /// # Read current .txt file
WiredHome 3:c69fff55fc60 41 /// open (FT, "<$txt") || die("Can't read $txt.");
WiredHome 3:c69fff55fc60 42 /// $ver = <FT>; chomp $ver; close FT;
WiredHome 3:c69fff55fc60 43 /// $ver =~ s/(\d+),.*/$1/;
WiredHome 3:c69fff55fc60 44 /// print "Current Version is {$ver}\n";
WiredHome 3:c69fff55fc60 45 ///
WiredHome 3:c69fff55fc60 46 /// # Read new .bin file
WiredHome 3:c69fff55fc60 47 /// open (FB, "<$bin") || die("Can't read $bin.");
WiredHome 3:c69fff55fc60 48 /// binmode FB;
WiredHome 3:c69fff55fc60 49 /// while (sysread(FB, $c, 1))
WiredHome 3:c69fff55fc60 50 /// {
WiredHome 3:c69fff55fc60 51 /// $cksum = ($cksum + ord($c)) & 0xFFFF;
WiredHome 3:c69fff55fc60 52 /// $byteCount++;
WiredHome 3:c69fff55fc60 53 /// }
WiredHome 3:c69fff55fc60 54 /// close FB;
WiredHome 4:1a3656ae80dc 55 /// # Advance version number and write the new .txt file
WiredHome 3:c69fff55fc60 56 /// $ver++; print "$ver Checksum is $cksum over $byteCount bytes.\n";
WiredHome 3:c69fff55fc60 57 /// open (FT, ">$txt") || die("Can't write update to $txt.");
WiredHome 3:c69fff55fc60 58 /// printf(FT "%d,%d,%d\n", $ver, $cksum,$byteCount);
WiredHome 3:c69fff55fc60 59 /// close FT;
WiredHome 6:6025fddc1af9 60 /// @endcode
WiredHome 1:208de08b1a19 61 ///
WiredHome 1:208de08b1a19 62 /// @param url is a pointer to a text string of the url from which to download.
WiredHome 1:208de08b1a19 63 /// @param name is the base filename of the binary file.
WiredHome 1:208de08b1a19 64 /// @param reboot determines whether to automatically reboot to activate the new bin.
WiredHome 2:ef2ac9627546 65 /// @return true if the update succeeded (and the reboot was set to DEFER_REBOOT).
WiredHome 1:208de08b1a19 66 ///
WiredHome 0:e221363f7942 67 bool SoftwareUpdate(const char *url, const char * name, Reboot_T reboot = DEFER_REBOOT);
WiredHome 0:e221363f7942 68
WiredHome 0:e221363f7942 69 #endif // SWUPDATE_H