iopsys-feed/uboot/files/uboot-upgrade
Oussama Ghorbel 1a4f39918d uboot: provides lib for uboot upgrade
This will allows to update uboot from other script
disable the init.d/uboot script on intel as it's no longer needed
2019-03-19 14:50:53 +01:00

87 lines
2.2 KiB
Text
Executable file

. /usr/share/libubox/jshn.sh
sanity_check_env(){
# make sure iboot is used to start board, but only if verify_boot != 1
# that allows a person to change the bootcmd and not have it overwritten automatically
# but still force it to iboot for old boards.
vb=$(fw_printenv -n verify_boot 2>/dev/null)
if [ "1" != "$verify_boot" ]
then
if ! fw_printenv -n bootcmd 2>/dev/null| grep iboot >/dev/null
then
echo "update uboot boot command"
fw_setenv bootcmd "rescue;iboot"
fw_setenv verify_boot 1
fi
fi
# just set 115200 baudrate as it is really hardcoded in the binary blob
fw_setenv baudrate 115200
}
do_uboot_upgrade(){
local u_ver
echo "doing upgrade of u-boot old version $cur_Major.$cur_Minor new version $Major.$Minor"
mtd erase /dev/mtd0
mtd write $1 /dev/mtd0
u_ver=$(strings /dev/mtd0 | grep 938f0820-2ffb-11e7-bbc9-2f21351ee6fb)
[ -n "$u_ver" ] && fw_setenv uboot_inteno_version "$u_ver"
sanity_check_env
}
# Return:
# 0: update is successfull
# 1: update is not needed
# 2: error occured
uboot_upgrade() {
[ ! -f $1 ] && return 2
iver=$(fw_printenv -n uboot_inteno_version 2>/dev/null)
# Fixup improper json string for major and minor key.
# this adds the missing "
iver=$(echo $iver | sed -e 's/{Major:/{"Major":/' | sed -e 's/,Minor:/,"Minor":/')
if [ -z "$iver" ]
then
# if this variable is not set by u-boot the u-boot version is too old.
do_uboot_upgrade $1
return 0
fi
# read in current version into Major Minor variables
json_init
json_load $(echo $iver |sed -e 's/938f0820-2ffb-11e7-bbc9-2f21351ee6fb: //')
json_get_vars Major Minor
# echo "Major $Major"
# echo "Minor $Minor"
cur_Major=$Major
cur_Minor=$Minor
# read in new uboot version into Major Minor variables
json_load $(strings $1 | grep 938f0820-2ffb-11e7-bbc9-2f21351ee6fb |sed -e 's/938f0820-2ffb-11e7-bbc9-2f21351ee6fb: //')
json_get_vars Major Minor
# echo "Major $Major"
# echo "Minor $Minor"
if [ $Major -gt $cur_Major ]
then
do_uboot_upgrade $1
return 0
fi
if [ $Major -eq $cur_Major -a $Minor -gt $cur_Minor ]
then
do_uboot_upgrade $1
return 0
fi
return 1
}