Current section
Files
Jump to
Current section
Files
uboot/uboot.env
# Custom U-Boot base environment for Nerves
#
# Why?
# 1. We want to store settings in the U-boot environment so that they're
# accessible both to Elixir and U-boot.
# 2. This makes us add an environment block.
# 3. Unfortunately, if we point U-Boot to this block, it replaces its
# default environment settings which contain all of the logic to
# boot the boards. Therefore we have to copy/paste the relevant
# parts here.
# 4. We can support more complicated firmware validation methods by
# deferring validation of new software to the application. The
# default below is to automatically validate new software.
#
# IMPORTANT:
# Calling saveenv saves everything. Some of the variables it saves override
# automatically detected defaults and you can't know whether the variable was
# supplied automatically or via the saved environment. There is no way to
# selectively save environment variables. Here are problematic variables:
#
# * ethaddr
# * eth1addr
# * board_name
# * board_rev
# * board_serial
#
# If you move MicroSD cards around between boards, you currently need to clear
# those variables out so that they're detected again. The most visible issue is
# that Ethernet MAC addresses will travel with MicroSD cards. See
# https://github.com/nerves-project/nerves_system_bbb/issues/151.
#
# Nerves variables
#
nerves_fw_active=a
# nerves_fw_autovalidate controls whether updates are considered valid once
# applied. If set to 0, the user needs to set nerves_fw_validated to 1 in their
# application. If they don't set it before a reboot, then the previous software
# is run. If 1, then no further action needs to be taken.
nerves_fw_autovalidate=1
# nerves_fw_validated is 1 if the current boot selection is accepted It is set
# to 1 here, since this environment is written in the factory, so it is
# implicitly valid.
nerves_fw_validated=1
# nerves_fw_booted is 0 for the first boot and 1 for all reboots after that.
# NOTE: Keep this '0' so that all new boards run a 'saveenv' to exercise the
# code that writes back to the eMMC early on.
nerves_fw_booted=0
# The nerves initialization logic
#
# The nerves_init code is run at boot (see the last line of the file). It
# checks whether this is a first boot or not. If it's not the first boot, then
# the firmware better be validated or it reverts to running the firmware on
# the opposite partition.
nerves_revert=\
if test ${nerves_fw_active} = "a"; then\
echo "Reverting to partition B";\
setenv nerves_fw_active "b";\
else\
echo "Reverting to partition A";\
setenv nerves_fw_active "a";\
fi
nerves_init=\
if test ${nerves_fw_booted} = 1; then\
if test ${nerves_fw_validated} = 0; then\
run nerves_revert;\
setenv nerves_fw_validated 1;\
saveenv;\
fi;\
else\
setenv nerves_fw_booted 1;\
if test ${nerves_fw_autovalidate} = 1; then\
setenv nerves_fw_validated 1;\
fi;\
saveenv;\
fi;\
if test ${nerves_fw_active} = "a"; then\
setenv uenv_part 2;\
else\
setenv uenv_part 3;\
fi
# Defaults
devtype=mmc
devnum=0
# Values from default environment (quite a few of these look like they can be cleaned up)
fdt_addr_r=0x41800000
fdtoverlay_addr_r=0x41B00000
kernel_addr_r=0x40040000
kernel_comp_size=0xb000000
loadaddr=0x4a000000
scriptaddr=0x41900000
# Helper functions
uname_boot=sysboot ${devtype} ${devnum}:${uenv_part} any ${scriptaddr} /boot/extlinux/extlinux-${nerves_fw_active}.conf
# Boot
bootcmd=run nerves_init uname_boot