mediatek: Add support for the UniElec U7623-02
[openwrt/openwrt.git] / target / linux / mediatek / base-files / lib / upgrade / platform.sh
index 646ce0dc530c459796bfd186fee751c5fddc4447..487a262dc20a83cc46b324811ad57e3efcd1f7a9 100755 (executable)
@@ -1,6 +1,28 @@
 platform_do_upgrade() {                 
-       default_do_upgrade "$ARGV"                                               
-}                                                                                
+       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
+
+               #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
+
+               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 "$ARGV"
+               ;;
+       esac
+}
 
 PART_NAME=firmware
 
@@ -11,7 +33,8 @@ platform_check_image() {
        [ "$#" -gt 1 ] && return 1                                               
 
        case "$board" in                                                       
-       bananapi,bpi-r2)                                                       
+       bananapi,bpi-r2|\
+       "unielec,u7623"*)
                [ "$magic" != "27051956" ] && {   
                        echo "Invalid image type."
                        return 1                                     
@@ -26,4 +49,20 @@ platform_check_image() {
        esac                                      
 
        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
+}