mediatek: mt7622: convert unifi6lr-v{1,2,3}-ubootmod to fitblk
[openwrt/openwrt.git] / target / linux / mediatek / mt7622 / base-files / lib / upgrade / platform.sh
index ea3176d2d1e79fda8a2e5a72e4a3137756ab3a66..6417eb1a3a76d982c3b80a109f7a541aaffb9ace 100755 (executable)
@@ -1,26 +1,49 @@
 REQUIRE_IMAGE_METADATA=1
+RAMFS_COPY_BIN='fitblk'
+
+platform_get_bootdev() {
+       local rootdisk="$(cat /sys/firmware/devicetree/base/chosen/rootdisk)"
+       local handle bootdev
+       for handle in /sys/class/block/*/of_node/phandle /sys/class/block/*/device/of_node/phandle; do
+               [ ! -e "$handle" ] && continue
+               if [ "$rootdisk" = "$(cat $handle)" ]; then
+                       bootdev="${handle%/of_node/phandle}"
+                       bootdev="${bootdev%/device}"
+                       bootdev="${bootdev#/sys/class/block/}"
+                       echo "$bootdev"
+                       break
+               fi
+       done
+}
 
 platform_do_upgrade() {
        local board=$(board_name)
        local file_type=$(identify $1)
 
        case "$board" in
-       bananapi,bpi-r64)
-               local rootdev="$(cmdline_get_var root)"
-               rootdev="${rootdev##*/}"
-               rootdev="${rootdev%p[0-9]*}"
-               case "$rootdev" in
-               mmc*)
-                       CI_ROOTDEV="$rootdev"
-                       CI_KERNPART="production"
+       bananapi,bpi-r64|\
+       ubnt,unifi-6-lr-v1-ubootmod|\
+       ubnt,unifi-6-lr-v2-ubootmod|\
+       ubnt,unifi-6-lr-v3-ubootmod)
+               [ -e /dev/fit0 ] && fitblk /dev/fit0
+               [ -e /dev/fitrw ] && fitblk /dev/fitrw
+               bootdev="$(platform_get_bootdev)"
+               case "$bootdev" in
+               mmcblk*)
+                       EMMC_KERN_DEV="/dev/$bootdev"
                        emmc_do_upgrade "$1"
                        ;;
-               *)
+               mtdblock*)
+                       PART_NAME="/dev/mtd${bootdev:8}"
+                       default_do_upgrade "$1"
+                       ;;
+               ubiblock*)
                        CI_KERNPART="fit"
                        nand_do_upgrade "$1"
                        ;;
                esac
                ;;
+
        buffalo,wsr-2533dhp2|\
        buffalo,wsr-3200ax4s)
                local magic="$(get_magic_long "$1")"
@@ -34,6 +57,8 @@ platform_do_upgrade() {
                        nand_do_upgrade "$1"
                fi
                ;;
+       dlink,eagle-pro-ai-m32-a1|\
+       dlink,eagle-pro-ai-r32-a1|\
        elecom,wrc-x3200gst3|\
        mediatek,mt7622-rfb1-ubi|\
        netgear,wax206|\
@@ -72,6 +97,8 @@ platform_check_image() {
        buffalo,wsr-3200ax4s)
                buffalo_check_image "$board" "$magic" "$1" || return 1
                ;;
+       dlink,eagle-pro-ai-m32-a1|\
+       dlink,eagle-pro-ai-r32-a1|\
        elecom,wrc-x3200gst3|\
        mediatek,mt7622-rfb1-ubi|\
        netgear,wax206|\
@@ -95,9 +122,7 @@ platform_check_image() {
 platform_copy_config() {
        case "$(board_name)" in
        bananapi,bpi-r64)
-               export_bootdevice
-               export_partdevice rootdev 0
-               if echo $rootdev | grep -q mmc; then
+               if platform_get_bootdev | grep -q mmc; then
                        emmc_copy_config
                fi
                ;;