|
NetBurner 3.5.8
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. That page holds the table shell; the device fills in only the file rows through a <!--CPPCALL ShowDirList --> tag, whose handler walks the card with 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(). The upload only stores the file on the card; flashing it is a separate, explicit step, so an upload does not reboot the device.update.html. The filename comes from a drop-down <select> whose <option> entries are filled by a <!--CPPCALL ShowBinOptions --> tag, which lists the application images on the card (.bin binary images and .s19 S-record files) and preselects APP.BIN. The handler opens the chosen file and passes it to UpdateBinaryFromFat(). The AppUpdateRecord parser auto-detects the format by content - a NetBurner binary image or ASCII S-records (S0 platform header, S3 data, S7 end) - validates the platform and checksum, 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.
A successful firmware update (from either the web or serial interface) triggers 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 updates, 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 the directory-listing / file-options CPPCALLs |
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 |
html/dirlist.html | Table shell loaded in the iframe; rows filled by CPPCALL ShowDirList |
html/style.css | Self-contained stylesheet shared by the pages (plain CSS, no framework or CDN) |
html/logo.png | Logo shown in the page header |
makefile | Build configuration, comphtml rule for HTML compilation |