Skip to main content
A delta update sends a device the difference between the firmware it runs and the firmware it is updating to, instead of the whole file. NervesHub builds the delta, and fwup on the device applies it against the inactive firmware slot. Use delta updates when download size matters, for example on cellular or metered links. This page covers fwup firmware (.fw). ESP-IDF images have their own delta format, described in ESP-IDF. RAUC bundles and AtomVM archives have no delta updates.

Requirements

The fwup version a device needs depends on what the target firmware’s fwup.conf uses: NervesHub takes the highest version that applies. A device that reports no fwup version is treated as running 0.2.0, so it always gets the full firmware.

How it works

  1. When you upload firmware, NervesHub reads the meta.conf inside the .fw file. It records whether the firmware declares delta sources and which fwup version a delta of it needs.
  2. When a deployment group with Delta updates on gets a new release, NervesHub looks at the firmware each device in the group runs. It queues one delta build per pair of running firmware and release firmware.
  3. A build unpacks both .fw files and runs xdelta3 on each resource that declares a delta source. It then writes a new .fw file that holds the patches in place of those resources. Resources that no upgrade task uses are left out.
  4. When a device is due for the update, NervesHub sends it the delta’s URL instead of the full firmware’s URL, provided the device qualifies. The update message is otherwise the same.
  5. fwup on the device reads the old data from the locations fwup.conf names, applies the patch, and writes the result to the other slot.
A delta is a .fw file that keeps the target firmware’s metadata and signature. The device verifies it with the same signing keys, and your Client callbacks run the same way.

Enable delta updates

1

Declare delta sources in fwup.conf

In the upgrade tasks of your fwup.conf, each resource you want patched needs a delta source. It tells fwup where on the device the old version of that resource is.For a resource written with raw_write, which is the usual case for the root filesystem, set both delta-source-raw-offset and delta-source-raw-count. The upgrade.a task writes slot A, so its source is slot B, and the other way round:
For a resource written with fat_write, set both delta-source-fat-offset and delta-source-fat-path:
For a raw_write that uses cipher= and secret=, also set delta-source-raw-options with the cipher= and secret= of the source.A resource that sets only one of a pair, for example the offset without the count, does not count as a delta source.The raw snippet is the one in the Nerves Experimental features guide, under “Firmware patches”. The FAT snippet comes from fwup.conf.eex in nerves_system_rpi4, the template that system generates its fwup.conf from.Check what your system already declares.Official Nerves systems such as nerves_system_rpi4 already declare a raw delta source for rootfs.img, so you may have nothing to add. nerves_system_rpi4 also declares FAT delta sources for its boot files. Because of those, a device running it needs fwup 1.10.0 or later to be sent a delta.To see what your system declares, copy its fwup.conf into your project and search it for delta-source. With nerves 1.15.0 or later:
Use your own fwup.conf.If the system’s fwup.conf declares no delta source, edit the copy in config/ and tell Nerves to build with it:
If you already have a config :nerves, :firmware entry, add fwup_conf to it. If you maintain a custom system, you can add the lines to the system’s fwup.conf instead.
The Nerves guide says these fwup.conf changes “must be applied in full to a running target before it is capable of applying firmware update patches”. Send the first firmware that declares delta sources as a full update, with Delta updates off for the deployment group. Turn Delta updates on once your devices run it.
2

Build firmware that produces small deltas

This step is optional. It does not decide whether a delta can be built, only how small it is.A compressed root filesystem changes throughout when a few files change, which leaves xdelta3 little to reuse. The Nerves Experimental features guide, under “Tips for smaller patches”, suggests turning squashfs compression off and fixing the build date. Both are build settings, so they go in config/config.exs:
Keep your existing rootfs_overlay value. An uncompressed root filesystem is larger on the device and as a full download.The firmware a device already runs has to be built this way too, because the delta is computed against it.
3

Upload the firmware

Upload the new firmware as usual. NervesHub can only build a delta from firmware it holds, so the firmware your devices currently run must also be uploaded to the same product.Open the firmware from the product’s Firmware page. The Delta updates to section shows either the deltas built for it or the message “This firmware can’t be delta updated, so devices always download the full file.” The second means NervesHub found no complete delta source in its fwup.conf.
4

Turn on delta updates for the deployment group

New deployment groups have Delta updates on. To change it, open the deployment group, go to the Settings tab, and set Delta updates. Changing it needs a role with permission to toggle delta updates.With nh, pass --delta-updatable to nh deployment create or nh deployment update.

Check that it works

  • Firmware page. Open the target firmware. Delta updates to lists one row per source version with From, Size, Saving and Status. Status is Building, Ready, Failed or Timed out.
  • Releases tab. On the deployment group’s Releases tab, expand a release. Delta updates lists the deltas that release’s devices need, with the same statuses.
  • Stats tab. On the deployment group’s Stats tab, By the version devices came from has a Download column that reads Delta or Full for each source version.
  • Device page. When you pick a version under Send a specific version, outside the deployment group and a delta from the device’s firmware is ready, a Send delta update button appears next to the normal send button.

When a device gets the full firmware

NervesHub sends a device the delta when the deployment group has Delta updates on and a delta from the firmware the device runs to the target has finished building. It sends the full firmware in these cases:
  • The deployment group has Delta updates off.
  • The firmware the device reports running is not uploaded to the same product, or has been deleted. No delta can be built from it.
  • The delta is built, and the device’s reported fwup version is lower than the version the delta needs.
  • The target firmware cannot produce a delta.
  • The delta failed to build or timed out.
While a delta is still building, the devices that need it wait. See Releases wait for their deltas. While it builds a delta, NervesHub skips any single resource whose patch is not smaller than the resource.

Releases wait for their deltas

A release in a group with delta updates on waits while its deltas are building. Devices headed for that release are not offered the update while a delta they need is still building. When a delta fails or times out, the devices that need it are sent the full firmware. To build the delta again, click Retry next to the failed delta, on the release in the Releases tab or on the firmware’s page. A retry fails again unless the cause is gone. A build fails when:
  • The target firmware declares no delta source.
  • The target uses a raw delta for a resource, and the source firmware does not write that resource with raw_write. The same applies to FAT deltas and fat_write.
  • The source firmware encrypts a resource, and the target has no cipher= and secret= in delta-source-raw-options for it.
  • No resource produced a patch smaller than itself, or the finished delta is not smaller than the full firmware.
  • xdelta3 is missing on the server, or a firmware file cannot be downloaded or unpacked.

Limits

  • A delta is tied to one source firmware and one target firmware. Every deployment group that sends the same target shares it.
  • Deleting firmware deletes the deltas built from it. Devices running it then download the full file.
  • nerves_hub_link does not fall back to the full firmware on its own. If fwup fails to apply a delta, the update fails and the device reports it to NervesHub like any other failed update. See failed updates.
  • If a device runs out of memory applying a delta, set block-cache-size-mb in the target firmware’s fwup.conf. NervesHub passes that size to xdelta3 as the source window when it builds the delta.