Module nh_slots

The two packbeam partitions an update alternates between.

Description

The two packbeam partitions an update alternates between.

An update never writes over the running application. It writes the whole archive into the slot that is not running, points AtomVM's boot path at it, and reboots — so a download that fails, a power cut halfway through, or an archive that turns out to be corrupt all leave the device booting the firmware it already had.

Why the names are not symmetric

esp32init falls back to /dev/partition/by-name/main.avm when NVS holds no boot path, so a device flashed at the factory boots from main.avm with nothing provisioned. Naming the pair a/b would mean every device needed an NVS write before it would boot at all.

So the slot a fresh device runs keeps the name the loader already looks for, and the second slot is the one that has to be named. See nh_flash for how the running slot is read back.

Function Index

all/0Both slots, in no meaningful order.
boot_path/1The NVS boot path that makes AtomVM boot a slot.
default/0The slot a device boots when nothing has told it otherwise.
from_boot_path/1The slot a stored boot path refers to.
is_slot/1Whether a partition label is one of the pair.
other/1The slot an update should be written into, given the running one.

Function Details

all/0

all() -> [binary()]

Both slots, in no meaningful order.

boot_path/1

boot_path(Slot::binary()) -> binary()

The NVS boot path that makes AtomVM boot a slot.

default/0

default() -> binary()

The slot a device boots when nothing has told it otherwise.

from_boot_path/1

from_boot_path(Path::binary() | string()) -> {ok, binary()} | {error, {unknown_slot, binary()}}

The slot a stored boot path refers to.

Accepts a bare label as well as a full path, because a device that has never been updated has no stored path at all and falls back to default/0.

is_slot/1

is_slot(Label::binary()) -> boolean()

Whether a partition label is one of the pair.

other/1

other(Label::binary()) -> {ok, binary()} | {error, {unknown_slot, binary()}}

The slot an update should be written into, given the running one.

An error rather than a guess when the running slot is not one of the pair: a device booting something else is one this scheme does not describe, and writing to whichever slot happened to be free could overwrite what it is running.


Generated by EDoc