Skip to content

Instantly share code, notes, and snippets.

@wongsyrone
Created November 20, 2015 01:20
Show Gist options
  • Save wongsyrone/787694c5defad76a91b5 to your computer and use it in GitHub Desktop.
Save wongsyrone/787694c5defad76a91b5 to your computer and use it in GitHub Desktop.
Qihoo C301 OP patch
From 7f0f570213b7056a28d7d352ac1666e0937ffa4b Mon Sep 17 00:00:00 2001
From: Weijie Gao <hackpascal@gmail.com>
Date: Wed, 24 Sep 2014 01:13:34 +0800
Subject: [PATCH] complete c301 support
---
package/boot/uboot-envtools/files/ar71xx | 6 +++
package/network/utils/iwinfo/src/iwinfo_lua.c | 3 ++
target/linux/ar71xx/base-files/etc/diag.sh | 8 ++++
.../lib/preinit/81_load_ath10k_board_bin | 7 +++-
.../ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c | 49 +++++++++++++++++++---
target/linux/ar71xx/image/Makefile | 9 +++-
.../419-mtd-seama-add-c301-part-name-check.patch | 14 +++++++
.../419-mtd-seama-add-c301-part-name-check.patch | 14 +++++++
8 files changed, 101 insertions(+), 9 deletions(-)
create mode 100644 target/linux/ar71xx/patches-3.10/419-mtd-seama-add-c301-part-name-check.patch
create mode 100644 target/linux/ar71xx/patches-3.14/419-mtd-seama-add-c301-part-name-check.patch
diff --git a/package/boot/uboot-envtools/files/ar71xx b/package/boot/uboot-envtools/files/ar71xx
index 5deed9c..2383c45 100644
--- a/package/boot/uboot-envtools/files/ar71xx
+++ b/package/boot/uboot-envtools/files/ar71xx
@@ -41,6 +41,12 @@ om2p-lc)
wzr-hp-ag300h)
ubootenv_add_uci_config "/dev/mtd3" "0x0" "0x10000" "0x10000"
;;
+qihoo-c301)
+ if cat /proc/mtd | grep action_image_config; then
+ local mtd=$(cat /proc/mtd | grep action_image_config | sed 's/mtd\([0-9]*\):.*/\1/g')
+ ubootenv_add_uci_config "/dev/mtd${mtd}" "0x0" "0x10000" "0x10000"
+ fi
+ ;;
esac
config_load ubootenv
diff --git a/package/network/utils/iwinfo/src/iwinfo_lua.c b/package/network/utils/iwinfo/src/iwinfo_lua.c
index cdb90d5..3201af4 100644
--- a/package/network/utils/iwinfo/src/iwinfo_lua.c
+++ b/package/network/utils/iwinfo/src/iwinfo_lua.c
@@ -499,6 +499,9 @@ static int iwinfo_L_hwmodelist(lua_State *L, int (*func)(const char *, int *))
lua_pushboolean(L, hwmodes & IWINFO_80211_N);
lua_setfield(L, -2, "n");
+ lua_pushboolean(L, hwmodes & IWINFO_80211_AC);
+ lua_setfield(L, -2, "ac");
+
return 1;
}
diff --git a/target/linux/ar71xx/base-files/etc/diag.sh b/target/linux/ar71xx/base-files/etc/diag.sh
index ac7e20d..2e4e263 100755
--- a/target/linux/ar71xx/base-files/etc/diag.sh
+++ b/target/linux/ar71xx/base-files/etc/diag.sh
@@ -294,6 +294,14 @@ set_state() {
;;
done)
status_led_on
+ case $(ar71xx_board_name) in
+ qihoo-c301)
+ if cat /proc/mtd | grep action_image_config; then
+ local n=$(fw_printenv activeregion | cut -d = -f 2)
+ fw_setenv "image${n}trynum" 0
+ fi
+ ;;
+ esac
;;
esac
}
diff --git a/target/linux/ar71xx/base-files/lib/preinit/81_load_ath10k_board_bin b/target/linux/ar71xx/base-files/lib/preinit/81_load_ath10k_board_bin
index 2c06d7f..969de06 100644
--- a/target/linux/ar71xx/base-files/lib/preinit/81_load_ath10k_board_bin
+++ b/target/linux/ar71xx/base-files/lib/preinit/81_load_ath10k_board_bin
@@ -26,6 +26,9 @@ do_load_ath10k_board_bin() {
;;
qihoo-c301)
local mac
+ local mtd
+
+ mtd=$(cat /proc/mtd | grep radiocfg | sed 's/mtd\([0-9]*\):.*/\1/g')
mac=$(mtd_get_mac_ascii devdata wlan5mac)
@@ -33,11 +36,11 @@ do_load_ath10k_board_bin() {
mac=$(macaddr_add $(cat /sys/class/net/eth0/address) -2)
fi
- dd if=/dev/mtdblock10 \
+ dd if=/dev/mtdblock${mtd} \
bs=1 skip=20480 count=6 \
of=/tmp/ath10k-board.bin
macaddr_2bin $mac >> /tmp/ath10k-board.bin
- dd if=/dev/mtdblock10 \
+ dd if=/dev/mtdblock${mtd} \
bs=1 skip=20492 count=2104 >> /tmp/ath10k-board.bin
;;
diff --git a/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c b/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c
index 08a602f..5193d2d 100644
--- a/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c
+++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c
@@ -14,6 +14,8 @@
#include <linux/gpio.h>
#include <linux/platform_device.h>
#include <linux/ath9k_platform.h>
+#include <linux/crc32.h>
+#include <linux/mtd/mtd.h>
#include <asm/mach-ath79/ar71xx_regs.h>
@@ -81,6 +83,10 @@ static struct gpio_keys_button qihoo_c301_gpio_keys[] __initdata = {
struct flash_platform_data flash __initdata = {NULL, NULL, 0};
+static int qihoo_c301_board = 0;
+
+static u8 wlan24mac[ETH_ALEN];
+
static void qihoo_c301_get_mac(const char *name, char *mac)
{
u8 *nvram = (u8 *) KSEG1ADDR(QIHOO_C301_NVRAM_ADDR);
@@ -94,9 +100,6 @@ static void qihoo_c301_get_mac(const char *name, char *mac)
static void __init qihoo_c301_setup(void)
{
- u8 *art = (u8 *) KSEG1ADDR(0x1fff0000);
- u8 tmpmac[ETH_ALEN];
-
ath79_register_m25p80_multi(&flash);
ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE);
@@ -125,8 +128,7 @@ static void __init qihoo_c301_setup(void)
ath79_wmac_set_ext_lna_gpio(0, QIHOO_C301_GPIO_EXTERNAL_LNA0);
ath79_wmac_set_ext_lna_gpio(1, QIHOO_C301_GPIO_EXTERNAL_LNA1);
- qihoo_c301_get_mac("wlan24mac=", tmpmac);
- ath79_register_wmac(art + QIHOO_C301_WMAC_CALDATA_OFFSET, tmpmac);
+ qihoo_c301_get_mac("wlan24mac=", wlan24mac);
ath79_register_pci();
@@ -160,7 +162,44 @@ static void __init qihoo_c301_setup(void)
GPIOF_OUT_INIT_HIGH | GPIOF_EXPORT_DIR_FIXED,
"USB power");
ath79_register_usb();
+
+ qihoo_c301_board = 1;
}
MIPS_MACHINE(ATH79_MACH_QIHOO_C301, "QIHOO-C301", "Qihoo 360 C301",
qihoo_c301_setup);
+
+static int qihoo_init_wmac(void)
+{
+ struct mtd_info * mtd;
+ size_t nb = 0;
+ u8 *art;
+ int ret;
+
+ if (!qihoo_c301_board)
+ return 0;
+
+ mtd = get_mtd_device_nm("radiocfg");
+ if (IS_ERR(mtd))
+ return PTR_ERR(mtd);
+
+ if (mtd->size != 0x10000)
+ return -1;
+
+ art = kzalloc(0x1000, GFP_KERNEL);
+ if (!art)
+ return -1;
+
+ ret = mtd_read(mtd, QIHOO_C301_WMAC_CALDATA_OFFSET, 0x1000, &nb, art);
+ if (nb != 0x1000)
+ {
+ kfree(art);
+ return ret;
+ }
+
+ ath79_register_wmac(art, wlan24mac);
+
+ return 0;
+}
+
+late_initcall(qihoo_init_wmac);
diff --git a/target/linux/ar71xx/image/Makefile b/target/linux/ar71xx/image/Makefile
index b374391..5ad2c7c 100644
--- a/target/linux/ar71xx/image/Makefile
+++ b/target/linux/ar71xx/image/Makefile
@@ -290,7 +290,9 @@ zcn1523h_mtdlayout=mtdparts=spi0.0:256k(u-boot)ro,64k(u-boot-env)ro,6208k(rootfs
mynet_n600_mtdlayout=mtdparts=spi0.0:256k(u-boot)ro,64k(u-boot-env)ro,64k(devdata)ro,64k(devconf)ro,15872k(firmware),64k(radiocfg)ro
mynet_rext_mtdlayout=mtdparts=spi0.0:256k(u-boot)ro,7808k(firmware),64k(nvram)ro,64k(ART)ro,6848k@0x130000(filesystem)
zyx_nbg6716_mtdlayout=mtdparts=spi0.0:256k(u-boot)ro,64k(env)ro,64k(RFdata)ro,-(nbu);ar934x-nfc:2048k(zyxel_rfsd),2048k(romd),1024k(header),2048k(kernel),-(ubi)
-qihoo_c301_mtdlayout=mtdparts=spi0.0:256k(u-boot)ro,64k(u-boot-env),64k(devdata),64k(devconf),15744k(firmware),64k(warm_start),64k(action_image_config),64k(radiocfg)ro;spi0.1:15360k(upgrade2),1024k(privatedata)
+qihoo_c301_mtdlayout=mtdparts=spi0.0:256k(u-boot),64k(u-boot-env),64k(devdata),64k(devconf),15744k(firmware),64k(warm_start),64k(action_image_config),64k(radiocfg);spi0.1:15360k(upgrade2),1024k(privatedata)
+qihoo_c301_flash2_mtdlayout=mtdparts=spi0.0:256k(u-boot),64k(u-boot-env),64k(devdata),64k(devconf),15744k(upgrade1),64k(warm_start),64k(action_image_config),64k(radiocfg);spi0.1:15360k(firmware),1024k(privatedata)
+qihoo_c301_32m_mtdlayout=mtdparts=flash:256k(u-boot),64k(u-boot-env),64k(devdata),64k(devconf),32256k(firmware),64k(radiocfg)
define Image/BuildKernel
@@ -1157,7 +1159,9 @@ $(eval $(call SingleProfile,Planex,64kraw,MZKW300NH,mzk-w300nh,MZK-W300NH,ttyS0,
$(eval $(call SingleProfile,Seama,64k,MYNETN600,mynet-n600,MYNET-N600,ttyS0,115200,$$(mynet_n600_mtdlayout),wrgnd16_wd_db600,1310720,16187392))
$(eval $(call SingleProfile,Seama,64k,MYNETN750,mynet-n750,MYNET-N750,ttyS0,115200,$$(mynet_n600_mtdlayout),wrgnd13_wd_av,1310720,16187392))
-$(eval $(call SingleProfile,Seama,64k,QIHOO360,qihoo-c301,QIHOO-C301,ttyS0,115200,$$(qihoo_c301_mtdlayout),wrgac26_qihoo360_360rg,1310720,16121856))
+$(eval $(call SingleProfile,Seama,64k,QIHOO36016M,qihoo-c301,QIHOO-C301,ttyS0,115200,$$(qihoo_c301_mtdlayout),wrgac26_qihoo360_360rg,1310720,16121856))
+$(eval $(call SingleProfile,Seama,64k,QIHOO360FLASH2,qihoo-c301-flash2,QIHOO-C301,ttyS0,115200,$$(qihoo_c301_flash2_mtdlayout),wrgac26_qihoo360_360rg,1310720,15728640))
+$(eval $(call SingleProfile,Seama,64k,QIHOO36032M,qihoo-c301-32m,QIHOO-C301,ttyS0,115200,$$(qihoo_c301_32m_mtdlayout),wrgac26_qihoo360_360rg,1310720,33030144))
$(eval $(call SingleProfile,Senao,squashfs-only,EAP300V2,eap300v2,EAP300V2,ttyS0,115200,$$(eap300v2_mtdlayout)))
@@ -1276,6 +1280,7 @@ $(eval $(call MultiProfile,ARCHERC7, ARCHERC5 ARCHERC7V1 ARCHERC7V2))
$(eval $(call MultiProfile,EWDORIN, EWDORINAP EWDORINRT EWDORIN16M))
$(eval $(call MultiProfile,OPENMESH,OM2P OM5P MR600))
$(eval $(call MultiProfile,TEW652BRP,TEW652BRP_FW TEW652BRP_RECOVERY))
+$(eval $(call MultiProfile,QIHOO360,QIHOO36016M QIHOO360FLASH2 QIHOO36032M))
$(eval $(call MultiProfile,TLMR11U,TLMR11UV1 TLMR11UV2))
$(eval $(call MultiProfile,TLMR3040,TLMR3040V1 TLMR3040V2))
$(eval $(call MultiProfile,TLMR3220,TLMR3220V1 TLMR3220V2))
diff --git a/target/linux/ar71xx/patches-3.10/419-mtd-seama-add-c301-part-name-check.patch b/target/linux/ar71xx/patches-3.10/419-mtd-seama-add-c301-part-name-check.patch
new file mode 100644
index 0000000..16c08ae
--- /dev/null
+++ b/target/linux/ar71xx/patches-3.10/419-mtd-seama-add-c301-part-name-check.patch
@@ -0,0 +1,14 @@
+--- a/drivers/mtd/mtdsplit_seama.c
++++ b/drivers/mtd/mtdsplit_seama.c
+@@ -38,6 +38,11 @@
+ struct mtd_partition *parts;
+ int err;
+
++ if (!strcmp(master->name, "upgrade1") ||
++ !strcmp(master->name, "upgrade2")) {
++ return -EINVAL;
++ }
++
+ hdr_len = sizeof(hdr);
+ err = mtd_read(master, 0, hdr_len, &retlen, (void *) &hdr);
+ if (err)
diff --git a/target/linux/ar71xx/patches-3.14/419-mtd-seama-add-c301-part-name-check.patch b/target/linux/ar71xx/patches-3.14/419-mtd-seama-add-c301-part-name-check.patch
new file mode 100644
index 0000000..16c08ae
--- /dev/null
+++ b/target/linux/ar71xx/patches-3.14/419-mtd-seama-add-c301-part-name-check.patch
@@ -0,0 +1,14 @@
+--- a/drivers/mtd/mtdsplit_seama.c
++++ b/drivers/mtd/mtdsplit_seama.c
+@@ -38,6 +38,11 @@
+ struct mtd_partition *parts;
+ int err;
+
++ if (!strcmp(master->name, "upgrade1") ||
++ !strcmp(master->name, "upgrade2")) {
++ return -EINVAL;
++ }
++
+ hdr_len = sizeof(hdr);
+ err = mtd_read(master, 0, hdr_len, &retlen, (void *) &hdr);
+ if (err)
--
2.1.0.GIT
此 patch 可以让 OpenWrt 直接编译生成三种完美使用的固件 (常规版、第二 Flash 版、32M 双 Flash 利用版),而且不会被官方 U-Boot 还原。
特别感谢 swigger 提供的用于在内核中复位固件启动次数的代码。
此 patch 基于已成功提交 360 路由初始化支持之后的 trunk 代码
[2014-09-24 改动]
更换内核重置固件启动次数的方式为使用 uboot-envtools,此方法兼容性更好。
准备工作:
1. 准备最新版 OpenWrt trunk 代码,这里不做讲解
2. 若已在使用 trunk 代码,请 git pull 到最新版本,需要注意备份数据
应用补丁:
补丁文件有两个,分别用在不同的地方
0001-complete-c301-support.patch:
复制到 OpenWrt 代码根目录,然后运行
git apply --whitespace=nowarn 0001-complete-c301-support.patch
复制代码
完成后删除 0001-complete-c301-support.patch
0001-add-ieee-802.11ac-support.patch:
复制到 OpenWrt 代码根目录下的 feeds/luci 文件夹下
然后 shell 进入到 feeds/luci
cd feeds/luci
复制代码
然后运行
git apply 0001-add-ieee-802.11ac-support.patch
复制代码
完成后删除 0001-add-ieee-802.11ac-support.patch
注意:需要 make clean 后再编译;切记选中 Utilities -> uboot-envtools 包,否则重置固件启动次数的功能不会生效
另外需要在 Kernel modules -> Wireless Drivers 里选上 kmod-ath9k 和 kmod-ath10k 以保证无线能够正常使用
大功告成:
刷机请使用 sysupgrade 结尾的文件
Uboot刷sysupgrade
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment