编译环境 ubuntu 22.04
编译的版本是 openwrt-23.05
树莓派 4B
1. 安装开发环境
1 2 3 4 |
sudo apt update sudo apt install build-essential clang flex bison g++ gawk \ gcc-multilib g++-multilib gettext git libncurses-dev libssl-dev \ python3-distutils rsync unzip zlib1g-dev file wget xsltproc |
2. 下载OpenWrt
这里分 git 自动下载和手动下载两种方法
2.1 git 下载
1 2 3 4 5 6 7 |
git clone https://github.com/openwrt/openwrt.git cd openwrt git branch -a git tag git checkout v23.05.0 git checkout -b openwrt-23.05 origin/openwrt-23.05 git pull |
2.2 手动下载
有时候,git clone 不好使,可以手动去网页下载下面的链接:
1 2 3 4 5 6 |
https://github.com/openwrt/openwrt/tree/openwrt-23.05 https://github.com/openwrt/packages/tree/openwrt-23.05 https://github.com/openwrt/luci/tree/openwrt-23.05 https://github.com/openwrt/telephony/tree/openwrt-23.05 https://github.com/openwrt/routing/tree/openwrt-23.05 |
复制到项目目录,然后解压
1 2 3 4 5 6 |
cd /home/tony/git unzip openwrt-openwrt-23.05.zip unzip packages-openwrt-23.05.zip unzip luci-openwrt-23.05.zip unzip routing-openwrt-23.05.zip unzip telephony-openwrt-23.05.zip |
复制 feeds.conf
1 2 |
cd openwrt-openwrt-23.05 cp feeds.conf.default feeds.conf |
修改 feeds.conf,修改后的内容,
1 2 3 4 |
src-link packages /home/tony/git/packages-openwrt-23.05 src-link luci /home/tony/git/luci-openwrt-23.05 src-link routing /home/tony/git/routing-openwrt-23.05 src-link telephony /home/tony/git/telephony-openwrt-23.05 |
3. 更新并安装软件包源
1 2 |
./scripts/feeds update -a ./scripts/feeds install -a |
确保运行正常
4. 配置 firmware image
运行命令:
1 |
make menuconfig |
也可以下载 23.05 的配置文件,作为 .config
1 |
cp config.buildinfo .config |
根据自己的配置修改,下面是我需要的修改内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
Target System (Broadcom BCM27xx) ---> Broadcom BCM27xx Subtarget (BCM2711 boards (64 bit)) ---> (X) BCM2711 boards (64 bit) Target Profile (Raspberry Pi 4B/400/CM4 (64bit)) ---> (X) Raspberry Pi 4B/400/CM4 (64bit) Target Images ---> (2048) Kernel partition size (in MiB) (26624) Root filesystem partition size (in MiB) [*] Make /var persistent [*] Build the OpenWrt Image Builder [*] Include package repositories Kernel modules ---> GPIO support ---> <*> kmod-gpio-cascade................................... Generic GPIO cascade Network Devices ---> <*> kmod-wwan............................................... WWAN Driver Core Other modules ---> <*> kmod-gpio-beeper..................................... GPIO beeper support <*> kmod-gpio-button-hotplug............... Simple GPIO Button Hotplug driver <*> kmod-gpio-nxp-74hc164.................. NXP 74HC164 GPIO expander support <*> kmod-gpio-pca953x................ PCA95xx, TCA64xx, and MAX7310 I/O ports <*> kmod-gpio-pcf857x........ PCX857x, PCA967x and MAX732X I2C GPIO expanders USB Support ---> -*- kmod-usb-core............................................ Support for USB <*> kmod-usb-hid......................... Support for USB Human Input Devices (NEW) <*> kmod-usb-net............... Kernel modules for USB-to-Ethernet convertors <*> kmod-usb-net-cdc-ether.............. Support for cdc ethernet connections <*> kmod-usb-net-qmi-wwan.................................... QMI WWAN driver <*> kmod-usb-net-rndis......................... Support for RNDIS connections <*> kmod-usb-serial..................... Support for USB-to-Serial converters <*> kmod-usb-serial-option................... Support for Option HSDPA modems Libraries ---> SSL ---> -*- libopenssl........................... Open source SSL toolkit (libraries) LuCI ---> 1. Collections ---> <*> luci................... LuCI interface with Uhttpd as Webserver (default) < > luci-lib-docker.................................. LuCI library for docker -*- luci-light............... LuCI interface with Uhttpd as Webserver (light) < > luci-nginx........................ LuCI interface with Nginx as Webserver <*> luci-ssl................ LuCI with HTTPS support (mbedtls as SSL backend) < > luci-ssl-nginx. LuCI with HTTPS support on Nginx (OpenSSL as SSL backend) <*> luci-ssl-openssl........ LuCI with HTTPS support (OpenSSL as SSL backend) Network ---> Web Servers/Proxies -*- uhttpd........................ uHTTPd - tiny, single threaded HTTP server <*> uhttpd-mod-lua... uHTTPd - tiny, single threaded HTTP server (Lua plugin) <*> uhttpd-mod-ubus. uHTTPd - tiny, single threaded HTTP server (ubus plugin) <*> uhttpd-mod-ucode |
Target Images 的 分区大小,根据您的卡的大小来,如果太大,可能写入会有问题。
记得保存为 .config
5. 编译
根据您的CPU数量,在make 后面的参数j, 后面可以跟数量,多线程编译
1 |
make -j$(nproc) |
在 bin/ 目录下有 packages 和 targets 目录
在这些目录里面可以找到您想要的东西
1 2 |
zip -r openwrt_23.05_packages.zip bin/packages zip -r openwrt_23.05_targets.zip bin/targets |
6. 清除环境
6.1 清除编译产物
make clean: 这个命令会删除大部分编译产物,但会保留配置和工具链,让下一次编译速度更快。
1 |
make clean |
6.2 完全清除所有编译产物和配置
make dirclean: 使用这个命令可以更彻底地清理,它会删除所有编译产物、配置和工具链。这基本上会让你的编译环境恢复到克隆源代码之后的原始状态。
1 |
make dirclean |
6.3 清除构建目录和配置
make distclean: 这个命令会删除所有编译产物和工具链,但与dirclean
不同的是,它还会删除配置文件。这意味着你的.config
文件也会被清除,你需要重新进行配置。
1 |
make distclean |
7. 安装 image 到 卡上
可以使用官方的 imager 进行加载然后写道 卡上
8. 其他
如果你是从 github.com 上直接下载 zip 包的,可以通过如下命令,转换为 git 库
8.1 初始化Git仓库
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
cd openwrt-openwrt-23.05 git init hint: Using 'master' as the name for the initial branch. This default branch name hint: is subject to change. To configure the initial branch name to use in all hint: of your new repositories, which will suppress this warning, call: hint: hint: git config --global init.defaultBranch <name> hint: hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and hint: 'development'. The just-created branch can be renamed via this command: hint: hint: git branch -m <name> Initialized empty Git repository in /home/tony/git/openwrt-openwrt-23.05/.git/ |
8.2 添加远程仓库
1 |
git remote add origin https://github.com/openwrt/openwrt.git |
8.3 拉取最新的代码
1 |
git pull origin openwrt-23.05 --allow-unrelated-histories |