> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nerves-hub.org/llms.txt
> Use this file to discover all available pages before exploring further.

# How firmware updates work

> The firmware formats NervesHub accepts, and the path an update takes from upload to a rebooted device.

A firmware update starts with a file you upload and ends with a device that has rebooted into it and reported back.

## Firmware formats

NervesHub picks an update tool for each file from the file's contents, not its name.

| Tool | File | Device side | Delta updates | Status |
| - | - | - | - | - |
| fwup | `.fw` | `nerves_hub_link` on Nerves, or the [Linux agent](https://docs.nerves-hub.org/integrations/linux-agent.md) | [Yes](https://docs.nerves-hub.org/management/delta-updates.md) | Default. Products accept it without any setup. |
| ESP-IDF | `.bin` | [ESP32 with ESP-IDF](https://docs.nerves-hub.org/updates/esp-idf.md) | Yes | Experimental, off by default |
| AtomVM | `.avm` | [ESP32 with AtomVM](https://docs.nerves-hub.org/updates/atomvm.md) | No | Experimental, off by default |
| RAUC | `.raucb` | [Linux with RAUC](https://docs.nerves-hub.org/updates/rauc.md) | No | Experimental, off by default |

The three experimental formats need NervesHub 2.5.0 or later. Each has to be enabled for the instance and then allowed for the product. See [feature prerequisites](https://docs.nerves-hub.org/hosting/feature-prerequisites.md#firmware-formats).

The rest of this section describes fwup firmware on a Nerves device running `nerves_hub_link`.

## The path of an update

**1. You upload signed firmware**

You build a `.fw` file, sign it, and [upload it](https://docs.nerves-hub.org/setup/firmware.md) to a product. NervesHub verifies the signature against your organization's [signing keys](https://docs.nerves-hub.org/concepts/firmware-signing.md). It reads the firmware's metadata: product, version, platform, architecture and UUID. NervesHub 2.5.0 and later also store a SHA-256 checksum of the file and one of each 1 MiB part.

**2. A release makes it the target**

You [create a release](https://docs.nerves-hub.org/deployments/releases.md) in a [deployment group](https://docs.nerves-hub.org/setup/deployments.md). Devices in the group that are not on that firmware become due for it. You can also send one device a specific version from its page in the web UI.

If the group has [delta updates](https://docs.nerves-hub.org/management/delta-updates.md) on, NervesHub first builds deltas from the firmware its devices are running.

**3. NervesHub offers the update**

NervesHub offers the update to connected devices at the pace the group's [rollout controls](https://docs.nerves-hub.org/deployments/rollout-controls.md) allow. A device that connects later is offered it then.

The offer is an `update` message on the device's WebSocket. It carries a signed, time-limited URL for the file, the target firmware's metadata, and, from NervesHub 2.5.0, the file's size and checksums. The URL points at the delta when the device qualifies for one, and at the full file otherwise.

A device in [device-managed mode](https://docs.nerves-hub.org/updates/device-managed-updates.md) is not sent the offer. It asks for it instead.

**4. The device decides**

`nerves_hub_link` first checks that it holds a public key to verify the firmware with. If it has none, it [refuses the update](https://docs.nerves-hub.org/concepts/firmware-signing.md#unverifiable-firmware-is-refused).

It then calls [`update_available/1`](https://docs.nerves-hub.org/updates/applying-updates) on your Client module. Your code returns `:apply`, `:ignore`, or a request to be asked again later. The default applies every update.

**5. The device downloads and applies**

The configured [updater](https://docs.nerves-hub.org/updates/download-strategies.md) downloads the file over HTTPS and hands it to `fwup`, which verifies the signature and writes the firmware to the inactive slot. The default updater streams the download straight into `fwup`.

The device reports download and install progress to NervesHub as it goes, and passes each `fwup` message to your Client.

**6. The device reboots and reports back**

When `fwup` finishes, the device reports the update as completed and reboots. After it reconnects, it reports the firmware it is now running and whether that firmware has been [validated](https://docs.nerves-hub.org/updates/applying-updates.md#validation-and-auto-revert).

If the device reverted to the previous firmware, it reports that too.

## What you configure on the device

All of these are optional. A device with only connection settings takes every update it is offered.

| To | Set | Page |
| - | - | - |
| Decide when an update is applied | `client: MyApp.NervesHubLinkClient` | [Applying updates](https://docs.nerves-hub.org/updates/applying-updates.md) |
| Build verification keys into the firmware | `fwup_public_keys: [...]` | [Firmware signing](https://docs.nerves-hub.org/concepts/firmware-signing.md) |
| Resume or verify downloads | `updater: ...` | [Download strategies](https://docs.nerves-hub.org/updates/download-strategies.md) |
| Let the device ask for updates | `NervesHubLink.check_for_update/0` and friends | [Device-managed updates](https://docs.nerves-hub.org/updates/device-managed-updates.md) |
| Receive files that are not firmware | `archive_available/1`, `archive_ready/2` | [Archives](https://docs.nerves-hub.org/updates/archives.md) |

## How fwup is invoked

`nerves_hub_link` runs `fwup` with the `upgrade` task against the device's firmware block device. These settings change that:

```elixir theme={null}
# config/target.exs
config :nerves_hub_link,
  fwup_task: "upgrade",
  fwup_env: [{"MY_VAR", "value"}],
  fwup_extra_options: ["--unsafe"]
```

| Key | Default | Description |
| - | - | - |
| `fwup_task` | `"upgrade"` | The task in `fwup.conf` to run. |
| `fwup_env` | `[]` | Environment variables for the `fwup` process, as `{name, value}` tuples. |
| `fwup_extra_options` | `[]` | Extra command line arguments for `fwup`. |

The block device is read from the `nerves_fw_devpath` key in the device's Nerves key-value store when `nerves_hub_link` starts.

## Related pages

* [Applying updates on the device](https://docs.nerves-hub.org/updates/applying-updates.md)
* [Download strategies](https://docs.nerves-hub.org/updates/download-strategies.md)
* [Device-managed updates](https://docs.nerves-hub.org/updates/device-managed-updates.md)
* [Archives](https://docs.nerves-hub.org/updates/archives.md)
* [Delta updates](https://docs.nerves-hub.org/management/delta-updates.md)
* [Releases](https://docs.nerves-hub.org/deployments/releases.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.