### Clone and build the Blinky example project Source: https://github.com/nerves-project/nerves/blob/main/guides/introduction/getting-started.md Clone the Nerves examples repository and build the 'Blinky' project, a basic hardware example. Set the MIX_TARGET environment variable before building. ```bash git clone https://github.com/nerves-project/nerves_examples export MIX_TARGET=rpi0_2 cd nerves_examples/blinky mix do deps.get, firmware, firmware.burn ``` -------------------------------- ### erlinit Configuration Example Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/porting-guide.md Configure erlinit, the PID 1 process that starts the BEAM VM. This example sets the console TTY, hostname, uses nbtty for the console, and mounts the application data partition. ```shell # erlinit.config for my_board -v # Console TTY --ctty ttyS0 # Hostname --hostname nerves # Use nbtty for the console --pre-run-exec /usr/bin/nbtty # Mount the application data partition --mount /dev/mmcblk0p3:/data:f2fs:: ``` -------------------------------- ### Main fwup.conf Example for Nerves Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/porting-guide.md This configuration defines firmware metadata, file resources, and tasks for complete firmware installation and upgrades. It includes partition setup and resource writing for both boot and rootfs partitions. ```conf require-fwup-version="1.0.0" # Include partition layout include("fwup_include/fwup-common.conf") # Firmware metadata meta-product = "My Board Nerves Image" meta-description = "Nerves firmware for My Board" meta-version = ${NERVES_FW_VERSION} meta-platform = "my_board" meta-architecture = "aarch64" meta-author = "Your Name" # File resources - these are files that get packed into the .fw bundle file-resource bootpart.vfat { host-path = "${NERVES_SYSTEM}/images/bootpart.vfat" } file-resource rootfs.img { host-path = "${NERVES_SYSTEM}/images/rootfs.squashfs" } # Task: complete - write everything to a blank SD card task complete { on-init { mbr_write(mbr-a) fat_mkfs(${BOOT_A_PART_OFFSET}, ${BOOT_A_PART_COUNT}) fat_mkfs(${BOOT_B_PART_OFFSET}, ${BOOT_B_PART_COUNT}) } on-resource bootpart.vfat { raw_write(${BOOT_A_PART_OFFSET}) } on-resource rootfs.img { raw_write(${ROOTFS_A_PART_OFFSET}) } on-finish { # Initialize the application data partition raw_memset(${APP_PART_OFFSET}, 256, 0xff) } } # Task: upgrade - update the inactive slot task upgrade.a { # Upgrade B -> A require-partition1-offset = ${BOOT_B_PART_OFFSET} on-resource bootpart.vfat { raw_write(${BOOT_A_PART_OFFSET}) } on-resource rootfs.img { raw_write(${ROOTFS_A_PART_OFFSET}) } on-finish { mbr_write(mbr-a) } } task upgrade.b { # Upgrade A -> B require-partition1-offset = ${BOOT_A_PART_OFFSET} on-resource bootpart.vfat { raw_write(${BOOT_B_PART_OFFSET}) } on-resource rootfs.img { raw_write(${ROOTFS_B_PART_OFFSET}) } on-finish { mbr_write(mbr-b) } } ``` -------------------------------- ### Custom Buildroot Package Config.in Example Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/building-systems.md Example of a root `Config.in` file for a Nerves system, including a custom package menu. ```plain menu "Custom Packages" source "$NERVES_DEFCONFIG_DIR/packages/libfoo/Config.in" endmenu ``` -------------------------------- ### Erlinit Mount Command Example Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/advanced-configuration.md Example of an erlinit.config command to mount the configdata and logdata partitions. ```bash # Mount the configdata and logdata partitions -m /dev/mmcblk0p3:/root:ext4::;/dev/mmcblk0p4:/mnt/log:ext4:: ``` -------------------------------- ### Custom Buildroot Package External.mk Example Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/building-systems.md Example of a root `external.mk` file for a Nerves system, including custom package makefiles. ```make include $(sort $(wildcard $(NERVES_DEFCONFIG_DIR)/packages/*/*.mk)) ``` -------------------------------- ### U-Boot Boot Script Example Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/porting-guide.md An example U-Boot boot script (`boot.cmd`) for an Allwinner AArch64 board. It defines standard U-Boot environment variables for loading the kernel, device tree, and setting kernel command line arguments. ```shell # boot.cmd - U-Boot boot script for Nerves ``` -------------------------------- ### Install Build Tools for Arch Linux Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/building-systems.md Installs necessary packages for building Nerves systems on Arch Linux. ```bash sudo pacman -Syu git base-devel bc cmake cvs wget curl mercurial python python-aiohttp flake8 python-ijson python-nose2 python-pexpect python-pip python-requests rsync subversion unzip gawk jq squashfs-tools openssl automake autoconf ncurses ``` -------------------------------- ### Board ID Configuration Example Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/porting-guide.md Configure the `boardid` tool to read a unique identifier for the board. This example shows how to attempt reading from U-Boot environment variables and CPU information. ```shell # Try reading the serial number from different sources -b uboot_env -u nerves_serial_number -b cpuinfo -f Serial ``` -------------------------------- ### Install Nerves Archives Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/building-systems.md Installs the Nerves bootstrap archive and local rebar if they are not already set up. ```bash mix archive.install hex nerves_bootstrap mix local.rebar ``` -------------------------------- ### View Zig Targets Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/environment-variables.md Install zig and run this command to view available target configurations. ```shell zig targets | less ``` -------------------------------- ### U-Boot Boot Script Example Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/porting-guide.md This U-Boot script loads the kernel and device tree from the active boot partition and then boots the kernel. Ensure the `root=` parameter matches your rootfs partition. ```bash setenv bootargs console=ttyS0,115200 root=/dev/mmcblk0p2 rootfstype=squashfs rootwait fatload mmc 0 ${kernel_addr_r} Image fatload mmc 0 ${fdt_addr_r} sun50i-a64-pine64-plus.dtb booti ${kernel_addr_r} - ${fdt_addr_r} ``` -------------------------------- ### Manually install mise plugins Source: https://github.com/nerves-project/nerves/blob/main/guides/introduction/installation.md Manually installs Erlang and Elixir plugins for mise if automatic installation fails. ```bash mise plugin install erlang ``` ```bash mise plugin install elixir ``` -------------------------------- ### Install nerves_bootstrap archive Source: https://github.com/nerves-project/nerves/blob/main/guides/introduction/installation.md Installs the nerves_bootstrap Mix archive, which is required for bootstrapping the Nerves Mix environment and generating new Nerves projects. ```bash mix archive.install hex nerves_bootstrap ``` -------------------------------- ### Nerves Partition Definition File Example Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/porting-guide.md An example configuration file defining partition offsets and sizes for a standard Nerves MBR layout on an SD card. It uses `define` and `define-eval` for dynamic offset calculations. ```conf # Firmware partition definitions # Let fwup know the image is for an SD card define(NERVES_FW_DEVPATH, "/dev/mmcblk0") # U-Boot environment (small key/value store before the partitions) define(UBOOT_ENV_OFFSET, 16) define(UBOOT_ENV_COUNT, 16) # Boot A partition (FAT32, holds kernel + DTB + boot.scr) define(BOOT_A_PART_OFFSET, 63) define(BOOT_A_PART_COUNT, 65536) # Boot B partition define-eval(BOOT_B_PART_OFFSET, "${BOOT_A_PART_OFFSET} + ${BOOT_A_PART_COUNT}") define(BOOT_B_PART_COUNT, 65536) # Rootfs A partition (squashfs) define-eval(ROOTFS_A_PART_OFFSET, "${BOOT_B_PART_OFFSET} + ${BOOT_B_PART_COUNT}") define(ROOTFS_A_PART_COUNT, 524288) # Rootfs B partition define-eval(ROOTFS_B_PART_OFFSET, "${ROOTFS_A_PART_OFFSET} + ${ROOTFS_A_PART_COUNT}") define(ROOTFS_B_PART_COUNT, 524288) # Application data partition (F2FS, fills the rest) define-eval(APP_PART_OFFSET, "${ROOTFS_B_PART_OFFSET} + ${ROOTFS_B_PART_COUNT}") define(APP_PART_COUNT, 0) define(NERVES_FW_APPLICATION_PART0_DEVPATH, "/dev/mmcblk0p3") define(NERVES_FW_APPLICATION_PART0_FSTYPE, "f2fs") define(NERVES_FW_APPLICATION_PART0_TARGET, "/data") ``` -------------------------------- ### Install Build Tools for Apt-based Linux Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/building-systems.md Installs essential packages for building Nerves systems on Ubuntu and Debian-based distributions. ```bash sudo apt update && sudo apt install -y git build-essential bc cmake cvs wget curl mercurial python3 python3-aiohttp python3-flake8 python3-ijson python3-nose2 python3-pexpect python3-pip python3-requests rsync subversion unzip gawk jq squashfs-tools libssl-dev automake autoconf libncurses5-dev ``` -------------------------------- ### Install Arch Linux Dependencies Source: https://github.com/nerves-project/nerves/blob/main/guides/introduction/installation.md Installs essential build tools and libraries for Nerves on Arch-based systems using yay. ```bash yay -S base-devel ncurses5-compat-libs git squashfs-tools curl wget bc cpio ``` -------------------------------- ### Complete Nerves Defconfig Example for AArch64 Board Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/porting-guide.md A comprehensive `nerves_defconfig` example for an AArch64 Allwinner board, demonstrating configurations for architecture, toolchain, system, kernel, U-Boot, packages, root filesystem, and build hooks. ```kconfig # Architecture BR2_aarch64=y BR2_cortex_a53=y # Toolchain (Nerves external) BR2_TOOLCHAIN_EXTERNAL=y BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y BR2_TOOLCHAIN_EXTERNAL_URL="https://github.com/nerves-project/toolchains/releases/download/v13.2.0/nerves_toolchain_aarch64_nerves_linux_gnu-linux_x86_64-13.2.0-B21A7B8.tar.xz" BR2_TOOLCHAIN_EXTERNAL_CUSTOM_PREFIX="aarch64-nerves-linux-gnu" BR2_TOOLCHAIN_EXTERNAL_GCC_13=y BR2_TOOLCHAIN_EXTERNAL_HEADERS_5_4=y BR2_TOOLCHAIN_EXTERNAL_CUSTOM_GLIBC=y BR2_TOOLCHAIN_EXTERNAL_CXX=y BR2_TOOLCHAIN_EXTERNAL_FORTRAN=y BR2_TOOLCHAIN_EXTERNAL_OPENMP=y # System BR2_INIT_NONE=y BR2_ROOTFS_SKELETON_CUSTOM=y BR2_ROOTFS_SKELETON_CUSTOM_PATH="${BR2_EXTERNAL_NERVES_PATH}/board/nerves-common/skeleton" BR2_NERVES_SYSTEM_NAME="nerves_system_my_board" # Kernel BR2_LINUX_KERNEL=y BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="${NERVES_DEFCONFIG_DIR}/linux-6.6.defconfig" BR2_LINUX_KERNEL_DTS_SUPPORT=y BR2_LINUX_KERNEL_INTREE_DTS_NAME="allwinner/sun50i-a64-pine64-plus" # U-Boot BR2_TARGET_UBOOT=y BR2_TARGET_UBOOT_BUILD_SYSTEM_KCONFIG=y BR2_TARGET_UBOOT_CUSTOM_VERSION=y BR2_TARGET_UBOOT_CUSTOM_VERSION_VALUE="2024.04" BR2_TARGET_UBOOT_BOARD_DEFCONFIG="pine64_plus" # Packages BR2_PACKAGE_NERVES_CONFIG=y BR2_PACKAGE_BUSYBOX_CONFIG="${BR2_EXTERNAL_NERVES_PATH}/board/nerves-common/busybox.config" BR2_PACKAGE_NBTTY=y BR2_PACKAGE_CA_CERTIFICATES=y # Root filesystem BR2_TARGET_ROOTFS_SQUASHFS=y BR2_TARGET_ROOTFS_SQUASHFS_LZ4=y # Build hooks BR2_ROOTFS_OVERLAY="${BR2_EXTERNAL_NERVES_PATH}/board/nerves-common/rootfs_overlay ${NERVES_DEFCONFIG_DIR}/rootfs_overlay" BR2_ROOTFS_POST_BUILD_SCRIPT="${BR2_EXTERNAL_NERVES_PATH}/board/nerves-common/post-build.sh ${NERVES_DEFCONFIG_DIR}/post-build.sh" BR2_ROOTFS_POST_SCRIPT_ARGS="${NERVES_DEFCONFIG_DIR}" ``` -------------------------------- ### extlinux.conf Example for Distroboot Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/porting-guide.md This configuration file is used by U-Boot's distroboot mechanism. It specifies the kernel image and kernel command line arguments. Place this file in the `extlinux/` directory on the boot partition. ```bash DEFAULT nerves TIMEOUT 0 LABEL nerves LINUX /bzImage APPEND root=/dev/sda2 rootfstype=squashfs rootwait console=ttyS0,115200 ``` -------------------------------- ### Get Project Dependencies Source: https://github.com/nerves-project/nerves/blob/main/guides/introduction/getting-started.md Navigate to your Nerves project directory and fetch all necessary dependencies for the specified target. ```bash cd hello_nerves MIX_TARGET=rpi0_2 mix deps.get ``` -------------------------------- ### Install Nerves Dependencies on MacOS Source: https://github.com/nerves-project/nerves/blob/main/guides/introduction/installation.md Installs essential tools like fwup, squashfs, coreutils, xz, and pkg-config using Homebrew. ```bash brew update brew install fwup squashfs coreutils xz pkg-config ``` -------------------------------- ### Install Avahi Utilities on Linux Source: https://github.com/nerves-project/nerves/blob/main/guides/core/connecting-to-a-nerves-target.md Installs the necessary Avahi utilities for improved mDNS discovery on Debian/Ubuntu and Fedora/RHEL systems. ```bash # On Ubuntu/Debian sudo apt-get install avahi-utils # On Fedora/RHEL sudo dnf install avahi-tools ``` -------------------------------- ### Install Nerves Dependencies on Fedora Source: https://github.com/nerves-project/nerves/blob/main/guides/introduction/installation.md Installs development tools, git, squashfs-tools, and development libraries required for Nerves on Fedora systems. ```bash sudo dnf install @development-tools automake autoconf git squashfs-tools pkgconf-pkg-config curl libmnl-devel openssl-devel ncurses-devel help2man libconfuse-devel libarchive-devel ``` -------------------------------- ### Configure Erlinit Console Output Source: https://github.com/nerves-project/nerves/blob/main/guides/core/iex-with-nerves.md Example configuration for `erlinit.config` to specify where the IEx prompt should be sent. Only one console output option can be enabled at a time. ```text Specify where erlinit should send the IEx prompt. Only one may be enabled at # a time. -c ttyAMA0 # UART pins on the GPIO connector ``` -------------------------------- ### Install Build Tools for RPM-based Linux Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/building-systems.md Installs required packages for building Nerves systems on Red Hat, Fedora, and similar RPM-based distributions. ```bash sudo dnf install -y git @development-tools @c-development kernel-devel cvs wget curl mercurial python3 python3-aiohttp python3-flake8 python3-ijson python3-nose2 python3-pexpect python3-pip python3-requests rsync unzip gawk jq squashfs-tools openssl-devel ncurses-devel ``` -------------------------------- ### Update application.ex to use Mix.target() Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/updating-projects.md Replace `Mix.Project.config()[:target]` with `Mix.target()` in `application.ex` when determining runtime configurations or starting processes. ```elixir @target Mix.Project.config()[:target] ``` ```elixir @target Mix.target() ``` -------------------------------- ### Install Nerves Dependencies on Ubuntu/Debian Source: https://github.com/nerves-project/nerves/blob/main/guides/introduction/installation.md Installs build tools, git, squashfs-tools, and development libraries required for Nerves on Ubuntu and Debian-based systems. ```bash sudo apt install build-essential automake autoconf git squashfs-tools pkg-config curl libmnl-dev libnl-genl-3-dev libssl-dev libncurses5-dev help2man libconfuse-dev libarchive-dev file unzip libgnutls28-dev ``` -------------------------------- ### Define Custom Partition Sizes in fwup.conf Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/advanced-configuration.md Use 'define' and 'define-eval' in fwup.conf to specify the offsets and sizes for new partitions. This example defines partitions for configuration and log data. ```bash # fwup.conf # (Sizes are in 512 byte blocks) define(UBOOT_ENV_OFFSET, 16) define(UBOOT_ENV_COUNT, 16) # 8 KB define(BOOT_A_PART_OFFSET, 63) define(BOOT_A_PART_COUNT, 38630) define-eval(BOOT_B_PART_OFFSET, "${BOOT_A_PART_OFFSET} + ${BOOT_A_PART_COUNT}") define(BOOT_B_PART_COUNT, ${BOOT_A_PART_COUNT}) # Let the rootfs have room to grow up to 128 MiB and align it to the nearest 1 # MB boundary define(ROOTFS_A_PART_OFFSET, 77324) define(ROOTFS_A_PART_COUNT, 289044) define-eval(ROOTFS_B_PART_OFFSET, "${ROOTFS_A_PART_OFFSET} + ${ROOTFS_A_PART_COUNT}") define(ROOTFS_B_PART_COUNT, ${ROOTFS_A_PART_COUNT}) # Configuration partition define-eval(CONFIG_PART_OFFSET, "${ROOTFS_B_PART_OFFSET} + ${ROOTFS_B_PART_COUNT}") define(CONFIG_PART_COUNT, 1048576) # Log partition define-eval(LOG_PART_OFFSET, "${CONFIG_PART_OFFSET} + ${CONFIG_PART_COUNT}") define(CONFIG_PART_COUNT, 1048576) # ... ``` -------------------------------- ### Enter Nerves System Shell Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/customizing-systems.md Starts the Nerves system shell for customizing the system. This provides a Buildroot environment for configuration. ```bash $ mix nerves.system.shell Mix environment MIX_TARGET: custom_rpi3 MIX_ENV: dev ==> nerves Compiling 25 files (.ex) Generated nerves app Preparing Nerves Shell Creating build directory... Cleaning up... Nerves /nerves/build > ``` -------------------------------- ### Nerves Bootstrap Call Tree - mix firmware Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/internals.md This outlines the sequence of tasks executed when running `mix firmware`, including precompilation and environment setup. ```Elixir alias nerves.precompile NERVES_PRECOMPILE = 1 Mix.Tasks.Nerves.Env Mix.Tasks.Deps.Loadpaths.run ["--no-compile"] Mix.Tasks.Deps.Compile.run ["nerves", "--include-children"] Nerves.Env.start() load_packages() Mix.Project.deps_paths Package.config_path Package.load_config build_runner() validate_packages() Mix.Tasks.Deps.Compile Nerves.Env.system.app Mix.Tasks.Compile.run(--no-deps-check) Only if parent == system_app NERVES_PRECOMPILE = 0 Mix.Tasks.Nerves.Loadpaths.run() Mix.task.run(nerves.env) Nerves.Env Nerves.Env.start() ?? See above Nerves.Env.bootstrap() system_path() Nerves.Env.system() Nerves.Artifact.dir() System.get_env(env_var(pkg)) NERVES_SYSTEM toolchain_path() Nerves.Env.toolchain() Nerves.Artifact.dir() System.get_env(env_var(pkg)) NERVES_TOOLCHAIN platform.bootstrap(pkg) Nerves.Env.system.platform ||Nerves.Env.system.config[:build_platform] nerves_env.exs Nerves.System.BR ``` -------------------------------- ### Get Dependencies and Compile Project Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/porting-guide.md Standard Mix commands to fetch project dependencies and compile the Elixir code. The initial compilation may take a significant amount of time. ```bash mix deps.get mix compile ``` -------------------------------- ### Nerves Init System and Skeleton Configuration Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/porting-guide.md Configure Nerves to use no init system and a custom root filesystem skeleton provided by `nerves_system_br`. This setup is essential for Nerves's unique approach where `erlinit` acts as PID 1. ```kconfig BR2_INIT_NONE=y BR2_ROOTFS_SKELETON_CUSTOM=y BR2_ROOTFS_SKELETON_CUSTOM_PATH="${BR2_EXTERNAL_NERVES_PATH}/board/nerves-common/skeleton" ``` -------------------------------- ### Get Network Interface Information with VintageNet Source: https://github.com/nerves-project/nerves/blob/main/guides/core/iex-with-nerves.md Use VintageNet.info to display all network interfaces, their types, states, and configurations. This is useful for understanding the current network setup. ```elixir iex> VintageNet.info All interfaces: ["eth0", "lo", "wlan0", "wwan0"] Available interfaces: ["wlan0", "wwan0"] Interface eth0 Type: VintageNetEthernet Present: true State: :configured (1 days, 14:59:09) Connection: :disconnected (1 days, 14:59:09) Configuration: %{type: VintageNetEthernet, ipv4: %{method: :dhcp}} Interface wlan0 Type: VintageNetWiFi Present: true State: :configured (1 days, 14:59:05) Connection: :internet (5:02:35) Addresses: 192.168.99.81/24, fe80::9a48:27ff:fedd:a10e/64 Configuration: %{ type: VintageNetWiFi, ipv4: %{method: :dhcp}, vintage_net_wifi: ... } Interface wwan0 Type: VintageNetQMI Power: On (watchdog timeout in 59969 ms) Present: true State: :configured (14:44:50) Connection: :internet (14:43:51) Addresses: 100.101.32.76/29, fe80::8eb:885f:3fce:d37d/64 Configuration: %{ ... } ``` -------------------------------- ### Copy Starter Configuration Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/building-systems.md Copies the starter configuration file to create a new configuration for building Nerves systems. ```bash cp config/starter-config.exs config/config.exs ``` -------------------------------- ### Download and Buildroot System Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/porting-guide.md Clone the Buildroot repository and configure it for your specific board. This is a prerequisite for creating a Nerves system. ```bash git clone https://gitlab.com/buildroot.org/buildroot/ cd buildroot # If using a built-in defconfig make _defconfig make ``` -------------------------------- ### Install Erlang and Elixir with asdf Source: https://github.com/nerves-project/nerves/blob/main/guides/introduction/installation.md Adds Erlang and Elixir plugins to asdf and installs specific versions compatible with Nerves. ```bash asdf plugin add erlang ``` ```bash asdf plugin add elixir ``` ```bash asdf install erlang 28.1.1 ``` ```bash asdf install elixir 1.19.1-otp-28 ``` ```bash asdf set -u erlang 28.1.1 ``` ```bash asdf set -u elixir 1.19.1-otp-28 ``` -------------------------------- ### Set MIX_TARGET and Build Firmware Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/customizing-systems.md Set the MIX_TARGET environment variable to your custom system name and run `mix deps.get` and `mix firmware` to build your custom firmware. The first build may take 15-30 minutes. ```bash cd ~/projects/your_project export MIX_TARGET=custom_rpi3 mix deps.get mix firmware ``` -------------------------------- ### Build Nerves Project with Custom System Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/building-systems.md Build your Nerves project using 'mix deps.get' and 'mix firmware'. The environment variables ensure your custom-built system is used. ```bash mix deps.get mix firmware ``` -------------------------------- ### Install Latest Nerves Bootstrap Archive Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/updating-projects.md Use this command to install the latest Nerves Bootstrap archive, which is required for Nerves v0.9.0 and later. ```bash mix local.nerves ``` ```bash mix archive.install hex nerves_bootstrap ``` -------------------------------- ### Linux Boot Sequence Flowchart Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/porting-guide.md Visualizes the step-by-step process of a Linux system booting up, from power on to running the initial process (PID 1). ```text Power on Bootloader Kernel mounts rootfs runs PID 1 ``` -------------------------------- ### Install fwup on Windows with Chocolatey Source: https://github.com/nerves-project/nerves/blob/main/guides/introduction/installation.md Installs the Windows version of fwup using Chocolatey. This is required for burning firmware to SD cards when using WSL2. ```powershell choco install fwup /y ``` -------------------------------- ### Configure Git Repository for Custom System Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/building-systems.md Set up a Git repository for your custom Nerves system, including renaming the default remote and pushing to a new origin. ```bash cd custom_rpi3 git remote rename origin upstream git remote add origin git@github.com:YourGitHubUserName/custom_rpi3.git git checkout -b main git push origin main ``` -------------------------------- ### Build Nerves Systems Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/building-systems.md Initiate the build process for all systems defined in your configuration file. This task generates Buildroot `.config` files and compiles the systems. ```bash mix ns.build ``` -------------------------------- ### Force nerves_bootstrap installation for older Elixir versions Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/updating-projects.md If you cannot update Elixir to 1.9+ but need to create new projects, use this command to install a compatible version of nerves_bootstrap. ```bash mix archive.install hex nerves_bootstrap "~> 1.5.0" ``` -------------------------------- ### Configure Buildroot Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/building-systems.md Use 'make menuconfig' to modify the Buildroot configuration for your Nerves system. ```bash make menuconfig ``` -------------------------------- ### Add and Install fwup via asdf on Ubuntu/Debian Source: https://github.com/nerves-project/nerves/blob/main/guides/introduction/installation.md Adds the fwup plugin to asdf and installs the latest version. Nerves uses fwup for firmware image creation. ```bash asdf plugin add fwup https://github.com/fwup-home/asdf-fwup.git asdf install fwup latest asdf set -u fwup latest ``` -------------------------------- ### Copy fwup.conf and cmdline.txt for Overlays Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/advanced-configuration.md These bash commands demonstrate how to locate and copy the `fwup.conf` and `cmdline.txt` files from a Nerves system dependency to your project's `config` directory. This is the first step in customizing boot partition files. ```bash # Locate the fwup.conf files available in your deps directory find deps -name fwup.conf # Copy the one that matches your target to the config directory. cp deps/nerves_system_rpi0/fwup.conf config/ # Also copy cmdline.txt as you'll need it below. ``` ```bash cp deps/nerves_system_rpi0/cmdline.txt config/ ``` -------------------------------- ### Build External Tree and Configure Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/porting-guide.md Use this command to build with an external tree from a manufacturer. It configures the build system for a specific board. ```bash make BR2_EXTERNAL=../my-external my_board_defconfig make ``` -------------------------------- ### Build and Burn Nerves Firmware Source: https://github.com/nerves-project/nerves/blob/main/README.md Set the target environment, fetch dependencies, compile firmware, and burn it to an SD card. The `mix firmware.burn` command may require sudo privileges. ```bash export MIX_TARGET=rpi3 mix deps.get # Fetch the dependencies mix firmware # Cross-compile dependencies and create a .fw file mix firmware.burn # Burn firmware to an inserted SD card ``` -------------------------------- ### Display Toolshed Help Source: https://github.com/nerves-project/nerves/blob/main/guides/introduction/getting-started.md Access the help documentation for the `Toolshed` package within the IEx prompt. This command is useful for exploring available runtime commands. ```elixir iex> h Toolshed ``` -------------------------------- ### Firmware Build Success Message Source: https://github.com/nerves-project/nerves/blob/main/guides/introduction/getting-started.md This message indicates that the firmware compilation was successful and provides options for installation. ```plain Firmware built successfully! 🎉 Now you may install it to a MicroSD card using `mix burn` or upload it to a device with `mix upload` or `mix firmware.gen.script`+`./upload.sh`. ``` -------------------------------- ### Preload Build Dependencies Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/building-systems.md Download all required files for a Nerves system in advance within its output directory. This can speed up subsequent builds, especially when working offline or on slow networks. ```bash cd o/ make source ``` -------------------------------- ### Verify nerves_bootstrap version for Elixir 1.9+ Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/updating-projects.md Check that nerves_bootstrap version 1.6.0 or later is installed before proceeding with Elixir 1.9+ updates. ```bash $ mix archive ``` -------------------------------- ### Uninstall Erlang and Elixir on MacOS Source: https://github.com/nerves-project/nerves/blob/main/guides/introduction/installation.md Removes existing Erlang and Elixir installations managed by Homebrew to prevent conflicts with asdf or mise. ```bash brew uninstall elixir brew uninstall erlang ``` -------------------------------- ### Linux Boot Components Diagram Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/porting-guide.md Illustrates the three fundamental pieces of any Linux system: the bootloader, the kernel, and the root filesystem, and their interaction during the boot process. ```text +-------------------+ | Bootloader | +-------------------+ +-------------------+ | | | Kernel | | Initializes HW | +-------------------+ | Loads kernel into | | | | memory, starts it |--->| Manages processes | | | | Memory mgmt | +-------------------+ | Device drivers | | Filesystems | +-------------------+ | Rootfs | +-------------------+ | | | Programs, | | libraries, | | config, your app | | | +-------------------+ ``` -------------------------------- ### Generate a New Nerves Application Source: https://github.com/nerves-project/nerves/blob/main/README.md Use this command to create a new Nerves project. Ensure Elixir and the Nerves toolchain are installed. ```bash mix nerves.new my_app ``` -------------------------------- ### Remove Nerves Systems Source Directory Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/building-systems.md Delete the `src` directory to reset the Nerves systems environment. This is useful before reconfiguring or starting over. ```bash rm -rf src ``` -------------------------------- ### Define Device Tree Overlay Resource in fwup.conf Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/advanced-configuration.md This bash snippet illustrates how to define a file resource for a device tree overlay (`.dtbo`) file within `fwup.conf`. This allows Nerves to include custom hardware configurations, such as for sensors, during the firmware build process. ```bash # fwup.conf file-resource overlays/bosch-bmp280.dtbo { host-path = "${NERVES_APP}/config/overlays/bosch-bmp280.dtbo" } ``` -------------------------------- ### Verify Custom System Usage Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/building-systems.md Run 'mix nerves.info' to confirm that your project is utilizing the custom-built Nerves system, indicated by the output referencing your custom build location. ```bash mix nerves.info ``` -------------------------------- ### Source Environment Script Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/building-systems.md Source the nerves.env.sh script to set up environment variables for your custom-built system. Remember to do this each time you start a new terminal session. ```bash . ~/path/to/nerves_systems/o/rpi0/nerves.env.sh ``` -------------------------------- ### U-Boot Environment Configuration Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/porting-guide.md Configure the `fw_printenv`/`fw_setenv` tools to locate the U-Boot environment on disk. Specify the device, offset, and size for the environment storage. ```shell /dev/mmcblk0 0x100000 0x20000 ``` -------------------------------- ### Start picocom Communication Source: https://github.com/nerves-project/nerves/blob/main/guides/core/connecting-to-a-nerves-target.md Initiate a serial connection to your Nerves target using picocom. Replace `/dev/ttyUSB0` with the actual TTY device name for your cable. ```bash picocom -b 115200 /dev/ttyUSB0 ``` -------------------------------- ### Set Target and Build Firmware Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/porting-guide.md Set the MIX_TARGET environment variable to your custom board and then build the firmware. This command compiles the Nerves system and application into a firmware image. ```bash export MIX_TARGET=my_board mix deps.get mix firmware ``` -------------------------------- ### Define Nerves Package Environment Variables Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/environment-variables.md Example of defining TARGET_* environment variables within the `nerves_package` function in `mix.exs` for a Raspberry Pi Zero system. ```elixir defp nerves_package do [ type: :system, ... env: [ {"TARGET_ARCH", "arm"}, {"TARGET_CPU", "arm1176jzf_s"}, {"TARGET_OS", "linux"}, {"TARGET_ABI", "gnueabihf"} ] ... ] end ``` -------------------------------- ### Customize mksquashfs flags in mix config Source: https://github.com/nerves-project/nerves/blob/main/guides/advanced/experimental-features.md Example of customizing non-Elixir parts of the firmware, specifically mksquashfs flags, within a project's mix configuration. ```elixir # Customize non-Elixir parts of the firmware. See ```