NetBurner 3.5.8
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 the static 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 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(). 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 Firmware - A form that POSTs a filename to 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.

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

A successful firmware update (from either the web or serial interface) triggers 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 updates, 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 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