ACRH17适配OPENWRT

环境配置说明

  • 适用硬件:ASUS RT ACRH17
  • 编译系统:Debian For Win10 WSL
  • 参考借鉴:lede源添加acrh17
  1. 稳定版19.07无法识别和使用5G无线网卡,而Master分支可用但无法开启160MHZ
  2. 注意不要使用root用户编译,最好使用梯子来加速源码的下载速度
  3. 使用Win10 WSL环境编译的,编译前建议先将Win10系统变量剔除,否则可能报错:export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
1
2
3
4
5
6
# ASUS RT ACRH17 的配置
CPU : IPQ4019 @ 717MHz (Quad ARM Cortex A7)
RAM : 256MB NT5CC128M16IP-DI
ROM : 128MB MX30LF1G18AC-TI
2.4G: IPQ4019 + RTC6649EX
5 G : QCA9984 + QFE1952

获取编译源码

1
2
3
4
5
6
7
8
# 安装配置编译环境
sudo apt-get update
sudo apt-get install build-essential asciidoc binutils bzip2 \
gawk gettext git libncurses5-dev libz-dev patch unzip zlib1g-dev \
lib32gcc1 libc6-dev-i386 subversion flex uglifyjs libssl-dev upx \
gcc-multilib p7zip p7zip-full msmtp texinfo libglib2.0-dev xmlto \
git-core qemu-utils libelf-dev autoconf automake libtool autopoint \
curl wget device-tree-compiler
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 设置代理来加速源码下载,没有代理可跳过或根据需求设置
# export http_proxy="127.0.0.1:7890" && export https_proxy="127.0.0.1:7890"

# 获取openwrt官方源码及更新软件包
git clone https://github.com/openwrt/openwrt.git
./scripts/feeds update -a && ./scripts/feeds install -a

make menuconfig # 进入固件配置界面,下面是极简的参数配置
##########################################################
## Target System -> Qualcomm Atheros IPQ40XX ##
## Subtarget -> Generic ##
## Target Profile -> Asus RT-ACRH17 ##
## LuCI -> Collections -> luci ##
## LuCI -> Modules -> Translations -> Chinese(zh_Hans) ##
## LuCI -> Themes -> luci-theme-material ##
##########################################################

make download -j8 V=s # 下载所需源码,请尽量使用梯子
make -j5 V=s # 首次编译推荐用单线程

添加设备源码

  1. 为ACRH17适配官方OPENWRT需要修改和添加以下文件
1
2
3
4
5
6
7
8
9
10
11
12
13
# 要修改的基本文件,用于添加ARCH17设备
target/linux/ipq40xx/base-files/etc/board.d/01_leds
target/linux/ipq40xx/base-files/etc/board.d/02_network
target/linux/ipq40xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
target/linux/ipq40xx/base-files/lib/preinit/05_set_iface_mac_ipq40xx.sh
target/linux/ipq40xx/base-files/lib/upgrade/platform.sh
target/linux/ipq40xx/files/arch/arm/boot/dts/qcom-ipq4019-rt-acrh17.dts
target/linux/ipq40xx/image/Makefile
target/linux/ipq40xx/patches-5.4/901-arm-boot-add-dts-files.patch

# 用来开启5G无线网络的驱动,不用可忽略
openwrt/package/firmware/ipq-wifi/Makefile
openwrt/package/firmware/ipq-wifi/board-asus_rt-acrh17.qca4019
  1. 修改 01_leds 来设置LED灯的状态
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
--- openwrt-master/target/linux/ipq40xx/base-files/etc/board.d/01_leds	2020-12-06 19:35:18.471161900 +0800
+++ lede/target/linux/ipq40xx/base-files/etc/board.d/01_leds 2020-12-07 20:02:28.238898600 +0800
@@ -17,6 +17,16 @@ asus,rt-ac58u)
ucidef_set_led_netdev "wan" "WAN" "blue:wan" "eth1"
ucidef_set_led_switch "lan" "LAN" "blue:lan" "switch0" "0x1e"
;;
+asus,rt-acrh17)
+ ucidef_set_led_default "status" "STATUS" "${boardname}:blue:status" "1"
+ ucidef_set_led_wlan "wlan2g" "WLAN2G" "${boardname}:blue:wlan2g" "phy1tpt"
+ ucidef_set_led_wlan "wlan5g" "WLAN5G" "${boardname}:blue:wlan5g" "phy0tpt"
+ ucidef_set_led_netdev "wan" "WAN" "${boardname}:blue:wan" "eth1"
+ ucidef_set_led_switch "lan1" "LAN1" "${boardname}:blue:lan1" "switch0" "0x02"
+ ucidef_set_led_switch "lan2" "LAN2" "${boardname}:blue:lan2" "switch0" "0x04"
+ ucidef_set_led_switch "lan3" "LAN3" "${boardname}:blue:lan3" "switch0" "0x08"
+ ucidef_set_led_switch "lan4" "LAN4" "${boardname}:blue:lan4" "switch0" "0x10"
+ ;;
avm,fritzbox-4040)
ucidef_set_led_wlan "wlan" "WLAN" "green:wlan" "phy0tpt" "phy1tpt"
ucidef_set_led_netdev "wan" "WAN" "green:wan" "eth1"
  1. 修改 02_network 来设置网卡
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
--- openwrt-master/target/linux/ipq40xx/base-files/etc/board.d/02_network	2020-12-06 19:35:18.471161900 +0800
+++ lede/target/linux/ipq40xx/base-files/etc/board.d/02_network 2020-12-06 20:20:59.048078800 +0800
@@ -45,6 +45,7 @@ ipq40xx_setup_interfaces()
openmesh,a62)
ucidef_set_interfaces_lan_wan "eth1" "eth0"
;;
+ asus,rt-acrh17|\
asus,rt-ac58u|\
zyxel,nbg6617)
ucidef_set_interfaces_lan_wan "eth0" "eth1"
@@ -126,6 +127,7 @@ ipq40xx_setup_macs()
8dev,habanero-dvk)
label_mac=$(mtd_get_mac_binary "ART" 0x1006)
;;
+ asus,rt-acrh17|\
asus,rt-ac58u)
CI_UBIPART=UBI_DEV
wan_mac=$(mtd_get_mac_binary_ubi Factory 0x1006)
  1. 修改 11-ath10k-caldata 选择SOC要加载的固件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
--- openwrt-master/target/linux/ipq40xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata	2020-12-06 19:35:18.471161900 +0800
+++ lede/target/linux/ipq40xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata 2020-12-06 20:23:12.333528800 +0800
@@ -23,6 +23,10 @@ case "$FIRMWARE" in
ln -sf /lib/firmware/ath10k/pre-cal-pci-0000\:00\:00.0.bin \
/lib/firmware/ath10k/QCA9888/hw2.0/board.bin
;;
+ asus,rt-acrh17)
+ CI_UBIPART=UBI_DEV
+ caldata_extract_ubi "Factory" 0x9000 0x2f20
+ ;;
avm,fritzrepeater-3000)
/usr/bin/fritz_cal_extract -i 1 -s 0x3D000 -e 0x212 -l 12064 -o /lib/firmware/$FIRMWARE $(find_mtd_chardev "urlader0") || \
/usr/bin/fritz_cal_extract -i 1 -s 0x3C800 -e 0x212 -l 12064 -o /lib/firmware/$FIRMWARE $(find_mtd_chardev "urlader0") || \
@@ -70,6 +74,7 @@ case "$FIRMWARE" in
asus,map-ac2200)
caldata_extract_ubi "Factory" 0x1000 0x2f20
;;
+ asus,rt-acrh17|\
asus,rt-ac58u)
CI_UBIPART=UBI_DEV
caldata_extract_ubi "Factory" 0x1000 0x2f20
  1. 修改 05_set_iface_mac_ipq40xx.sh 来设置MAC
1
2
3
4
5
6
7
8
9
10
--- openwrt-master/target/linux/ipq40xx/base-files/lib/preinit/05_set_iface_mac_ipq40xx.sh	2020-12-06 19:35:18.471161900 +0800
+++ lede/target/linux/ipq40xx/base-files/lib/preinit/05_set_iface_mac_ipq40xx.sh 2020-12-06 20:24:32.822407600 +0800
@@ -2,6 +2,7 @@

preinit_set_mac_address() {
case $(board_name) in
+ asus,rt-acrh17|\
asus,map-ac2200)
base_mac=$(mtd_get_mac_binary_ubi Factory 0x1006)
ip link set dev eth0 address $(macaddr_add "$base_mac" +1)
  1. 修改 platform.sh 来设置升级时的操作
1
2
3
4
5
6
7
8
9
10
--- openwrt-master/target/linux/ipq40xx/base-files/lib/upgrade/platform.sh	2020-12-06 19:35:18.471161900 +0800
+++ lede/target/linux/ipq40xx/base-files/lib/upgrade/platform.sh 2020-12-06 20:27:50.792301100 +0800
@@ -89,6 +89,7 @@ platform_do_upgrade() {
CI_KERNPART="linux"
nand_do_upgrade "$1"
;;
+ asus,rt-acrh17|\
asus,rt-ac58u)
CI_UBIPART="UBI_DEV"
CI_KERNPART="linux"
  1. 添加 qcom-ipq4019-rt-acrh17.dts 用来生成DTB设备树
1
2
wget -O target/linux/ipq40xx/files/arch/arm/boot/dts/qcom-ipq4019-rt-acrh17.dts \
https://github.com/coolsnowwolf/lede/raw/master/target/linux/ipq40xx/files/arch/arm/boot/dts/qcom-ipq4019-rt-acrh17.dts
  1. 最重要的来了,修改 image/Makefile 来添加ACRH17设备
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
--- openwrt-master/target/linux/ipq40xx/image/Makefile	2020-12-06 19:35:18.519107200 +0800
+++ lede/target/linux/ipq40xx/image/Makefile 2020-12-06 20:42:35.496598100 +0800
@@ -202,6 +202,24 @@ define Device/asus_rt-ac58u
endef
TARGET_DEVICES += asus_rt-ac58u

+define Device/asus_rt-acrh17
+ $(call Device/FitImageLzma)
+ DEVICE_VENDOR := ASUS
+ DEVICE_MODEL := RT-ACRH17
+ SOC := qcom-ipq4019
+ BLOCKSIZE := 128k
+ PAGESIZE := 2048
+ DTB_SIZE := 65536
+ IMAGE_SIZE := 20439364
+ FILESYSTEMS := squashfs
+ UIMAGE_NAME:=$(shell echo -e '\03\01\01\01RT-ACRH17')
+ KERNEL_INITRAMFS := $$(KERNEL) | uImage none
+ KERNEL_INITRAMFS_SUFFIX := -factory.trx
+ IMAGES := sysupgrade.bin
+ DEVICE_PACKAGES := ath10k-firmware-qca9984-ct ipq-wifi-asus_rt-acrh17 kmod-usb-ledtrig-usbport
+endef
+TARGET_DEVICES += asus_rt-acrh17
+
define Device/avm_fritzbox-4040
$(call Device/FitImageLzma)
DEVICE_VENDOR := AVM
  1. 修改 901-arm-boot-add-dts-files.patch 来添加ACRH17的DTB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
--- openwrt-master/target/linux/ipq40xx/patches-5.4/901-arm-boot-add-dts-files.patch	2020-12-06 19:35:18.534728700 +0800
+++ lede/target/linux/ipq40xx/patches-5.4/901-arm-boot-add-dts-files.patch 2020-12-06 20:44:15.513499900 +0800
@@ -10,7 +10,7 @@ Signed-off-by: John Crispin <john@phroze

--- a/arch/arm/boot/dts/Makefile
+++ b/arch/arm/boot/dts/Makefile
-@@ -837,11 +837,54 @@ dtb-$(CONFIG_ARCH_QCOM) += \
+@@ -837,11 +837,55 @@ dtb-$(CONFIG_ARCH_QCOM) += \
qcom-apq8074-dragonboard.dtb \
qcom-apq8084-ifc6540.dtb \
qcom-apq8084-mtp.dtb \
@@ -53,6 +53,7 @@ Signed-off-by: John Crispin <john@phroze
+ qcom-ipq4019-habanero-dvk.dtb \
+ qcom-ipq4019-rtl30vw.dtb \
+ qcom-ipq4019-u4019-32m.dtb \
++ qcom-ipq4019-rt-acrh17.dtb \
+ qcom-ipq4019-wpj419.dtb \
+ qcom-ipq4019-wtr-m2133hp.dtb \
+ qcom-ipq4028-wpj428.dtb \
  1. 修改 package/firmware/ipq-wifi/Makefile 驱动QCA9984网卡
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
--- openwrt-master/package/firmware/ipq-wifi/Makefile	2020-12-06 19:35:15.873926900 +0800
+++ lede/package/firmware/ipq-wifi/Makefile 2020-12-06 20:48:09.827242400 +0800
@@ -27,6 +27,7 @@ endef
ALLWIFIBOARDS:= \
8dev_habanero-dvk \
aruba_ap-303 \
+ asus_rt-acrh17 \
avm_fritzrepeater-1200 \
buffalo_wtr-m2133hp \
cellc_rtl30vw \
@@ -105,6 +106,7 @@ endef

$(eval $(call generate-ipq-wifi-package,8dev_habanero-dvk,8devices Habanero DVK))
$(eval $(call generate-ipq-wifi-package,aruba_ap-303,Aruba AP-303))
+$(eval $(call generate-ipq-wifi-package,asus_rt-acrh17,ASUS RT-ACRH17))
$(eval $(call generate-ipq-wifi-package,avm_fritzrepeater-1200,AVM FRITZRepeater 1200))
$(eval $(call generate-ipq-wifi-package,buffalo_wtr-m2133hp,Buffalo WTR-M2133HP))
$(eval $(call generate-ipq-wifi-package,cellc_rtl30vw, Cell C RTL30VW))
  1. 添加 board-asus_rt-acrh17.qca4019 固件文件
1
2
wget  -O lede/package/firmware/ipq-wifi/board-asus_rt-acrh17.qca4019 \
https://github.com/coolsnowwolf/lede/raw/master/package/firmware/ipq-wifi/board-asus_rt-acrh17.qca4019

其他实用技巧

  1. 再次编译时可能要用到的参数

    1
    2
    3
    4
    5
    6
    7
    8
    # 获取最新源码及重置软件包源
    git pull && ./scripts/feeds clean
    ./scripts/feeds update -a && ./scripts/feeds install -a

    # 再次编译前建议使用make clean清理
    make clean # 清除bin目录
    make dirclean # 清除bin目录和交叉编译工具及工具链目录
    make distclean # 清除所有相关的东西,包括下载的软件包,配置文件,feed内容等
  2. 额外配置内核参数,一般不需要配置

    1
    2
    3
    4
    # 在OpenWRT的 `.config` 文件中内核的选项都是形如 `CONFIG_KERNEL_XXX` 
    # 自己手动添加内核选项时不要忘了在中间添加 `_KERNEL_` 前缀
    # 只能包含到内核而不能作为模块,因为编译后的模块不会添加到固件内
    # make kernel_menuconfig # 进入内核配置界面
  3. 使用自有软件包源

    1
    2
    3
    4
    5
    6
    7
    # 生成自有软件包的索引
    openwrt/scripts/ipkg-make-index.sh ./ipkg-dir > Packages
    gzip -9c Packages > Packages.gz

    # 上传到路由器并添加源
    ln -s /mnt/sda1/packages/ /www/
    src/gz 19.02_packages http://192.168.1.1/packages
  4. 编译所有包(CONFIG_ALL=y)耗时很长且经常出错,lean源无效。

1
2
3
4
Global build settings --->
[*] Select all target specific packages by default
[*] Select all kernel module packages by default
[*] Select all userspace packages by default