- • This article uses the friendlywrt22-rk3568 distribution as an example to explain how to customize an OpenWrt firmware. The customization features include modifying network parameters, login passwords, boot interface (banner), proxy ARP, opkg sources, hostname, default application configuration parameters, adding arbitrary files (not limited to applications and their libraries), etc. Finally, a complete practical example is provided.
- Follow our public account to get more OpenWrt learning materials; see the list at the end of the article.
Customizing Network Configuration
Using config_generate
You can modify the default network port address and protocol mode, such as DHCP or static.
ney@test:~/test/friendlywrt22-rk3568/friendlywrt$ git diff
diff --git a/package/base-files/files/bin/config_generate b/package/base-files/files/bin/config_generate
index 38362813d1..e4aa2631bc 100755
--- a/package/base-files/files/bin/config_generate
+++ b/package/base-files/files/bin/config_generate
@@ -162,7 +162,7 @@ generate_network() {
static)
local ipad
case "$1" in
- lan) ipad=${ipaddr:-"192.168.1.1"} ;;
+ lan) ipad=${ipaddr:-"192.1.10.165"} ;;
*) ipad=${ipaddr:-"192.168.$((addr_offset++)).1"} ;;
esac
@@ -172,6 +172,8 @@ generate_network() {
set network.$1.proto='static'
set network.$1.ipaddr='$ipad'
set network.$1.netmask='$netm'
+ set network.$1.gateway='192.1.10.254'
+ set network.$1.dns='192.16.3.38 127.0.0.1 223.5.5.5 8.8.8.8'
EOF
[ -e /proc/sys/net/ipv6 ] && uci set network.$1.ip6assign='60'
;
diff --git a/package/base-files/files/etc/shadow b/package/base-files/files/etc/shadow
index 630ef74566..0e985d3810 100644
--- a/package/base-files/files/etc/shadow
+++ b/package/base-files/files/etc/shadow
@@ -1,4 +1,4 @@
-root:$1$sI9XK.bT$vfaeX5elDEUyrgC11IfGT/:0:0:99999:7:::
+root:$1$utc.7xL6$ecFTDzatgWF86JLSoB4od0:18628:0:99999:7:::
daemon:*:0:0:99999:7:::
ftp:*:0:0:99999:7:::
network:*:0:0:99999:7:::
Using etc/config/network
# Path: friendlywrt22-rk3568/friendlywrt/package/base-files/files/etc/config/network
config device
option name 'eth0'
config device
option name 'eth1'
config interface 'eth0'
option proto 'static'
option device 'eth0'
option ipaddr '192.10.70.252'
option netmask '255.255.0.0'
option gateway '192.10.1.254'
Modifying the Banner
The banner file in the WRT SDK source code belongs to the base-files package.
# Path: friendlywrt/target/linux/rockchip/armv8/base-files/etc/banner
# If base-files exists in the target/linux/{generic,rockchip} directory, it will be used preferentially.
/home/test/fdWRT/friendlywrt22-rk3568/friendlywrt/target/linux/generic/base-files
/home/test/fdWRT/friendlywrt22-rk3568/friendlywrt/target/linux/rockchip/base-files/
/home/test/fdWRT/friendlywrt22-rk3568/friendlywrt/target/linux/rockchip/armv8/base-files/
if [ -d $(GENERIC_PLATFORM_DIR)/base-files/. ]; then \
$(CP) $(GENERIC_PLATFORM_DIR)/base-files/* $(1)/; \
fi
if [ -d $(PLATFORM_DIR)/base-files/. ]; then \
$(CP) $(PLATFORM_DIR)/base-files/* $(1)/; \
fi
$(if $(filter-out $(PLATFORM_DIR),$(PLATFORM_SUBDIR)), \
if [ -d $(PLATFORM_SUBDIR)/base-files/. ]; then \
$(CP) $(PLATFORM_SUBDIR)/base-files/* $(1)/; \
fi; \
)
Comparison before and after modification.
root@test:/home/ney/rk3568-r5s/friendlywrt# git diff
diff --git a/package/base-files/files/etc/banner b/package/base-files/files/etc/banner
index f3af3c014f..730988136d 100644
--- a/package/base-files/files/etc/banner
+++ b/package/base-files/files/etc/banner
@@ -1,8 +1,21 @@
- _______ ________ __
- | |.-----.-----.-----.| | | |.----.| |_
- | - || _ | -__| || | | || _|| _|
- |_______|| __|_____|__|__||________||__| |____|
- |__| W I R E L E S S F R E E D O M
- -----------------------------------------------------
- %D %V, %C
- -----------------------------------------------------
+ _ _ _ _ _ _ _ _ _ _ _ _
+ (c).-.(c) (c).-.(c) (c).-.(c) (c).-.(c) (c).-.(c) (c).-.(c)
+ / ._. \ / ._. \ / ._. \ / ._. \ / ._. \ / ._. \
+ __\( Y )/__ __\( Y )/__ __\( Y )/__ __\( Y )/__ __\( Y )/__ __\( Y )/__
+(_.-/'-\-._)(_.-/'-\-._)(_.-/'-\-._)(_.-/'-\-._)(_.-/'-\-._)(_.-/'-\-._)
+ || H || || A || || H || || A || || H || || A ||
+ _.' `-' '._ _.' `-' '._ _.' `-' '._ _.' `-' '._ _.' `-' '._ _.' `-' '._
+(.-./`-\.-.)(.-./`-\.-.)(.-./`-\.-.)(.-./`-\.-.)(.-./`-\.-.)(.-./`-\.-.)
+ `-' `-' `-' `-' `-' `-' `-' `-' `-' `-' `-' `-'
Modifying the Login Password
diff --git a/package/base-files/files/etc/shadow b/package/base-files/files/etc/shadow
index 630ef74566..0e985d3810 100644
--- a/package/base-files/files/etc/shadow
+++ b/package/base-files/files/etc/shadow
@@ -1,4 +1,4 @@
-root:$1$sI9XK.bT$vfaxxxxC11IfGT/:0:0:99999:7:::
+root:$1$utc.7xL6$ecFTDxxxxB4od0:18628:0:99999:7:::
daemon:*:0:0:99999:7:::
ftp:*:0:0:99999:7:::
network:*:0:0:99999:7:::
Modifying Proxy ARP
The hostname can also be modified in the system.
Note: The build tool copies the sysctl.conf file from device/common/default-settings when creating the emmc-img.
diff --git a/default-settings/sysctl/etc/sysctl.conf b/default-settings/sysctl/etc/sysctl.conf
index 1380782..227d14f 100644
--- a/default-settings/sysctl/etc/sysctl.conf
+++ b/default-settings/sysctl/etc/sysctl.conf
@@ -1,2 +1,4 @@
# Defaults are configured in /etc/sysctl.d/* and can be customized in this file
-#
+net.ipv4.conf.all.proxy_arp=1
+net.ipv4.conf.eth1.proxy_arp=1
+net.ipv4.conf.eth0.proxy_arp=1
+kernel.hostname=test
System Modifications (hostname, timezone, NTP)
Modifications and customizations related to hostname, timezone, NTP, and other parameters are involved in the system.
# Note: friendlywrt/package/base-files/files/etc/config/system
#
config system
option log_size '64'
option urandom_seed '0'
option hostname 'test'
option ttylogin '1'
option timezone 'CST-8'
option zonename 'Asia/Shanghai'
config timeserver 'ntp'
option enabled '1'
option enable_server '0'
list server '0.openwrt.pool.ntp.org'
list server '1.openwrt.pool.ntp.org'
list server '2.openwrt.pool.ntp.org'
list server '3.openwrt.pool.ntp.org'
Modifying opkg Source
Change the opkg source to a domestic source.
diff --git a/distfeeds/install.sh b/distfeeds/install.sh
index 43ed5cc..2305303 100755
--- a/distfeeds/install.sh
+++ b/distfeeds/install.sh
@@ -11,10 +11,10 @@ ROOTFS_DIR=$1
# opkg update
#
-src/gz openwrt_base https://mirrors.cloud.tencent.com/openwrt/releases/${VERSION}/packages/aarch64_generic/base
-src/gz openwrt_luci https://mirrors.cloud.tencent.com/openwrt/releases/${VERSION}/packages/aarch64_generic/luci
-src/gz openwrt_packages https://mirrors.cloud.tencent.com/openwrt/releases/${VERSION}/packages/aarch64_generic/packages
-src/gz openwrt_routing https://mirrors.cloud.tencent.com/openwrt/releases/${VERSION}/packages/aarch64_generic/routing
-src/gz openwrt_telephony https://mirrors.cloud.tencent.com/openwrt/releases/${VERSION}/packages/aarch64_generic/telephony
+src/gz openwrt_base http://mirrors.cloud.tencent.com/openwrt/releases/${VERSION}/packages/aarch64_generic/base
+src/gz openwrt_luci http://mirrors.cloud.tencent.com/openwrt/releases/${VERSION}/packages/aarch64_generic/luci
+src/gz openwrt_packages http://mirrors.cloud.tencent.com/openwrt/releases/${VERSION}/packages/aarch64_generic/packages
+src/gz openwrt_routing http://mirrors.cloud.tencent.com/openwrt/releases/${VERSION}/packages/aarch64_generic/routing
+src/gz openwrt_telephony http://mirrors.cloud.tencent.com/openwrt/releases/${VERSION}/packages/aarch64_generic/telephony
EOF
})
Adding Applications During Image Packaging
install.sh Invocation
The compilation tool has one last chance to customize the rootfs before packaging the image. By modifying the friendlywrt22-rk3568/device/common/default-settings/install.sh script, you can add private items: including modifying application parameters, adding some applications and files.
root@test:/home/friendlywrt/friendlywrt22-rk3568# ./build.sh emmc-img
[INFO]: Copying /home/test/friendlywrt22-rk3568/friendlyelec/build_dir/target-aarch64_generic_musl/root-rockchip to /home/test/friendlywrt22-rk3568/scripts/sd-fuse/out/rootfs.zH8e9zT11/
[INFO]: Applying device/common/ntfs3 to /home/test/friendlywrt22-rk3568/scripts/sd-fuse/out/rootfs.zH8e9zT11
[INFO]: Applying device/common/uas to /home/test/friendlywrt22-rk3568/scripts/sd-fuse/out/rootfs.zH8e9zT11
[INFO]: Applying device/common/nft-fullcone to /home/test/friendlywrt22-rk3568/scripts/sd-fuse/out/rootfs.zH8e9zT11
[INFO]: Applying device/common/emmc-tools to /home/test/friendlywrt22-rk3568/scripts/sd-fuse/out/rootfs.zH8e9zT11
[INFO]: Applying device/common/distfeeds to /home/test/friendlywrt22-rk3568/scripts/sd-fuse/out/rootfs.zH8e9zT11
[INFO]: Applying device/common/default-settings to /home/test/friendlywrt22-rk3568/scripts/sd-fuse/out/rootfs.zH8e9zT11
[INFO]: Applying device/friendlyelec/rk3568/r8125 to /home/test/friendlywrt22-rk3568/scripts/sd-fuse/out/rootfs.zH8e9zT11
[INFO]: prepare boot.img ...
Packaging Existing Applications
Prepare the applications or files to be packaged in advance (e.g., friendlywrt22-rk3568/device/common/default-settings/wrtobj), and modify the friendlywrt22-rk3568/device/common/default-settings/install.sh script.
Here, $CURRPATH represents the current directory: friendlywrt22-rk3568/device/common/default-settings
${ROOTFS_DIR} is the root filesystem to be packaged; just place the required files into the rootfs directory to be released with the image.
#srs
cp -avf $CURRPATH/wrtobj/openwrt.conf ${ROOTFS_DIR}/etc/srs/conf/
mkdir -p ${ROOTFS_DIR}/root/.objs/
cp -avfr $CURRPATH/wrtobj/nginx ${ROOTFS_DIR}/root/.objs/
#cmake
cp -avfr $CURRPATH/cmake-3.27 ${ROOTFS_DIR}/usr/share/
Order of Operations for Custom Firmware (Complete Practical Example)
This is a complete step-by-step process based on the original friendlywrt22-rk3568 firmware, incorporating customized features.
# Note: Pay attention to path replacements.
# First, compile the original firmware. If errors occur, repeat the compilation multiple times and enable logging for easier problem localization. Start with single-process compilation for easier success.
./build.sh cleanall
./build.sh nanopi_r5s.mk
cd friendlywrt/
make -j1 V=s
make -j10 package/feeds/packages/gcc/compile V=s
make -j1 V=s
make -j10 V=s
make -j10 V=s
make -j1 V=s
# Preparation before compilation, back up kernel 3rd library source code
pwd /home/ney/data/friendlywrt22-rk3568/friendlywrt22-rk3568/friendlyelec/
cp /home/test/rockdev/friendlywrt22-rk3568/friendlywrt22-rk3568/scripts/sd-fuse/out/r8125/ ../scripts/sd-fuse/out/ -r
#copy dl packages
cp /home/ney/data/friendlywrt22-rk3568/friendlyelec/dl/* ./dl/ -v
# Application customization, ffmpeg makefile integration
# Prepare makefile for customization of ffmpeg to support [mpp/h264]
cp package/feeds/packages/ffmpeg/Makefile /home/ney/data/friendlywrt22-rk3568/friendlywrt22-rk3568/friendlyelec/package/feeds/packages/ffmpeg/
# Prepare include/lib/pkg-config for drmlib/mpp
root@test:/home/ney/data/friendlywrt22-rk3568/friendlywrt22-rk3568/friendlyelec# cp ../device/common/default-settings/{libdrm/*,rkmpp/*} staging_dir/target-aarch64_generic_musl/usr/ -rv
# Prepare srs feeds makefile
cp package/ossrs /home/ney/data/friendlywrt22-rk3568/friendlywrt22-rk3568/friendlyelec/package/ -r
# Default-settings config
##> firewall config, disable fullcone
cp package/network/config/firewall4/patches/999-01-firewall4-add-fullcone-support.patch /home/ney/data/friendlywrt22-rk3568/friendlywrt22-rk3568/friendlyelec/package/network/config/firewall4/patches/999-01-firewall4-add-fullcone-support.patch
##> add cmake
cp ../device/common/default-settings/cmake-3.27/ /home/ney/data/friendlywrt22-rk3568/friendlywrt22-rk3568/device/common/default-settings/ -r
##> add srs config
cp ../device/common/default-settings/wrtobj/ /home/ney/data/friendlywrt22-rk3568/friendlywrt22-rk3568/device/common/default-settings/ -r
##> add pjsip
##> update install.sh
cp ../device/common/default-settings/install.sh /home/ney/data/friendlywrt22-rk3568/friendlywrt22-rk3568/device/common/default-settings/
vim ../device/common/default-settings/install.sh
###default-settings/install
#!/bin/bash
set -eu
ROOTFS_DIR=$1
CURRPATH=$PWD
function clean_rootfs()
{
mkdir -p run
mkdir -p root/.ssh
chmod 0700 root root/.ssh
rm -f lib/preinit/79_move_config
rm -rf rom/
}
(cd ${ROOTFS_DIR} && {
cp -avf $CURRPATH/sysctl/* ${ROOTFS_DIR}/
cp -avf $CURRPATH/opkg-conf/* ${ROOTFS_DIR}/
#pjsip
cp -avfr $CURRPATH/pjsip/pjsip ${ROOTFS_DIR}/usr/bin/
#libmpp/libdrm
cp -avfr $CURRPATH/{libdrm/*,rkmpp/*} ${ROOTFS_DIR}/usr/
clean_rootfs
})
# Basefile config
##> test/package/base-files/files/etc/config/network
root@test:/home/ney/data/friendlywrt22-rk3568/friendlyelec# cp package/base-files/files/etc/config /home/ney/data/friendlywrt22-rk3568/friendlywrt22-rk3568/friendlywrt/package/base-files/files/etc/ -r
config device
option name 'eth0'
config device
option name 'eth1'
config interface 'eth0'
option proto 'static'
option device 'eth0'
option ipaddr '192.1.5.252'
option netmask '255.255.255.0'
option gateway '192.1.5.254'
##> Default Password
root@test:/home/ney/data/friendlywrt22-rk3568/friendlyelec# cp package/base-files/files/etc/shadow /home/ney/data/friendlywrt22-rk3568/friendlywrt22-rk3568/friendlyelec/package/base-files/files/etc/shadow
##> OS-RELEASE
root@test:/home/ney/data/friendlywrt22-rk3568/friendlyelec# vim /home/ney/data/friendlywrt22-rk3568/friendlywrt22-rk3568/friendlywrt/package/base-files/files/etc/os-release
Distributor ID: Linux
Description: Kernel 5.10
Release: 2023.11.22
##> arp/ipforward/hostname
root@test:/home/ney/data/friendlywrt22-rk3568/friendlyelec# vim /home/ney/data/friendlywrt22-rk3568/friendlywrt22-rk3568/friendlywrt/../device/common/default-settings/sysctl/etc/sysctl.conf
root@test:/home/ney/data/friendlywrt22-rk3568/friendlyelec#
# Defaults are configured in /etc/sysctl.d/* and can be customized in this file
net.ipv6.conf.default.forwarding=1
net.ipv6.conf.all.forwarding=1
net.ipv4.conf.all.proxy_arp=1
net.ipv4.conf.eth1.proxy_arp=1
net.ipv4.conf.eth0.proxy_arp=1
net.ipv4.ip_forward=1
kernel.hostname=test
##> banner
## https://www.bootschool.net/ascii#google_vignette
_ _ _ _ _ _ _ _ _ _ _ _
(c).-.(c) (c).-.(c) (c).-.(c) (c).-.(c) (c).-.(c) (c).-.(c)
/ ._. \ / ._. \ / ._. \ / ._. \ / ._. \ / ._. \
__\( Y )/__ __\( Y )/__ __\( Y )/__ __\( Y )/__ __\( Y )/__ __\( Y )/__
(_.-/'-\-._)(_.-/'-\-._)(_.-/'-\-._)(_.-/'-\-._)(_.-/'-\-._)(_.-/'-\-._)
|| H || || A || || H || || A || || H || || A ||
_.' `-' '._ _.' `-' '._ _.' `-' '._ _.' `-' '._ _.' `-' '._ _.' `-' '._
(.-./`-\.-.)(.-./`-\.-.)(.-./`-\.-.)(.-./`-\.-.)(.-./`-\.-.)(.-./`-\.-.)
`-' `-' `-' `-' `-' `-' `-' `-' `-' `-' `-' `-'
---------------------------------------------------------------------
dtu 23.11.22, dtu.xxx
---------------------------------------------------------------------
##> Clear Three Files
root@test:/home/ney/data/friendlywrt22-rk3568/friendlyelec# cp package/base-files/files/etc/{openwrt_*,device_info} /home/ney/data/friendlywrt22-rk3568/friendlywrt22-rk3568/friendlywrt/package/base-files/files/etc/
Two Small Compilation Issues
Freeswitch Compilation Failure Issue
## Freeswitch Compilation Failure Issue
riendlywrt/staging_dir/target-aarch64_generic_musl/usr/lib/libintl-stub/include -c src/switch_curl.c -fPIC -DPIC -o src/.libs/libfreeswitch_la-switch_curl.o
src/switch_curl.c: In function 'switch_curl_process_form_post_params':
src/switch_curl.c:90:41: error: 'curl_formadd' is deprecated: since 7.56.0. Use curl_mime_init() [-Werror=deprecated-declarations]
90 | curl_formadd(&formpost,
| ^~~~~~~~~~~~
In file included from ./src/include/switch_curl.h:33,
from src/switch_curl.c:2:
/home/ney/data/friendlywrt22-rk3568/friendlywrt22-rk3568/friendlywrt/staging_dir/target-aarch64_generic_musl/usr/include/curl/curl.h:2575:1: note: declared here
2575 | curl_formadd(struct curl_httppost **httppost,
| ^~~~~~~~~~~~
src/switch_curl.c:92:66: error: 'CURLFORM_COPYNAME' is deprecated: since 7.56.0. Use curl_mime_name() [-Werror=deprecated-declarations]
92 | CURLFORM_COPYNAME, pname,
|
# Solution
root@test:/home/ney/data/friendlywrt22-rk3568/friendlyelec# diff package/feeds/telephony/freeswitch/ /home/ney/data/friendlywrt22-rk3568/friendlywrt22-rk3568/friendlywrt/package/feeds/telephony/freeswitch/
Common subdirectories: package/feeds/telephony/freeswitch/files and /home/ney/data/friendlywrt22-rk3568/friendlywrt22-rk3568/friendlywrt/package/feeds/telephony/freeswitch/files
diff package/feeds/telephony/freeswitch/Makefile /home/ney/data/friendlywrt22-rk3568/friendlywrt22-rk3568/friendlywrt/package/feeds/telephony/freeswitch/Makefile
240,242d239
< # Allow compiling with OpenSSL 3.0
< TARGET_CFLAGS+=-Wno-error=deprecated-declarations
<
Common subdirectories: package/feeds/telephony/freeswitch/patches and /home/ney/data/friendlywrt22-rk3568/friendlywrt22-rk3568/friendlywrt/package/feeds/telephony/freeswitch/patches
LTTng Compilation Failure Issue
# Solution for LTTng Compilation Failure Issue
# Modify the ../scripts/mk-friendlywrt.sh file, add a line after echo "using .config file" to delete the lttng ko compilation
echo "using .config file"
sed -i '/CONFIG_PACKAGE_kmod-lttng=m/d' .config
Follow our public account and reply “openwrt” to get more learning materials.