mediatek: mt7622: convert BPi-R64 to all-UBI layout and fitblk
[openwrt/staging/dangole.git] / target / linux / mediatek / mt7622 / base-files / lib / upgrade / platform.sh
index 3a2d7a4cd62d0577850501527b572e78e4650003..5836e1aa3ee4685d862e832f03fa101fcd05db57 100755 (executable)
@@ -1,4 +1,20 @@
 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)
@@ -6,21 +22,21 @@ platform_do_upgrade() {
 
        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"
+               [ -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"
                        ;;
-               *)
+               ubiblock*)
                        CI_KERNPART="fit"
                        nand_do_upgrade "$1"
                        ;;
                esac
                ;;
+
        buffalo,wsr-2533dhp2|\
        buffalo,wsr-3200ax4s)
                local magic="$(get_magic_long "$1")"
@@ -99,9 +115,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
                ;;