Packages
nerves_system_rpi
2.0.4
2.1.0
2.0.4
2.0.3
2.0.2
2.0.1
2.0.0
2.0.0-rc.3
2.0.0-rc.2
2.0.0-rc.1
retired
2.0.0-rc.0
retired
1.33.1
1.33.0
1.32.0
1.31.4
1.31.3
1.31.2
1.31.1
1.31.0
1.30.1
1.30.0
1.29.1
1.29.0
1.28.1
1.28.0
1.27.1
1.27.0
1.26.0
1.25.1
1.25.0
1.24.1
1.24.0
1.23.2
1.23.1
1.23.0
1.22.2
1.22.1
1.22.0
1.21.2
1.21.1
1.21.0
1.20.2
1.20.1
1.20.0
1.19.0
1.18.4
1.18.3
1.18.2
1.18.1
1.18.0
1.17.3
1.17.2
1.17.1
1.17.0
1.16.2
1.16.1
1.16.0
1.15.1
1.15.0
1.14.1
1.14.0
1.13.3
1.13.2
1.13.1
retired
1.13.0
1.12.2
1.12.1
1.12.0
1.11.2
1.11.1
1.11.0
1.10.2
1.10.1
1.10.0
1.9.2
1.9.1
1.9.0
1.8.2
1.8.1
1.8.0
1.7.2
1.7.1
1.7.0
1.6.3
1.6.2
1.6.1
1.6.0
1.5.1
1.5.0
1.4.0
1.3.0
1.2.1
1.2.0
1.1.1
1.1.0
1.0.0
1.0.0-rc.0
0.20.0
0.18.0
0.17.1
0.17.0
0.16.1
0.16.0
0.15.0
0.14.0
0.13.0
0.12.0
0.11.0
0.10.0
0.9.1
0.9.0
0.7.0
0.6.1
0.6.0
0.5.2
0.5.1
0.5.0
0.4.1
Nerves System - Raspberry Pi A+ / B+ / B
Current section
Files
Jump to
Current section
Files
nerves_system_rpi
fwup-ops.conf
fwup-ops.conf
# Post-installation firmware operations for the Raspberry Pi
#
# Tasks include:
#
# * `factory-reset` - Clear out the writable filesystem and any other writable
# areas so that they can be re-initialized on the next boot.
# * `prevent-revert` - Prevent `revert` from working until the next firmware
# * `revert` - Revert to the previous firmware if it's still available
# * `validate` - Mark this firmware as a good update.
# * `status` - Print out which partition is active (`a` or `b`)
#
# To use:
#
# 1. Run `fwup -c -f fwup-ops.conf -o ops.fw` and copy ops.fw to
# the device. This is done automatically as part of the Nerves system
# build process. The file is stored in `/usr/share/fwup/ops.fw`.
# 2. On the device, run `fwup -t <task> -d /dev/rootdisk0 --enable-trim /usr/share/fwup/ops.fw`.
# 3. Reboot after running `revert` or `factory-reset`.
#
# It is critical that this is kept in sync with the main fwup.conf.
require-fwup-version="1.0.0"
include("${NERVES_SDK_IMAGES:-.}/fwup_include/fwup-common.conf")
##
# factory-reset
##
task factory-reset {
on-init {
info("Erasing all writable data")
# This works better with --enable-trim
# Trim may not work on MicroSD card, so don't rely on it
trim(${APP_PART_OFFSET}, ${APP_PART_COUNT})
raw_memset(${APP_PART_OFFSET}, 256, 0xff)
}
}
##
# prevent-revert
#
# Pass `--enable-trim` to also clear out the partition that no longer should be used.
##
task prevent-revert.a {
# Check that we're running on B
require-path-at-offset("/", ${ROOTFS_B_PART_OFFSET})
on-resource autoboot-b.txt {
info("Preventing reverts to partition A")
# Ensure that autoboot is booting the B partition
fat_write(${AUTOBOOT_PART_OFFSET}, "autoboot.txt")
uboot_setenv(uboot-env, "b.nerves_fw_validated", "1")
# Remove U-Boot variables that fwup uses to allow reverting images
uboot_unsetenv(uboot-env, "a.nerves_fw_platform")
uboot_unsetenv(uboot-env, "a.nerves_fw_architecture")
uboot_setenv(uboot-env, "a.nerves_fw_validated", "0")
# Clear out the old image using TRIM. This requires --enable-trim
trim(${ROOTFS_A_PART_OFFSET}, ${ROOTFS_A_PART_COUNT})
trim(${BOOT_A_PART_OFFSET}, ${BOOT_A_PART_COUNT})
}
}
task prevent-revert.b {
# Check that we're running on A
require-path-at-offset("/", ${ROOTFS_A_PART_OFFSET})
on-resource autoboot-a.txt {
info("Preventing reverts to partition B")
# Ensure that autoboot is booting the A partition
fat_write(${AUTOBOOT_PART_OFFSET}, "autoboot.txt")
uboot_setenv(uboot-env, "a.nerves_fw_validated", "1")
# Remove U-Boot variables that fwup uses to allow reverting images
uboot_unsetenv(uboot-env, "b.nerves_fw_platform")
uboot_unsetenv(uboot-env, "b.nerves_fw_architecture")
uboot_setenv(uboot-env, "b.nerves_fw_validated", "0")
# Clear out the image using TRIM. This requires --enable-trim
trim(${ROOTFS_B_PART_OFFSET}, ${ROOTFS_B_PART_COUNT})
trim(${BOOT_B_PART_OFFSET}, ${BOOT_B_PART_COUNT})
}
}
task prevent-revert.fail {
on-init {
error("Error detecting active partition")
}
}
##
# revert
##
task revert.a {
# This task reverts to the A partition, so check that we're running on B
# and A is valid.
require-path-at-offset("/", ${ROOTFS_B_PART_OFFSET})
require-uboot-variable(uboot-env, "a.nerves_fw_validated", "1")
on-resource autoboot-a.txt {
info("Reverting to partition A")
fat_write(${AUTOBOOT_PART_OFFSET}, "autoboot.txt")
}
}
task revert.b {
# This task reverts to the B partition, so check that we're running on A
require-path-at-offset("/", ${ROOTFS_A_PART_OFFSET})
require-uboot-variable(uboot-env, "b.nerves_fw_validated", "1")
on-resource autoboot-b.txt {
info("Reverting to partition B")
fat_write(${AUTOBOOT_PART_OFFSET}, "autoboot.txt")
}
}
task revert.unexpected.a {
require-uboot-variable(uboot-env, "a.nerves_fw_validated", "1")
on-init {
# Case where A is good, and the desire is to go to B.
error("It doesn't look like there's valid firmware to revert to in partition B.")
}
}
task revert.unexpected.b {
require-uboot-variable(uboot-env, "b.nerves_fw_validated", "1")
on-init {
# Case where B is good, and the desire is to go to A.
error("It doesn't look like there's valid firmware to revert to in partition A.")
}
}
task revert.fail {
on-init { error("Failed") }
}
##
# status
#
# Run "fwup /usr/share/fwup/ops.fw -t status -d /dev/rootdisk0 -q -U" to check the status.
##
task status.ab {
require-uboot-variable(uboot-env, "a.nerves_fw_validated", "0")
require-path-at-offset("/", ${ROOTFS_A_PART_OFFSET})
on-init { info("a->b") }
}
task status.ba {
require-uboot-variable(uboot-env, "b.nerves_fw_validated", "0")
require-path-at-offset("/", ${ROOTFS_B_PART_OFFSET})
on-init { info("b->a") }
}
task status.aa {
require-path-at-offset("/", ${ROOTFS_A_PART_OFFSET})
on-init { info("a") }
}
task status.bb {
require-path-at-offset("/", ${ROOTFS_B_PART_OFFSET})
on-init { info("b") }
}
task status.fail {
on-init { error("fail") }
}
##
# validate
#
# Update the autoboot.txt file to unconditionally boot the active partition.
##
task validate.a {
require-path-at-offset("/", ${ROOTFS_A_PART_OFFSET})
on-resource autoboot-a.txt {
info("Validate A")
fat_write(${AUTOBOOT_PART_OFFSET}, "autoboot.txt")
uboot_setenv(uboot-env, "a.nerves_fw_validated", "1")
uboot_unsetenv(uboot-env, "nerves_fw_active") # Ensure not used to avoid confusion
}
}
task validate.b {
require-path-at-offset("/", ${ROOTFS_B_PART_OFFSET})
on-resource autoboot-b.txt {
info("Validate B")
fat_write(${AUTOBOOT_PART_OFFSET}, "autoboot.txt")
uboot_setenv(uboot-env, "b.nerves_fw_validated", "1")
uboot_unsetenv(uboot-env, "nerves_fw_active") # Ensure not used to avoid confusion
}
}
task validate.fail {
on-init { error("Failed") }
}