这里真的非常感谢这篇博客提供了大量支持,本文有大量篇幅抄袭。
https://blog.csdn.net/qq_44730817/article/details/135258664
Clone the Git repository using the following command.
git clone https://git.openwrt.org/openwrt/openwrt.git []
//如果直接下载到当前路径[]可以省略
//如果不想到当前目录,其中 [] 替换为你的编译目录,比如我的为 ~/tmp/build/openwrt/
git branch -a
git tag
git checkout v23.05.2
//这里其实是git切换分支到子仓库
./scripts/feeds update -a
./scripts/feeds install -a
//如果运行显示找不到可以先运行下面的
apt search qemu-img --- 查找文件名
apt install qemu-utils -- 得到文件名,install
因为网络环境的问题,建议重复执行上面的命令直到能够看到完全正常为止,正常如下
重复运行 ./scripts/feeds update -a 直到显示如下
shenyanwu@shenyanwu:~/tmp/build/openwrt$ ./scripts/feeds update -a
Updating feed 'packages' from 'https://git.openwrt.org/feed/packages.git^8e3a1824645f5e73ec44c897ac0755c53fb4a1f8' ...
Updating feed 'luci' from 'https://git.openwrt.org/project/luci.git^7739e9f5b03b830f51d53c384be4baef95054cb3' ...
Updating feed 'routing' from 'https://git.openwrt.org/feed/routing.git^83ef3784a9092cfd0a900cc28e2ed4e13671d667' ...
Updating feed 'telephony' from 'https://git.openwrt.org/feed/telephony.git^9746ae8f964e18f04b64fbe1956366954ff223f8' ...
Create index file './feeds/packages.index'
Create index file './feeds/luci.index'
Create index file './feeds/routing.index'
Create index file './feeds/telephony.index'
shenyanwu@shenyanwu:~/tmp/build/openwrt$
重复运行 ./scripts/feeds install -a 直到显示如下
shenyanwu@shenyanwu:~/tmp/build/openwrt$ ./scripts/feeds install -a
Collecting package info: package/feeds/packages/udp-broadcast-relay-redux-openwr
Collecting package info: done
Installing all packages from feed packages.
Installing all packages from feed luci.
Installing all packages from feed routing.
Installing all packages from feed telephony.
shenyanwu@shenyanwu:~/tmp/build/openwrt$
我的版本是 23.05.2,树莓派4B
如果你的设备不是树莓派,你可以在官方的下载目录去找到与你设备芯片对应的配置文件链接: 传送门
这里可以直接使用官网的配置文件,这样就可以跳过后续的make menuconfig
wget https://downloads.openwrt.org/releases/23.05.2/targets/bcm27xx/bcm2711/config.buildinfo -O .config
这一串代码是把网站上的config.buildinfo拷贝成本地的.config配置文件
make menuconfig
运行此命令后等待片刻则会出现配置选择,通过上下方向键 ↑ ↓ 进行选择,回车键 ↵ 进入,空格键 Space 选择,其中选项前面的 表示编译为独立的包,即类似安装包,不会在编译好的系统中存在,需要另外安装, <*> 表示编译为内建包,即相当于直接编译至系统内部,不需要另外再安装,连续按下两次退出键 ESC 返回上一级目录,最后保存好的配置文件将会在当前的 OpenWrt 目录下生成一个名为 .config 的隐藏文件
我们在上一步已经导入了官方的config配置文件,这一步可以不执行,但是可以进去看看学习参考。
在编译命令之前,可以运行一个检查命令,用来检查你的依赖项,包的一些先决条件等是否满足要求,还会从中删除过时的项目,例如对不存在的软件包或配置选项的引用
make defconfig
我的运行如下图所示:
shenyanwu@shenyanwu:~/tmp/build/openwrt$ make defconfig
tmp/.config-package.in:33826:error: recursive dependency detected!
tmp/.config-package.in:33826: symbol PACKAGE_python3-pymysql depends on PYTHON3_PYMYSQL_SHA_PASSWORD_SUPPORT
feeds/packages/lang/python/pymysql/Config.in:4: symbol PYTHON3_PYMYSQL_SHA_PASSWORD_SUPPORT depends on PACKAGE_python3-pymysql
For a resolution refer to Documentation/kbuild/kconfig-language.rst
subsection "Kconfig recursive dependency limitations"
#
# configuration written to .config
#
shenyanwu@shenyanwu:~/tmp/build/openwrt$
此处检测到发生了一个依赖错误,通过查询 OpenWrt 官方 Github 的 issues,找到解决方案,链接 issues #22668
问题在于 feeds/packages/lang/python/pymysql 路径下 Makefile 里面的依赖冲突(具体路径是./feeds/packages/lang/python/pymysql/Makefile ),该 issues 给出了解决方案,对 Makefile 文件修改如下,其中段落前面的 - 代表需要删除的部分, + 代表需要增添的部分
#
# Copyright (C) Alexandru Ardelean
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=pymysql
PKG_VERSION:=1.0.2
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PYPI_NAME:=PyMySQL
PKG_HASH:=816927a350f38d56072aeca5dfb10221fe1dc653745853d30a216637f5d7ad36
PKG_MAINTAINER:=Alexandru Ardelean
PKG_LICENSE:=MIT
PKG_LICENSE_FILES:=LICENSE
PKG_CONFIG_DEPENDS:=CONFIG_PYTHON3_PYMYSQL_SHA_PASSWORD_SUPPORT
include ../pypi.mk
include $(INCLUDE_DIR)/package.mk
include ../python3-package.mk
-define Package/python3-pymysql
+define Package/python3-pymysql/Default
SUBMENU:=Python
SECTION:=lang
CATEGORY:=Languages
TITLE:=Pure Python MySQL Client
URL:=https://pymysql.readthedocs.io/
- DEPENDS:=+python3 +PYTHON3_PYMYSQL_SHA_PASSWORD_SUPPORT:python3-cryptography
endef
-define Package/python3-pymysql/config
- source "$(SOURCE)/Config.in"
+define Package/python3-pymysql
+$(call Package/python3-pymysql/Default)
+ DEPENDS:=+python3
endef
define Package/python3-pymysql/description
This package contains a pure-Python MySQL client library, based on PEP 249.
endef
+define Package/python3-pymysql-sha-pwd
+$(call Package/python3-pymysql/Default)
+ TITLE+=w/ SHA256 password auth
+ DEPENDS:=+python3-pymysql $(RUST_ARCH_DEPENDS) +PACKAGE_python3-pymysql-sha-pwd:python3-cryptography
+endef
+define Package/python3-pymysql-sha-pwd/description
+ This is a meta-package installing python3-pymysql and python3-cryptography
+ packages to be able to use pymysql with “sha256_password” or
+ “caching_sha2_password” for authentication.
+endef
+
+define Package/python3-pymysql-sha-pwd/install
+ true
+endef
$(eval $(call Py3Package,python3-pymysql))
$(eval $(call BuildPackage,python3-pymysql))
$(eval $(call BuildPackage,python3-pymysql-src))
+$(eval $(call BuildPackage,python3-pymysql-sha-pwd))
修改后的完整文件如下
#
# Copyright (C) Alexandru Ardelean
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=pymysql
PKG_VERSION:=1.0.2
PKG_RELEASE:=2
PYPI_NAME:=PyMySQL
PKG_HASH:=816927a350f38d56072aeca5dfb10221fe1dc653745853d30a216637f5d7ad36
PKG_MAINTAINER:=Alexandru Ardelean
PKG_LICENSE:=MIT
PKG_LICENSE_FILES:=LICENSE
PKG_CONFIG_DEPENDS:=CONFIG_PYTHON3_PYMYSQL_SHA_PASSWORD_SUPPORT
include ../pypi.mk
include $(INCLUDE_DIR)/package.mk
include ../python3-package.mk
define Package/python3-pymysql/Default
SUBMENU:=Python
SECTION:=lang
CATEGORY:=Languages
TITLE:=Pure Python MySQL Client
URL:=https://pymysql.readthedocs.io/
endef
define Package/python3-pymysql
$(call Package/python3-pymysql/Default)
DEPENDS:=+python3
endef
define Package/python3-pymysql/description
This package contains a pure-Python MySQL client library, based on PEP 249.
endef
define Package/python3-pymysql-sha-pwd
$(call Package/python3-pymysql/Default)
TITLE+=w/ SHA256 password auth
DEPENDS:=+python3-pymysql $(RUST_ARCH_DEPENDS) +PACKAGE_python3-pymysql-sha-pwd:python3-cryptography
endef
define Package/python3-pymysql-sha-pwd/description
This is a meta-package installing python3-pymysql and python3-cryptography
packages to be able to use pymysql with “sha256_password” or
“caching_sha2_password” for authentication.
endef
define Package/python3-pymysql-sha-pwd/install
true
endef
$(eval $(call Py3Package,python3-pymysql))
$(eval $(call BuildPackage,python3-pymysql))
$(eval $(call BuildPackage,python3-pymysql-src))
$(eval $(call BuildPackage,python3-pymysql-sha-pwd))
修改完成后重新运行 make defconfig,结果如下
shenyanwu@shenyanwu:~/tmp/build/openwrt$ make defconfig
Collecting package info: done
#
# configuration written to .config
#
shenyanwu@shenyanwu:~/tmp/build/openwrt$
下载相关源以及多核编译的依赖(Download sources and multi core compile)
make download
此命令将会预先下载你依赖的所有源代码,同时开启支持多核编译的功能,这样你才可以成功编译,并且使用多核编译提升编译速度
make -j $(($(nproc)+1))
这个命令属于多核编译开启,使用你所有的核心进行编译,当然如果你想使用指定核心数量编译,请在 -j 命令后指定核心数,例如单核编译
make -j1
当然你要是不放心之前下载的相关源以及多核编译的依赖,你可以执行下面的代码,在编译前重新下载一次,然后自动开始编译
make -j $(nproc) download world
你可能在别的教程里面见过在命令后面还有 V=sc 或者 V=s,这是打开日志显示,在你编译出错排错时,会在终端进行显示错误信息,对于排除错误很有用,比如以下命令会输出很多日志提供错误帮助
make -j1 download world V=s
建议在第一次编译时,如果你不确定你的配置项都满足编译要求,可以使用单核,日志输出编译 make -j1 V=s 来确保出错后进行排除。
导入操作见:https://hackpi.fun/docs/installation/installing-images/windows/
导出操作见:https://blog.51cto.com/lifulin/4287811
编译生成的映像的目录为:/bin/targets/bcm27xx/bcm2711/openwrt-23.05.2-bcm27xx-bcm2711-rpi-4-squashfs-factory.img.gz
我天,我最难以接受的是我真的在网上找这个路径找了半天,没人写。
图中红色框框
GPIO8,12就是串口的tx rx,8是树莓派tx接电脑rx,12树莓派rx接电脑tx。
建议使用moba做串口调试助手。
初始化结束后敲回车进入openwrt界面(不敲回车不会出现红框内容)。
这里我是让树莓派作为设备上网
先用ifconfig br-lan down 停掉网桥
再用brctl delbr br-lan 删除网桥
ifconfig br-lan down
brctl delbr br-lan
然后作为sta上网
root@OpenWrt:/etc/init.d# cat /etc/config/wireless
config wifi-device 'radio0'
option type 'mac80211'
option path 'platform/soc/fe300000.mmcnr/mmc_host/mmc1/mmc1:0001/mmc1:0001:1'
option channel '36'
option band '5g'
option htmode 'VHT80'
option disabled '1'
config wifi-iface 'default_radio0'
option device 'radio0'
option network 'lan'
option mode 'sta' //就只要修改这一句就OK
option ssid 'H3C_477227_5G'
option key 'happy-boy'
再
vi /etc/wpa_supplicant.conf
写入内容
ctrl_interface=/var/run/wpa_supplicant
#update_config=1
country=CN
#ap_scan=1
network={
ssid="WiFi名"
psk="WiFi密码"
#key_mgmt=WPA-PSK
#disabled=1
#priority=2
}
然后运行之
wpa_supplicant -D nl80211 -i wlan0 -c /etc/wpa_supplicant.conf -B
udhcpc -i wlan0
接下来这一步很关键
进行上面的步骤是解析不到dns的,可以试一下ping www.baidu.com 发现显示bad address(类似),然后执行nslookup www.baidu.com 8.8.8.8得到IP地址再访问就可以成功。执行后续步骤后就可以让wrt自动解析域名得到地址。
echo nameserver 8.8.8.8 > /etc/resolv.conf
//这一步原理见https://blog.csdn.net/hahachenchen789/article/details/52295087
echo "export set FORCE_UNSAFE_CONFIGURE=1" >> /etc/profile
source /etc/profile
//最好重启终端
//如果还是不行,看看是否存在~/profile文件,如果存在,在~/profile中也添加相应内容
//个人认为出现这个问题基本就是包不齐或者有误,就得重新下载包
./scripts/feeds update -a
./scripts/feeds install -a
//一般前俩就够用,反正一共两部分,你觉得哪边出问题就重新下载哪边
make download -j$(nproc)
//要是上面的走完了还不行
//先make with -j1 V=s看看哪个包有问题,然后给他删了
//可以先在项目目录直接
find -name xxxxxx
//然后把找到的全删了,然后单独重新下载
./scripts/feeds update -a
./scripts/feeds install -a
//然后先将这个包的编译删除,clean前为对于的地址,其余同理
make package/xxx/clean
make package/xxx/compile
make package/xxx/install
//如果上面的不会可以直接暴力一点,但是会相应的很慢。先删删缓存,杂七杂八玩意删删,然后重新下载包
make clean
make dirclean
sudo rm -rf tmp
sudo rm -rf staging_dir
/*
究极方案之——只要不是重要的包全部可以在menuconfig中取消选中
在界面中输入"/"进入查找,查找你出问题的包,然后按"1"或者你想要进入的那一项
然后取消选择重新编译
*/