NetBurner 3.5.7
PDF Version
Application Update

Example Path: examples/EFFS/Fat/AppUpdate

EFFS Fat Application Update

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.

Features

  • Web interface (port 80) - Browse the SD card directory, upload .bin files to the card, and trigger a firmware update, all from a web browser.
  • FTP server (port 21) - Add, delete, or modify files on the flash card using any standard FTP client.
  • Serial console - View the SD card directory listing and trigger a firmware update by entering a filename at the prompt.
  • Automatic reboot - After a successful file upload or firmware update via the web interface, the device reboots automatically to run the new firmware.

Supported Platforms

MOD5441X, NANO54415, MODM7AE70, SBE70LC, SB800EX, SOMRT1061

How It Works

Startup (main.cpp)

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.

Web Interface (web.cpp, html/index.html)

The web page at the device's IP address provides:

  • SD Card Directory - An iframe that loads 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 File - A multipart form that POSTs to 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 Firmware - A form that POSTs a filename to 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.

Firmware Update (fileup.cpp)

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.

Reboot Mechanism

Both the web and serial interfaces trigger the same reboot sequence:

  1. Unmount the flash volume with f_delvolume()
  2. Wait 2 seconds with OSTimeDly() to allow the HTTP response to be sent
  3. Call ForceReboot() to restart the device with the new firmware

For 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.

Source Files

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