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 e6afb9547c9b9db0be66433f21a12a6fb20fa50e..6417eb1a3a76d982c3b80a109f7a541aaffb9ace 100755 (executable)
@@ -1,28 +1,51 @@
 REQUIRE_IMAGE_METADATA=1
-RAMFS_COPY_BIN='fw_printenv fw_setenv fwtool'
-RAMFS_COPY_DATA='/etc/fw_env.config /var/lock/fw_printenv.lock'
+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)
-               export_bootdevice
-               export_partdevice rootdev 0
-               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-2533dhp2|\
+       buffalo,wsr-3200ax4s)
                local magic="$(get_magic_long "$1")"
 
                # use "mtd write" if the magic is "DHP2 (0x44485032)"
@@ -34,8 +57,16 @@ platform_do_upgrade() {
                        nand_do_upgrade "$1"
                fi
                ;;
-       linksys,e8450-ubi|\
-       mediatek,mt7622,ubi)
+       dlink,eagle-pro-ai-m32-a1|\
+       dlink,eagle-pro-ai-r32-a1|\
+       elecom,wrc-x3200gst3|\
+       mediatek,mt7622-rfb1-ubi|\
+       netgear,wax206|\
+       totolink,a8000ru|\
+       xiaomi,redmi-router-ax6s)
+               nand_do_upgrade "$1"
+               ;;
+       linksys,e8450-ubi)
                CI_KERNPART="fit"
                nand_do_upgrade "$1"
                ;;
@@ -47,9 +78,6 @@ platform_do_upgrade() {
                fi
                default_do_upgrade "$1"
                ;;
-       totolink,a8000ru)
-               nand_do_upgrade "$1"
-               ;;
        *)
                default_do_upgrade "$1"
                ;;
@@ -65,11 +93,19 @@ platform_check_image() {
        [ "$#" -gt 1 ] && return 1
 
        case "$board" in
-       buffalo,wsr-2533dhp2)
+       buffalo,wsr-2533dhp2|\
+       buffalo,wsr-3200ax4s)
                buffalo_check_image "$board" "$magic" "$1" || return 1
                ;;
-       totolink,a8000ru)
+       dlink,eagle-pro-ai-m32-a1|\
+       dlink,eagle-pro-ai-r32-a1|\
+       elecom,wrc-x3200gst3|\
+       mediatek,mt7622-rfb1-ubi|\
+       netgear,wax206|\
+       totolink,a8000ru|\
+       xiaomi,redmi-router-ax6s)
                nand_do_platform_check "$board" "$1"
+               return $?
                ;;
        *)
                [ "$magic" != "d00dfeed" ] && {
@@ -86,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
                ;;