gluon/patches/lede/0099-ar71xx-Add-TP-Link-Pharos-v2-board-detection.patch

140 lines
4.6 KiB
Diff
Raw Normal View History

From: Adrian Schmutzler <freifunk@adrianschmutzler.de>
Date: Fri, 19 Jan 2018 12:58:40 +0100
Subject: 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 was written mostly by Alexander Couzens <lynxis@fe80.eu>
Signed-off-by: Robert Marko <robimarko@gmail.com>
Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
Origin: backport, https://github.com/openwrt/openwrt/commit/2524febf7927a1bf430d64b7790feb126023e3d1
diff --git a/target/linux/ar71xx/base-files/lib/ar71xx.sh b/target/linux/ar71xx/base-files/lib/ar71xx.sh
index b365b6ae4aa6021960499b3889d846b5171eec0f..94311f75989b0861e188dc89b3e714b5545c1ad8 100755
--- a/target/linux/ar71xx/base-files/lib/ar71xx.sh
+++ b/target/linux/ar71xx/base-files/lib/ar71xx.sh
@@ -375,7 +375,7 @@ tplink_pharos_get_model_string() {
}
tplink_pharos_board_detect() {
- local model_string="$(tplink_pharos_get_model_string | tr -d '\r')"
+ local model_string="$1"
local oIFS="$IFS"; IFS=":"; set -- $model_string; IFS="$oIFS"
local model="${1%%\(*}"
@@ -396,6 +396,14 @@ gl_inet_board_detect() {
esac
}
+tplink_pharos_v2_get_model_string() {
+ local part
+ part=$(find_mtd_part 'product-info')
+ [ -z "$part" ] && return 1
+
+ dd if=$part bs=1 skip=4360 count=64 2>/dev/null | tr -d '\r\0' | head -n 1
+}
+
ar71xx_board_detect() {
local machine
local name
@@ -546,11 +554,15 @@ ar71xx_board_detect() {
;;
*"CPE210/220")
name="cpe210"
- tplink_pharos_board_detect
+ tplink_pharos_board_detect "$(tplink_pharos_get_model_string | tr -d '\r')"
+ ;;
+ *"CPE210 v2")
+ name="cpe210-v2"
+ tplink_pharos_board_detect "$(tplink_pharos_v2_get_model_string)"
;;
*"CPE510/520")
name="cpe510"
- tplink_pharos_board_detect
+ tplink_pharos_board_detect "$(tplink_pharos_get_model_string | tr -d '\r')"
;;
*CPE830)
name="cpe830"
@@ -560,11 +572,11 @@ ar71xx_board_detect() {
;;
*WBS210)
name="wbs210"
- tplink_pharos_board_detect
+ tplink_pharos_board_detect "$(tplink_pharos_get_model_string | tr -d '\r')"
;;
*WBS510)
name="wbs510"
- tplink_pharos_board_detect
+ tplink_pharos_board_detect "$(tplink_pharos_get_model_string | tr -d '\r')"
;;
*CR3000)
name="cr3000"
@@ -641,7 +653,7 @@ ar71xx_board_detect() {
;;
*"EAP120")
name="eap120"
- tplink_pharos_board_detect
+ tplink_pharos_board_detect "$(tplink_pharos_get_model_string | tr -d '\r')"
;;
*"EAP300 v2")
name="eap300v2"
diff --git a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
index 0b422d71c2639a31bc7e88a20976266b66ec4490..9bc49c41a6308b732e45a7ae35c851133c367254 100755
--- a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
+++ b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
@@ -97,10 +97,11 @@ 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 | (
+ 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
@@ -110,17 +111,19 @@ tplink_pharos_check_support_list() {
}
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 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" || \
- tplink_pharos_check_support_list "$1" 1511432 "$model_string" || {
+ 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
}
@@ -507,7 +510,11 @@ platform_check_image() {
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
;;
a40|\