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:23:04 2014 +0000
Revision:
4:1a3656ae80dc
Parent:
3:c69fff55fc60
Child:
5:e10f18e9b93a
doc update

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