OpenWrt编译环境搭建
-
基于Ubuntu 22.04,64bit的操作系统
-
先clone仓库:
git clone https://git.openwrt.org/openwrt/openwrt.git
可能会比较久,取决于网络状况。笔者是23年Q4写的,此时openwrt已经为v23了。
clone成功后,会在clone的路径下有
openwrt
的文件夹。 -
进入文件夹:
cd openwrt
更新软件包:
./scripts/feed update ./scripts/feed install
后续有需要,也可以手动再更新。
-
生成配置文件:
make defconfig
这一步和电脑安装软件的情况有关。可能会有报错,此时需根据报错日志来判断安装软件,如:
sudo apt-get install git
建议有报错后再安装即可,没必要一次性安装推荐的所有软件,浪费电脑磁盘。
-
进入定制页面:
make menuconfig
通过键盘的上下方向键选择机型,包括CPU等,通过空格键选中,保存并退出。
如果有需要定制的package,也可以在这一步操作,如可以参考笔者的:
-
编译:
make -j4 V=sc
-j4
表示使用4核编译,如果电脑的CPU比较强,则推荐,如果有更多的核,可以-j99
,编译时会自动调整核心,不过单核的电脑,这个参数就没有意义了。当然,第一次编译,建议先不用该参数,先单核编译,出错率会少一些V=sc
表示输出更多的报错日志,方便debug,例如是否是download某些源文件失败等,如果是download失败,可能是国内网络环境受限,可通过报错日志中的URL等信息,手动下载对应的压缩包文件,放在dl
目录下,然后重新编译即可
-
附完整编译日志,笔者这里是编译时不带
V=sc
参数,芯片方案为高通的ipq40xx
:make[2]: Entering directory '/home/ubuntu/openwrt/scripts/config' make[2]: 'conf' is up to date. make[2]: Leaving directory '/home/ubuntu/openwrt/scripts/config' make[1] world make[2] package/cleanup make[2] target/compile make[3] -C target/linux compile make[2] buildinfo make[2] package/compile make[3] diffconfig buildversion feedsversion make[3] -C package/libs/toolchain compile make[3] -C package/libs/libjson-c host-compile make[3] -C package/kernel/gpio-button-hotplug compile make[3] -C package/libs/ncurses host-compile make[3] -C package/system/fwtool host-compile make[3] -C package/system/usign host-compile make[3] -C package/system/openwrt-keyring compile make[3] -C feeds/luci/modules/luci-base host-compile make[3] -C package/libs/mbedtls compile make[3] -C package/utils/lua host-compile make[4] scripts/config/conf make[3] -C feeds/luci/contrib/package/csstidy host-compile make[3] -C package/libs/jansson compile make[3] -C package/libs/libmnl compile make[3] -C package/system/ca-certificates compile make[3] -C feeds/packages/libs/nghttp2 compile make[3] -C package/firmware/ath11k-firmware compile make[3] -C package/firmware/ipq-wifi compile make[3] -C package/firmware/wireless-regdb compile make[3] -C package/kernel/qca-ssdk compile make[3] -C package/network/services/dropbear compile make[3] -C package/libs/libpcap compile make[3] -C package/network/utils/linux-atm compile make[3] -C package/network/utils/resolveip compile make[3] -C package/libs/libsepol compile make[3] -C package/libs/musl-fts compile make[3] -C package/utils/e2fsprogs host-compile make[3] -C package/libs/libubox host-compile make[3] -C package/libs/libnl-tiny compile make[3] -C package/libs/libjson-c compile make[3] -C package/utils/lua compile make[3] -C package/firmware/linux-firmware compile make[3] -C package/libs/zlib compile make[3] -C package/system/fwtool compile make[3] -C package/system/ucert host-compile make[3] -C package/libs/libnftnl compile make[3] -C feeds/luci/protocols/luci-proto-ppp compile make[3] -C feeds/luci/themes/luci-theme-bootstrap compile make[3] -C feeds/luci/protocols/luci-proto-ipv6 compile make[3] -C feeds/luci/libs/luci-lib-ip compile make[3] -C feeds/luci/libs/luci-lib-jsonc compile make[3] -C feeds/luci/libs/luci-lib-nixio compile make[3] -C feeds/luci/themes/luci-theme-material compile make[3] -C feeds/packages/net/curl compile make[3] -C package/network/utils/iw compile make[3] -C package/libs/pcre2 compile make[3] -C package/system/opkg host-compile make[3] -C package/libs/libubox compile make[3] -C package/kernel/linux compile make[3] -C package/libs/ncurses compile make[3] -C package/utils/jsonfilter compile make[3] -C package/system/usign compile make[3] -C package/libs/ustream-ssl compile make[3] -C feeds/packages/admin/htop compile make[3] -C package/network/ipv6/odhcp6c compile make[3] -C package/system/mtd compile make[3] -C package/libs/libselinux compile make[3] -C package/system/urngd compile make[3] -C package/utils/busybox compile make[3] -C package/system/ubus compile make[3] -C package/system/uci compile make[3] -C package/utils/util-linux compile make[3] -C package/libs/uclient compile make[3] -C package/utils/ucode compile make[3] -C package/network/utils/iwinfo compile make[3] -C feeds/luci/contrib/package/ucode-mod-html compile make[3] -C feeds/packages/net/cgi-io compile make[3] -C package/network/services/uhttpd compile make[3] -C feeds/luci/contrib/package/ucode-mod-lua compile make[3] -C package/network/services/hostapd compile make[3] -C package/network/services/dnsmasq compile make[3] -C package/network/services/odhcpd compile make[3] -C package/utils/e2fsprogs compile make[3] -C package/network/config/netifd compile make[3] -C package/system/ubox compile make[3] -C package/utils/mtd-utils compile make[3] -C package/system/opkg compile make[3] -C package/network/utils/nftables compile make[3] -C feeds/luci/contrib/package/lucihttp compile make[3] -C package/system/rpcd compile make[3] -C feeds/luci/libs/luci-lib-base compile make[3] -C package/kernel/mac80211 compile make[3] -C package/system/urandom-seed compile make[3] -C package/system/fstools compile make[3] -C feeds/luci/applications/luci-app-opkg compile make[3] -C package/network/config/firewall4 compile make[3] -C feeds/luci/libs/rpcd-mod-luci compile make[3] -C feeds/luci/libs/rpcd-mod-rrdns compile make[3] -C package/system/procd compile make[3] -C package/base-files compile make[3] -C package/boot/uboot-envtools compile make[3] -C feeds/luci/applications/luci-app-firewall compile make[3] -C feeds/luci/modules/luci-base compile make[3] -C package/network/services/ppp compile make[3] -C feeds/luci/modules/luci-mod-network compile make[3] -C feeds/luci/modules/luci-mod-status compile make[3] -C feeds/luci/modules/luci-mod-system compile make[3] -C feeds/luci/modules/luci-lua-runtime compile make[3] -C feeds/luci/modules/luci-mod-admin-full compile make[3] -C feeds/luci/modules/luci-compat compile make[3] -C feeds/luci/libs/luci-lib-ipkg compile make[3] -C package/luci-theme-argon compile make[3] -C feeds/luci/collections/luci-light compile make[3] -C package/luci-app-argon-config compile make[3] -C feeds/luci/collections/luci compile make[3] -C package/kernel/qca-nss-dp compile make[2] package/install make[2] target/install make[3] -C target/linux install make[2] package/index make[2] json_overview_image_info make[2] checksum
后续这些便是可选的编译目标,例如需要单独编译
procd
,则:make package/system/procd compile
-
编译后的镜像文件在
bin
目录下,如笔者的为:bin/targets/ipq40xx/generic/
-
说明下几个镜像:
镜像 说明 备注 initramfs-recovery.itb itb固件,并且带initramfs,即可以进入uboot,直接通过加载该镜像启动,如:bootm xxx.initramfs-recovery.itb 通常可用于测试固件是否正常,此时uboot启动,并不会破坏原有的FW分区等数据 squashfs-factory.ubi 带factory字样,一般会覆盖旧有的配置,如第一次刷机 squashfs-sysupgrade.bin 即经过刷机后的可通过openwrt页面直接升级的FW 在刷机稳定后,通过此固件升级;如果已经是openwrt固件,即可直接通过web升级该固件 -
TBD