1. 程式人生 > >斐訊K2路由編譯Padavan華碩韌體和心得

斐訊K2路由編譯Padavan華碩韌體和心得

2017-01-18更新:這個日誌(2016-09-01)有些內容已經過時了,要自己注意一下。

確保你的K2已經刷上breed並能刷上第三方韌體!

準備

準備工作:安裝virtualbox虛擬機器,安裝lubuntu16.04 i386系統,確定虛擬系統能正常上網,順便給虛擬機器共享實體機的一個目錄,方便檔案傳送。
進入虛擬系統,並開啟終端(Tips:可以關閉lightdm,在tty終端下執行,節省記憶體)

12 sudo apt-get update && sudo apt-get upgrade -ysudo apt-get install git autoconf automake bison build-essential flex gawk gettext gperf libtool pkg-config zlib1g-dev libgmp3-dev libmpc-dev libmpfr-dev texinfo python-docutils mc autopoint -y
1234567 sudo passwd root#輸入root密碼2次su#輸入root密碼,切換到root使用者cd /optgit clone https://bitbucket.org/padavan/rt-n56u.git#等N分鐘下載原始碼
123456 ===這裡是編譯mips工具===cd /opt/rt-n56u/toolchain-mipsel./clean_sources#這裡很快就完成./build_toolchain#這裡要等幾十分鐘具體看機器,最後會顯示ALL DONE相關資訊

這樣子,前期工作完成,開始修正padavan韌體適配k2的問題。

一:修正K2的GPIO

這裡的K2硬體版本為A2
Reset:GPIO 1

LED顏色 GPIO lo hi
8
11
10

編輯 /opt/rt-n56u/trunk/configs/boards/RT-AC54U/board.h檔案
並把內容改為如下,注意沒有數字引數的請確定前面是“#undef”,否則編譯時報錯。

12345678910111213141516171819202122232425262728 /* ASUS RT-AC54U */#define BOARD_PID "RT-AC54U"#define BOARD_NAME "RT-AC54U"
#define BOARD_DESC "ASUS RT-AC54U Wireless Router"#define BOARD_VENDOR_NAME "ASUSTek Computer Inc."#define BOARD_VENDOR_URL "http://www.asus.com/"#define BOARD_MODEL_URL "http://www.asus.com/Networking/RTAC54U/"#define BOARD_BOOT_TIME 25#define BOARD_FLASH_TIME 60#undef BOARD_GPIO_BTN_RESET#define BOARD_GPIO_BTN_WPS 1#undef BOARD_GPIO_LED_ALL#define BOARD_GPIO_LED_WIFI 11#define BOARD_GPIO_LED_POWER 8#undef BOARD_GPIO_LED_LAN#define BOARD_GPIO_LED_WAN 10#undef BOARD_GPIO_LED_USB#undef BOARD_GPIO_LED_ROUTER#undef BOARD_GPIO_PWR_USB#define BOARD_HAS_5G_11AC 1#define BOARD_NUM_ANT_5G_TX 2#define BOARD_NUM_ANT_5G_RX 2#define BOARD_NUM_ANT_2G_TX 2#define BOARD_NUM_ANT_2G_RX 2#define BOARD_NUM_ETH_LEDS 0#define BOARD_HAS_EPHY_L1000 0#define BOARD_HAS_EPHY_W1000 0

然後儲存檔案

二:呼叫原廠無線引數

把/opt/rt-n56u/trunk/configs/boards/RT-AC54U目錄下”SingleSKU”開頭的檔案全刪除
並編輯/opt/rt-n56u/trunk/configs/boards/RT-AC54U/kernel-3.4.x.config檔案
查詢並修改為如下內容(主要修正是刪除#號,或者將is not set改為=y或=n)

12345678910 CONFIG_RT_SINGLE_SKU=nCONFIG_RT2860V2_AP_GREENAP=yCONFIG_INTERNAL_PA_INTERNAL_LNA=nCONFIG_INTERNAL_PA_EXTERNAL_LNA=nCONFIG_EXTERNAL_PA_EXTERNAL_LNA=yCONFIG_MT76X2_AP_GREENAP=yCONFIG_MT76X2_AP_INTERNAL_PA_INTERNAL_LNA=nCONFIG_MT76X2_AP_INTERNAL_PA_EXTERNAL_LNA=nCONFIG_MT76X2_AP_EXTERNAL_PA_EXTERNAL_LNA=yCONFIG_RALINK_UART_BRATE=57600

然後儲存檔案

三:修正WAN/LAN順序

預設情況下,WAN口會變成LAN4口,LAN4口會變成WAN口
編輯/opt/rt-n56u/trunk/configs/boards/RT-AC54U/kernel-3.4.x.config檔案
查詢WAN=0並修改為如下內容

12345 CONFIG_RAETH_ESW_PORT_WAN=4CONFIG_RAETH_ESW_PORT_LAN1=3CONFIG_RAETH_ESW_PORT_LAN2=2CONFIG_RAETH_ESW_PORT_LAN3=1CONFIG_RAETH_ESW_PORT_LAN4=0

然後儲存檔案

四:漢化

(有能力的自己漢化也行,我這借用hiboy的漢化)
下載hiboy的韌體,並用7-zip開啟trx韌體檔案,提取裡面的/www/EN.dict,編輯EN.dict,修改第二,三行內容如下,

12 LANG_RU=簡體中文LANG_EN=English

並另存為RU.dict檔案,替換/opt/rt-n56u/trunk/user/www/dict/RU.dict檔案

再編輯/opt/rt-n56u/trunk/user/www/Makefile檔案,查詢並將RU=後面的內容改為”簡體中文”

1 echo "LANG_RU=簡體中文" >> $(ROMFS_DIR)/www/EN.header

然後儲存檔案

五:預設配置(可選)

給路由設定個人的預設配置
編輯/opt/rt-n56u/trunk/user/shared/defaults.c
使路由器不用ISP的dns,用第三方dns

123 {wan_dnsenable_x", "0" },{ "wan_dns1_x", "223.5.5.5" },{ "wan_dns2_x", "119.29.29.29" },

承接上面,如果電腦將路由器當用dns伺服器,則進入路由頁面
http://192.168.1.1/Advanced_DHCP_Content.asp
“DHCP伺服器”
自定義配置檔案 “dnsmasq.conf”
(配置路由裡的dnsmasq,如googlevideo用sni,則新增address=/.googlevideo.com/xxx.xx.x.x)

自定義配置檔案 “hosts”
(配置路由裡的hosts)

路由預設登陸ip

12 { "lan_ipaddr", "192.168.1.1" },{ "lan_netmask", "255.255.255.0" },

dhcp客戶機分配數量

12 { "dhcp_start", "192.168.1.101" },{ "dhcp_end", "192.168.1.250" },

關閉telnet開啟ssh

12 { "telnetd", "0" },{ "sshd_enable", "1" },

然後儲存檔案

編輯/opt/rt-n56u/trunk/user/shared/defaults.h

下面內容主要是配置2G/5G無線區碼,預設SSID名字(ABC_x),預設密碼(1234567890),預設路由管理員密碼(admin8888),預設時區,預設NTP時間伺服器

12345678910111213141516171819 #define SYS_USER_ROOT "admin"#define SYS_GROUP_ROOT "root"#define SYS_USER_NOBODY "nobody"#define SYS_GROUP_NOGROUP "nogroup"#define DEF_WLAN_2G_CC "CN"#define DEF_WLAN_5G_CC "CN"#define DEF_WLAN_2G_SSID "ABC_2016"#define DEF_WLAN_5G_SSID "ABC_2016_5G"#define DEF_WLAN_2G_GSSID "ABC_GUEST"#define DEF_WLAN_5G_GSSID "ABC_GUEST_5G"#define DEF_WLAN_2G_PSK "1234567890"#define DEF_WLAN_5G_PSK "1234567890"#define DEF_ROOT_PASSWORD "admin8888"#define DEF_SMB_WORKGROUP "WORKGROUP"#define DEF_TIMEZONE "CST-8"#define DEF_NTP_SERVER0 "ntp1.aliyun.com"#define DEF_NTP_SERVER1 "time.nist.gov"

編輯/opt/rt-n56u/trunk/user/scripts/profile檔案內容如下
當進入ssh時,文字不再黑白了,有色彩

123456789101112131415161718192021 # /etc/profile# If running interactively, thenif [ "$PS1" ] ; then export PATH='/opt/usr/sbin:/opt/usr/bin:/opt/sbin:/opt/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin' export HOSTNAME=`/bin/hostname` export TERMINFO=/usr/share/terminfo export TERM=xterm export LD_LIBRARY_PATH=/lib:/etc_ro/lib:/opt/lib export LANG='en_US.UTF-8' export LC_ALL='en_US.UTF-8' export PS1='\[\033[35;1m\]\u\[\033[0m\]@\[\033[31;1m\]\h \[\033[32;1m\]$PWD\[\033[0m\] [\[\033[35m\]\$\[\033[0m\]] 'fi; alias ls='ls --color=auto -F' alias dir='ls --color=auto -lAhF' alias ll='ls --color=auto -lAhFe'[ -r /opt/etc/profile ] && . /opt/etc/profile

開始編譯韌體!(上面的全部操作都是在切換到root使用者操作的,下面也是一樣。)
編輯/opt/rt-n56u/trunk/.config檔案內容如下(這個檔案是隱藏的),我這個配置是禁用usb相關東西的。

如果你的檔案路徑沒有按照本教程,則要注意下面的“CONFIG_TOOLCHAIN_DIR=/opt/rt-n56u/toolchain-mipsel”改為你自己的路徑

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 ### Target Vendor/Product (support only Ralink RT3883/MT7620/MT7621/MT7628)CONFIG_VENDOR=RalinkCONFIG_PRODUCT=MT7620### Target ProductID (board select, max 12 symbols)CONFIG_FIRMWARE_PRODUCT_ID="RT-AC54U"### Linux kernel and toolchainCONFIG_LINUXDIR=linux-3.4.xCONFIG_TOOLCHAIN_DIR=/opt/rt-n56u/toolchain-mipsel############################################################### Linux kernel configuration############################################################### Build ROOTFS_IN_RAM firmware mode (kernel+initramfs).### Decreased firmware size, but more RAM used, slow boot.### Also allow build image for load w/o flash from UART console#CONFIG_FIRMWARE_TYPE_ROOTFS_IN_RAM=y### Force MT7620 CPU clock to 600MHz (override Uboot settings)#CONFIG_FIRMWARE_CPU_600MHZ=y### Enable MT7620 CPU sleep mode (downclock to 200MHz on idle)CONFIG_FIRMWARE_CPU_SLEEP=y### Kernel driver select for WiFi AP 2.4GHz### 2.7 = MT7620 v2.7.2.0### 3.0 = MT7620 v3.0.4.0CONFIG_FIRMWARE_WIFI2_DRIVER=2.7### Kernel driver select for WiFi AP 5GHz### 3.0 = MT7612E v3.0.4.0CONFIG_FIRMWARE_WIFI5_DRIVER=3.0### Enable IPv6 supportCONFIG_FIRMWARE_ENABLE_IPV6=y### Enable USB support#CONFIG_FIRMWARE_ENABLE_USB=y### Enable NTFS filesystem support via Paragon "ufsd" driver. ~0.4MB#CONFIG_FIRMWARE_ENABLE_UFSD=y### Enable FAT/FAT32 filesystem support. ~0.1MB#CONFIG_FIRMWARE_ENABLE_FAT=y### Enable exFAT (FAT/FAT32 too) filesystem support. ~0.12MB#CONFIG_FIRMWARE_ENABLE_EXFAT=y### Enable EXT2 filesystem support. ~0.1MB#CONFIG_FIRMWARE_ENABLE_EXT2=y### Enable EXT3 filesystem support. ~0.2MB#CONFIG_FIRMWARE_ENABLE_EXT3=y### Enable EXT4 (EXT3/2 too) filesystem support. ~0.4MB#CONFIG_FIRMWARE_ENABLE_EXT4=y### Enable XFS filesystem support. ~0.6MB#CONFIG_FIRMWARE_ENABLE_XFS=y### Enable FUSE (filesystems in userspace) support. ~0.1MB#CONFIG_FIRMWARE_ENABLE_FUSE=y### Enable swap files/partitions support. ~0.05MB#CONFIG_FIRMWARE_ENABLE_SWAP=y### Include UVC camera modules. ~0.2MB#CONFIG_FIRMWARE_INCLUDE_UVC=y### Include USB-HID modules. ~0.2MB#CONFIG_FIRMWARE_INCLUDE_HID=y### Include USB-Serial modules (e.g. pl2303). ~0.03MB#CONFIG_FIRMWARE_INCLUDE_SERIAL=y### Include USB-Audio modules ~0.46MB#CONFIG_FIRMWARE_INCLUDE_AUDIO=y### Include network QoS scheduling modules. ~0.2MBCONFIG_FIRMWARE_INCLUDE_QOS=y### Include IMQ module for shapers (a bit of performance degradation). ~0.02MB#CONFIG_FIRMWARE_INCLUDE_IMQ=y### Include IFB module for shapers. ~0.03MB#CONFIG_FIRMWARE_INCLUDE_IFB=y### Include IPSet utility and kernel modules. ~0.4MBCONFIG_FIRMWARE_INCLUDE_IPSET=y### Include NFSv3 server. ~0.6MB#CONFIG_FIRMWARE_INCLUDE_NFSD=y### Include NFSv3 client. ~0.5MB#CONFIG_FIRMWARE_INCLUDE_NFSC=y### Include CIFS (SMB) client. ~0.2MB#CONFIG_FIRMWARE_INCLUDE_CIFS=y############################################################### Userspace configuration############################################################### Include WebUI international resources. Increased firmware size#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=yCONFIG_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=y### Include LPR printer daemon. ~0.12MB#CONFIG_FIRMWARE_INCLUDE_LPRD=y### Include USB-over-Ethernet printer daemon. ~0.05MB#CONFIG_FIRMWARE_INCLUDE_U2EC=y### Include "tcpdump" utility. ~0.6MB#CONFIG_FIRMWARE_INCLUDE_TCPDUMP=y### Include "hdparm" utility (allow set HDD spindown timeout and APM). ~0.1MB#CONFIG_FIRMWARE_INCLUDE_HDPARM=y### Include "parted" utility (allow make GPT partitions). ~0.3MB#CONFIG_FIRMWARE_INCLUDE_PARTED=y### Include SMB (and WINS) server. ~1.5MB#CONFIG_FIRMWARE_INCLUDE_SMBD=y### Include WINS server only. ~0.4MB#CONFIG_FIRMWARE_INCLUDE_WINS=y### Include syslog for SMB and WINS server. ~0.3MB#CONFIG_FIRMWARE_INCLUDE_SMBD_SYSLOG=y### Include FTP server. ~0.2MB#CONFIG_FIRMWARE_INCLUDE_FTPD=y### Include alternative L2TP control client RP-L2TP. ~0.1MB#CONFIG_FIRMWARE_INCLUDE_RPL2TP=y### Include EAP-TTLS and EAP-PEAP authentication support. openssl ~1.2MB, wpa_supplicant +0.04MBCONFIG_FIRMWARE_INCLUDE_EAP_PEAP=y### Include HTTPS support for DDNS client. openssl ~1.2MBCONFIG_FIRMWARE_INCLUDE_DDNS_SSL=y### Include HTTPS support. openssl ~1.2MBCONFIG_FIRMWARE_INCLUDE_HTTPS=y### Include sftp-server. openssl ~1.2MB, sftp-server ~0.06MBCONFIG_FIRMWARE_INCLUDE_SFTP=y### Include dropbear SSH. ~0.3MBCONFIG_FIRMWARE_INCLUDE_DROPBEAR=y### Make the dropbear symmetrical ciphers and hashes faster. ~0.06MBCONFIG_FIRMWARE_INCLUDE_DROPBEAR_FAST_CODE=y### Include OpenSSH instead of dropbear. openssl ~1.2MB, openssh ~1.0MB#CONFIG_FIRMWARE_INCLUDE_OPENSSH=y### Include OpenVPN. IPv6 required. openssl ~1.2MB, openvpn ~0.4MBCONFIG_FIRMWARE_INCLUDE_OPENVPN=y### Include Elliptic Curves (EC) to openssl library. ~0.1MBCONFIG_FIRMWARE_INCLUDE_OPENSSL_EC=y### Include "openssl" executable for generate certificates. ~0.4MBCONFIG_FIRMWARE_INCLUDE_OPENSSL_EXE=y### Include xUPNPd IPTV mediaserver. ~0.3MB#CONFIG_FIRMWARE_INCLUDE_XUPNPD=y### Include Minidlna UPnP mediaserver. ~1.6MB#CONFIG_FIRMWARE_INCLUDE_MINIDLNA=y### Include Firefly iTunes mediaserver. ~1.0MB#CONFIG_FIRMWARE_INCLUDE_FIREFLY=y### Include ffmpeg 0.11.x instead of 0.6.x for Minidlna and Firefly. ~0.1MB#CONFIG_FIRMWARE_INCLUDE_FFMPEG_NEW=y### Include Transmission torrent. openssl ~1.2MB, transmission ~1.5MB#CONFIG_FIRMWARE_INCLUDE_TRANSMISSION=y### Include Transmission-Web-Control (advanced WebUI). ~0.8MB#CONFIG_FIRMWARE_INCLUDE_TRANSMISSION_WEB_CONTROL=y### Include Aria2 download manager. openssl ~1.2MB, aria2 ~3.5MB#CONFIG_FIRMWARE_INCLUDE_ARIA=y### Include Aria2 WEB control. ~0.7MB#CONFIG_FIRMWARE_INCLUDE_ARIA_WEB_CONTROL=y

所有配置都好了,現在開始編譯

12345 cd /opt/rt-n56u/trunk./clear_tree#每次編譯都要先執行這句./build_firmware#開始編譯了

去看個電影動畫什麼的,等待結果,如果不出錯,最後會顯示資訊包括韌體大小,名字,位置等
最後韌體生成在/opt/rt-n56u/trunk/images下.trx副檔名的。

後續升級原始碼

1234567891011 git pull#如果toolchain-mipsel有改過,則要重新編譯cd /opt/rt-n56u/toolchain-mipsel/clean_sources/clean_toolchain/build_toolchain#再編譯更新過的韌體cd /opt/rt-n56u/trunk./clear_tree./build_firmware

心得

1 有時候自己的sh指令碼執行不了,要用dos2unix轉一下檔案才行

2 nvram引數的作用過程(用adbyby作例子)
先命名nvram引數,寫好執行/停止adbyby的指令碼,在services.c裡定義通過nvram引數值來如何執行指令碼。
最後就是在asp頁面裡改變nvram引數值
可以參考aria相關指令碼和引數

3 去廣告時要開啟cron功能,因為adbyby的透明代理有時候會掉

5 指令碼執行adbyby
在/etc/storage/下新建adbyby.sh內容如下

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 #!/bin/shLOGTIME=$(date "+%Y-%m-%d %H:%M:%S")TAG="adbyby" # iptables tagdir_crond="/etc/storage/cron/crontabs"username=$(whoami)urla="https://raw.githubusercontent.com/adbyby/xwhyc-rules/master/video.txt"dladb="https://raw.githubusercontent.com/adbyby/Files/master/7620n.tar.gz"func_create_config(){ cd /tmp wget --continue --no-check-certificate -s -q -T 3 $urla if [ "$?" == "0" ] ; then echo "[$LOGTIME] update.adbyby.com have no problem." wget -q --no-check-certificate $dladb -P /tmp/ tar -xzf /tmp/7620n.tar.gz -C /tmp/ rm -rf /tmp/7620n.tar.gz chmod 777 /tmp/bin/adbyby logger -t "【$TAG】" "['$LOGTIME'] 下載成功." else echo "[$LOGTIME] update.adbyby.com have problem." logger -t "【$TAG】" "['$LOGTIME'] 下載失敗,檢查網路." fi}func_start(){ if [ ! -d "/tmp/bin" ] ; then func_create_config fi if [ ! -z "`pidof "$TAG"`" ] ; then echo "$TAG" still running exit 1; else /tmp/bin/adbyby >/dev/null 2>&1 & if iptables -t nat -nL --line-numbers | grep -q "$TAG"; then echo "$TAG" still running!; else iptables -t nat -N "$TAG" iptables -t nat -A "$TAG" -p tcp --dport