Module nh_metadata

What the device reports about the firmware it is running.

Description

What the device reports about the firmware it is running.

A Nerves device reports nerves_fw_* keys it was built with. An AtomVM device has no such build-time values, and does not need them: the packbeam it booted carries its own application metadata, and the VM underneath reports its version. So the device reports what is actually running rather than what it was compiled to believe.

  atomvm_app_name      <- the packbeam's application name
  atomvm_app_version   <- its vsn
  atomvm_avm_sha256    <- SHA-256 of the packbeam
  atomvm_version       <- erlang:system_info(atomvm_version)

Two versions, not one

atomvm_app_version is the firmware NervesHub manages. atomvm_version is the VM the firmware runs on, which no packbeam can know and which is replaced on a different schedule by a different mechanism. NervesHub records the second alongside the first rather than confusing them.

No UUID

NervesHub derives a firmware's UUID from the SHA-256 of the archive when it is uploaded, so a device reporting the digest reports something the server can match exactly. Deriving the UUID is the server's rule, kept in one place so an agent cannot get it subtly wrong.

The digest has to cover the archive and nothing else — see nh_packbeam:byte_length/1, since a partition is bigger than what was written into it.

Function Index

atomvm_version/0The version of the VM this is running on.
describe/2Build the metadata from an application spec and a digest.
from_packbeam/1Describe a packbeam held in memory.
hex/1Lower case hex, the encoding NervesHub reads a digest in.
join_params/1The join payload NervesHub expects from an AtomVM device.

Function Details

atomvm_version/0

atomvm_version() -> binary() | undefined

The version of the VM this is running on.

undefined anywhere that is not AtomVM, which is what makes the rest of the library testable off-device.

describe/2

describe(Application::map(), Sha256::binary()) -> map()

Build the metadata from an application spec and a digest.

Separate from from_packbeam/1 so that a device which hashed the archive as it read it does not have to hold the archive to describe it.

from_packbeam/1

from_packbeam(Archive::binary()) -> {ok, map()} | {error, term()}

Describe a packbeam held in memory.

Hashes only the archive, so passing a whole partition is fine. For a device that would rather not hold the archive at all, nh_flash walks and hashes it in chunks and calls describe/2.

hex/1

hex(Bin::binary()) -> binary()

Lower case hex, the encoding NervesHub reads a digest in.

join_params/1

join_params(Metadata::map()) -> map()

The join payload NervesHub expects from an AtomVM device.

Keys the device could not determine are left out rather than sent empty. A missing key and a key holding nothing mean the same thing to NervesHub, and leaving it out keeps the agent from asserting something it does not know.


Generated by EDoc