ar71xx: add support for MikroTik RouterBOARD 922UAGS-5HPacD
[openwrt/staging/chunkeey.git] / target / linux / ar71xx / base-files / lib / upgrade / platform.sh
index 7738db33a7f5ccb5c53e606651a9f79eb741a6c4..e9227aaa7b77be70ea7571d9636a8ccb90793a6b 100755 (executable)
@@ -6,8 +6,8 @@
 . /lib/ar71xx.sh
 
 PART_NAME=firmware
-RAMFS_COPY_DATA=/lib/ar71xx.sh
-RAMFS_COPY_BIN='nandwrite'
+RAMFS_COPY_DATA='/lib/ar71xx.sh /etc/fw_env.config /var/lock/fw_printenv.lock'
+RAMFS_COPY_BIN='nandwrite fw_printenv fw_setenv'
 
 CI_BLKSZ=65536
 CI_LDADR=0x80060000
@@ -93,26 +93,37 @@ tplink_get_image_boot_size() {
        get_image "$@" | dd bs=4 count=1 skip=37 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
 }
 
+tplink_pharos_check_support_list() {
+       local image="$1"
+       local offset="$2"
+       local model="$3"
+       local trargs="$4"
+
+       # Here $image is given to dd directly instead of using get_image;
+       # otherwise the skip will take almost a second (as dd can't seek)
+       dd if="$image" bs=1 skip=$offset count=1024 2>/dev/null | tr -d "$trargs" | (
+               while IFS= read -r line; do
+                       [ "$line" = "$model" ] && exit 0
+               done
+
+               exit 1
+       )
+}
+
 tplink_pharos_check_image() {
-       local magic_long="$(get_magic_long "$1")"
-       [ "$magic_long" != "7f454c46" ] && {
-               echo "Invalid image magic '$magic_long'"
+       local image_magic="$(get_magic_long "$1")"
+       local board_magic="$2"
+       [ "$image_magic" != "$board_magic" ] && {
+               echo "Invalid image magic '$image_magic'. Expected '$board_magic'."
                return 1
        }
 
-       local model_string="$(tplink_pharos_get_model_string)"
-       local line
-
-       # Here $1 is given to dd directly instead of get_image as otherwise the skip
-       # will take almost a second (as dd can't seek then)
-       #
-       # This will fail if the image isn't local, but that's fine: as the
-       # read loop won't be executed at all, it will return true, so the image
-       # is accepted (loading the first 1.5M of a remote image for this check seems
-       # a bit extreme)
-       dd if="$1" bs=1 skip=1511432 count=1024 2>/dev/null | while read line; do
-               [ "$line" = "$model_string" ] && break
-       done || {
+       local model_string="$3"
+       local trargs="$4"
+
+       # New images have the support list at 7802888, old ones at 1511432
+       tplink_pharos_check_support_list "$1" 7802888 "$model_string" "$trargs" || \
+       tplink_pharos_check_support_list "$1" 1511432 "$model_string" "$trargs" || {
                echo "Unsupported image (model not in support-list)"
                return 1
        }
@@ -201,8 +212,11 @@ platform_check_image() {
        archer-c25-v1|\
        archer-c58-v1|\
        archer-c59-v1|\
+       archer-c59-v2|\
        archer-c60-v1|\
+       archer-c60-v2|\
        archer-c7-v4|\
+       archer-c7-v5|\
        bullet-m|\
        c-55|\
        carambola2|\
@@ -219,6 +233,7 @@ platform_check_image() {
        cpe505n|\
        cpe830|\
        cpe870|\
+       dap-1330-a1|\
        dgl-5500-a1|\
        dhp-1565-a1|\
        dir-505-a1|\
@@ -236,8 +251,11 @@ platform_check_image() {
        dr531|\
        dragino2|\
        e1700ac-v2|\
+       e558-v2|\
        e600g-v2|\
        e600gac-v2|\
+       e750a-v4|\
+       e750g-v8|\
        ebr-2310-c1|\
        ens202ext|\
        epg5000|\
@@ -250,12 +268,14 @@ platform_check_image() {
        gl-ar300m|\
        gl-ar300|\
        gl-ar750|\
+       gl-ar750s|\
        gl-domino|\
        gl-mifi|\
        gl-usb150|\
        hiwifi-hc6361|\
        hornet-ub-x2|\
        jwap230|\
+       lbe-m5|\
        lima|\
        loco-m-xw|\
        mzk-w04nu|\
@@ -395,6 +415,7 @@ platform_check_image() {
        lan-turtle|\
        mc-mac1200r|\
        minibox-v1|\
+       minibox-v3.2|\
        omy-g1|\
        omy-x1|\
        onion-omega|\
@@ -468,9 +489,11 @@ platform_check_image() {
        tl-wr842n-v3|\
        tl-wr902ac-v1|\
        tl-wr940n-v4|\
+       tl-wr940n-v6|\
        tl-wr941nd|\
        tl-wr941nd-v5|\
        tl-wr941nd-v6|\
+       ts-d084|\
        wifi-pineapple-nano)
                local magic_ver="0100"
 
@@ -534,10 +557,12 @@ platform_check_image() {
        rb-912uag-2hpnd|\
        rb-912uag-5hpnd|\
        rb-921gs-5hpacd-r2|\
+       rb-922uags-5hpacd|\
        rb-951g-2hnd|\
        rb-951ui-2hnd|\
        rb-2011l|\
        rb-2011il|\
+       rb-2011ils|\
        rb-2011uas|\
        rb-2011uas-2hnd|\
        rb-2011uias|\
@@ -559,13 +584,30 @@ platform_check_image() {
                return $?
                ;;
        cpe210|\
-       cpe510|\
        eap120|\
        wbs210|\
        wbs510)
-               tplink_pharos_check_image "$1" && return 0
+               tplink_pharos_check_image "$1" "7f454c46" "$(tplink_pharos_get_model_string)" '' && return 0
+               return 1
+               ;;
+       cpe210-v2)
+               tplink_pharos_check_image "$1" "01000000" "$(tplink_pharos_v2_get_model_string)" '\0\xff\r' && return 0
                return 1
                ;;
+       cpe510)
+               local modelstr="$(tplink_pharos_v2_get_model_string)"
+               tplink_pharos_board_detect $modelstr
+               case $AR71XX_MODEL in
+               'TP-Link CPE510 v2.0')
+                       tplink_pharos_check_image "$1" "7f454c46" "$modelstr" '\0\xff\r' && return 0
+                       return 1
+                       ;;
+               *)
+                       tplink_pharos_check_image "$1" "7f454c46" "$(tplink_pharos_get_model_string)" '' && return 0
+                       return 1
+                       ;;
+               esac
+               ;;
        a40|\
        a60|\
        mr1750|\
@@ -673,11 +715,15 @@ platform_check_image() {
                ;;
        # these boards use metadata images
        fritz300e|\
+       fritz4020|\
+       fritz450e|\
+       koala|\
        rb-750-r2|\
        rb-750p-pbr2|\
        rb-750up-r2|\
        rb-911-2hn|\
        rb-911-5hn|\
+       rb-931-2nd|\
        rb-941-2nd|\
        rb-951ui-2nd|\
        rb-952ui-5ac2nd|\
@@ -685,8 +731,10 @@ platform_check_image() {
        rb-lhg-5nd|\
        rb-map-2nd|\
        rb-mapl-2nd|\
+       rb-sxt-2nd-r3|\
        rb-wap-2nd|\
-       rb-wapg-5hact2hnd)
+       rb-wapg-5hact2hnd|\
+       rb-wapr-2nd)
                return 0
                ;;
        esac
@@ -704,6 +752,7 @@ platform_pre_upgrade() {
        rb-750up-r2|\
        rb-911-2hn|\
        rb-911-5hn|\
+       rb-931-2nd|\
        rb-941-2nd|\
        rb-951ui-2nd|\
        rb-952ui-5ac2nd|\
@@ -711,8 +760,10 @@ platform_pre_upgrade() {
        rb-lhg-5nd|\
        rb-map-2nd|\
        rb-mapl-2nd|\
+       rb-sxt-2nd-r3|\
        rb-wap-2nd|\
-       rb-wapg-5hact2hnd)
+       rb-wapg-5hact2hnd|\
+       rb-wapr-2nd)
                # erase firmware if booted from initramfs
                [ -z "$(rootfs_type)" ] && mtd erase firmware
                ;;
@@ -828,9 +879,11 @@ platform_do_upgrade() {
        rb-912uag-2hpnd|\
        rb-912uag-5hpnd|\
        rb-921gs-5hpacd-r2|\
+       rb-922uags-5hpacd|\
        rb-951g-2hnd|\
        rb-951ui-2hnd|\
        rb-2011il|\
+       rb-2011ils|\
        rb-2011l|\
        rb-2011uas|\
        rb-2011uas-2hnd|\