Created
January 14, 2020 21:55
-
-
Save ConnorRigby/644c2e31aea0edc1da368e603f2dbf9f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require-fwup-version="0.15.0" # For the trim() call | |
# | |
# Firmware metadata | |
# | |
# All of these can be overriden using environment variables of the same name. | |
# | |
# Run 'fwup -m' to query values in a .fw file. | |
# Use 'fw_printenv' to query values on the target. | |
# | |
# These are used by Nerves libraries to introspect. | |
define(NERVES_FW_PRODUCT, "Nerves Firmware") | |
define(NERVES_FW_DESCRIPTION, "") | |
define(NERVES_FW_VERSION, "${NERVES_SDK_VERSION}") | |
define(NERVES_FW_PLATFORM, "lichee_nano") | |
define(NERVES_FW_ARCHITECTURE, "arm") | |
define(NERVES_FW_AUTHOR, "Connor Rigby") | |
define(NERVES_FW_DEVPATH, "/dev/mmcblk0") | |
define(NERVES_FW_APPLICATION_PART0_DEVPATH, "/dev/mmcblk0p3") # Linux part number is 1-based | |
define(NERVES_FW_APPLICATION_PART0_FSTYPE, "ext4") | |
define(NERVES_FW_APPLICATION_PART0_TARGET, "/root") | |
define(NERVES_PROVISIONING, "${NERVES_SYSTEM}/images/fwup_include/provisioning.conf") | |
# Default paths if not specified via the commandline | |
define(ROOTFS, "${NERVES_SYSTEM}/images/rootfs.squashfs") | |
define(UBOOT_OFFSET, 8) | |
define(UBOOT_ENV_OFFSET, 2030) | |
define(UBOOT_ENV_COUNT, 16) # 8 KB | |
define(BOOT_A_PART_OFFSET, 2048) | |
define(BOOT_A_PART_COUNT, 32768) | |
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}) | |
# Application partition. This partition can occupy all of the remaining space. | |
# Size it to fit the destination. | |
define-eval(APP_PART_OFFSET, "${ROOTFS_B_PART_OFFSET} + ${ROOTFS_B_PART_COUNT}") | |
define(APP_PART_COUNT, 1048576) | |
# Firmware archive metadata | |
meta-product = ${NERVES_FW_PRODUCT} | |
meta-description = ${NERVES_FW_DESCRIPTION} | |
meta-version = ${NERVES_FW_VERSION} | |
meta-platform = ${NERVES_FW_PLATFORM} | |
meta-architecture = ${NERVES_FW_ARCHITECTURE} | |
meta-author = ${NERVES_FW_AUTHOR} | |
meta-vcs-identifier = ${NERVES_FW_VCS_IDENTIFIER} | |
meta-misc = ${NERVES_FW_MISC} | |
# File resources are listed in the order that they are included in the .fw file | |
# This is important, since this is the order that they're written on a firmware | |
# update due to the event driven nature of the update system. | |
file-resource boot.scr { | |
host-path = "${NERVES_SYSTEM}/images/boot.scr" | |
} | |
file-resource zImage { | |
host-path = "${NERVES_SYSTEM}/images/zImage" | |
} | |
file-resource suniv-f1c100s-licheepi-nano.dtb { | |
host-path = "${NERVES_SYSTEM}/images/suniv-f1c100s-licheepi-nano.dtb" | |
} | |
file-resource u-boot-sunxi-with-spl.bin { | |
host-path = "${NERVES_SYSTEM}/images/u-boot-sunxi-with-spl.bin" | |
} | |
file-resource rootfs.img { | |
host-path = ${ROOTFS} | |
# Error out if the rootfs size exceeds the partition size | |
assert-size-lte = ${ROOTFS_A_PART_COUNT} | |
} | |
mbr mbr-a { | |
signature = 0x5f57945f | |
partition 0 { | |
block-offset = ${BOOT_A_PART_OFFSET} | |
block-count = ${BOOT_A_PART_COUNT} | |
type = 0xc # FAT32 | |
boot = false | |
} | |
partition 1 { | |
block-offset = ${ROOTFS_A_PART_OFFSET} | |
block-count = ${ROOTFS_A_PART_COUNT} | |
type = 0x83 # Linux | |
} | |
partition 2 { | |
block-offset = ${APP_PART_OFFSET} | |
block-count = ${APP_PART_COUNT} | |
type = 0x83 # Linux | |
} | |
# partition 3 is unused | |
} | |
mbr mbr-b { | |
partition 0 { | |
block-offset = ${BOOT_B_PART_OFFSET} | |
block-count = ${BOOT_B_PART_COUNT} | |
type = 0xc # FAT32 | |
boot = false | |
} | |
partition 1 { | |
block-offset = ${ROOTFS_B_PART_OFFSET} | |
block-count = ${ROOTFS_B_PART_COUNT} | |
type = 0x83 # Linux | |
} | |
partition 2 { | |
block-offset = ${APP_PART_OFFSET} | |
block-count = ${APP_PART_COUNT} | |
type = 0x83 # Linux | |
} | |
# partition 3 is unused | |
} | |
# Location where installed firmware information is stored. | |
# While this is called "u-boot", u-boot isn't involved in this | |
# setup. It just provides a convenient key/value store format. | |
uboot-environment uboot-env { | |
block-offset = ${UBOOT_ENV_OFFSET} | |
block-count = ${UBOOT_ENV_COUNT} | |
} | |
# This firmware task writes everything to the destination media | |
task complete { | |
# Only match if not mounted | |
require-unmounted-destination = true | |
on-init { | |
mbr_write(mbr-a) | |
fat_mkfs(${BOOT_A_PART_OFFSET}, ${BOOT_A_PART_COUNT}) | |
fat_setlabel(${BOOT_A_PART_OFFSET}, "BOOT-A") | |
fat_mkdir(${BOOT_A_PART_OFFSET}, "overlays") | |
uboot_clearenv(uboot-env) | |
include("${NERVES_PROVISIONING}") | |
uboot_setenv(uboot-env, "nerves_fw_active", "a") | |
uboot_setenv(uboot-env, "nerves_fw_devpath", ${NERVES_FW_DEVPATH}) | |
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}) | |
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_vcs_identifier", ${NERVES_FW_VCS_IDENTIFIER}) | |
uboot_setenv(uboot-env, "a.nerves_fw_misc", ${NERVES_FW_MISC}) | |
uboot_setenv(uboot-env, "a.nerves_fw_uuid", "\${FWUP_META_UUID}") | |
} | |
on-resource u-boot-sunxi-with-spl.bin { raw_write(${UBOOT_OFFSET}) } | |
on-resource boot.scr { fat_write(${BOOT_A_PART_OFFSET}, "boot.scr") } | |
on-resource zImage { fat_write(${BOOT_A_PART_OFFSET}, "zImage") } | |
on-resource suniv-f1c100s-licheepi-nano.dtb { fat_write(${BOOT_A_PART_OFFSET}, "suniv-f1c100s-licheepi-nano.dtb") } | |
on-resource rootfs.img { raw_write(${ROOTFS_A_PART_OFFSET}) } | |
on-finish { | |
# Clear out any old data in the B partition that might be mistaken for | |
# a file system. This is mostly to avoid confusion in humans when | |
# reprogramming SDCards with unknown contents. | |
raw_memset(${BOOT_B_PART_OFFSET}, 256, 0xff) | |
raw_memset(${ROOTFS_B_PART_OFFSET}, 256, 0xff) | |
# Invalidate the application data partition so that it is guaranteed to | |
# trigger the corrupt filesystem detection code on first boot and get | |
# formatted. If this isn't done and an old SDCard is reused, the | |
# application data could be in a weird state. | |
raw_memset(${APP_PART_OFFSET}, 256, 0xff) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment