diff --git a/iopsys-brcm63xx-arm/base-files/lib/upgrade/platform.sh b/iopsys-brcm63xx-arm/base-files/lib/upgrade/platform.sh index d9da34f335e8b657ffb83dba00f3927993f24a85..17bf6a02a07db22a063ccc953c608c8640164977 100644 --- a/iopsys-brcm63xx-arm/base-files/lib/upgrade/platform.sh +++ b/iopsys-brcm63xx-arm/base-files/lib/upgrade/platform.sh @@ -44,13 +44,42 @@ platform_set_bootbank() { esac; status=$? set +o pipefail - - [ $status -eq 0 ] && return 0 || return 1 + # We store the value that we SET here, because bcm_bootstate does not return + # the correct value when the system has been powered off and on. + # It only works when there has been a reset_reason like normal reboot for example. + # The bcm_bootstate utility uses /proc/bootstate (bcm_bootstate module). + # The way that this works is that each bank has a commit-flag, in the metadata-volume. + # This determines which bank is the one to boot. + # To facilitate booting another bank once, a flag will be set using + # the bcm_bootstate-driver in HW. + # Retrieving this flag does not work if the reset_reason was PWR_ON. + # Writing to reset_reason works, but in case of power off/on, the driver + # always returns the hardcoded value of 0xffffffff. + # This seems to be by design, but right now it is not clear, + # whether there is some limitation behind it or whether it is a design miss. + # + # Note that this workaround here does not catch someone (a developer) setting + # the bank manually using the bcm_bootstate command outside of this function, + # if set_bootbank has at least been called once. + if [ $status -eq 0 ]; then + echo -n "$1" > /var/run/bcm_bootbank || return 1 + return 0 + else + return 1 + fi } #-------------------------------------------------------------- # Return what "bank" the bootloader will select next time. platform_get_bootbank() { + # See comment in platform_set_bootbank for the reason for + # this file existing + stored_bcm_bootbank="$(cat /var/run/bcm_bootbank 2>/dev/null)" + if [ -n "$stored_bcm_bootbank" ]; then + echo -n "$stored_bcm_bootbank" + return 0 + fi + # Call bcm_bootstate only once. bootstate_output=$(bcm_bootstate | grep "Reboot Partition") if echo "$bootstate_output" | grep -q First; then