|
NetBurner 3.5.7
PDF Version |
Example Path: examples/EFFS/Fat/AppUpdate
This example demonstrates how to update a NetBurner device's firmware from a .bin file stored on an external SD/MMC flash card. It provides three interfaces for managing files on the flash card and triggering firmware updates: a web browser interface, an FTP server, and a serial console.
.bin files to the card, and trigger a firmware update, all from a web browser.MOD5441X, NANO54415, MODM7AE70, SBE70LC, SB800EX, SOMRT1061
UserMain() initializes the network stack, registers the HTTP and FTP tasks for EFFS filesystem access, starts the web server and FTP server, then initializes the external flash drive. The main loop uses non-blocking serial input (charavail()) so it can continuously check for a web-triggered reboot via the gRebootPending flag.
The web page at the device's IP address provides:
dirlist.html, a dynamically generated page listing all files on the card with their sizes. The directory listing is produced by a CallBackFunctionPageHandler using f_findfirst()/f_findnext().upload.html. The HtmlPostVariableListCallback handler receives the uploaded file data via a FilePostStruct, reads it in 512-byte chunks, and writes it to the SD card using EFFS f_open()/f_write(). After a successful upload, the handler sets gRebootPending = true to trigger a reboot from the main task.update.html. The handler opens the specified file on the SD card and passes it to UpdateBinaryFromFat(), which parses the NetBurner binary format (S-record headers, address records, checksums) via the AppUpdateRecord class and programs the onboard flash. On success, the handler sets gRebootPending = true.UpdateBinaryFromFat() reads the .bin file in 512-byte chunks and feeds them to AppUpdateRecord::ParseChars(), which handles the full NetBurner binary format: S0 platform header validation, S3 address records, image parsing, and checksum verification. After parsing completes, it calls DoFlashProgram() to write the new firmware to onboard flash. Return codes indicate success, version match, platform mismatch, format errors, memory allocation failure, or flash programming failure.
Both the web and serial interfaces trigger the same reboot sequence:
f_delvolume()OSTimeDly() to allow the HTTP response to be sentForceReboot() to restart the device with the new firmwareFor web-triggered reboots, the handler sets gRebootPending = true and the main loop performs the reboot, ensuring the HTTP response is fully sent before the device restarts.
| File | Description |
|---|---|
src/main.cpp | Application entry point, task registration, serial console interface |
src/web.cpp | HTTP handlers for file upload, firmware update, and directory listing |
src/fileup.cpp | UpdateBinaryFromFat() - parses .bin files and programs flash |
src/fileup.h | Header for fileup.cpp, defines return code constants |
html/index.html | Web page with directory listing, upload form, and update form |
makefile | Build configuration, comphtml rule for HTML compilation |