hotplug-preinit: remove superfluous `and`
[openwrt.git] / package / system / procd / files / nand.sh
index 0d30810..8b0564d 100644 (file)
@@ -250,10 +250,10 @@ nand_upgrade_tar() {
        local has_kernel=1
        local has_env=0
 
-       [ "kernel_length" = 0 -o -z "$kernel_mtd" ] || {
+       [ "$kernel_length" != 0 -a -n "$kernel_mtd" ] && {
                tar xf $tar_file sysupgrade-$board_name/kernel -O | mtd write - $CI_KERNPART
        }
-       [ "kernel_length" = 0 -o ! -z "$kernel_mtd" ] && has_kernel=0
+       [ "$kernel_length" = 0 -o ! -z "$kernel_mtd" ] && has_kernel=0
 
        nand_upgrade_prepare_ubi "$rootfs_length" "$rootfs_type" "$has_kernel" "$has_env"
 
@@ -275,11 +275,17 @@ nand_upgrade_tar() {
 nand_do_upgrade_stage2() {
        local file_type=$(identify $1)
 
+       if type 'platform_nand_pre_upgrade' >/dev/null 2>/dev/null; then
+               platform_nand_pre_upgrade "$1"
+       fi
+
        [ ! "$(find_mtd_index "$CI_UBIPART")" ] && CI_UBIPART="rootfs"
 
-       [ "$file_type" = "ubi" ] && nand_upgrade_ubinized $1
-       [ "$file_type" = "ubifs" ] && nand_upgrade_ubifs $1
-       nand_upgrade_tar $1
+       case "$file_type" in
+               "ubi")          nand_upgrade_ubinized $1;;
+               "ubifs")        nand_upgrade_ubifs $1;;
+               *)              nand_upgrade_tar $1;;
+       esac
 }
 
 nand_upgrade_stage2() {
@@ -320,7 +326,6 @@ nand_upgrade_stage1() {
                exit 0
        }
 }
-append sysupgrade_pre_upgrade nand_upgrade_stage1
 
 # Check if passed file is a valid one for NAND sysupgrade. Currently it accepts
 # 3 types of files:
@@ -328,12 +333,12 @@ append sysupgrade_pre_upgrade nand_upgrade_stage1
 #    MAGIC
 # 2) UBIFS - should contain UBIFS partition that will replace "rootfs" volume,
 #    header is checked for the proper MAGIC
-# 3) TRX - archive has to include "sysupgrade-BOARD" directory with a non-empty
+# 3) TAR - archive has to include "sysupgrade-BOARD" directory with a non-empty
 #    "CONTROL" file (at this point its content isn't verified)
 #
 # You usually want to call this function in platform_check_image.
 #
-# $(1): board name, used in case of passing TRX file
+# $(1): board name, used in case of passing TAR file
 # $(2): file to be checked
 nand_do_platform_check() {
        local board_name="$1"
@@ -346,8 +351,14 @@ nand_do_platform_check() {
                return 1
        }
 
-       echo -n $2 > /tmp/sysupgrade-nand-path
-       cp /sbin/upgraded /tmp/
-
        return 0
 }
+
+# Start NAND upgrade process
+#
+# $(1): file to be used for upgrade
+nand_do_upgrade() {
+       echo -n $1 > /tmp/sysupgrade-nand-path
+       cp /sbin/upgraded /tmp/
+       nand_upgrade_stage1
+}