说明
- 改造 Mercury MW305R v3.0(芯片 9533)
- OpenWRT 版本:LEDE 17
- 环境:Ubuntu 16.04 x64
- ➀ ➁ ➂... only use to match, please remove.
第一步:修改硬件
- 换 RAN 为 64M
- 换 flash 为 16M
注:本教程主要说明制作镜像部分,具体修改硬件步骤请参考:链接
第二步:获取源码
使用以下命令克隆我当时使用的版本源码:
git clone -b lede-17.01 https://github.com/lede-project/source.git lede
第三步:target profile 添加新路由器
修改文件:/target/linux/ar71xx/image/tp-link.mk
添加以下内容:
define Device/mc-mw305r-v3➀
$(Device/tplink-16mlzma)
DEVICE_TITLE := MERCURY MC-MW305R v3➁
BOARDNAME := MC-MW305R-v3➂
TPLINK_HWID := 0x30500003
endef
TARGET_DEVICES += mc-mw305r-v3➀
删除 /tmp 目录,使用以下命令配置:
make menuconfig
-> Atheros AR7xxx/AR9xxx
-> Target Profile
[v] MERCURY MC-MW305R v3➁
在 Target System 里选择 Atheros AR7xxx/AR9xxx,然后在 Target Profile 里找到 MERCURY MC-MW305R v3 并选中。此时,编译一下,看看有没有错误。
make
make 成功后,/bin/targets/ar71xx/generic/ 目录下面会生成 MW305R 的 factory.bin,但是这时候下载到 flash 还不能启动,因为内核并没有支持 MW305R,继续下面的步骤。
第四步:kernel arch machine 新增路由器
新建文件:/build_dir/target-mips_24kc_musl/linux-ar71xx_generic/linux-4.4.74/arch/mips/ath79/mach-mc-mw305r-v3.c
文件内容:
/*
* Mercury MW305R v3
*
* Copyright (C) 2014 Matthias Schiffer <mschiffer@universe-factory.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 MC_MW305RV3_GPIO_LED_WLAN 13
#define MC_MW305RV3_GPIO_LED_WAN 4
#define MC_MW305RV3_GPIO_LED_LAN4 11
#define MC_MW305RV3_GPIO_LED_LAN3 14
#define MC_MW305RV3_GPIO_LED_LAN2 15
#define MC_MW305RV3_GPIO_LED_LAN1 16
#define MC_MW305RV3_GPIO_BTN_RESET 12
#define MC_MW305RV3_GPIO_BTN_WIFI 17
#define MC_MW305RV3_KEYS_POLL_INTERVAL 20 /* msecs */
#define MC_MW305RV3_KEYS_DEBOUNCE_INTERVAL (3 * MC_MW305RV3_KEYS_POLL_INTERVAL)
static const char *mc_mw305r_v3_part_probes[] = {
"tp-link",
NULL,
};
static struct flash_platform_data mc_mw305r_v3_flash_data = {
.part_probes = mc_mw305r_v3_part_probes,
};
static struct gpio_led mc_mw305r_v3_leds_gpio[] __initdata = {
{
.name = "mercury:green:lan1",
.gpio = MC_MW305RV3_GPIO_LED_LAN1,
.active_low = 1,
}, {
.name = "mercury:green:lan2",
.gpio = MC_MW305RV3_GPIO_LED_LAN2,
.active_low = 1,
}, {
.name = "mercury:green:lan3",
.gpio = MC_MW305RV3_GPIO_LED_LAN3,
.active_low = 1,
}, {
.name = "mercury:green:lan4",
.gpio = MC_MW305RV3_GPIO_LED_LAN4,
.active_low = 1,
}, {
.name = "mercury:green:wan",
.gpio = MC_MW305RV3_GPIO_LED_WAN,
.active_low = 1,
}, {
.name = "mercury:green:wlan",
.gpio = MC_MW305RV3_GPIO_LED_WLAN,
.active_low = 1,
.default_trigger = "heartbeat",
},
};
static struct gpio_keys_button mc_mw305r_v3_gpio_keys[] __initdata = {
{
.desc = "Reset button",
.type = EV_KEY,
.code = KEY_RESTART,
.debounce_interval = MC_MW305RV3_KEYS_DEBOUNCE_INTERVAL,
.gpio = MC_MW305RV3_GPIO_BTN_RESET,
.active_low = 1,
}, {
.desc = "WIFI button",
.type = EV_KEY,
.code = KEY_RFKILL,
.debounce_interval = MC_MW305RV3_KEYS_DEBOUNCE_INTERVAL,
.gpio = MC_MW305RV3_GPIO_BTN_WIFI,
.active_low = 1,
}
};
static void __init tl_ap143_setup(void)
{
u8 *mac = (u8 *) KSEG1ADDR(0x1f01fc00);
u8 *ee = (u8 *) KSEG1ADDR(0x1fff1000);
u8 tmpmac[ETH_ALEN];
ath79_register_m25p80(&mc_mw305r_v3_flash_data);
ath79_setup_ar933x_phy4_switch(false, false);
ath79_register_mdio(0, 0x0);
/* LAN */
ath79_eth1_data.phy_if_mode = PHY_INTERFACE_MODE_GMII;
ath79_eth1_data.duplex = DUPLEX_FULL;
ath79_switch_data.phy_poll_mask |= BIT(4);
ath79_init_mac(ath79_eth1_data.mac_addr, mac, 0);
ath79_register_eth(1);
/* WAN */
ath79_switch_data.phy4_mii_en = 1;
ath79_eth0_data.phy_if_mode = PHY_INTERFACE_MODE_MII;
ath79_eth0_data.duplex = DUPLEX_FULL;
ath79_eth0_data.speed = SPEED_100;
ath79_eth0_data.phy_mask = BIT(4);
ath79_init_mac(ath79_eth0_data.mac_addr, mac, 1);
ath79_register_eth(0);
ath79_init_mac(tmpmac, mac, 0);
ath79_register_wmac(ee, tmpmac);
}
static void __init mc_mw305r_v3_setup➄(void)
{
tl_ap143_setup();
ath79_gpio_output_select(3, AR934X_GPIO_OUT_GPIO);
ath79_gpio_output_select(4, AR934X_GPIO_OUT_GPIO);
ath79_gpio_output_select(11, AR934X_GPIO_OUT_GPIO);
ath79_gpio_output_select(14, AR934X_GPIO_OUT_GPIO);
ath79_gpio_output_select(15, AR934X_GPIO_OUT_GPIO);
ath79_gpio_output_select(16, AR934X_GPIO_OUT_GPIO);
ath79_register_leds_gpio(-1, ARRAY_SIZE(mc_mw305r_v3_leds_gpio),
mc_mw305r_v3_leds_gpio);
ath79_register_gpio_keys_polled(1, MC_MW305RV3_KEYS_POLL_INTERVAL,
ARRAY_SIZE(mc_mw305r_v3_gpio_keys),
mc_mw305r_v3_gpio_keys);
}
MIPS_MACHINE(ATH79_MACH_MC_MW305R➃, "MC-MW305R-v3➂", "MERCURY MC-MW305R v3➋",
mc_mw305r_v3_setup➄);
修改文件:/build_dir/target-mips_24kc_musl/linux-ar71xx_generic/linux-4.4.74/arch/mips/ath79/Kconfig
添加以下内容:
config ATH79_MACH_MC_MW305R➅
bool "MERCURY MC-MW305R v3 support➇"
select SOC_AR933X
select ATH79_DEV_ETH
select ATH79_DEV_GPIO_BUTTONS
select ATH79_DEV_LEDS_GPIO
select ATH79_DEV_M25P80
select ATH79_DEV_WMAC
help
Say 'Y' here if you want your kernel to support the
MERCURY MC-MW305R v3➋.
修改文件:/build_dir/target-mips_24kc_musl/linux-ar71xx_generic/linux-4.4.74/arch/mips/ath79/machtypes.h
添加以下内容:
ATH79_MACH_MC_MW305R➃,
修改文件:/build_dir/target-mips_24kc_musl/linux-ar71xx_generic/linux-4.4.74/arch/mips/ath79/Makefile
添加以下内容:
obj-$(CONFIG_ATH79_MACH_MC_MW305R➅) += mach-mc-mw305r-v3➊.o
使用以下命令配置:
make kernel_menuconfig
-> Machine selection
-> Atheros AR71XX/AR724X/AR913X machine selection
MERCURY MC-MW305R v3 support➇
此时,编译一次看看有没有问题:
make
make 成功后,如果直接固件下载到 flash,已经能启动了,但会出现网络问题,继续看第五步。
第五步:network 配置问题(ar71xx系列)
修改文件:/target/linux/ar71xx/base-files/lib/ar71xx.sh
添加以下内容:
*"MC-MW305R v3➋"*)
name="mc-mw305r-v3➆"
;;
修改文件:/target/linux/ar71xx/base-files/etc/board.d/02_network
添加以下内容:
mc-mw305r-v3➆)
ucidef_set_interfaces_lan_wan "eth0.1" "eth1"
ucidef_add_switch "switch0" \
"0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1"
;;
此时,再编译一次看看有没有问题:
make
make 成功后,如果下载固件到 flash,网络已经没问题了,但是会发现 LED 灯工作得不正常,继续看第六步。
第六步:LED 灯问题
修改文件:/target/linux/ar71xx/base-files/etc/board.d/01_leds
添加以下内容:
mc-mw305r-v3➆)
ucidef_set_led_netdev "wan" "WAN" "mercury:green:wan" "eth1"
ucidef_set_led_switch "lan0" "LAN0" "mercury:green:lan1" "switch0" "0x10"
ucidef_set_led_switch "lan1" "LAN1" "mercury:green:lan2" "switch0" "0x08"
ucidef_set_led_switch "lan2" "LAN2" "mercury:green:lan3" "switch0" "0x04"
ucidef_set_led_switch "lan3" "LAN3" "mercury:green:lan4" "switch0" "0x02"
ucidef_set_led_wlan "wlan" "WLAN" "mercury:green:wlan" "phy0tpt"
;;
这时候已经大功告成了,最后编译一次:
make