Targets

Nerves provides support for a set of common targets. Each target is referenced with a unique tag name. These tags are used when instructing Nerves which target you would like to compile for. It is important to note that a single tag name may offer support for more than one target board.

Supported Targets and Systems

TargetSystemTag
Raspberry Pi A+, B, B+ and Zeronerves_system_rpirpi
Raspberry Pi 2nerves_system_rpi2rpi2
Raspberry Pi 3nerves_system_rpi3rpi3
BeagleBone Blacknerves_system_bbbbbb
Alixnerves_system_alixalix
AG150nerves_system_ag150ag150
Intel Galileo 2nerves_system_galileogalileo
Lego EV3nerves_system_ev3ev3
QEmu Armnerves_system_qemu_armqemu_arm

Changing Targets

Nerves projects are configured to allow you to switch between targets by changing the value for the environment variable NERVES_TARGET. We configure our project to include the correct system for the target you choose by interpolating it into a string atom for the system reference.

def system(target) do
  [{:"nerves_system_#{target}", ">= 0.0.0"}]
end

Targets can be set and persisted several ways.

Global Level In your shell, you can export NERVES_TARGET=rpi3. This is useful if you only own a certain board and want to checkout and play with a variety of published nerves projects.

Project Level At the top of the mix file for a Nerves project, you can specify a default target tag:

@target System.get_env("NERVES_TARGET") || "rpi3"

Run Level You can switch targets at the issue of every mix command by specifying, for example, NERVES_TARGET=rpi3 mix compile

A Run Level setting will override a Project Level setting, which will override a Global Level setting.

Example

If you started your nerves project with mix nerves.new hello_nerves --target rpi3, and wish to compile for the Raspberry Pi 0, you can do so with:

NERVES_TARGET=rpi mix compile
NERVES_TARGET=rpi mix firmware
NERVES_TARGET=rpi mix firmware.burn

These commands will successively compile the code, create the firmware, and burn it to the SD card, for the rpi target (which covers the Raspberry Pi 0).

Note: if you want to change the target for the current shell session, you can type: export NERVES_TARGET=rpi. For the rest of your shell session, you won’t need to type NERVES_TARGET=rpi before your commands. If you wish to change the target permanently, you need to edit mix.exs.

@target System.get_env("NERVES_TARGET") || "rpi3"

Target Dependencies

It is important to note that, although Nerves supports multiple targets for a single application codebase, only one nerves_system can be included in a given firmware. Because of this, we recommend taking the following approach for including the system dependency separately from your application dependencies.

First, tell the project configuration to concatenate the global application dependencies from the system dependencies:

def project do
  [app: :hello_nerves,
   version: "0.0.1",
   target: @target,
   archives: [nerves_bootstrap: "0.1.2"],
   deps_path: "deps/#{@target}",
   build_path: "_build/#{@target}",
   build_embedded: Mix.env == :prod,
   start_permanent: Mix.env == :prod,
   aliases: aliases,
   deps: deps ++ system(@target)]
end

This allows you to keep the nerves_system separate form the rest of your dependencies:

def deps do
  [{:nerves, "~> 0.3.0"}]
end

def system(target) do
  [{:"nerves_system_#{target}", ">= 0.0.0"}]
end