ASUSWRT添加其他软件到固件

自定义内核的设置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 修改官方AX86U预设的内核配置,其他设备自测
vi ~/asuswrt/release/src-rt-5.02p1axhnd.675x/kernel/linux-4.1/config_base.6a.62118

# 例如将USB转串口驱动option模块编进内核,将以下默认的值设置为y
CONFIG_USB=m
CONFIG_USB_SUPPORT=y
CONFIG_USB_COMMON=m
CONFIG_USB_SERIAL=m
CONFIG_USB_SERIAL_WWAN=m
CONFIG_USB_SERIAL_OPTION=m
CONFIG_USB_SERIAL_CONSOLE=m


# 也可通过字符界面配置内核, config_rt-ax86u需要编译一次才会出现,因为它是几个文件合成的
cd ~/asuswrt/release/src-rt-5.02p1axhnd.675x/kernel/linux-4.1/
make ARCH=arm64 menuconfig config_rt-ax86u

更改软件编译配置

1
2
3
4
5
6
# 例如为默认BUSYBOX添加MICROCOM支持
vi ~/asuswrt/release/src/router/busybox-1.24.1/busybox-1.24.1/config_base
CONFIG_MICROCOM=y # 修改或添加该行

# 编译完成后可使用microcom操作模块,Ctrl + Z 退出
microcom -s 115200 /dev/ttyUSB2

单独编译某个软件

1
2
3
4
5
# 软件包的编译在 ~/asuswrt/release/src/router/Makefile 中定义
cd ~/asuswrt/release/src-rt-5.02p1axhnd.675x
make file-5.43
make htop-3.2.1-clean
make quectel-CM-install

编译添加file命令

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
28
#####################################################################
# 编译file需要指定版本的magic.mgc数据,可先从其他编译好的包中提取:/usr/share/file/misc/magic.mgc
# http://mirrors.ustc.edu.cn/archlinuxarm/aarch64/core/file-5.43-1-aarch64.pkg.tar.xz
# wget https://astron.com/pub/file/file-5.43.tar.gz -P ~/prebuilt
# tar -xzvf ~/prebuilt/file-5.43.tar.gz -C ~/asuswrt/release/src/router/
# cp /home/leux/prebuilt/magic.mgc /home/leux/asuswrt/release/src/router/file-5.43/magic/magic.mgc
#####################################################################
# 在 ~/asuswrt/release/src/router/Makefile 中1684行后面添加如下:
obj-y += file-5.43

# 在 ~/asuswrt/release/src/router/Makefile 中8842行后面添加如下:
file-5.43/Makefile: file-5.43/configure
cd file-5.43 && $(CONFIGURE) \
--prefix=/usr --exec_prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib \
--sysconfdir=/etc --datadir=/usr/share --localstatedir=/var --mandir=/usr/man \
--disable-shared --enable-static

file-5.43: file-5.43/Makefile
@$(SEP)
cd file-5.43 && $(MAKE)

file-5.43-clean:
[ ! -f file-5.43/Makefile ] || $(MAKE) -C file-5.43 distclean

file-5.43-install: file-5.43
install -D file-5.43/src/file $(INSTALLDIR)/file-5.43/usr/bin/file
install -D -m 644 file-5.43/magic/magic.mgc $(INSTALLDIR)/file-5.43/usr/share/misc/magic.mgc
$(STRIP) $(INSTALLDIR)/file-5.43/usr/bin/file

添加移远拨号工具

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 添加quectel-CM到固件内,解压quectel-CM源码到指定路径
# wget https://forums.quectel.com/uploads/short-url/v9dGj5GFz9BVjaAS4s3hMEIQLUO.zip -P ~/prebuilt
# unzip -d ~/asuswrt/release/src/router ~/prebuilt/QConnectManager_Linux_V1.6.1.zip

# 在 ~/asuswrt/release/src/router/Makefile 中1684行后面添加如下:
obj-y += quectel-CM

# 在 ~/asuswrt/release/src/router/Makefile 中8842行后面添加如下:
quectel-CM:
$(MAKE) -C $@

quectel-CM-install: quectel-CM
install -D quectel-CM/quectel-CM $(INSTALLDIR)/usr/sbin/quectel-CM
install -D -m 755 busybox-1.24.1/busybox-1.24.1/examples/udhcp/simple.script $(INSTALLDIR)/usr/share/udhcpc/default.script
@$(STRIP) $(INSTALLDIR)/usr/sbin/quectel-CM

quectel-CM-clean:
$(MAKE) -C quectel-CM clean

将预编译拷到固件

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
28
29
30
31
32
33
34
35
36
37
38
39
# 交叉编译htop的依赖ncurses库
wget https://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.3.tar.gz
tar -xzvf ncurses-6.3.tar.gz && cd ncurses-6.3
../configure --host=arm-buildroot-linux-gnueabi \
--prefix=/usr --exec_prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib \
--sysconfdir=/etc --datadir=/usr/share --localstatedir=/var --mandir=/usr/man \
--without-normal --without-tests --without-progs --without-manpages \
--disable-home-terminfo --disable-termcap --disable-database \
--with-fallbacks="xterm,vt100,vt200,linux,ansi,xterm-256color"

make && make DESTDIR=/home/leux install

# 交叉编译htop
wget https://github.com/htop-dev/htop/releases/download/3.2.1/htop-3.2.1.tar.xz
xz -d htop-3.2.1.tar.xz && tar -xvf htop-3.2.1.tar && cd htop-3.2.1
../configure --host=arm-buildroot-linux-gnueabi --disable-unicode --enable-static \
--prefix=/usr --exec_prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib \
--sysconfdir=/etc --datadir=/usr/share --localstatedir=/var --mandir=/usr/man \
LDFLAGS=-L/home/leux/usr/lib CPPFLAGS=-I/home/leux/usr/include

make && arm-buildroot-linux-gnueabi-strip htop

# 将编译好的文件复制到指定路径备用,ax86默认是xterm而htop依赖terminfo
cp ~/htop-3.2.1/htop ~/prebuilt/htop-prebuilt/htop
cp ~/usr/usr/share/terminfo/x/xterm ~/prebuilt/htop-prebuilt/xterm


###########################################################
# cp ~/prebuilt/htop-prebuilt ~/asuswrt/release/src/router/htop-prebuilt

# 在 ~/asuswrt/release/src/router/Makefile 中1684行后面添加如下:
obj-y += htop-prebuilt

# 在 ~/asuswrt/release/src/router/Makefile 中8842行后面添加如下:
htop-prebuilt:
install -D -m 755 htop-prebuilt/htop $(INSTALLDIR)/usr/bin/htop

htop-prebuilt-install: htop-prebuilt
install -D -m 644 htop-prebuilt/xterm $(INSTALLDIR)/usr/share/terminfo/x/xterm

编译 htop 到固件

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# 在 ~/asuswrt/release/src/router/Makefile 中1684行后面添加如下:
obj-y += ncurses-6.0

# 官方源码里面自带了ncurses库的源码,configure 中添加 --with-terminfo-dirs 即可
ncurses-6.0/Makefile: ncurses-6.0/configure
cd ncurses-6.0 && $(CONFIGURE)\
--prefix=/usr --exec_prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib\
--sysconfdir=/etc --datadir=/usr/share --localstatedir=/var --mandir=/usr/man\
--without-normal --with-debug --with-shared\
--without-tests --without-progs --without-manpages \
--with-terminfo-dirs=/usr/share/terminfo \
CFLAGS="-I$(STAGEDIR)/usr/local/include"\
LDFLAGS="-L$(STAGEDIR)/usr/local/lib -ldl -lpthread"

ncurses-6.0: ncurses-6.0/Makefile
$(MAKE) -C $@ && $(MAKE) $@-stage

ncurses-6.0-clean:
[ ! -f ncurses-6.0/Makefile ] || $(MAKE) -C ncurses-6.0 distclean

ncurses-6.0-install: ncurses-6.0
install -D ncurses-6.0/lib/libform.so.6.0 $(INSTALLDIR)/ncurses-6.0/usr/lib/libform.so.6.0
install -D ncurses-6.0/lib/libmenu.so.6.0 $(INSTALLDIR)/ncurses-6.0/usr/lib/libmenu.so.6.0
install -D ncurses-6.0/lib/libncurses.so.6.0 $(INSTALLDIR)/ncurses-6.0/usr/lib/libncurses.so.6.0
install -D ncurses-6.0/lib/libpanel.so.6.0 $(INSTALLDIR)/ncurses-6.0/usr/lib/libpanel.so.6.0
$(STRIP) $(INSTALLDIR)/ncurses-6.0/usr/lib/libform.so.6.0
$(STRIP) $(INSTALLDIR)/ncurses-6.0/usr/lib/libmenu.so.6.0
$(STRIP) $(INSTALLDIR)/ncurses-6.0/usr/lib/libncurses.so.6.0
$(STRIP) $(INSTALLDIR)/ncurses-6.0/usr/lib/libpanel.so.6.0
cd $(INSTALLDIR)/ncurses-6.0/usr/lib && \
ln -sf libncurses.so.6.0 libncurses.so.6 &&\
ln -sf libncurses.so.6.0 libncurses.so &&\
ln -sf libform.so.6.0 libform.so.6 &&\
ln -sf libform.so.6.0 libform.so &&\
ln -sf libmenu.so.6.0 libmenu.so.6 &&\
ln -sf libmenu.so.6.0 libmenu.so &&\
ln -sf libpanel.so.6.0 libpanel.so.6 &&\
ln -sf libpanel.so.6.0 libpanel.so

###############################################################################
# wget https://github.com/htop-dev/htop/releases/download/3.2.1/htop-3.2.1.tar.xz -P ~/prebuilt
# xz -d ~/prebuilt/htop-3.2.1.tar.xz && tar -xvf ~/prebuilt/htop-3.2.1.tar -C ~/asuswrt/release/src/router/
# 在 ~/asuswrt/release/src/router/Makefile 中1684行后面添加如下:
obj-y += htop-3.2.1

# 在 ~/asuswrt/release/src/router/Makefile 中8842行后面添加如下:
htop-3.2.1/Makefile: htop-3.2.1/configure
cd htop-3.2.1 && $(CONFIGURE) \
CFLAGS="$(EXTRACFLAGS) -Os -I$(TOP)/ncurses-6.0/include -ffunction-sections -fdata-sections -fPIC" \
LDFLAGS="$(LDFLAGS) -L$(TOP)/ncurses-6.0/lib -ffunction-sections -fdata-sections -Wl,--gc-sections" \
PKG_CONFIG_LIBDIR="$(TOP)/ncurses-6.0/misc" PKG_CONFIG_PATH="$(TOP)/ncurses-6.0/misc" \
--prefix=/usr --exec_prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib \
--sysconfdir=/etc --datadir=/usr/share --localstatedir=/var --mandir=/usr/man --disable-unicode

htop-3.2.1: ncurses-6.0 htop-3.2.1/Makefile
@$(SEP)
cd htop-3.2.1 && $(MAKE)

htop-3.2.1-clean:
[ ! -f htop-3.2.1/Makefile ] || $(MAKE) -C htop-3.2.1 distclean

htop-3.2.1-install: htop-3.2.1
install -D htop-3.2.1/htop $(INSTALLDIR)/htop-3.2.1/usr/bin/htop
install -D -m 644 $(STAGEDIR)/usr/share/terminfo/x/xterm $(INSTALLDIR)/htop-3.2.1/usr/share/terminfo/x/xterm
$(STRIP) $(INSTALLDIR)/htop-3.2.1/usr/bin/htop

修改预设文件及包

1
2
3
4
5
6
7
8
9
10
11
12
13
# 固件的编译参数再固件内的位置:/rom/etc/build_profile -> 962118GW
~/asuswrt/release/src/router/rom/apps_scripts/ # 获取 模块,APP,真实IP 等信息的相关脚本
~/asuswrt/release/src/router/rom/packages/ # 下载大师,optware等预设应用

# 以下文件都会被拷到固件内指定位置,可以修改相关设置
~/asuswrt/release/src/router/rom/rom/etc/profile.hnd # /etc/profile
~/asuswrt/release/src/router/rom/rom/etc/ld.so.conf # /etc/ld.so.conf
~/asuswrt/release/src/router/rom/rom/etc/resolv.conf # /etc/resolv.conf
~/asuswrt/release/src-rt-5.02p1axhnd.675x/targets/fs.src/rom/etc/ # /rom/etc/
~/asuswrt/release/src-rt-5.02p1axhnd.675x/targets/fs.src/rom/etc/fstab # /rom/etc/fstab
~/asuswrt/release/src-rt-5.02p1axhnd.675x/targets/fs.src/rom/etc/ppp/options # /rom/etc/ppp/options
~/asuswrt/release/src/router/comgt-0.32/scripts/devices/ # 包含/etc/ppp/3g/内所有拨号脚本
~/asuswrt/release/src/router/rom/spn_asus.dat # /rom/spn_asus.dat 记录了所有APN信息

编译中的相关变量

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 根据如上的config_base和Makefile生成config_rt-ax86u
~/asuswrt/release/src/router/config_base # 是否编译某软件的变量
# RTCONFIG_WEBDAV is not set
# RTCONFIG_USB_MODEM is not set

~/asuswrt/release/src/router/Makefile # 是否编译包含软件包在这确定
obj-y += busybox-1.24.1
obj-$(RTCONFIG_WEBDAV) += lighttpd-1.4.39 # 如果config_base中RTCONFIG_WEBDAV没有设置,所以这个不会编译
obj-$(RTCONFIG_USB_MODEM) += json-c libubox uqmi # 如果config_base中RTCONFIG_USB_MODEM有设置,所以这个会编译


# 下面是相关变量的定义
# ~/asuswrt/release/src-rt-5.02p1axhnd.675x/target/buildFS
TARGETDIR TARGETS_DIR ~/asuswrt/release/src-rt-5.02p1axhnd.675x/target
INSTALLDIR INSTALL_DIR ~/asuswrt/release/src-rt-5.02p1axhnd.675x/target/962118GW/fs.install
BUILD_DIR ~/asuswrt/release/src-rt-5.02p1axhnd.675x
PROFILE ~/asuswrt/release/src-rt-5.02p1axhnd.675x/target/962118GW
ROOTFS ~/asuswrt/release/src-rt-5.02p1axhnd.675x/target/962118GW/fs
MOD_DIR ~/asuswrt/release/src-rt-5.02p1axhnd.675x/target/962118GW/modules

# ~/asuswrt/release/src/router/Makefile
# 可不需要将编译链放入profile中,Makefile中337行已添加到$(PATH)了
CROSS_COMPILE_64 /opt/toolchains/crosstools-aarch64-gcc-5.5-linux-4.1-glibc-2.26-binutils-2.28.1/usr/bin/aarch64-buildroot-linux-gnu-
TOOLCHAIN_64 /opt/toolchains/crosstools-aarch64-gcc-5.5-linux-4.1-glibc-2.26-binutils-2.28.1/usr/bin

# 大部分预设的目录变量都在这里定义:~/asuswrt/release/src/router/common.mak
$(SRCBASE) ~/asuswrt/release/src-rt-5.02p1axhnd.675x/
$(LINUXDIR) ~/asuswrt/release/src-rt-5.02p1axhnd.675x/kernel/linux-4.1
$(TOP) ~/asuswrt/release/src-rt-5.02p1axhnd.675x/router
$(PLATFORM) $(PLATFORM_ARCH) arm-glibc
$(TOP_PLATFORM) ~/asuswrt/release/src-rt-5.02p1axhnd.675x/router-sysdep
$(PLATFORMDIR) ~/asuswrt/release/src-rt-5.02p1axhnd.675x/router/arm-glibc
$(STAGEDIR) ~/asuswrt/release/src-rt-5.02p1axhnd.675x/router/arm-glibc/stage

PKG_CONFIG_SYSROOT_DIR $(STAGEDIR)
PKG_CONFIG_PATH $(STAGEDIR)/usr/lib/pkgconfig:$(STAGEDIR)/etc/lib/pkgconfig
PKG_CONFIG_LIBDIR $(STAGEDIR)/usr/lib/pkgconfig:$(STAGEDIR)/usr/local/lib/pkgconfig:$(STAGEDIR)/etc/lib/pkgconfig
EXTRACFLAGS -DLINUX_KERNEL_VERSION=$(LINUX_KERNEL_VERSION) $(if $(STAGING_DIR),--sysroot=$(STAGING_DIR))
EXTRALDFLAGS $(if $(STAGING_DIR),--sysroot=$(STAGING_DIR))

# 交叉编译器相关信息在这里定义:~/asuswrt/release/src-rt/platform.mak
ARCH arm
TOOLS /opt/toolchains/crosstools-arm-gcc-5.5-linux-4.1-glibc-2.26-binutils-2.28.1
TOOLCHAIN /opt/toolchains/crosstools-arm-gcc-5.5-linux-4.1-glibc-2.26-binutils-2.28.1/usr/bin
CROSS_COMPILE /opt/toolchains/crosstools-arm-gcc-5.5-linux-4.1-glibc-2.26-binutils-2.28.1/usr/bin/arm-buildroot-linux-gnueabi-
CROSS_COMPILER $(CROSS_COMPILE)
CONFIGURE ./configure LD=$(CROSS_COMPILE)ld --host=arm-buildroot-linux-gnueabi
CONFIGURE_64 ./configure LD=$(CROSS_COMPILE_64)ld --host=aarch64-buildroot-linux-gnu
HOSTCONFIG linux-armv4 -DL_ENDIAN -march=armv8-a -fomit-frame-pointer -mabi=aapcs-linux -marm -ffixed-r8 -msoft-float -D__ARM_ARCH_8A__
HOSTCONFIG_64 linux-aarch64 -DL_ENDIAN -march=armv8-a -fomit-frame-pointer -mabi=lp64 -ffixed-r8 -D__ARM_ARCH_8A__

# 因为源码包内自带了几十个私有的二进制32位的库,所以不能改为64位
file ~/asuswrt/release/src/router/protect_srv/lib/prebuild/libptcsrv.so
/home/leux/asuswrt/release/src/router/protect_srv/lib/prebuild/libptcsrv.so: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, not stripped