Files
Matt SpencerandCopilot 9ea25c3aab feat: add A/B firmware slots
Split the single app partition into two slots, ota_0 and ota_1, with an
otadata partition that tells the bootloader which to run, so an update can
be written to the idle slot while the other keeps running. The Zigbee
storage partition is unchanged, so the light keeps its network. Moving from
the old table needs one USB flash.

* src/ota.rs logs the running slot and the state of its image at boot,
  marks an image valid after it has stayed up for 20 seconds, and can
  switch to the other slot and restart. The slot in use is read from the
  flash mapping, not from otadata.
* src/flash.rs shares the one flash handle: esp-storage allows only one, and
  both the Zigbee stack and the update code need it.
* The runner clears otadata on every USB flash. A USB flash always writes
  slot 0, so without this a board that had switched to slot 1 would keep
  booting the old image.
* Two development features, ota-test and ota-test-crash, exercise slot
  switching and an unconfirmed image without an update source. FW_LABEL tells
  builds apart in the log.

Tested on the hardware: switching between two images across six reboots, each
booting the slot it had just selected, resuming its Zigbee network, and
confirming itself. Rollback is not available: the bootloader espflash installs
is not built with it, so a newly selected image reports "New" rather than
"PendingVerify", and an image that resets without confirming itself is booted
again indefinitely. Needs a rollback-enabled bootloader. Nothing delivers
updates yet. Both are recorded in TODO.md.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-29 00:32:40 +00:00

5.6 KiB

TODO

Things that are known to be open. None of these is being worked on yet.

Firmware updates (OTA)

A/B firmware slots are in place and tested (see the README). What is missing:

  • Rollback. The bootloader espflash installs is not built with CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE: a newly selected image reports its state as New rather than PendingVerify, and an image that resets without confirming itself is booted again forever (checked with the ota-test-crash build). Needs a bootloader built from ESP-IDF with rollback enabled and flashed with espflash --bootloader. No ESP-IDF is installed here.
  • Zigbee OTA client. zigbee-rs has no OTA Upgrade cluster (0x0019) and no client-side cluster support. The generic client belongs on its own upstream branch, writing through a trait; the flash writing and policy stay here.
  • A real "image works" test. The firmware currently confirms an image after 20 seconds up. It should require that the light has rejoined its Zigbee network, and mark the image invalid and switch back if it has not.
  • Hung images. A panic hangs rather than resets, so a new image that hangs would never reach the confirmation. Enable a watchdog.
  • Image tooling and Home Assistant. A host tool to wrap the app image in a Zigbee OTA file, and a ZHA z2m_local provider index for it. Choose a version scheme and image type.
  • Flash writes versus the radio. Writing an image while the radio is active stalls the CPU for each sector erase; not yet measured against frame loss.

Reliability

  • The Zigbee stack forgets its network after a short coordinator outage. A failed rejoin is followed by a second attempt that, if it also fails, wipes the network keys and falls back to a fresh join, which needs the coordinator's pairing window to be open. This took the light off the network when the server rebooted (18 Nov) and, most likely, again when Home Assistant restarted (24 Nov; inferred, the failure itself was not captured). Each time it needed re-pairing.
    • Where: commission and link_maintenance in vendor/zigbee-rs/zigbee/src/stack.rs, and the retry loop in stack_task (src/zigbee_stack.rs).
    • Idea: keep the saved network and keep retrying the rejoin with a back-off, and only forget it after a long failure (say 30 minutes), an explicit leave, or a network mismatch.
    • It is a library change, so it belongs on its own branch off upstream main, separate from the effects work.
    • The 10-second button hold makes recovery easy, but does not prevent it.

Configuration

  • The Zigbee network ID and channel are hardcoded in src/zigbee_stack.rs (EXTENDED_PAN_ID, CHANNEL). The ID is broadcast by the network and is not a secret, but it means a light only pairs with one network.
    • Why it is pinned: the stack takes both from its configuration. Resuming after a reboot tunes to the first configured channel rather than the channel that was joined, and rejoin looks for the configured network ID. A wildcard ID or a range of channels would therefore break resume.
    • Options: change the library to use the channel and ID it remembers, or have the app save the network it joined in its own flash and build the configuration from that.
  • Light and effect state is not saved across reboots. On/off, level, colour and the selected effect all start from their defaults.
  • The effects cluster uses development identifiers. Manufacturer code 0xC0DE is not assigned to anyone, and the cluster ID is 0xFD00. Decide on proper values and change them together in src/effects_cluster.rs and ha/zha_quirks/smart_light.py.
  • The effect attributes are not reportable, so Home Assistant only knows what it last wrote. Fine while nothing else changes them; revisit if effects can be changed locally.

Upstream zigbee-rs

  • Open PRs for the two branches already pushed to the fork, each as its own PR off upstream main:
    • feature/identify-trigger-effect
    • feature/manufacturer-specific-clusters
  • PR #109 (RGB colour control) is open and has had review comments applied. Squash-merge when approved.
  • Spec questions to raise in review. Neither PR can say what ZCL requires, so both pick an answer and flag it:
    • Trigger Effect with an undefined effect or variant answers INVALID_FIELD.
    • A frame for a manufacturer-specific cluster with the wrong manufacturer code answers UNSUP_COMMAND.
  • After the PRs merge, point the submodule at upstream (or the fork's main) instead of feature/lighting-effects-integration, and delete the integration branch.

Testing gaps

Not yet tried on the hardware (the commit messages say so too):

  • Trigger Effect: Okay, Channel change, Finish effect and Stop effect sent from a coordinator. Only blink and breathe (ZHA's flash) were tried.
  • Manufacturer-specific attribute reports.
  • Rejection of a frame that carries the wrong manufacturer code.

Housekeeping

  • .gitmodules uses an SSH URL for the submodule (git@github.com:m5p3nc3r/zigbee-rs.git). Switch to HTTPS if cloning from a network that blocks SSH.
  • Older commits point at submodule commits that no longer exist on any branch, because the integration branch was rebased. The tip works, but checking out an old commit and updating the submodule can fail.
  • Pre-existing rustfmt differences: 1 in src/light.rs and 7 in src/zigbee_stack.rs. Cosmetic; fix in a commit of their own.
  • No licence file. Decide on one.