[WIP] add basic support cpe210v2
[openwrt/staging/lynxis.git] / target / linux / ar71xx / base-files / lib / upgrade / platform.sh
index 65d90d40090bc0019636a8ad71501676dfb37b22..36ee082e5e67dd32a8412713811cce673e477e18 100755 (executable)
@@ -94,9 +94,10 @@ tplink_get_image_boot_size() {
 }
 
 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
        }
 
@@ -110,7 +111,7 @@ tplink_pharos_check_image() {
        # 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
+       dd if="$1" bs=1 skip=1511432 count=1024 2>/dev/null | tr -d '\0\xff\r' | while read line; do
                [ "$line" = "$model_string" ] && break
        done || {
                echo "Unsupported image (model not in support-list)"
@@ -544,7 +545,14 @@ platform_check_image() {
        eap120|\
        wbs210|\
        wbs510)
-               tplink_pharos_check_image "$1" && return 0
+               # magic = .ELF
+               tplink_pharos_check_image "$1" "7f454c46" && return 0
+               return 1
+               ;;
+       cpe210v2|\
+       cpe510v2)
+               # magic = mktplinkfw v1 header
+               tplink_pharos_check_image "$1" "01000000" && return 0
                return 1
                ;;
        a40|\