Skip to content

Ethernet: add eth.ota to update firmware over Ethernet - #3986

Open
jpdborgna wants to merge 4 commits into
meshcore-dev:devfrom
jpdborgna:ethernet-ota
Open

jpdborgna wants to merge 4 commits into
meshcore-dev:devfrom
jpdborgna:ethernet-ota

Conversation

@jpdborgna

@jpdborgna jpdborgna commented Nov 28, 2026 •

Copy link
Copy Markdown

Second half of #3983: firmware updates without climbing the pole. This adds eth.ota, an Ethernet-only command next to eth.status. It reboots into the bootloader's Ethernet update mode, so the node gets updated over the network instead of USB or Bluetooth.

  • It needs the Ethernet-capable OTAFIX bootloader, which I sent as Add firmware update over Ethernet for RAK4631 + RAK13800 oltaco/Adafruit_nRF52_Bootloader_OTAFIX#66. That isn't merged or released yet, so this PR is really waiting on it; I'm opening it now so the two can be looked at together. The firmware checks for that bootloader first: eth.status shows ota:8024 or ota:no-bootloader, and on any other bootloader eth.ota answers with an error and nothing happens. So merging this early is harmless.
  • How it works: the current IP, netmask, gateway and MAC go to the bootloader in no-init RAM, then a reset. The bootloader takes the firmware over TCP (raw, for adafruit-nrfutil) or WebSocket (for the browser).
  • The radio is put to sleep before the reboot.
  • No changes to the shared CLI; start ota is untouched.

It's stacked on the WebSocket PR (#3985), which is stacked on #3980 and #3981; only the top commit (Add "eth.ota": firmware update over Ethernet) is new here.

Ethernet builds only: +1.3 KB flash. The docs cover the command and its limits: no authentication (trusted networks only), PoE power, and what to do after a power loss.

What I tested on my node (RAK4631 + RAK13800 + RAK19018):

  • eth.ota from telnet (also with a trailing space), WebSocket and USB, each followed by an update;
  • full updates over Ethernet from the command line and from the browser, about 34 s each; LoRa works afterwards (pinged it from another node);
  • cancelled and interrupted uploads, then a retry;
  • the cable pulled mid-upload, then a retry;
  • on the regular OTAFIX bootloader it refuses and the node keeps running.

Not tested: PoE-only power, since my unit's battery can't be removed.

Want to use it before it's merged? The bootloader and firmware I tested, the uploader script and a step-by-step guide (USB once, then everything over Ethernet) are in my repo: https://github.com/jpdborgna/ham/tree/main/meshcore/rak (downloads: https://github.com/jpdborgna/ham/releases/tag/meshcore-rak-ethernet-2026-11-27).

I wrote this with help from Claude Code; I read every line and tested it on my node.

…s it

When a line filled the buffer, ethernet_read_line() wrote '\r' over the
terminating NUL at buf_size-1, so the next call's strlen() ran past the
end of the buffer (AddressSanitizer: stack-buffer-overflow with a 200-
character line into the 160-byte buffer). Treat a full buffer as a
completed line instead, the way the serial CLI loop already does.
A telnet line longer than the 160-byte command buffer was cut at the
buffer size and the first part run as a command; the rest then ran as a
second command. A truncated command can do something other than what was
typed (a cut-off "set" value, for example).

Now the line is answered with "ERR: line too long", the rest of it is
discarded up to the end of the line, and nothing runs. The longest line
that fits still runs as before.
Browsers cannot open raw TCP sockets, so web tools (e.g. the MeshCore
web config) could not reach the Ethernet CLI on the telnet port. Add a
WebSocket server (default port 8023, -D ETHERNET_WS_PORT=0 disables) to
the RAK13800 Ethernet builds, serving the same CLI.

- Minimal RFC 6455 server (EthernetWebSocket.h): strict handshake and
  frame validation, ping/pong, close, binary frames.
- Browser Origin allowlist: localhost by default, plus
  -D ETHERNET_WS_ALLOWED_ORIGIN or -D ETHERNET_WS_ALLOW_ANY_ORIGIN=1.
- One CLI session at a time: a new telnet connection, or a WebSocket
  connection once its handshake succeeds, replaces the current one. A
  half-typed line is not carried into the new session.
- DHCP renewal is held back while all four W5100S sockets are in use
  (two listeners, the active session and a pending handshake): the
  library gives up renewing for good when it finds no free socket.
- A client socket whose peer is gone is released before accept(): the
  library reuses closed sockets, and a stale handle could later stop()
  a socket that now belongs to a new connection.
- Writes to a peer that stopped answering are bounded: the W5100S
  retransmission count is set to 3 (about 3 s instead of the chip's
  ~32 s worst case; -D ETHERNET_RETRANSMIT_COUNT to change it), and each
  telnet reply goes out in one write instead of three.
- eth.status also reports the WebSocket port.
- docs/cli_commands.md: WebSocket access, and a security note (the
  network console has no password).

Tested on a RAK4631 + RAK13800 (W5100S).
On RAK13800 Ethernet builds, "eth.ota" (local serial console and
Ethernet sessions only, not remote admin) reboots into the
bootloader's Ethernet update mode, handing over the current IP,
netmask, gateway, MAC and port 8024 in no-init RAM (EthernetDfu.h).
The LoRa radio is put to sleep first. The command lives in the
Ethernet CLI next to eth.status; no shared CLI code changes.

It needs the OTAFIX bootloader built for
wiscore_rak4631_ethernet_board: the firmware looks for that
bootloader's marker string in the first 1 KB of the bootloader
(cached) and refuses otherwise. eth.status reports "ota:<port>" or
"ota:no-bootloader" so tools can tell before trying.

The firmware is then uploaded from the MeshCore config tool (browser,
over a WebSocket) or with the bootloader's tools/eth_dfu_upload.py.
docs/cli_commands.md covers usage, security and known limitations.

Tested on a RAK4631 + RAK13800 (W5100S).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant