Current section

Files

Jump to
Raw

fwup.conf

# -----------------------------------------------------------------
# SG2002 – A/B + data layout
# -----------------------------------------------------------------
require-fwup-version = "1.0.0"
include("${NERVES_SDK_IMAGES:-.}/fwup_include/fwup-common.conf")
# -----------------------------------------------------------------
# File resources
# -----------------------------------------------------------------
file-resource fip.bin { host-path = "${NERVES_SYSTEM}/images/fip.bin" }
file-resource uboot-env.bin { host-path = "${NERVES_SYSTEM}/images/uboot-env.bin" }
file-resource boot.vfat { host-path = "${NERVES_SYSTEM}/images/boot.vfat" }
file-resource rootfs.img {
host-path = ${ROOTFS}
assert-size-lte = ${ROOTFS_A_PART_COUNT}
}
# -----------------------------------------------------------------
# Partition table
# -----------------------------------------------------------------
mbr mbr-sg2002 {
partition 0 { # Boot (FAT16, 16 MiB)
block-offset = ${BOOT_PART_OFFSET}
block-count = ${BOOT_PART_COUNT}
type = 0x06 # FAT16
boot = true
}
partition 1 { # Rootfs A (squashfs, 256 MiB)
block-offset = ${ROOTFS_A_PART_OFFSET}
block-count = ${ROOTFS_A_PART_COUNT}
type = 0x83 # Linux
}
partition 2 { # Rootfs B (squashfs, 256 MiB)
block-offset = ${ROOTFS_B_PART_OFFSET}
block-count = ${ROOTFS_B_PART_COUNT}
type = 0x83 # Linux
}
partition 3 { # Data (ext4, 512 MiB+, blank, grows to fill space)
block-offset = ${APP_PART_OFFSET}
block-count = ${APP_PART_COUNT}
type = 0x83 # Linux
expand = true
}
}
# -----------------------------------------------------------------
# 1) Factory image (writes everything)
# -----------------------------------------------------------------
task complete {
require-unmounted-destination = true
on-init {
mbr_write(mbr-sg2002)
}
on-resource fip.bin { raw_write(${UBOOT_OFFSET}) }
on-resource uboot-env.bin { raw_write(${UBOOT_ENV_OFFSET}) }
on-resource boot.vfat { raw_write(${BOOT_PART_OFFSET}) }
on-resource rootfs.img { raw_write(${ROOTFS_A_PART_OFFSET})}
on-finish {
include("${NERVES_PROVISIONING}")
# Generic Nerves metadata – mark A active & validated
uboot_setenv(uboot-env, "nerves_fw_active", "a")
uboot_setenv(uboot-env, "nerves_fw_validated", "1")
uboot_setenv(uboot-env, "nerves_fw_booted", "0")
uboot_setenv(uboot-env, "nerves_fw_devpath", ${NERVES_FW_DEVPATH})
# Partition-specific metadata for A
uboot_setenv(uboot-env, "a.nerves_fw_application_part0_devpath",
${NERVES_FW_APPLICATION_PART0_DEVPATH})
uboot_setenv(uboot-env, "a.nerves_fw_application_part0_fstype",
${NERVES_FW_APPLICATION_PART0_FSTYPE})
uboot_setenv(uboot-env, "a.nerves_fw_application_part0_target",
${NERVES_FW_APPLICATION_PART0_TARGET})
# Product metadata
uboot_setenv(uboot-env, "a.nerves_fw_product", ${NERVES_FW_PRODUCT})
uboot_setenv(uboot-env, "a.nerves_fw_description", ${NERVES_FW_DESCRIPTION})
uboot_setenv(uboot-env, "a.nerves_fw_version", ${NERVES_FW_VERSION})
uboot_setenv(uboot-env, "a.nerves_fw_platform", ${NERVES_FW_PLATFORM})
uboot_setenv(uboot-env, "a.nerves_fw_architecture", ${NERVES_FW_ARCHITECTURE})
uboot_setenv(uboot-env, "a.nerves_fw_author", ${NERVES_FW_AUTHOR})
uboot_setenv(uboot-env, "a.nerves_fw_uuid", "${FWUP_META_UUID}")
# Zero-fill B + data to avoid stale data
raw_memset(${ROOTFS_B_PART_OFFSET}, 256, 0xff)
raw_memset(${APP_PART_OFFSET}, 256, 0xff)
}
}
# -----------------------------------------------------------------
# 2) OTA upgrades – write to the *inactive* slot
# -----------------------------------------------------------------
task upgrade.a {
require-uboot-variable(uboot-env, "nerves_fw_active", "b")
require-uboot-variable(uboot-env, "nerves_fw_validated", "1")
on-init {
info("Upgrading partition A")
trim(${ROOTFS_A_PART_OFFSET}, ${ROOTFS_A_PART_COUNT})
}
on-resource rootfs.img {
delta-source-raw-offset = ${ROOTFS_B_PART_OFFSET}
delta-source-raw-count = ${ROOTFS_B_PART_COUNT}
raw_write(${ROOTFS_A_PART_OFFSET})
}
on-finish {
# Copy metadata to A
include("${NERVES_PROVISIONING}")
uboot_setenv(uboot-env, "a.nerves_fw_version", ${NERVES_FW_VERSION})
uboot_setenv(uboot-env, "a.nerves_fw_uuid", "${FWUP_META_UUID}")
uboot_setenv(uboot-env, "nerves_fw_active", "a")
uboot_setenv(uboot-env, "nerves_fw_validated","0")
uboot_setenv(uboot-env, "nerves_fw_booted", "0")
}
}
task upgrade.b {
require-uboot-variable(uboot-env, "nerves_fw_active", "a")
require-uboot-variable(uboot-env, "nerves_fw_validated", "1")
on-init {
info("Upgrading partition B")
trim(${ROOTFS_B_PART_OFFSET}, ${ROOTFS_B_PART_COUNT})
}
on-resource rootfs.img {
delta-source-raw-offset = ${ROOTFS_A_PART_OFFSET}
delta-source-raw-count = ${ROOTFS_A_PART_COUNT}
raw_write(${ROOTFS_B_PART_OFFSET})
}
on-finish {
include("${NERVES_PROVISIONING}")
uboot_setenv(uboot-env, "b.nerves_fw_version", ${NERVES_FW_VERSION})
uboot_setenv(uboot-env, "b.nerves_fw_uuid", "${FWUP_META_UUID}")
uboot_setenv(uboot-env, "nerves_fw_active", "b")
uboot_setenv(uboot-env, "nerves_fw_validated","0")
uboot_setenv(uboot-env, "nerves_fw_booted", "0")
}
}
# Guard tasks
task upgrade.unvalidated {
require-uboot-variable(uboot-env, "nerves_fw_validated","0")
on-init{ error("Validate firmware before upgrading again.")}
}
task upgrade.wrongplatform {
on-init { error("Expecting platform=${NERVES_FW_PLATFORM} arch=${NERVES_FW_ARCHITECTURE}") }
}