treewide: sysupgrade: don't use $ARGV in platform_do_upgrade()
[openwrt/staging/lynxis.git] / target / linux / mediatek / base-files / lib / upgrade / platform.sh
index 3f3c5a021ca7af419c221e60d774e351860efc0e..d812a48720b83edbcf8e01f41462f3a749e9d44e 100755 (executable)
@@ -1,41 +1,68 @@
-#
-# Copyright (C) 2016 OpenWrt.org
-#
+platform_do_upgrade() {                 
+       local board=$(board_name)
+       case "$board" in
+       "unielec,u7623"*)
+               #Keep the persisten random mac address (if it exists)
+               mkdir -p /tmp/recovery
+               mount -o rw,noatime /dev/mmcblk0p1 /tmp/recovery
+               [ -f "/tmp/recovery/mac_addr" ] && \
+                       mv -f /tmp/recovery/mac_addr /tmp/
+               umount /tmp/recovery
 
-platform_do_upgrade() {
-       local tar_file="$1"
-       local board="$(board_name)"
+               #1310720 is the offset in bytes from the start of eMMC and to
+               #the location of the kernel (2560 512 byte sectors)
+               get_image "$1" | dd of=/dev/mmcblk0 bs=1310720 seek=1 conv=fsync
 
-       echo "flashing kernel"
-       tar xf $tar_file sysupgrade-$board/kernel -O | mtd write - kernel
+               mount -o rw,noatime /dev/mmcblk0p1 /tmp/recovery
+               [ -f "/tmp/mac_addr" ] && mv -f /tmp/mac_addr /tmp/recovery
+               sync
+               umount /tmp/recovery
+               ;;
+       *)
+               default_do_upgrade "$1"
+               ;;
+       esac
+}
 
-       echo "flashing rootfs"
-       tar xf $tar_file sysupgrade-$board/root -O | mtd write - rootfs
+PART_NAME=firmware
 
-       return 0
-}
+platform_check_image() {                                                         
+       local board=$(board_name)                                                
+       local magic="$(get_magic_long "$1")"                                     
 
-platform_check_image() {
-       local tar_file="$1"
-       local board=$(board_name)
+       [ "$#" -gt 1 ] && return 1                                               
 
-       case "$board" in
-       bananapi,bpi-r2 |\
-       mediatek,mt7623a-rfb-emmc)
-               local kernel_length=`(tar xf $tar_file sysupgrade-$board/kernel -O | wc -c) 2> /dev/null`
-               local rootfs_length=`(tar xf $tar_file sysupgrade-$board/root -O | wc -c) 2> /dev/null`
-               ;;
+       case "$board" in                                                       
+       bananapi,bpi-r2|\
+       "unielec,u7623"*)
+               [ "$magic" != "27051956" ] && {   
+                       echo "Invalid image type."
+                       return 1                                     
+               }                                                    
+               return 0                                             
+               ;;                                                   
 
-       *)
+       *)                                                           
                echo "Sysupgrade is not supported on your board yet."
-               return 1
-               ;;
-       esac
+               return 1                                             
+               ;;                                
+       esac                                      
 
-       [ "$kernel_length" = 0 -o "$rootfs_length" = 0 ] && {
-               echo "The upgarde image is corrupt."
-               return 1
-       }
+       return 0                                                                                         
+}
 
-       return 0
+platform_copy_config_emmc() {
+       mkdir -p /recovery
+       mount -o rw,noatime /dev/mmcblk0p1 /recovery
+       cp -af "$CONF_TAR" /recovery/
+       sync
+       umount /recovery
+}
+
+platform_copy_config() {
+       case "$(board_name)" in
+       "unielec,u7623"*)
+               platform_copy_config_emmc
+               ;;
+       esac
 }