Skip to content
Permalink
Browse files

u-boot: Add support to boot previous rootfs if rolling back

This patch adds a simple check in env_resin.h.

If bootcount is found to be greater than bootlimit, switch the
partitions. Both bootcount and bootlimit are standard u-boot env
variables.

To enable rollback in devices, devices have to do the following in
their u-boot

Enable CONFIG_CMD_SETEXPR, CONFIG_BOOTCOUNT_LIMIT and depending on the
device, save the bootcount in some persistant location whether that
is an area in the SoC or an ext partition etc.

If you are using the CONFIG_BOOTCOUNT_EXT driver, use only the boot
partition and use the filename "bootcount.env"

E.g. for rpi3
CONFIG_CMD_SETEXPR=y
CONFIG_BOOTCOUNT_LIMIT=y
CONFIG_SYS_BOOTCOUNT_ADDR=0x02300000
CONFIG_BOOTCOUNT_EXT=y
CONFIG_SYS_BOOTCOUNT_EXT_DEVPART=0:1
CONFIG_SYS_BOOTCOUNT_EXT_NAME="bootcount.env"

Change-type: minor
Changelog-entry: Add Automated Rollback support in u-boot env_resin.h
Signed-off-by: Zubair Lutfullah Kakakhel <zubair@resin.io>
  • Loading branch information...
ZubairLK committed Sep 5, 2018
1 parent b93b655 commit c6145d1f535098ef46f44d44d061b04fd7174f77
Showing with 15 additions and 0 deletions.
  1. +15 −0 meta-resin-common/recipes-bsp/u-boot/patches/env_resin.h
@@ -81,9 +81,24 @@
"run resin_import_env_file;" \
"fi;\0" \
\
"resin_check_altroot=" \
"setexpr resin_roota ${resin_boot_part} + 1; " \
"setexpr resin_rootb ${resin_boot_part} + 2; " \
"if test -n ${bootlimit}; then " \
"if test ${bootcount} -gt ${bootlimit}; then " \
"echo WARNING! BOOTLIMIT EXCEEDED. SWITCHING TO PREVIOUS ROOTFS; " \
"if test ${resin_root_part} -eq ${resin_roota}; then "\
"env set resin_root_part ${resin_rootb}; " \
"else; "\
"env set resin_root_part ${resin_roota}; " \
"fi;" \
"fi;" \
"fi;\0" \
\
"resin_set_kernel_root=" \
"run resin_set_dev_index;" \
"run resin_inject_env_file;" \
"run resin_check_altroot;" \
"run resin_find_root_part_uuid;" \
"setenv resin_kernel_root root=PARTUUID=${resin_root_part_uuid}\0"

0 comments on commit c6145d1

Please sign in to comment.
You can’t perform that action at this time.