在讲解固件刷入板块时,我们就曾经讲过WR886N-V5刷OpenWrt固件的方法,当时我们采用的固件是TL-WR940N-V4的二次编译版本。今天我们讲解自编译Tl-wr886n-v5的OpenWrt固件时,我们准备采用添加新设备的方式来生成属于Tl-wr886n-v5自己的固件。
英文版参考资料:https://openwrt.org/docs/guide-developer/adding_new_device
自编译环境:OpenWrt的官方源码,版本号为v18.06.9(目前Tl-wr940n-v4官方能支持的最高版本)
那接下来我们计划将整个过程完完整整地呈现给大家,供大家参考!
一、获取需要修改的文件列表
grep -lri wr940 target/
target/linux/ar71xx/base-files/etc/diag.sh target/linux/ar71xx/base-files/etc/board.d/01_leds target/linux/ar71xx/base-files/etc/board.d/02_network target/linux/ar71xx/base-files/lib/preinit/05_set_preinit_iface_ar71xx target/linux/ar71xx/base-files/lib/ar71xx.sh target/linux/ar71xx/base-files/lib/upgrade/platform.sh target/linux/ar71xx/image/tiny-tp-link.mk target/linux/ar71xx/config-4.9 target/linux/ar71xx/tiny/config-default target/linux/ar71xx/files/arch/mips/ath79/machtypes.h target/linux/ar71xx/files/arch/mips/ath79/mach-tl-wr940n-v4.c target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt target/linux/ar71xx/files/arch/mips/ath79/Makefile
二、对照列表文件逐一修改
1、~/target/linux/ar71xx/base-files/etc/diag.sh
tl-wr810n-v2|\ tl-wr940n-v4|\ tl-wr941nd-v6) status_led="tp-link:blue:system" ;;
查询到 tl-wr940n-v4行,在上一行添加 tl-wr886n-v5|\
tl-wr810n-v2|\ tl-wr886n-v5|\ tl-wr940n-v4|\ tl-wr941nd-v6) status_led="tp-link:blue:system" ;;
2、~/target/linux/ar71xx/base-files/etc/board.d/01_leds
tl-wr940n-v4|\ tl-wr941nd-v6) ucidef_set_led_netdev "wan" "WAN" "tp-link:blue:wan" "eth0" ucidef_set_led_switch "lan1" "LAN1" "tp-link:blue:lan1" "switch0" "0x10" ucidef_set_led_switch "lan2" "LAN2" "tp-link:blue:lan2" "switch0" "0x08" ucidef_set_led_switch "lan3" "LAN3" "tp-link:blue:lan3" "switch0" "0x04" ucidef_set_led_switch "lan4" "LAN4" "tp-link:blue:lan4" "switch0" "0x02" ucidef_set_led_wlan "wlan" "WLAN" "tp-link:blue:wlan" "phy0tpt" ;;
查询到 tl-wr940n-v4行,在上一行添加 tl-wr886n-v5|\
tl-wr886n-v5|\ tl-wr940n-v4|\ tl-wr941nd-v6) ucidef_set_led_netdev "wan" "WAN" "tp-link:blue:wan" "eth0" ucidef_set_led_switch "lan1" "LAN1" "tp-link:blue:lan1" "switch0" "0x10" ucidef_set_led_switch "lan2" "LAN2" "tp-link:blue:lan2" "switch0" "0x08" ucidef_set_led_switch "lan3" "LAN3" "tp-link:blue:lan3" "switch0" "0x04" ucidef_set_led_switch "lan4" "LAN4" "tp-link:blue:lan4" "switch0" "0x02" ucidef_set_led_wlan "wlan" "WLAN" "tp-link:blue:wlan" "phy0tpt" ;;
3、~/target/linux/ar71xx/base-files/etc/board.d/02_network
tl-wdr6500-v2|\ tl-wr940n-v4|\ tl-wr940n-v6|\ tl-wr941nd-v6|\ wnr1000-v2|\ wnr2000-v4|\ wnr2200|\ wnr612-v2|\ wpn824n) ucidef_set_interfaces_lan_wan "eth1.1" "eth0" ucidef_add_switch "switch0" \ "0@eth1" "1:lan:1" "2:lan:2" "3:lan:3" "4:lan:4" ;;
查询到 tl-wr940n-v4行,注意这里需要修改并新增 tl-wr886n-v5 的相关信息
tl-wdr6500-v2|\ tl-wr940n-v4|\ tl-wr940n-v6|\ tl-wr941nd-v6|\ wnr1000-v2|\ wnr2000-v4|\ wnr2200|\ wnr612-v2|\ wpn824n) ucidef_set_interfaces_lan_wan "eth1.1" "eth0" ucidef_add_switch "switch0" \ "0@eth1" "1:lan:1" "2:lan:2" "3:lan:3" "4:lan:4" ;; tl-wr886n-v5) ucidef_set_interfaces_lan_wan "eth1.1" "eth0" ucidef_add_switch "switch0" \ "0@eth1" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" ;;
4、~/target/linux/ar71xx/base-files/lib/preinit/05_set_preinit_iface_ar71xx
tl-wr842n-v2|\ tl-wr940n-v4|\ tl-wr941nd-v6|\ wnr1000-v2|\ wnr2000-v3|\ wnr2200|\ wnr612-v2|\ wpe72|\ wpn824n) ifname=eth1 ;;
查询到 tl-wr940n-v4行,在上一行添加 tl-wr886n-v5|\
tl-wr842n-v2|\ tl-wr886n-v5|\ tl-wr940n-v4|\ tl-wr941nd-v6|\ wnr1000-v2|\ wnr2000-v3|\ wnr2200|\ wnr612-v2|\ wpe72|\ wpn824n) ifname=eth1 ;;
5、~/target/linux/ar71xx/base-files/lib/ar71xx.sh
"094000"*) model="TP-Link TL-WR940N" ;;
查询到 wr940n 相关信息行,添加 wr886n 的信息
"088600"*) model="TP-Link TL-WR886N" ;; "094000"*) model="TP-Link TL-WR940N" ;;
还有以下的 tl-wr940n-v4 相关信息行
*"TL-WR940N v4") name="tl-wr940n-v4" ;;
也需要依葫芦画瓢,添加 tl-wr886n-v5 的信息
*"TL-WR886N v5") name="tl-wr886n-v5" ;; *"TL-WR940N v4") name="tl-wr940n-v4" ;;
6、~/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
tl-wr902ac-v1|\ tl-wr940n-v4|\ tl-wr940n-v6|\ tl-wr941nd|\ tl-wr941nd-v5|\ tl-wr941nd-v6|\ ts-d084|\ wifi-pineapple-nano) local magic_ver="0100" case "$board" in tl-wdr3320-v2|tl-wdr6500-v2) magic_ver="0200" ;;
查询到 tl-wr940n-v4行,在上一行添加 tl-wr886n-v5|\
tl-wr902ac-v1|\ tl-wr886n-v5|\ tl-wr940n-v4|\ tl-wr940n-v6|\ tl-wr941nd|\ tl-wr941nd-v5|\ tl-wr941nd-v6|\ ts-d084|\ wifi-pineapple-nano) local magic_ver="0100" case "$board" in tl-wdr3320-v2|tl-wdr6500-v2) magic_ver="0200" ;;
7、~/target/linux/ar71xx/image/tiny-tp-link.mk
define Device/tl-wr940n-v4 $(Device/tplink-4mlzma) DEVICE_TITLE := TP-LINK TL-WR940N v4 BOARDNAME := TL-WR940N-v4 DEVICE_PROFILE := TLWR941 TPLINK_HWID := 0x09400004 IMAGES += factory-us.bin factory-eu.bin factory-br.bin IMAGE/factory-us.bin := append-rootfs | mktplinkfw factory -C US IMAGE/factory-eu.bin := append-rootfs | mktplinkfw factory -C EU IMAGE/factory-br.bin := append-rootfs | mktplinkfw factory -C BR endef TARGET_DEVICES += tl-wr940n-v4
查询到 tl-wr940n-v4 相关信息行,添加 tl-wr886n-v5 的信息(注:其它无关的语言固件可以删除)
define Device/tl-wr886n-v5 $(Device/tplink-4mlzma) DEVICE_TITLE := TP-LINK TL-WR886N v5 BOARDNAME := TL-WR886N-v5 DEVICE_PROFILE := TLWR941 TPLINK_HWID := 0x08860005 endef TARGET_DEVICES += tl-wr886n-v5 define Device/tl-wr940n-v4 $(Device/tplink-4mlzma) DEVICE_TITLE := TP-LINK TL-WR940N v4 BOARDNAME := TL-WR940N-v4 DEVICE_PROFILE := TLWR941 TPLINK_HWID := 0x09400004 IMAGES += factory-us.bin factory-eu.bin factory-br.bin IMAGE/factory-us.bin := append-rootfs | mktplinkfw factory -C US IMAGE/factory-eu.bin := append-rootfs | mktplinkfw factory -C EU IMAGE/factory-br.bin := append-rootfs | mktplinkfw factory -C BR endef TARGET_DEVICES += tl-wr940n-v4
8、~/target/linux/ar71xx/config-4.9
# CONFIG_ATH79_MACH_TL_WR841N_V9 is not set # CONFIG_ATH79_MACH_TL_WR902AC_V1 is not set # CONFIG_ATH79_MACH_TL_WR940N_V4 is not set
查询到 tl-wr940n-v4 相关信息行,添加 tl-wr886n-v5 的信息
# CONFIG_ATH79_MACH_TL_WR841N_V9 is not set # CONFIG_ATH79_MACH_TL_WR902AC_V1 is not set # CONFIG_ATH79_MACH_TL_WR886N_V5 is not set # CONFIG_ATH79_MACH_TL_WR940N_V4 is not set
9、~/target/linux/ar71xx/tiny/config-default
CONFIG_ATH79_MACH_TL_WR841N_V8=y CONFIG_ATH79_MACH_TL_WR841N_V9=y CONFIG_ATH79_MACH_TL_WR940N_V4=y CONFIG_ATH79_MACH_TL_WR941ND=y
查询到 tl-wr940n-v4 相关信息行,添加 tl-wr886n-v5 的信息
CONFIG_ATH79_MACH_TL_WR841N_V8=y CONFIG_ATH79_MACH_TL_WR841N_V9=y CONFIG_ATH79_MACH_TL_WR886N_V5=y CONFIG_ATH79_MACH_TL_WR940N_V4=y CONFIG_ATH79_MACH_TL_WR941ND=y
10、~/target/linux/ar71xx/files/arch/mips/ath79/machtypes.h
ATH79_MACH_TL_WR941ND_V6, /* TP-LINK TL-WR941ND v6 */ ATH79_MACH_TL_WR940N_V4, /* TP-LINK TL-WR940N v4 */
查询到 tl-wr940n-v4 相关信息行,添加 tl-wr886n-v5 的信息
ATH79_MACH_TL_WR941ND_V6, /* TP-LINK TL-WR941ND v6 */ ATH79_MACH_TL_WR886N_V5, /* TP-LINK TL-WR886N v5 */ ATH79_MACH_TL_WR940N_V4, /* TP-LINK TL-WR940N v4 */
11、~/target/linux/ar71xx/files/arch/mips/ath79/mach-tl-wr940n-v4.c
新建文件 mach-tl-wr886n-v5.c,然后将 mach-tl-wr940n-v4.c 的内容先全部拷贝过去,先将里面 wr940n-v6 特定的内容删除,再将 wr940n-v4 相关内容都一一对应换成wr886n-v5 的。
接下来,非常重要的一步,改变指示灯及按键的GPIO值,wr886n-v5 与 wr940n-v4 的相应值大部分都不一样,都需要改过来,否则路由器的相应功能都是混乱的。
以下是改好以后的 mach-tl-wr886n-v5.c 的文件内容,供大家参考:
/* * TP-LINK TL-WR886N v5 board support * * Copyright (C) 2016 David Lutz <kpanic@ff3l.net> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation. */ #include <linux/gpio.h> #include <linux/platform_device.h> #include <asm/mach-ath79/ath79.h> #include <asm/mach-ath79/ar71xx_regs.h> #include "common.h" #include "dev-eth.h" #include "dev-gpio-buttons.h" #include "dev-leds-gpio.h" #include "dev-m25p80.h" #include "dev-wmac.h" #include "machtypes.h" #define TL_WR886N_V5_GPIO_LED_WAN 2 #define TL_WR886N_V5_GPIO_LED_LAN4 7 #define TL_WR886N_V5_GPIO_LED_LAN3 6 #define TL_WR886N_V5_GPIO_LED_LAN2 5 #define TL_WR886N_V5_GPIO_LED_LAN1 4 #define TL_WR886N_V5_GPIO_LED_SYSTEM 18 #define TL_WR886N_V5_GPIO_BTN_RESET 1 #define TL_WR886N_KEYS_POLL_INTERVAL 20 #define TL_WR886N_KEYS_DEBOUNCE_INTERVAL (3 * TL_WR886N_KEYS_POLL_INTERVAL) static struct gpio_led tl_wr886n_v5_leds_gpio[] __initdata = { { .name = "tp-link:blue:wan", .gpio = TL_WR886N_V5_GPIO_LED_WAN, .active_low = 1, }, { .name = "tp-link:blue:lan1", .gpio = TL_WR886N_V5_GPIO_LED_LAN1, .active_low = 1, }, { .name = "tp-link:blue:lan2", .gpio = TL_WR886N_V5_GPIO_LED_LAN2, .active_low = 1, }, { .name = "tp-link:blue:lan3", .gpio = TL_WR886N_V5_GPIO_LED_LAN3, .active_low = 1, }, { .name = "tp-link:blue:lan4", .gpio = TL_WR886N_V5_GPIO_LED_LAN4, .active_low = 1, }, { .name = "tp-link:blue:system", .gpio = TL_WR886N_V5_GPIO_LED_SYSTEM, .active_low = 1, }, }; static struct gpio_keys_button tl_wr886n_v5_gpio_keys[] __initdata = { { .desc = "Reset button", .type = EV_KEY, .code = KEY_RESTART, .debounce_interval = TL_WR886N_KEYS_DEBOUNCE_INTERVAL, .gpio = TL_WR886N_V5_GPIO_BTN_RESET, .active_low = 1, }, }; static const char *tl_wr886n_part_probes[] = { "tp-link", NULL, }; static struct flash_platform_data tl_wr886n_flash_data = { .part_probes = tl_wr886n_part_probes, }; static void __init tl_wr886n_setup(void) { u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00); u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000); ath79_register_m25p80(&tl_wr886n_flash_data); ath79_register_mdio(0, 0x0); ath79_init_mac(ath79_eth0_data.mac_addr, mac, 1); ath79_init_mac(ath79_eth1_data.mac_addr, mac, -1); ath79_switch_data.phy4_mii_en = 1; ath79_register_eth(0); ath79_register_eth(1); ath79_register_wmac(ee, mac); } static void __init tl_wr886n_v5_setup(void) { tl_wr886n_setup(); ath79_register_leds_gpio(-1, ARRAY_SIZE(tl_wr886n_v5_leds_gpio), tl_wr886n_v5_leds_gpio); ath79_register_gpio_keys_polled(-1, TL_WR886N_KEYS_POLL_INTERVAL, ARRAY_SIZE(tl_wr886n_v5_gpio_keys), tl_wr886n_v5_gpio_keys); } MIPS_MACHINE(ATH79_MACH_TL_WR886N_V5, "TL-WR886N-v5", "TP-LINK TL-WR886N v5", tl_wr886n_v5_setup);
12、~/target/linux/ar71xx/files/arch/mips/ath79/Kconfig.openwrt
config ATH79_MACH_TL_WR940N_V4 bool "TP-LINK TL-WR940N v4 support" select SOC_QCA956X select ATH79_DEV_ETH select ATH79_DEV_GPIO_BUTTONS select ATH79_DEV_LEDS_GPIO select ATH79_DEV_M25P80 select ATH79_DEV_WMAC
查询到 tl-wr940n-v4 相关内容,添加 tl-wr886n-v5 的对应内容
config ATH79_MACH_TL_WR886N_V5 bool "TP-LINK TL-WR886N v5 support" select SOC_QCA956X select ATH79_DEV_ETH select ATH79_DEV_GPIO_BUTTONS select ATH79_DEV_LEDS_GPIO select ATH79_DEV_M25P80 select ATH79_DEV_WMAC config ATH79_MACH_TL_WR940N_V4 bool "TP-LINK TL-WR940N v4 support" select SOC_QCA956X select ATH79_DEV_ETH select ATH79_DEV_GPIO_BUTTONS select ATH79_DEV_LEDS_GPIO select ATH79_DEV_M25P80 select ATH79_DEV_WMAC
13、~/target/linux/ar71xx/files/arch/mips/ath79/Makefile
obj-$(CONFIG_ATH79_MACH_TL_WR941ND_V6) += mach-tl-wr941nd-v6.o obj-$(CONFIG_ATH79_MACH_TL_WR940N_V4) += mach-tl-wr940n-v4.o
查询到 tl-wr940n-v4 相关内容,添加 tl-wr886n-v5 的对应内容
obj-$(CONFIG_ATH79_MACH_TL_WR941ND_V6) += mach-tl-wr941nd-v6.o obj-$(CONFIG_ATH79_MACH_TL_WR886N_V5) += mach-tl-wr886n-v5.o obj-$(CONFIG_ATH79_MACH_TL_WR940N_V4) += mach-tl-wr940n-v4.o
三、配置及编译
1、先配置(注:建议直接添加luci应用)
rm -rf tmp touch target/linux/*/Makefile make menuconfig
2、编译
make -j1 V=s
编译完成后,就可以在 ~/bin/targets/ar71xx/tiny 目录下发现固件:openwrt-ar71xx-tiny-tl-wr886n-v5-squashfs-factory.bin
将新生成的固件刷入路由器,具体过程可参考 WR886N-V5刷OpenWrt固件 一文,最终Luci界面如下:
写的够详细了吧,但是你说我没有时间,不想自己编译,我就想拿现成的。OK,你可以给我邮件:hzshw@hz.cn