From 196722663ac79ed87b9d41b4935d4fd41f785586 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 2 Apr 2016 00:54:07 +0200 Subject: [PATCH] ar71xx-generic: backport a few TP-Link model detection and upgrade check patches --- ...HWREV-on-upgrades-of-TP-LINK-devices.patch | 48 +++++++++++++++++++ ...a-space-on-some-TP-LINK-like-devices.patch | 45 +++++++++++++++++ ...XX_MODEL-to-match-labels-image-names.patch | 39 +++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 patches/openwrt/0022-ar71xx-check-both-HWID-and-HWREV-on-upgrades-of-TP-LINK-devices.patch create mode 100644 patches/openwrt/0023-ar71xx-avoid-AR71XX_MODEL-ending-with-a-space-on-some-TP-LINK-like-devices.patch create mode 100644 patches/openwrt/0024-ar71xx-fix-the-revision-of-a-few-TP-LINK-devices-in-AR71XX_MODEL-to-match-labels-image-names.patch diff --git a/patches/openwrt/0022-ar71xx-check-both-HWID-and-HWREV-on-upgrades-of-TP-LINK-devices.patch b/patches/openwrt/0022-ar71xx-check-both-HWID-and-HWREV-on-upgrades-of-TP-LINK-devices.patch new file mode 100644 index 00000000..416de969 --- /dev/null +++ b/patches/openwrt/0022-ar71xx-check-both-HWID-and-HWREV-on-upgrades-of-TP-LINK-devices.patch @@ -0,0 +1,48 @@ +From: Matthias Schiffer +Date: Fri, 1 Apr 2016 23:16:13 +0200 +Subject: ar71xx: check both HWID and HWREV on upgrades of TP-LINK devices + +There's no reason for us to be more lenient than the stock firmware, so +better check the HWREV as well to avoid bricked devices. + +Signed-off-by: Matthias Schiffer + +Backport of r49105 + +diff --git a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh +index 2fc1d10..420b794 100755 +--- a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh ++++ b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh +@@ -66,6 +66,10 @@ tplink_get_image_hwid() { + get_image "$@" | dd bs=4 count=1 skip=16 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"' + } + ++tplink_get_image_mid() { ++ get_image "$@" | dd bs=4 count=1 skip=17 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"' ++} ++ + 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"' + } +@@ -365,13 +369,17 @@ platform_check_image() { + } + + local hwid +- local imageid ++ local mid ++ local imagehwid ++ local imagemid + + hwid=$(tplink_get_hwid) +- imageid=$(tplink_get_image_hwid "$1") ++ mid=$(tplink_get_mid) ++ imagehwid=$(tplink_get_image_hwid "$1") ++ imagemid=$(tplink_get_image_mid "$1") + +- [ "$hwid" != "$imageid" ] && { +- echo "Invalid image, hardware ID mismatch, hw:$hwid image:$imageid." ++ [ "$hwid" != "$imagehwid" -o "$mid" != "$imagemid" ] && { ++ echo "Invalid image, hardware ID mismatch, hw:$hwid $mid image:$imagehwid $imagemid." + return 1 + } + diff --git a/patches/openwrt/0023-ar71xx-avoid-AR71XX_MODEL-ending-with-a-space-on-some-TP-LINK-like-devices.patch b/patches/openwrt/0023-ar71xx-avoid-AR71XX_MODEL-ending-with-a-space-on-some-TP-LINK-like-devices.patch new file mode 100644 index 00000000..520b1d7a --- /dev/null +++ b/patches/openwrt/0023-ar71xx-avoid-AR71XX_MODEL-ending-with-a-space-on-some-TP-LINK-like-devices.patch @@ -0,0 +1,45 @@ +From: Matthias Schiffer +Date: Fri, 1 Apr 2016 23:19:16 +0200 +Subject: ar71xx: avoid AR71XX_MODEL ending with a space on some TP-LINK-like devices + +Instead of adding the space when combining $model and $hwver, add the space +to the beginning of $hwver, so the resulting string won't end with a space +when $hwver is set to the empty string. + +Signed-off-by: Matthias Schiffer + +Backport of r49106 + +diff --git a/target/linux/ar71xx/base-files/lib/ar71xx.sh b/target/linux/ar71xx/base-files/lib/ar71xx.sh +index 7f50d8a..9d650a1 100755 +--- a/target/linux/ar71xx/base-files/lib/ar71xx.sh ++++ b/target/linux/ar71xx/base-files/lib/ar71xx.sh +@@ -133,7 +133,7 @@ tplink_board_detect() { + hwid=$(tplink_get_hwid) + mid=$(tplink_get_mid) + hwver=${hwid:6:2} +- hwver="v${hwver#0}" ++ hwver=" v${hwver#0}" + + case "$hwid" in + "015000"*) +@@ -196,8 +196,8 @@ tplink_board_detect() { + "083000"*) + model="TP-Link TL-WA830RE" + +- if [ "$hwver" = 'v10' ]; then +- hwver='v1' ++ if [ "$hwver" = ' v10' ]; then ++ hwver=' v1' + fi + ;; + "084100"*) +@@ -296,7 +296,7 @@ tplink_board_detect() { + ;; + esac + +- AR71XX_MODEL="$model $hwver" ++ AR71XX_MODEL="$model$hwver" + } + + tplink_pharos_get_model_string() { diff --git a/patches/openwrt/0024-ar71xx-fix-the-revision-of-a-few-TP-LINK-devices-in-AR71XX_MODEL-to-match-labels-image-names.patch b/patches/openwrt/0024-ar71xx-fix-the-revision-of-a-few-TP-LINK-devices-in-AR71XX_MODEL-to-match-labels-image-names.patch new file mode 100644 index 00000000..e7d1ad12 --- /dev/null +++ b/patches/openwrt/0024-ar71xx-fix-the-revision-of-a-few-TP-LINK-devices-in-AR71XX_MODEL-to-match-labels-image-names.patch @@ -0,0 +1,39 @@ +From: Matthias Schiffer +Date: Fri, 1 Apr 2016 23:21:32 +0200 +Subject: ar71xx: fix the revision of a few TP-LINK devices in AR71XX_MODEL to match labels/image names + +Let's not confuse users about the revisions of their devices when we can +easily avoid it. + +Not tested on real hardware. + +Signed-off-by: Matthias Schiffer + +Backport of r49107 + +diff --git a/target/linux/ar71xx/base-files/lib/ar71xx.sh b/target/linux/ar71xx/base-files/lib/ar71xx.sh +index 9d650a1..52ca255 100755 +--- a/target/linux/ar71xx/base-files/lib/ar71xx.sh ++++ b/target/linux/ar71xx/base-files/lib/ar71xx.sh +@@ -162,6 +162,10 @@ tplink_board_detect() { + ;; + "071000"*) + model="TP-Link TL-WR710N" ++ ++ if [ "$hwid" = '07100002' -a "$mid" = '00000002' ]; then ++ hwver=' v2.1' ++ fi + ;; + "072001"*) + model="TP-Link TL-WR720N" +@@ -202,6 +206,10 @@ tplink_board_detect() { + ;; + "084100"*) + model="TP-Link TL-WR841N/ND" ++ ++ if [ "$hwid" = '08410002' -a "$mid" = '00000002' ]; then ++ hwver=' v1.5' ++ fi + ;; + "084200"*) + model="TP-Link TL-WR842N/ND"