aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/ath79/base-files
diff options
context:
space:
mode:
Diffstat (limited to 'target/linux/ath79/base-files')
-rwxr-xr-xtarget/linux/ath79/base-files/etc/board.d/02_network10
-rw-r--r--target/linux/ath79/base-files/etc/hotplug.d/firmware/11-ath10k-caldata52
-rw-r--r--target/linux/ath79/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac24
-rwxr-xr-xtarget/linux/ath79/base-files/lib/functions/k2t.sh55
4 files changed, 141 insertions, 0 deletions
diff --git a/target/linux/ath79/base-files/etc/board.d/02_network b/target/linux/ath79/base-files/etc/board.d/02_network
index 8e3c9177a2..0c9a5fa4e4 100755
--- a/target/linux/ath79/base-files/etc/board.d/02_network
+++ b/target/linux/ath79/base-files/etc/board.d/02_network
@@ -2,6 +2,7 @@
. /lib/functions/system.sh
. /lib/functions/uci-defaults.sh
+. /lib/functions/k2t.sh
ath79_setup_interfaces()
{
@@ -60,6 +61,10 @@ ath79_setup_interfaces()
ucidef_add_switch "switch0" \
"0@eth0" "2:lan" "3:lan" "4:lan" "5:lan" "1:wan"
;;
+ "phicomm,k2t")
+ ucidef_add_switch "switch0" \
+ "0@eth0" "3:lan:1" "5:lan:2" "4:wan"
+ ;;
*)
ucidef_set_interfaces_lan_wan "eth0" "eth1"
;;
@@ -74,9 +79,14 @@ ath79_setup_macs()
avm,fritz300e)
lan_mac=$(fritz_tffs -n maca -i $(find_mtd_part "tffs (1)"))
;;
+ phicomm,k2t)
+ lan_mac=$(k2t_get_mac "lan_mac")
+ wan_mac=$(k2t_get_mac "wan_mac")
+ ;;
esac
[ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
+ [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
}
board_config_update
diff --git a/target/linux/ath79/base-files/etc/hotplug.d/firmware/11-ath10k-caldata b/target/linux/ath79/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
index 2bbe5923bc..d862f611e5 100644
--- a/target/linux/ath79/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
+++ b/target/linux/ath79/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
@@ -1,5 +1,23 @@
#!/bin/sh
+. /lib/functions/k2t.sh
+
+# xor multiple hex values of the same length
+xor() {
+ local val
+ local ret="0x$1"
+ local retlen=${#1}
+
+ shift
+ while [ -n "$1" ]; do
+ val="0x$1"
+ ret=$((ret ^ val))
+ shift
+ done
+
+ printf "%0${retlen}x" "$ret"
+}
+
ath10kcal_die() {
echo "ath10cal: " "$*"
exit 1
@@ -36,6 +54,29 @@ ath10kcal_patch_mac() {
macaddr_2bin $mac | dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=6 count=6
}
+ath10kcal_patch_mac_crc() {
+ local mac=$1
+ local mac_offset=6
+ local chksum_offset=2
+ local xor_mac
+ local xor_fw_mac
+ local xor_fw_chksum
+
+ xor_fw_mac=$(hexdump -v -n 6 -s $mac_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE)
+ xor_fw_mac="${xor_fw_mac:0:4} ${xor_fw_mac:4:4} ${xor_fw_mac:8:4}"
+
+ ath10kcal_patch_mac "$mac" && {
+ xor_mac=${mac//:/}
+ xor_mac="${xor_mac:0:4} ${xor_mac:4:4} ${xor_mac:8:4}"
+
+ xor_fw_chksum=$(hexdump -v -n 2 -s $chksum_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE)
+ xor_fw_chksum=$(xor $xor_fw_chksum $xor_fw_mac $xor_mac)
+
+ printf "%b" "\x${xor_fw_chksum:0:2}\x${xor_fw_chksum:2:2}" | \
+ dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=$chksum_offset count=2
+ }
+}
+
[ -e /lib/firmware/$FIRMWARE ] && exit 0
. /lib/functions.sh
@@ -52,6 +93,17 @@ case "$FIRMWARE" in
;;
esac
;;
+"ath10k/pre-cal-pci-0000:00:00.0.bin")
+ case $board in
+ phicomm,k2t)
+ ath10kcal_extract "art" 20480 12064
+ ath10kcal_patch_mac_crc $(k2t_get_mac "5g_mac")
+
+ ln -sf /lib/firmware/ath10k/pre-cal-pci-0000\:00\:00.0.bin \
+ /lib/firmware/ath10k/QCA9888/hw2.0/board.bin
+ ;;
+ esac
+ ;;
*)
exit 1
;;
diff --git a/target/linux/ath79/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac b/target/linux/ath79/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac
new file mode 100644
index 0000000000..59c58f9c67
--- /dev/null
+++ b/target/linux/ath79/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac
@@ -0,0 +1,24 @@
+#!/bin/ash
+
+[ "$ACTION" == "add" ] || exit 0
+
+PHYNBR=${DEVPATH##*/phy}
+
+[ -n $PHYNBR ] || exit 0
+
+. /lib/functions.sh
+. /lib/functions/system.sh
+. /lib/functions/k2t.sh
+
+board=$(board_name)
+
+case "$board" in
+ phicomm,k2t)
+ # The K2T factory firmware does use LAN mac address as the 2.4G wifi mac address
+ [ "$PHYNBR" -eq 1 ] && \
+ echo $(k2t_get_mac "lan_mac") > /sys${DEVPATH}/macaddress
+ ;;
+ *)
+ ;;
+esac
+
diff --git a/target/linux/ath79/base-files/lib/functions/k2t.sh b/target/linux/ath79/base-files/lib/functions/k2t.sh
new file mode 100755
index 0000000000..1158df818b
--- /dev/null
+++ b/target/linux/ath79/base-files/lib/functions/k2t.sh
@@ -0,0 +1,55 @@
+#!/bin/sh
+#
+# Copyright (C) 2018 Weijie Gao <hackpascal@gmail.com>
+#
+# Helper function to extract mac addresses from mtd part for Phicomm K2T
+#
+
+. /lib/functions.sh
+. /lib/functions/system.sh
+. /usr/share/libubox/jshn.sh
+
+k2t_config_load() {
+ local mtd_blk=$(find_mtd_part config)
+
+ if [ -z "$mtd_blk" ]; then
+ echo "k2t_config_load: no mtd part named config" >&2
+ exit 1
+ fi
+
+ local json_size=$(dd if=$mtd_blk bs=1 count=8 2>/dev/null)
+
+ json_size="0x$json_size"
+ json_size=$((json_size))
+
+ if [ "$?" -ne 0 ]; then
+ echo "k2t_config_load: invalid json data size" >&2
+ exit 2
+ fi
+
+ if [ "$json_size" -eq 0 ]; then
+ echo "k2t_config_load: empty json data" >&2
+ exit 3
+ fi
+
+ local json_data=$(dd if=$mtd_blk bs=1 skip=8 count=$json_size 2>/dev/null)
+
+ json_load "$json_data"
+}
+
+k2t_get_mac() {
+ local old_ns
+
+ json_set_namespace "k2t" old_ns
+
+ if k2t_config_load; then
+ json_select "this_dev_info"
+ json_get_var val "$1"
+ json_select ..
+ fi
+
+ json_set_namespace old_ns
+
+ echo $val
+}
+