diff --git a/iopsys-brcm63xx-arm/base-files/lib/upgrade/platform.sh b/iopsys-brcm63xx-arm/base-files/lib/upgrade/platform.sh
index 17bf6a02a07db22a063ccc953c608c8640164977..fcb0c59417c5abf299a970dcc218ade161e9b031 100644
--- a/iopsys-brcm63xx-arm/base-files/lib/upgrade/platform.sh
+++ b/iopsys-brcm63xx-arm/base-files/lib/upgrade/platform.sh
@@ -2,14 +2,63 @@ platform_check_image() {
iopsys_check_image $1
}
+platform_compare_bootloader_version() {
+ # FIT image has newer bootloader than on flash => bootlaoder will be updated
+ # FIT image has same version or older version than on flash => bootloader will not be updated
+ # Bootloader does not have a version => version is 0 will get updated by new FIT image with a bootloader version
+ # FIT image does not have a bootloader in it or is old and does not have bootloader version => fit version is 0 and bootloader will not get updated.
+ # Bootloader does not have version and neither has the FIT-image => will not get updated (0 == 0)
+
+ local iopsys_bootloader_version="0"
+ local fit_iopsys_bootloader_version="0"
+ local image images
+
+ [ -z "$1" ] && return 1
+ [ "$(get_root_device_type())" != "nand" ] && return 1
+
+ json_init
+ json_load "$(strings /dev/mtd1 | awk '/938f0820-2ffb-11e7-bbc9-2f21351ee6fb:/ {$1=""; print $0}' 2> /dev/null | head -n1 | awk '{$1=$1; print}')"
+ json_get_vars iopsys_bootloader_version
+ iopsys_bootloader_version=$((iopsys_bootloader_version))
+
+ images="$(fdtextract -l "$1" 2> /dev/null | awk '{print $2}' | xargs)"
+ for image in $images; do
+ if fdtextract -i "$image" -a iopsys_bootloader_version "$1" > /dev/null 2>&1; then
+ fit_iopsys_bootloader_version="$(fdtextract -i "$image" -a iopsys_bootloader_version "$1" 2> /dev/null)"
+ break
+ fi
+ done
+ fit_iopsys_bootloader_version=$((fit_iopsys_bootloader_version))
+
+ if [ "$fit_iopsys_bootloader_version" -gt "$iopsys_bootloader_version" ]; then
+ return 1
+ else
+ return 0
+ fi
+}
+
platform_do_upgrade() {
local image="$1"
local status=0
+ local skip_bootloader=""
+
+ if ! platform_compare_bootloader_version "$1"; then
+ UPGRADE_OPT_FORCE_LOADER_UPGRADE=1
+ log "sysupgrade" "Bootloader with newer version is available in FIT-image. Enabling bootloader upgrade."
+ fi
+
+ [ -z "$UPGRADE_OPT_FORCE_LOADER_UPGRADE" ] && UPGRADE_OPT_FORCE_LOADER_UPGRADE=1
+ if [ "$UPGRADE_OPT_FORCE_LOADER_UPGRADE" = "0" ]; then
+ skip_bootloader="-s"
+ log "sysupgrade" "Bootloader upgrade is disabled."
+ else
+ log "sysupgrade" "Bootloader upgrade is enabled."
+ fi
iopsys_process_upgrade_bundle "$image" pre_upgrade || status=1
set -o pipefail
- [ $status -eq 0 ] && bcm_flasher "$image" 2>&1 | log "sysupgrade" || status=$?
+ [ $status -eq 0 ] && bcm_flasher $skip_bootloader "$image" 2>&1 | log "sysupgrade" || status=$?
log "sysupgrade" "bcm_flasher returned $status."
set +o pipefail