OpenWrt官网
https://openwrt.org/
OpenWrt源码地址
https://github.com/openwrt/openwrt
依赖库安装
binutils bzip2 diff find flex gawk gcc-6+ getopt grep install libc-dev libz-dev make4.1+ perl python3.6+ rsync subversion unzip which获取源码
git clone -b openwrt-18.06 https://github.com/openwrt/openwrt
其中-b后参数为代码版本,根据branches和tags进行指定版本拉取
2、自定义固件以编译mt7621为例,操作目录为
./target/linux/ramips/
其他平台类似
2.1添加机型mymodle.dts文件文件地址:
./target/linux/ramips/dts/mymodle.dts
复制已有的型号dts为mymodle.dts并根据硬件参数修改,要特别注意以下参数
compatible = "mycompany,mymodle", "mediatek,mt7621-soc";
model = "MyModle";
chosen {
bootargs = "console=ttyS0,115200";
};
其中:
mycompany为生产厂商
mymodle为生产型号
MyModle为系统中显示的设备型号
console=ttyS0,115200为串口波特率设置
文件地址:
./target/linux/ramips/image/mt7621.mk
添加设备:
define Device/mymodle DTS := mydts IMAGE_SIZE := $(ralink_default_fw_size_16M) DEVICE_TITLE := MYCOMPANY MYMODLE DEVICE_PACKAGES := kmod-ata-core kmod-ata-ahci kmod-mt76x2 kmod-sdhci-mt7620 kmod-usb3 kmod-usb-ledtrig-usbport wpad-mini endef TARGET_DEVICES += mymodle2.2、添加升级支持
为网页升级添加支持,防止出现以下错误
不支持所上传的映像文件格式,请选择适合当前平台的通用映像文件。修改platform.sh文件
文件地址:
./target/linux/ramips/base-files/lib/upgrade/platform.sh
添加机型:
*"MyModle") name="mymodle" ;;
Mymodle和mymodle需与2.1中提到的参数对应
修改ramips.sh文件文件地址:
./target/linux/ramips/base-files/lib/ramips.sh
添加设备:
case "$board" in mymodle|
mymodle需与2.1中提到的参数对应
3、添加系统文件固化自己的文件如:配置文件、脚本、程序等到系统中
在编译目录新建文件夹
mkdir ./files
此文件夹的文件将会固化到系统文件根目录
注意:编译前需要为文件赋予权限,否则文件权限不够,固化后系统无法执行
chmod 777 ./files/*4、编译 4.1、更新插件库
./scripts/feeds update -a ./scripts/feeds install -a4.2、编译设置
执行编译配置:
make menuconfig
选择所需要安装的插件,建议的基本插件如下:
Libraries libuci-lua Luci Collections luci Modules translations chinese Network SSH openssh-sftp-server
默认编译配置文件为
.config
你也可以备份编译配置为
myconf.config
开始编译,执行:
make -j2 V=s
其中-j2为系统核心数,可以加快编译速度;V=s为显示编译日志。
最后生成的固件在目录
./bin/targets/ramips/mt7621/



