Skip to content

Commit

Permalink
patches: update TP-Link CPE210v2-support
Browse files Browse the repository at this point in the history
update openwrt/openwrt#642, seems like
this patch waas incomplete before
  • Loading branch information
SvenRoederer committed Feb 20, 2018
1 parent 61ddf4f commit 006df45
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 92 deletions.
104 changes: 104 additions & 0 deletions patches/007-Add_TP-Link_Pharos_v2_board_detection.patch
@@ -0,0 +1,104 @@
commit 251906597f5aa3d06b96ae7368d11a4959e64c96
Author: Robert Marko <robimarko@gmail.com>
Date: Fri Jan 19 12:58:40 2018 +0100

ar71xx: Add TP-Link Pharos v2 board detection

Add support for detecting TP-Link Pharos v2 boards.
They use different format in product-info partition than v1 boards.

Code for this patch was written by Alexander Couzens <lynxis@fe80.eu>

Signed-off-by: Robert Marko <robimarko@gmail.com>

diff --git a/target/linux/ar71xx/base-files/lib/ar71xx.sh b/target/linux/ar71xx/base-files/lib/ar71xx.sh
index b6642495de..c40c83f5dd 100755
--- a/target/linux/ar71xx/base-files/lib/ar71xx.sh
+++ b/target/linux/ar71xx/base-files/lib/ar71xx.sh
@@ -361,6 +361,25 @@ tplink_pharos_board_detect() {
AR71XX_MODEL="TP-Link $model v$2"
}

+tplink_pharos_v2_get_model_string() {
+ local part
+ part=$(find_mtd_part 'product-info')
+ [ -z "$part" ] && return 1
+
+ # The returned string will end with \r\n, but we don't remove it here
+ # to simplify matching against it in the sysupgrade image check
+ dd if=$part bs=1 skip=4360 count=64 2>/dev/null | tr -d '\r\0' | head -n 1
+}
+
+tplink_pharos_v2_board_detect() {
+ local model_string="$(tplink_pharos_v2_get_model_string)"
+ local oIFS="$IFS"; IFS=":"; set -- $model_string; IFS="$oIFS"
+
+ local model="${1%%\(*}"
+
+ AR71XX_MODEL="TP-Link $model v$2"
+}
+
ar71xx_board_detect() {
local machine
local name
@@ -532,6 +551,10 @@ ar71xx_board_detect() {
name="cpe210"
tplink_pharos_board_detect
;;
+ *"CPE210 v2")
+ name="cpe210-v2"
+ tplink_pharos_v2_board_detect
+ ;;
*"CPE505N")
name="cpe505n"
;;
diff --git a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
index 3d7b1593e1..1ed6882741 100755
--- a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
+++ b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
@@ -120,6 +120,34 @@ tplink_pharos_check_image() {
return 0
}

+tplink_pharos_v2_check_image() {
+ 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_v2_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 | tr -d '\0\xff\r' | while read line; do
+ [ "$line" = "$model_string" ] && break
+ done || {
+ echo "Unsupported image (model not in support-list)"
+ return 1
+ }
+
+ return 0
+}
+
seama_get_type_magic() {
get_image "$@" | dd bs=1 count=4 skip=53 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
}
@@ -550,6 +578,10 @@ platform_check_image() {
tplink_pharos_check_image "$1" && return 0
return 1
;;
+ cpe210-v2)
+ tplink_pharos_v2_check_image "$1" "01000000" && return 0
+ return 1
+ ;;
a40|\
a60|\
mr1750|\
@@ -1,3 +1,39 @@
commit 7b711ff801d4c0f4740056481b156f96b5a0fbc8
Author: Robert Marko <robimarko@gmail.com>
Date: Fri Jan 19 14:45:42 2018 +0100

ar71xx: add support for TP-Link CPE210 v2

This PR adds support for a popular low-cost 2.4GHz N based AP

Specifications:
- SoC: Qualcomm Atheros QCA9533 (650MHz)
- RAM: 64MB
- Storage: 8 MB SPI NOR
- Wireless: 2.4GHz N based built into SoC 2x2
- Ethernet: 1x 100/10 Mbps, integrated into SoC, 24V POE IN

Installation:
Flash factory image through stock firmware WEB UI
or through TFTP
To get to TFTP recovery just hold reset button while powering on for
around 4-5 seconds and release.
Rename factory image to recovery.bin
Stock TFTP server IP:192.168.0.100
Stock device TFTP adress:192.168.0.254

Notes:
TP-Link does not use bootstrap registers so without this patch reference
clock detects as 40MHz while it is actually 25MHz.
This is due to messed up bootstrap resistor configuration on the PCB.
Provided GPL code just forces 25MHz reference clock.
That causes booting with completely wrong clocks, for example, CPU tries
to boot at 1040MHz while the stock is 650MHz.
So this PR depends on PR #672 to remove 40MHz reference clock.
Thanks to Sven Eckelmann <sven@narfation.org> for properly patching that.

Signed-off-by: Robert Marko <robimarko@gmail.com>

diff --git a/target/linux/ar71xx/base-files/etc/board.d/01_leds b/target/linux/ar71xx/base-files/etc/board.d/01_leds
index fb1f29dcfa..5ea9c3ee73 100755
--- a/target/linux/ar71xx/base-files/etc/board.d/01_leds
Expand Down Expand Up @@ -42,97 +78,6 @@ index 5a10a9f486..bab99bb852 100755
dr342|\
eap120|\
eap300v2|\
diff --git a/target/linux/ar71xx/base-files/lib/ar71xx.sh b/target/linux/ar71xx/base-files/lib/ar71xx.sh
index b6642495de..c40c83f5dd 100755
--- a/target/linux/ar71xx/base-files/lib/ar71xx.sh
+++ b/target/linux/ar71xx/base-files/lib/ar71xx.sh
@@ -361,6 +361,25 @@ tplink_pharos_board_detect() {
AR71XX_MODEL="TP-Link $model v$2"
}

+tplink_pharos_v2_get_model_string() {
+ local part
+ part=$(find_mtd_part 'product-info')
+ [ -z "$part" ] && return 1
+
+ # The returned string will end with \r\n, but we don't remove it here
+ # to simplify matching against it in the sysupgrade image check
+ dd if=$part bs=1 skip=4360 count=64 2>/dev/null | tr -d '\r\0' | head -n 1
+}
+
+tplink_pharos_v2_board_detect() {
+ local model_string="$(tplink_pharos_v2_get_model_string)"
+ local oIFS="$IFS"; IFS=":"; set -- $model_string; IFS="$oIFS"
+
+ local model="${1%%\(*}"
+
+ AR71XX_MODEL="TP-Link $model v$2"
+}
+
ar71xx_board_detect() {
local machine
local name
@@ -532,6 +551,10 @@ ar71xx_board_detect() {
name="cpe210"
tplink_pharos_board_detect
;;
+ *"CPE210 v2")
+ name="cpe210-v2"
+ tplink_pharos_v2_board_detect
+ ;;
*"CPE505N")
name="cpe505n"
;;
diff --git a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
index 3d7b1593e1..1ed6882741 100755
--- a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
+++ b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
@@ -120,6 +120,34 @@ tplink_pharos_check_image() {
return 0
}

+tplink_pharos_v2_check_image() {
+ 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_v2_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 | tr -d '\0\xff\r' | while read line; do
+ [ "$line" = "$model_string" ] && break
+ done || {
+ echo "Unsupported image (model not in support-list)"
+ return 1
+ }
+
+ return 0
+}
+
seama_get_type_magic() {
get_image "$@" | dd bs=1 count=4 skip=53 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
}
@@ -550,6 +578,10 @@ platform_check_image() {
tplink_pharos_check_image "$1" && return 0
return 1
;;
+ cpe210-v2)
+ tplink_pharos_v2_check_image "$1" "01000000" && return 0
+ return 1
+ ;;
a40|\
a60|\
mr1750|\
diff --git a/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt b/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt
index 3ca77550bc..ed19fa8ba4 100644
--- a/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt
Expand Down
3 changes: 2 additions & 1 deletion patches/series
Expand Up @@ -2,7 +2,8 @@
004-openwrt-release_use_configured_revision.patch
005-hostapd_nolegacy_by_default.patch
006-disable_40Mhz_refclk_for_QCA953x.patch
007_add_CPE210v2.patch
007-Add_TP-Link_Pharos_v2_board_detection.patch
008-add_support_for_TP-Link_CPE210_v2.patch
200-wifi_nolegacy_rates_by_default.patch
700-banner-info.patch
701-luci-freifunk-policyrouting-berlin.patch
Expand Down

0 comments on commit 006df45

Please sign in to comment.