@@ -111,6 +111,9 @@ file-resource cmdline.txt {
111111file-resource zImage {
112112 host-path = "${NERVES_SYSTEM}/images/zImage"
113113}
114+ file-resource nerves_initramfs {
115+ host-path = "${NERVES_SYSTEM}/images/nerves_initramfs_arm.xz;${NERVES_SYSTEM}/images/nerves_initramfs.conf.cpio;${NERVES_SYSTEM}/images/revert.fw.cpio"
116+ }
114117file-resource bcm2708-rpi-zero-w.dtb {
115118 host-path = "${NERVES_SYSTEM}/images/bcm2708-rpi-zero-w.dtb"
116119}
@@ -204,6 +207,8 @@ task complete {
204207 include("${NERVES_PROVISIONING}")
205208
206209 uboot_setenv(uboot-env, "nerves_fw_active", "a")
210+ uboot_setenv(uboot-env, "nerves_fw_validated", "1")
211+ uboot_setenv(uboot-env, "nerves_fw_booted", "0")
207212 uboot_setenv(uboot-env, "nerves_fw_devpath", ${NERVES_FW_DEVPATH})
208213 uboot_setenv(uboot-env, "a.nerves_fw_application_part0_devpath", ${NERVES_FW_APPLICATION_PART0_DEVPATH})
209214 uboot_setenv(uboot-env, "a.nerves_fw_application_part0_fstype", ${NERVES_FW_APPLICATION_PART0_FSTYPE})
@@ -225,6 +230,7 @@ task complete {
225230 on-resource start.elf { fat_write(${BOOT_A_PART_OFFSET}, "start.elf") }
226231 on-resource fixup.dat { fat_write(${BOOT_A_PART_OFFSET}, "fixup.dat") }
227232 on-resource zImage { fat_write(${BOOT_A_PART_OFFSET}, "zImage") }
233+ on-resource nerves_initramfs { fat_write(${BOOT_A_PART_OFFSET}, "nerves_initramfs") }
228234 on-resource bcm2708-rpi-zero-w.dtb { fat_write(${BOOT_A_PART_OFFSET}, "bcm2708-rpi-zero-w.dtb") }
229235 on-resource bcm2708-rpi-zero.dtb { fat_write(${BOOT_A_PART_OFFSET}, "bcm2708-rpi-zero.dtb") }
230236 on-resource w1-gpio-pullup.dtbo { fat_write(${BOOT_A_PART_OFFSET}, "overlays/w1-gpio-pullup.dtbo") }
@@ -256,6 +262,10 @@ task upgrade.a {
256262 # This task upgrades the A partition
257263 require-partition-offset(1, ${ROOTFS_B_PART_OFFSET})
258264
265+ # Require that the running version of firmware has been validated.
266+ # If it has not, then failing back is not guaranteed to work.
267+ require-uboot-variable(uboot-env, "nerves_fw_validated", "1")
268+
259269 # Verify the expected platform/architecture
260270 require-uboot-variable(uboot-env, "b.nerves_fw_platform", "${NERVES_FW_PLATFORM}")
261271 require-uboot-variable(uboot-env, "b.nerves_fw_architecture", "${NERVES_FW_ARCHITECTURE}")
@@ -289,6 +299,7 @@ task upgrade.a {
289299 on-resource start.elf { fat_write(${BOOT_A_PART_OFFSET}, "start.elf") }
290300 on-resource fixup.dat { fat_write(${BOOT_A_PART_OFFSET}, "fixup.dat") }
291301 on-resource zImage { fat_write(${BOOT_A_PART_OFFSET}, "zImage") }
302+ on-resource nerves_initramfs { fat_write(${BOOT_A_PART_OFFSET}, "nerves_initramfs") }
292303 on-resource bcm2708-rpi-zero-w.dtb { fat_write(${BOOT_A_PART_OFFSET}, "bcm2708-rpi-zero-w.dtb") }
293304 on-resource bcm2708-rpi-zero.dtb { fat_write(${BOOT_A_PART_OFFSET}, "bcm2708-rpi-zero.dtb") }
294305 on-resource w1-gpio-pullup.dtbo { fat_write(${BOOT_A_PART_OFFSET}, "overlays/w1-gpio-pullup.dtbo") }
@@ -314,6 +325,8 @@ task upgrade.a {
314325
315326 # Switch over to boot the new firmware
316327 uboot_setenv(uboot-env, "nerves_fw_active", "a")
328+ uboot_setenv(uboot-env, "nerves_fw_validated", "0")
329+ uboot_setenv(uboot-env, "nerves_fw_booted", "0")
317330 mbr_write(mbr-a)
318331 }
319332
@@ -324,6 +337,7 @@ task upgrade.a {
324337task upgrade.b {
325338 # This task upgrades the B partition
326339 require-partition-offset(1, ${ROOTFS_A_PART_OFFSET})
340+ require-uboot-variable(uboot-env, "nerves_fw_validated", "1")
327341
328342 # Verify the expected platform/architecture
329343 require-uboot-variable(uboot-env, "a.nerves_fw_platform", "${NERVES_FW_PLATFORM}")
@@ -356,6 +370,7 @@ task upgrade.b {
356370 on-resource start.elf { fat_write(${BOOT_B_PART_OFFSET}, "start.elf") }
357371 on-resource fixup.dat { fat_write(${BOOT_B_PART_OFFSET}, "fixup.dat") }
358372 on-resource zImage { fat_write(${BOOT_B_PART_OFFSET}, "zImage") }
373+ on-resource nerves_initramfs { fat_write(${BOOT_B_PART_OFFSET}, "nerves_initramfs") }
359374 on-resource bcm2708-rpi-zero-w.dtb { fat_write(${BOOT_B_PART_OFFSET}, "bcm2708-rpi-zero-w.dtb") }
360375 on-resource bcm2708-rpi-zero.dtb { fat_write(${BOOT_B_PART_OFFSET}, "bcm2708-rpi-zero.dtb") }
361376 on-resource w1-gpio-pullup.dtbo { fat_write(${BOOT_B_PART_OFFSET}, "overlays/w1-gpio-pullup.dtbo") }
@@ -381,13 +396,23 @@ task upgrade.b {
381396
382397 # Switch over to boot the new firmware
383398 uboot_setenv(uboot-env, "nerves_fw_active", "b")
399+ uboot_setenv(uboot-env, "nerves_fw_validated", "0")
400+ uboot_setenv(uboot-env, "nerves_fw_booted", "0")
384401 mbr_write(mbr-b)
385402 }
386403
387404 on-error {
388405 }
389406}
390407
408+ task upgrade.unvalidated {
409+ require-uboot-variable(uboot-env, "nerves_fw_validated", "0")
410+
411+ on-init {
412+ error("Please validate the running firmware before upgrading it again.")
413+ }
414+ }
415+
391416task upgrade.unexpected {
392417 require-uboot-variable(uboot-env, "a.nerves_fw_platform", "${NERVES_FW_PLATFORM}")
393418 require-uboot-variable(uboot-env, "a.nerves_fw_architecture", "${NERVES_FW_ARCHITECTURE}")
0 commit comments