AX86U的梅林固件编译

环境配置说明

1
2
3
4
5
6
7
CPU		BCM4908 Quad 1.8GHz Cortex-A53 28nm
RAM 1G DDR3
ROM 256MB
5G BCM43684 4×4mimo 4804Mbps
2.4G BCM6710 3×3mimo 861Mbps
LAN/WAN 2.5G×1/1G×5 BCM54991/RTL8226B
USB 3.1×2

1. 安装所需依赖

1
2
3
4
5
6
7
8
9
10
11
12
13
sudo dpkg --add-architecture i386	# 开启32位程序支持
sudo dpkg-reconfigure dash # 在提示中选NO把默认dash切换为bash
sudo apt update

sudo apt install tar bzip2 unzip python perl flex make pkg-config \
gcc-multilib g++-multilib g++ cmake autoconf automake bison patch \
autopoint autogen automake-1.15 build-essential intltool xsltproc \
subversion git cvs m4 uuid-dev groff-base gettext gperf file gawk \
sed shtool texinfo gconf-editor diffutils libslang2 gtk-doc-tools \
gitk xutils-dev zlib1g zlib1g-dev libxml-parser-perl libproxy-dev \
libncurses5 libncurses5-dev libncurses5-dev libxml2-dev mtd-utils \
libexpat1-dev libvorbis-dev libglib2.0-dev libssl-dev liblzo2-dev \
libtool-bin libtool lib32z1-dev lib32stdc++6 libelf1:i386

2. 获取官方源码

1
2
3
4
5
6
7
8
9
10
11
12
# 如果网络不好可以设置代理
# 可以通过cat /etc/resolv.conf来查看Win10系统的IP
# export http_proxy="127.0.0.1:7890"
# export https_proxy="127.0.0.1:7890"

# 获取编译要用的工具链和最新的官方源码
cd $HOME && mkdir ~/amng-build
git clone https://github.com/RMerl/am-toolchains
git clone https://github.com/RMerl/asuswrt-merlin.ng ~/amng-build

# 最好指定获取版本(例如:386.4,386.5_2,386.7_2),因为某些版本不是给AX86U准备的会报错
git clone --depth=1 -b 386.4 https://github.com/RMerl/asuswrt-merlin.ng ~/last-release

3. 配置环境变量

1
2
3
4
5
6
7
8
sudo ln -s ~/am-toolchains/brcm-arm-hnd /opt/toolchains

echo "export TOOLCHAIN_BASE=/opt/toolchains" >> ~/.profile
echo "PATH=\$PATH:/opt/toolchains/crosstools-arm-gcc-5.5-linux-4.1-glibc-2.26-binutils-2.28.1/usr/bin" >> ~/.profile
echo "PATH=\$PATH:/opt/toolchains/crosstools-aarch64-gcc-5.5-linux-4.1-glibc-2.26-binutils-2.28.1/usr/bin" >> ~/.profile
echo "export LD_LIBRARY_PATH=\$LD_LIBRARY:/opt/toolchains/crosstools-arm-gcc-5.5-linux-4.1-glibc-2.26-binutils-2.28.1/usr/lib" >> ~/.profile

source ~/.profile

4. 开始编译系统

1
2
3
4
5
6
7
# I9 9700K配16G内存及SSD在半小时左右可以编译完成
cd ~/amng-build/release/src-rt-5.02p1axhnd.675x
make rt-ax86u

# 如果编译成功的话,在下面路径中将生成适用于AX86U的梅林固件
~/amng-build/release/src-rt-5.02p1axhnd.675x/targets/962118GW/
RT-AX86U_386.4_0_cferom_pureubi.w

5. 错误解决方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/home/leux/last-release/release/src/router/wget/build-aux/missing: line 81: aclocal-1.15: command not found
WARNING: 'aclocal-1.15' is missing on your system.
...
/home/leux/last-release/release/src/router/wget/build-aux/missing: line 81: automake-1.15: command not found
WARNING: 'automake-1.15' is missing on your system.

解决:automake --version 版本不匹配
sudo ln -s /usr/bin/aclocal /usr/bin/aclocal-1.15
sudo ln -s /usr/bin/automake /usr/bin/automake-1.15

Ubuntu 20.04编译386.3_2需要安装这个:
sudo apt install automake-1.15

Ubuntu 18.04编译386.4需要这样:
解决:automake --version 版本不匹配
sudo ln -s /usr/bin/aclocal /usr/bin/aclocal-1.16
sudo ln -s /usr/bin/automake /usr/bin/automake-1.16
1
2
3
4
5
6
7
8
9
10
# 注意:WSL2上没有这个问题是WSL一代上的
# 原因是WSL一代不支持运行32位linux程序,而梅林的工具链是32位的,所以在WSL一代上不能正常编译。
/bin/sh: /opt/toolchains/crosstools-aarch64-gcc-5.5-linux-4.1-glibc-2.26-binutils-2.28.1/usr/bin/aarch64-buildroot-linux-gnu-gcc: cannot execute binary file: Exec format error

# 但是可以通过安装运行qemu和binfmt来模拟运行ELF-32程序
sudo apt update && sudo apt install qemu-user-static
sudo update-binfmts --install i386 /usr/bin/qemu-i386-static --magic '\x7fELF\x01\x01\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x03\x00\x01\x00\x00\x00' --mask '\xff\xff\xff\xff\xff\xff\xff\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xf8\xff\xff\xff\xff\xff\xff\xff'

# 每次重启 WSL1 后如果需要 i386 的支持需要以下命令
sudo service binfmt-support start