mirror of
https://github.com/openwrt/openwrt.git
synced 2024-12-21 22:47:56 +00:00
ec2dc60d57
Move shell functions used for sysupgrade into /lib/upgrade/fit.sh. Introduce improved fitblk boot device detection function which works also in case ubiblock devices have not yet been created or even UBI itself not yet being attached. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
64 lines
1.5 KiB
Bash
64 lines
1.5 KiB
Bash
export_fitblk_bootdev() {
|
|
[ -e /sys/firmware/devicetree/base/chosen/rootdisk ] || return
|
|
|
|
local rootdisk="$(cat /sys/firmware/devicetree/base/chosen/rootdisk)"
|
|
local handle bootdev
|
|
|
|
for handle in /sys/class/mtd/mtd*/of_node/volumes/*/phandle; do
|
|
[ ! -e "$handle" ] && continue
|
|
if [ "$rootdisk" = "$(cat "$handle")" ]; then
|
|
if [ -e "${handle%/phandle}/volname" ]; then
|
|
export CI_KERNPART="$(cat "${handle%/phandle}/volname")"
|
|
elif [ -e "${handle%/phandle}/volid" ]; then
|
|
export CI_KERNVOLID="$(cat "${handle%/phandle}/volid")"
|
|
else
|
|
return
|
|
fi
|
|
export CI_UBIPART="$(cat "${handle%%/of_node*}/name")"
|
|
export CI_METHOD="ubi"
|
|
return
|
|
fi
|
|
done
|
|
|
|
for handle in /sys/class/mtd/mtd*/of_node/phandle; do
|
|
[ ! -e "$handle" ] && continue
|
|
if [ "$rootdisk" = "$(cat $handle)" ]; then
|
|
bootdev="${handle%/of_node/phandle}"
|
|
bootdev="${bootdev#/sys/class/mtd/}"
|
|
export PART_NAME="/dev/$bootdev"
|
|
export CI_METHOD="default"
|
|
return
|
|
fi
|
|
done
|
|
|
|
for handle in /sys/class/block/*/of_node/phandle; do
|
|
[ ! -e "$handle" ] && continue
|
|
if [ "$rootdisk" = "$(cat $handle)" ]; then
|
|
bootdev="${handle%/of_node/phandle}"
|
|
bootdev="${bootdev#/sys/class/block/}"
|
|
export EMMC_KERN_DEV="/dev/$bootdev"
|
|
export CI_METHOD="emmc"
|
|
return
|
|
fi
|
|
done
|
|
}
|
|
|
|
fit_do_upgrade() {
|
|
export_fitblk_bootdev
|
|
[ -n "$CI_METHOD" ] || return 1
|
|
[ -e /dev/fit0 ] && fitblk /dev/fit0
|
|
[ -e /dev/fitrw ] && fitblk /dev/fitrw
|
|
|
|
case "$CI_METHOD" in
|
|
emmc)
|
|
emmc_do_upgrade "$1"
|
|
;;
|
|
default)
|
|
default_do_upgrade "$1"
|
|
;;
|
|
ubi)
|
|
nand_do_upgrade "$1"
|
|
;;
|
|
esac
|
|
}
|