利用 GitHub Action 自定义构建 Padavan 路由固件

status
Published
type
Post
slug
build-padavan-firmware-for-rm2100
date
Jan 12, 2024
tags
Linux
Config
Git
OpenWrt
summary
本文介绍了如何利用 GitHub Action 自定义构建红米 AC2100 路由器的 Padavan 固件。首先,在 GitHub 上新建一个仓库,并下载 Padavan 固件的源代码。然后,根据自己的需求修改配置文件和自定义脚本。接着,在 GitHub Action 的配置文件中设置编译环境和编译参数,并将编译生成的固件上传到 GitHub Release。最后,使用自定义脚本对固件进行进一步的配置和修改。通过这种方法,可以快速自定义构建适合自己需求的 Padavan 固件。
手头上使用的红米 AC2100 路由在到手刷为 OpenWRT 后一直稳定运行几年时间。前些日子将 OpenWRT 相关的功能需求转移到软路由上后,便想着将其再刷一下,只承担最基本的路由功能。于是选择了 Padavan 固件。
Padavan固件是一个基于华硕路由器的第三方固件,它提供了许多额外的功能和定制选项,使得用户可以更好地控制他们的路由器。Padavan固件基于开源项目,因此用户可以自由地定制和修改它以满足自己的需求。
关于Padavan固件的更多信息和下载链接可以在以下网站找到:
网上有较多现成的固件,可以直接下载刷入,但基本都经过了各种修改,综合考虑后决定利用 GitHub Action 来自行编译构建固件。
如下为内核基于 4.4 版本的 Padavan 源代码

GitHub Repo

新建一个仓库,参照上面源码中的编译说明,编写自定义配置及 GitHub Action 配置文件即可快速自定义构建固件。

GitHub Action

build.yml
name: Build-padavan-firmware on: workflow_dispatch: watch: types: [started] env: src_git: https://github.com/MeIsReallyBa/padavan-4.4.git src_dir: /opt/padavan work_dir: /opt/padavan/trunk firmware_dir: /opt/firmware config_file: config custom_script: custom.sh jobs: build: name: build runs-on: ubuntu-latest if: github.event.repository.owner.id == github.event.sender.id strategy: matrix: device: [RM2100] permissions: contents: write steps: - name: Checkout uses: actions/checkout@v4 - name: Install dependencies if: (!cancelled()) run: | sudo apt-get -qq install -y \ unzip libtool-bin curl cmake gperf gawk flex bison nano xxd \ fakeroot kmod cpio git python3-docutils gettext automake autopoint \ texinfo build-essential help2man pkg-config zlib1g-dev libgmp3-dev \ libmpc-dev libmpfr-dev libncurses5-dev libltdl-dev wget libc-dev-bin & wait sudo timedatectl set-timezone "Asia/Shanghai" - name: Clone source and Download toolchain if: (!cancelled()) run: | git clone --depth=1 $src_git $src_dir cd $src_dir/toolchain-mipsel && chmod +x dl_toolchain.sh ./dl_toolchain.sh - name: Import Custom configs if: (!cancelled()) run: | cp $config_file $work_dir/configs/templates/${{ matrix.device }}.config mv $config_file $work_dir/.config mv $custom_script $work_dir/ cd $work_dir chmod +x build_firmware_modify && chmod +x $custom_script ./$custom_script - name: Compile the firmware if: (!cancelled()) id: compile run: | cd $work_dir fakeroot ./build_firmware_modify ${{ matrix.device }} 0 echo "release_tag=$(date +"%Y.%m.%d-%H%M")" >> $GITHUB_OUTPUT mkdir -p $firmware_dir mv images/*.trx $firmware_dir - name: Upload firmware directory uses: actions/upload-artifact@v4 if: ${{ success() }} && !cancelled() with: name: ${{ matrix.device }} path: ${{ env.firmware_dir }} if-no-files-found: error - name: Upload firmware to release uses: softprops/action-gh-release@v1 env: GITHUB_TOKEN: ${{ github.token }} with: files: | ${{ env.firmware_dir }}/*.trx tag_name: ${{ steps.compile.outputs.release_tag }}

自定义设置脚本

custom.sh
#!/bin/bash user_name="root" # 用户名 user_password="root" # 登录密码 lan_ip="192.168.31" # LAN 地址 别写后面的 .1 wlan_2g_ssid="int_2.4G" # 2G 无线名称 wlan_5g_ssid="int_5G" # 5G 无线名称 wlan_guest_2g_ssid="int_pub_2.4G" # 2G 访客无线名称 wlan_guest_5g_ssid="int_pub_5G" # 5G 访客无线名称 wlan_2g_psk="12344321" # 2G WIFI密码最少8位 空白为不设置 wlan_5g_psk="12344321" # 5G WIFI密码最少8位 空白为不设置 version_time=$(date +%Y%m%d) # 更新时版本号时间: 20210101 default_file="./user/shared/defaults.h" # 默认配置文件 echo "修改用户名" sed -i 's/SYS_USER_ROOT "admin"/SYS_USER_ROOT "'$user_name'"/g' $default_file echo "修改登陆密码" sed -i 's/DEF_ROOT_PASSWORD "admin"/DEF_ROOT_PASSWORD "'$user_password'"/g' $default_file echo "修改 LAN IP 地址" sed -i "s/192.168.2/$lan_ip/g" $default_file echo "修改 2G 无线名称" sed -i 's/DEF_WLAN_2G_SSID BOARD_PID "_%s"/DEF_WLAN_2G_SSID "'$wlan_2g_ssid'"/g' $default_file echo "修改 5G 无线名称" sed -i 's/DEF_WLAN_5G_SSID BOARD_PID "_5G_%s"/DEF_WLAN_5G_SSID "'$wlan_5g_ssid'"/g' $default_file echo "修改 2G 访客无线名称" sed -i 's/DEF_WLAN_2G_GSSID BOARD_PID "_GUEST_%s"/DEF_WLAN_2G_GSSID "'$wlan_guest_2g_ssid'"/g' $default_file echo "修改 5G 访客无线名称" sed -i 's/DEF_WLAN_5G_GSSID BOARD_PID "_GUEST_5G_%s"/DEF_WLAN_5G_GSSID "'$wlan_guest_5g_ssid'"/g' $default_file echo "修改 2.4GHz WIFI 密码" sed -i 's/DEF_WLAN_2G_PSK "1234567890"/DEF_WLAN_2G_PSK "'$wlan_2g_psk'"/g' $default_file echo "修改 5GHz WIFI 密码" sed -i 's/DEF_WLAN_5G_PSK "1234567890"/DEF_WLAN_5G_PSK "'$wlan_5g_psk'"/g' $default_file echo "更新版本号时间" sed -i "s/FIRMWARE_BUILDS_REV=.*/FIRMWARE_BUILDS_REV=$version_time/g" ./versions.inc default_path="./user/shared" # 默认配置路径 #echo "设置为PPPOE模式并写入账号和密码" #sed -i 's/{ "wan_proto", "dhcp" }/{ "wan_proto", "pppoe" }/g' $default_path/defaults.c #sed -i 's/{ "wan_pppoe_username", "" }/{ "wan_pppoe_username", "宽带账号" }/g' $default_path/defaults.c #sed -i 's/{ "wan_pppoe_passwd", "" }/{ "wan_pppoe_passwd", "宽带密码" }/g' $default_path/defaults.c #echo "设置为 AP模式" #echo "#define BOARD_ROLE_REPEATER 1" >> ./configs/boards/RM2100/board.h #echo "打开2G无线桥接" #sed -i 's/{ "rt_mode_x", "0" }/{ "rt_mode_x", "4" }/g' $default_path/defaults.c #echo "打开5G无线桥接" #sed -i 's/{ "wl_mode_x", "0" }/{ "wl_mode_x", "4" }/g' $default_path/defaults.c

设备编译配置

可参考 Padavan 源码中对应的文件进行修改,这里我只添加了 Adbyby plus 和 WireGuard 两个额外插件,其余均未引入。
config
### Target Vendor/Product (support only Ralink RT3883/MT7620/MT7621/MT7628) CONFIG_VENDOR=Ralink CONFIG_PRODUCT=MT7621 ### Target ProductID (board select, max 12 symbols) CONFIG_FIRMWARE_PRODUCT_ID="RM2100" ### Linux kernel and toolchain CONFIG_FIRMWARE_INCLUDE_SFE=y CONFIG_LINUXDIR=linux-4.4.x ############################################################ ### Linux kernel configuration ############################################################ ### Enable IPv6 support CONFIG_FIRMWARE_ENABLE_IPV6=y ### Enable USB support CONFIG_FIRMWARE_ENABLE_USB=n ### Enable FAT/FAT32 filesystem support. ~0.1MB CONFIG_FIRMWARE_ENABLE_FAT=n ### Enable exFAT (FAT/FAT32 too) filesystem support. ~0.12MB CONFIG_FIRMWARE_ENABLE_EXFAT=n ### Enable EXT2 filesystem support. ~0.1MB CONFIG_FIRMWARE_ENABLE_EXT2=n ### Enable EXT3 filesystem support. ~0.2MB CONFIG_FIRMWARE_ENABLE_EXT3=n ### Enable EXT4 (EXT3/2 too) filesystem support. ~0.4MB CONFIG_FIRMWARE_ENABLE_EXT4=n ### Enable XFS filesystem support. ~0.6MB CONFIG_FIRMWARE_ENABLE_XFS=n ### Enable FUSE (filesystems in userspace) support. ~0.1MB CONFIG_FIRMWARE_ENABLE_FUSE=n ### Enable swap files/partitions support. ~0.05MB CONFIG_FIRMWARE_ENABLE_SWAP=n ### Include UVC camera modules. ~0.2MB CONFIG_FIRMWARE_INCLUDE_UVC=n ### Include USB-HID modules. ~0.2MB CONFIG_FIRMWARE_INCLUDE_HID=n ### Include USB-Serial modules (e.g. pl2303). ~0.03MB CONFIG_FIRMWARE_INCLUDE_SERIAL=n ### Include USB-Audio modules ~0.46MB CONFIG_FIRMWARE_INCLUDE_AUDIO=n ### Include XFRM (IPsec) modules & iptables extension ~ 0.2MB CONFIG_FIRMWARE_INCLUDE_XFRM=n ### Include network QoS scheduling modules. ~0.2MB CONFIG_FIRMWARE_INCLUDE_QOS=n ### Include IMQ module for shapers (a bit of performance degradation). ~0.02MB CONFIG_FIRMWARE_INCLUDE_IMQ=n ### Include IFB module for shapers. ~0.03MB CONFIG_FIRMWARE_INCLUDE_IFB=n ### Include IPSet utility and kernel modules. ~0.4MB CONFIG_FIRMWARE_INCLUDE_IPSET=y ### Include NFSv3 server. ~0.6MB CONFIG_FIRMWARE_INCLUDE_NFSD=n ### Include NFSv3 client. ~0.5MB CONFIG_FIRMWARE_INCLUDE_NFSC=n ### Include CIFS (SMB) client. ~0.2MB CONFIG_FIRMWARE_INCLUDE_CIFS=n ############################################################ ### Userspace configuration ############################################################ ### Include WebUI international resources. Increased firmware size CONFIG_FIRMWARE_INCLUDE_LANG_CN=y #CONFIG_FIRMWARE_INCLUDE_LANG_BR=y #CONFIG_FIRMWARE_INCLUDE_LANG_CZ=y #CONFIG_FIRMWARE_INCLUDE_LANG_DA=y #CONFIG_FIRMWARE_INCLUDE_LANG_DE=y #CONFIG_FIRMWARE_INCLUDE_LANG_ES=y #CONFIG_FIRMWARE_INCLUDE_LANG_FI=y #CONFIG_FIRMWARE_INCLUDE_LANG_FR=y #CONFIG_FIRMWARE_INCLUDE_LANG_NO=y #CONFIG_FIRMWARE_INCLUDE_LANG_PL=y #CONFIG_FIRMWARE_INCLUDE_LANG_RU=y #CONFIG_FIRMWARE_INCLUDE_LANG_SV=y #CONFIG_FIRMWARE_INCLUDE_LANG_UK=y ### Include NTFS-3G FUSE driver (instead of Paragon "ufsd"). ~0.4MB CONFIG_FIRMWARE_INCLUDE_NTFS_3G=n ### Include LPR printer daemon. ~0.12MB CONFIG_FIRMWARE_INCLUDE_LPRD=n ### Include USB-over-Ethernet printer daemon. ~0.05MB CONFIG_FIRMWARE_INCLUDE_U2EC=n ### Include "tcpdump" utility. ~0.6MB CONFIG_FIRMWARE_INCLUDE_TCPDUMP=n ### Include "hdparm" utility (allow set HDD spindown timeout and APM). ~0.1MB CONFIG_FIRMWARE_INCLUDE_HDPARM=n ### Include "parted" utility (allow make GPT partitions). ~0.3MB CONFIG_FIRMWARE_INCLUDE_PARTED=n ### Include SMB3.6 (and WINS) server. ~1.5MB CONFIG_FIRMWARE_INCLUDE_SMBD=n ### Include WINS server only. ~0.4MB CONFIG_FIRMWARE_INCLUDE_WINS=n ### Include syslog for SMB and WINS server. ~0.3MB CONFIG_FIRMWARE_INCLUDE_SMBD_SYSLOG=n ### Include FTP server. ~0.2MB CONFIG_FIRMWARE_INCLUDE_FTPD=n ### Include alternative L2TP control client RP-L2TP. ~0.1MB CONFIG_FIRMWARE_INCLUDE_RPL2TP=n ### Include EAP-TTLS and EAP-PEAP authentication support. openssl ~1.2MB, wpa_supplicant +0.04MB CONFIG_FIRMWARE_INCLUDE_EAP_PEAP=n ### Include HTTPS support. openssl ~1.2MB CONFIG_FIRMWARE_INCLUDE_HTTPS=n ### Include sftp-server. openssl ~1.2MB, sftp-server ~0.06MB CONFIG_FIRMWARE_INCLUDE_SFTP=n ### Include dropbear SSH. ~0.3MB CONFIG_FIRMWARE_INCLUDE_DROPBEAR=n ### Make the dropbear symmetrical ciphers and hashes faster. ~0.06MB CONFIG_FIRMWARE_INCLUDE_DROPBEAR_FAST_CODE=n ### Include OpenSSH instead of dropbear. openssl ~1.2MB, openssh ~1.0MB CONFIG_FIRMWARE_INCLUDE_OPENSSH=n ### Include OpenVPN. IPv6 required. openssl ~1.2MB, openvpn ~0.4MB CONFIG_FIRMWARE_INCLUDE_OPENVPN=n ### Include StrongSwan. XFRM modules ~0.2MB, strongswan ~0.7MB CONFIG_FIRMWARE_INCLUDE_SSWAN=n ### Include Elliptic Curves (EC) to openssl library. ~0.1MB CONFIG_FIRMWARE_INCLUDE_OPENSSL_EC=y ### Include "openssl" executable for generate certificates. ~0.4MB CONFIG_FIRMWARE_INCLUDE_OPENSSL_EXE=n ### Include xUPNPd IPTV mediaserver. ~0.3MB CONFIG_FIRMWARE_INCLUDE_XUPNPD=n ### Include Minidlna UPnP mediaserver. ~1.6MB CONFIG_FIRMWARE_INCLUDE_MINIDLNA=n ### Include Firefly iTunes mediaserver. ~1.0MB CONFIG_FIRMWARE_INCLUDE_FIREFLY=n ### Include ffmpeg 0.11.x instead of 0.6.x for Minidlna and Firefly. ~0.1MB CONFIG_FIRMWARE_INCLUDE_FFMPEG_NEW=n ### Include Transmission torrent. openssl ~1.2MB, transmission ~1.5MB CONFIG_FIRMWARE_INCLUDE_TRANSMISSION=n ### Include Transmission-Web-Control (advanced WebUI). ~0.8MB CONFIG_FIRMWARE_INCLUDE_TRANSMISSION_WEB_CONTROL=n ### Include Aria2 download manager. openssl ~1.2MB, aria2 ~3.5MB CONFIG_FIRMWARE_INCLUDE_ARIA=n ### Include Aria2 WEB control. ~0.7MB CONFIG_FIRMWARE_INCLUDE_ARIA_WEB_CONTROL=n CONFIG_FIRMWARE_INCLUDE_CURL=y CONFIG_FIRMWARE_INCLUDE_GDUT_DRCOM=n CONFIG_FIRMWARE_INCLUDE_DOGCOM=n CONFIG_FIRMWARE_INCLUDE_MINIEAP=n CONFIG_FIRMWARE_INCLUDE_NJIT_CLIENT=n CONFIG_FIRMWARE_INCLUDE_SOFTETHERVPN_SERVER=n CONFIG_FIRMWARE_INCLUDE_SOFTETHERVPN_CLIENT=n CONFIG_FIRMWARE_INCLUDE_SOFTETHERVPN_CMD=n CONFIG_FIRMWARE_INCLUDE_VLMCSD=n CONFIG_FIRMWARE_INCLUDE_TTYD=n CONFIG_FIRMWARE_INCLUDE_LRZSZ=n CONFIG_FIRMWARE_INCLUDE_HTOP=n CONFIG_FIRMWARE_INCLUDE_NANO=n CONFIG_FIRMWARE_INCLUDE_IPERF3=n CONFIG_FIRMWARE_INCLUDE_DUMP1090=n CONFIG_FIRMWARE_INCLUDE_RTL_SDR=n CONFIG_FIRMWARE_INCLUDE_MTR=n CONFIG_FIRMWARE_INCLUDE_SOCAT=n CONFIG_FIRMWARE_INCLUDE_FRPC=n CONFIG_FIRMWARE_INCLUDE_FRPS=n CONFIG_FIRMWARE_INCLUDE_DNSFORWARDER=n CONFIG_FIRMWARE_INCLUDE_SCUTCLIENT=n CONFIG_FIRMWARE_INCLUDE_SRELAY=n #科学上网插件,选择n后全部有关插件都不集成 CONFIG_FIRMWARE_INCLUDE_SHADOWSOCKS=n #集成xray执行文件 ~4.5M CONFIG_FIRMWARE_INCLUDE_XRAY=n #集成v2ray执行文件 CONFIG_FIRMWARE_INCLUDE_V2RAY=n #集成trojan执行文件 ~1.2M CONFIG_FIRMWARE_INCLUDE_TROJAN=n #simple-obfs混淆插件 CONFIG_FIRMWARE_INCLUDE_SSOBFS=n #adbyby plus+ CONFIG_FIRMWARE_INCLUDE_ADBYBY=y #smartdns CONFIG_FIRMWARE_INCLUDE_SMARTDNS=n #adg DNS去AD CONFIG_FIRMWARE_INCLUDE_ADGUARDHOME=n #zerotier ~1.3M CONFIG_FIRMWARE_INCLUDE_ZEROTIER=n #aliddns CONFIG_FIRMWARE_INCLUDE_ALIDDNS=n #ddnsto ~0.5M CONFIG_FIRMWARE_INCLUDE_DDNSTO=n #ALDRIVER ~3m CONFIG_FIRMWARE_INCLUDE_ALDRIVER=n #mentohust CONFIG_FIRMWARE_INCLUDE_MENTOHUST=n #SQM CONFIG_FIRMWARE_INCLUDE_SQM=n #wireguard 10k CONFIG_FIRMWARE_INCLUDE_WIREGUARD=y #frpc CONFIG_FIRMWARE_INCLUDE_FRPC=n #frps CONFIG_FIRMWARE_INCLUDE_FRPS=n #CPU超频开关 CONFIG_FIRMWARE_INCLUDE_OC=n #此处填写对应频率的十六进制:1000Mhz=0x312 1100Mhz=0x362 1120Mhz=0x372 1200Mhz=0x3B2 CONFIG_FIRMWARE_MT7621_OC="0x312"
 

文件编辑完毕提交后,手动运行 Action 或自己 star 仓库即可触发固件构建,最终固件可在 GitHub Action 编译任务的制品库中或在仓库的 Release 处查看并下载
notion image
将固件刷入路由器后,后台界面如下:
(固件刷入过程此处略去不表,网上已有很多)
notion image