nerves_runtime v0.11.3 Nerves.Runtime View Source

Nerves.Runtime contains functions useful for almost all Nerves-based devices.

Link to this section Summary

Functions

Run system command and log output into logger.

Halt the device (meaning hang, not power off, nor reboot).

Power off the device.

Reboot the device and gracefully shutdown the Erlang VM.

Revert the device to running the previous firmware.

Return the device's serial number

Return whether the application was built for either the host or the target

Mark the running firmware as valid

Link to this section Types

Specs

revert_options() :: {:reboot, boolean()}

Options for Nerves.Runtime.revert/1.

Link to this section Functions

Link to this function

cmd(cmd, params, log_level_or_return)

View Source

Specs

cmd(binary(), [binary()], :debug | :info | :warn | :error | :return) ::
  {Collectable.t(), exit_status :: non_neg_integer()}

Run system command and log output into logger.

NOTE: Unlike System.cmd/3, this does not raise if the executable isn't found

Specs

halt() :: no_return()

Halt the device (meaning hang, not power off, nor reboot).

Note: this is different than :erlang.halt(), which exits BEAM, and may end up rebooting the device if erlinit.config settings allow reboot on exit.

Specs

poweroff() :: no_return()

Power off the device.

This calls :init.stop/0 internally. If :init.stop/0 takes longer than the erlinit.config's --graceful-powerdown setting (likely 10 seconds) then the system will be hard rebooted.

Specs

reboot() :: no_return()

Reboot the device and gracefully shutdown the Erlang VM.

This calls :init.stop/0 internally. If :init.stop/0 takes longer than the erlinit.config's --graceful-powerdown setting (likely 10 seconds) then the system will be hard rebooted.

Specs

revert([revert_options()]) :: :ok | {:error, reason :: any()} | no_return()

Revert the device to running the previous firmware.

This requires a specially constructed fw file.

Specs

serial_number() :: String.t()

Return the device's serial number

Serial number storage is device-specific and configurable. Serial numbers can be programmed in one-time programmable locations like in CPU ROM or cryptographic elements. They can also be in rewritable locations like a U-Boot environment block.

Nerves uses the boardid by default (set :boardid_path key in the application environment to another program to override). Boardid uses the /etc/boardid.config file to determine how to read the serial number. Official Nerves systems provide reasonable default mechanisms for getting started. Override this file in your application's rootfs_overlay to customize it.

This function never raises. If a serial number isn't available for any reason, it will return a serial number of "unconfigured".

Specs

target() :: String.t()

Return whether the application was built for either the host or the target

Specs

validate_firmware() :: :ok

Mark the running firmware as valid

A device cannot receive a new firmware if the current one has not been validated. In the official Nerves systems, this typically happens automatically. If you are handling the firmware validation in your app, then this function can be used as a helper to mark firmware as valid.

For systems that support automatic reverting, if the firmware is not marked as valid, then the next reboot will cause a revert to the old firmware