ar71xx: remove hard-coded folder name from Mikrotik RB upgrade
[openwrt/openwrt.git] / target / linux / ar71xx / base-files / lib / upgrade / openmesh.sh
index fb8ef191f77f7fa49f3842d49d193939fd304794..f43bdcea7fc18e3798cbf720e70df6dd2c9248c2 100644 (file)
@@ -26,15 +26,65 @@ cfg_value_get()
                done
 }
 
-# make sure we got uboot-envtools and fw_env.config copied over to the ramfs
-# create /var/lock for the lock "fw_setenv.lock" of fw_setenv
-platform_add_ramfs_ubootenv()
+platform_check_image_target_openmesh()
 {
-       [ -e /usr/sbin/fw_printenv ] && install_bin /usr/sbin/fw_printenv /usr/sbin/fw_setenv
-       [ -e /etc/fw_env.config ] && install_file /etc/fw_env.config
-       mkdir -p $RAM_ROOT/var/lock
+       img_board_target="$1"
+
+       case "$img_board_target" in
+               A60)
+                       [ "$board" = "a40" ] && return 0
+                       [ "$board" = "a60" ] && return 0
+                       echo "Invalid image board target ($img_board_target) for this platform: $board. Use the correct image for this platform"
+                       return 1
+                       ;;
+               OM2P)
+                       [ "$board" = "om2p" ] && return 0
+                       [ "$board" = "om2pv2" ] && return 0
+                       [ "$board" = "om2pv4" ] && return 0
+                       [ "$board" = "om2p-lc" ] && return 0
+                       [ "$board" = "om2p-hs" ] && return 0
+                       [ "$board" = "om2p-hsv2" ] && return 0
+                       [ "$board" = "om2p-hsv3" ] && return 0
+                       [ "$board" = "om2p-hsv4" ] && return 0
+                       echo "Invalid image board target ($img_board_target) for this platform: $board. Use the correct image for this platform"
+                       return 1
+                       ;;
+               OM5P)
+                       [ "$board" = "om5p" ] && return 0
+                       [ "$board" = "om5p-an" ] && return 0
+                       echo "Invalid image board target ($img_board_target) for this platform: $board. Use the correct image for this platform"
+                       return 1
+                       ;;
+               OM5PAC)
+                       [ "$board" = "om5p-ac" ] && return 0
+                       [ "$board" = "om5p-acv2" ] && return 0
+                       echo "Invalid image board target ($img_board_target) for this platform: $board. Use the correct image for this platform"
+                       return 1
+                       ;;
+               MR1750)
+                       [ "$board" = "mr1750" ] && return 0
+                       [ "$board" = "mr1750v2" ] && return 0
+                       echo "Invalid image board target ($img_board_target) for this platform: $board. Use the correct image for this platform"
+                       return 1
+                       ;;
+               MR600)
+                       [ "$board" = "mr600" ] && return 0
+                       [ "$board" = "mr600v2" ] && return 0
+                       echo "Invalid image board target ($img_board_target) for this platform: $board. Use the correct image for this platform"
+                       return 1
+                       ;;
+               MR900)
+                       [ "$board" = "mr900" ] && return 0
+                       [ "$board" = "mr900v2" ] && return 0
+                       echo "Invalid image board target ($img_board_target) for this platform: $board. Use the correct image for this platform"
+                       return 1
+                       ;;
+               *)
+                       echo "Invalid board target ($img_board_target). Use the correct image for this platform"
+                       return 1
+                       ;;
+       esac
 }
-append sysupgrade_pre_upgrade platform_add_ramfs_ubootenv
 
 platform_check_image_openmesh()
 {
@@ -56,27 +106,9 @@ platform_check_image_openmesh()
                        ;;
        esac
 
-       case "$img_board_target" in
-               OM2P)
-                       [ "$board" = "om2p" ] && break
-                       [ "$board" = "om2p-lc" ] && break
-                       [ "$board" = "om2p-hs" ] && break
-                       echo "Invalid image board target ($img_board_target) for this platform: $board. Use the correct image for this platform"
-                       return 1
-                       ;;
-               MR600)
-                       [ "$board" = "mr600" ] && break
-                       [ "$board" = "mr600v2" ] && break
-                       echo "Invalid image board target ($img_board_target) for this platform: $board. Use the correct image for this platform"
-                       return 1
-                       ;;
-               *)
-                       echo "Invalid board target ($img_board_target). Use the correct image for this platform"
-                       return 1
-                       ;;
-       esac
+       platform_check_image_target_openmesh "$img_board_target" || return 1
 
-       [ $img_num_files -ne 3 ] && {
+       [ $img_num_files -lt 3 ] && {
                echo "Invalid number of embedded images ($img_num_files). Use the correct image for this platform"
                return 1
        }
@@ -127,7 +159,7 @@ platform_do_upgrade_openmesh()
        local cfg_size= kernel_size= rootfs_size=
        local append=""
 
-       [ -f "$CONF_TAR" -a "$SAVE_CONFIG" -eq 1 ] && append="-j $CONF_TAR"
+       [ -f "$UPGRADE_BACKUP" ] && append="-j $UPGRADE_BACKUP"
 
        cfg_size=$(dd if="$img_path" bs=2 skip=35 count=4 2>/dev/null)
        kernel_size=$(dd if="$img_path" bs=2 skip=71 count=4 2>/dev/null)
@@ -143,7 +175,7 @@ platform_do_upgrade_openmesh()
                        kernel_start_addr1=0x9f1c0000
                        kernel_start_addr2=0x9f8c0000
                        ;;
-               MR600)
+               OM5P|OM5PAC|MR600|MR900|MR1750|A60)
                        block_size=$((64 * 1024))
                        total_size=7995392
                        kernel_start_addr1=0x9f0b0000
@@ -192,6 +224,7 @@ platform_do_upgrade_openmesh()
        printf "rootfs_size %s\n" $rootfs_checksize >> $uboot_env_upgrade
        printf "rootfs_checksum %s\n" $rootfs_md5 >> $uboot_env_upgrade
 
+       mkdir -p /var/lock
        fw_setenv -s $uboot_env_upgrade || {
                echo "failed to update U-Boot environment"
                return 1