Difference between revisions of "Build drivers from source for rpi/zh"
(→本文修改记录) |
|||
| Line 5: | Line 5: | ||
我们提供了在树莓派上本地编译和在PC上交叉编译的方法。建议使用树莓派本地编译,这更简单,也更快捷。 | 我们提供了在树莓派上本地编译和在PC上交叉编译的方法。建议使用树莓派本地编译,这更简单,也更快捷。 | ||
| − | === 树莓派本地编译 === | + | ===树莓派本地编译=== |
以下操作均在树莓派上进行。 | 以下操作均在树莓派上进行。 | ||
以下以piOS 5.15.32为例: | 以下以piOS 5.15.32为例: | ||
| − | ==== 编译环境准备 ==== | + | ====编译环境准备==== |
<code>sudo apt install git bc bison flex libssl-dev make</code> | <code>sudo apt install git bc bison flex libssl-dev make</code> | ||
| − | ==== 下载本机piOS的内核头文件 ==== | + | ====下载本机piOS的内核头文件==== |
<code>sudo apt install raspberrypi-kernel-headers</code> | <code>sudo apt install raspberrypi-kernel-headers</code> | ||
| − | ==== 下载veye驱动代码 ==== | + | ====下载veye驱动代码==== |
<code>git clone <nowiki>https://github.com/veyeimaging/raspberrypi_v4l2.git</nowiki></code> | <code>git clone <nowiki>https://github.com/veyeimaging/raspberrypi_v4l2.git</nowiki></code> | ||
| Line 25: | Line 25: | ||
<code>Linux raspberrypi 5.15.32-v8+ #1538 SMP PREEMPT Thu Mar 31 19:40:39 BST 2022 aarch64 GNU/Linux</code> | <code>Linux raspberrypi 5.15.32-v8+ #1538 SMP PREEMPT Thu Mar 31 19:40:39 BST 2022 aarch64 GNU/Linux</code> | ||
| − | ==== 编译驱动 ==== | + | ====编译驱动==== |
进入对应目录并编译 | 进入对应目录并编译 | ||
| Line 34: | Line 34: | ||
完成。 | 完成。 | ||
| − | ==== 编译dts ==== | + | ====编译dts==== |
<code>cd ~/raspberrypi_v4l2/driver_source/dts/rpi-5.15.y</code> | <code>cd ~/raspberrypi_v4l2/driver_source/dts/rpi-5.15.y</code> | ||
| Line 41: | Line 41: | ||
完成。 | 完成。 | ||
| − | ==== 常见错误 ==== | + | ====常见错误==== |
| − | ===== 找不到build目录 ===== | + | =====找不到build目录===== |
<code>make[1]: *** /lib/modules/[version]/build: No such file or directory. Stop.</code> | <code>make[1]: *** /lib/modules/[version]/build: No such file or directory. Stop.</code> | ||
| Line 52: | Line 52: | ||
解决方法: | 解决方法: | ||
| − | ====== 1.升级piOS并重新编译。 ====== | + | ======1.升级piOS并重新编译。====== |
<code>sudo apt update</code> | <code>sudo apt update</code> | ||
| Line 71: | Line 71: | ||
此时可以在/boot/config.txt中添加<code>arm_64bit=0</code>然后重启,切换回32bit模式。 | 此时可以在/boot/config.txt中添加<code>arm_64bit=0</code>然后重启,切换回32bit模式。 | ||
| − | ===== 2. 安装对应的raspberrypi-kernel-header的deb包。 ===== | + | =====2. 安装对应的raspberrypi-kernel-header的deb包。===== |
从这个[https://archive.raspberrypi.org/debian/pool/main/r/raspberrypi-firmware/ 链接]中查找到对应当前的版本的deb安装包并安装。 | 从这个[https://archive.raspberrypi.org/debian/pool/main/r/raspberrypi-firmware/ 链接]中查找到对应当前的版本的deb安装包并安装。 | ||
tag请根据本机piOS版本与raspberrypi OS [https://github.com/raspberrypi/linux/tags tags]确定。 | tag请根据本机piOS版本与raspberrypi OS [https://github.com/raspberrypi/linux/tags tags]确定。 | ||
| − | ===== 3. 使用rpi-source ===== | + | =====3. 使用rpi-source===== |
使用[https://github.com/RPi-Distro/rpi-source rpi-source]工具,它会设置好构建自己内核所需的一切(默认情况下是从当前运行的内核构建)。 | 使用[https://github.com/RPi-Distro/rpi-source rpi-source]工具,它会设置好构建自己内核所需的一切(默认情况下是从当前运行的内核构建)。 | ||
| − | + | ===安装编译后的驱动=== | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | === 安装编译后的驱动 === | ||
编译完成后,就得到了指定版本的驱动和dtbo文件。 | 编译完成后,就得到了指定版本的驱动和dtbo文件。 | ||
| Line 218: | Line 108: | ||
https://www.raspberrypi.org/documentation/linux/kernel/building.md | https://www.raspberrypi.org/documentation/linux/kernel/building.md | ||
| − | === 本文修改记录 === | + | ===本文修改记录=== |
*20230326 | *20230326 | ||
| Line 224: | Line 114: | ||
完善'''找不到build目录'''错误的处理方法。 | 完善'''找不到build目录'''错误的处理方法。 | ||
| − | * 20230326 | + | *20230326 |
增加'''找不到build目录'''错误的描述和处理方法。 | 增加'''找不到build目录'''错误的描述和处理方法。 | ||
| − | * 20220424 | + | *20220424 |
增加在树莓派本地编译的支持方法。 | 增加在树莓派本地编译的支持方法。 | ||
Revision as of 07:46, 21 March 2026
本文主要参考资料为官方piOS编译方法。
我们提供了在树莓派上本地编译和在PC上交叉编译的方法。建议使用树莓派本地编译,这更简单,也更快捷。
1 树莓派本地编译
以下操作均在树莓派上进行。
以下以piOS 5.15.32为例:
1.1 编译环境准备
sudo apt install git bc bison flex libssl-dev make
1.2 下载本机piOS的内核头文件
sudo apt install raspberrypi-kernel-headers
1.3 下载veye驱动代码
git clone https://github.com/veyeimaging/raspberrypi_v4l2.git
1.4 确认自己的树莓派上的piOS版本:
$ uname -a
Linux raspberrypi 5.15.32-v8+ #1538 SMP PREEMPT Thu Mar 31 19:40:39 BST 2022 aarch64 GNU/Linux
1.5 编译驱动
进入对应目录并编译
cd ~/raspberrypi_v4l2/driver_source/cam_drv_src/rpi-5.15_all
make
完成。
1.6 编译dts
cd ~/raspberrypi_v4l2/driver_source/dts/rpi-5.15.y
./build_dtbo.sh
完成。
1.7 常见错误
1.7.1 找不到build目录
make[1]: *** /lib/modules/[version]/build: No such file or directory. Stop.
sudo apt install raspberrypi-kernel-headers只是简单地安装上可用的最新内核头文件。这不一定与当前你使用的piOS系统的内核匹配。
Raspbian维护者总是从存储库索引文件中删除旧的内核头文件。
解决方法:
1.7.1.1 1.升级piOS并重新编译。
sudo apt update
sudo apt full-upgrade
sudo apt install raspberrypi-kernel-headers
特别的,对于rpi4系列,32bit的PiOS升级到最新版本后会自动启用64-bit模式。但是raspberrypi-kernel-headers包中缺少v8+模式的build目录。
比如:
$ uname -a
Linux raspberrypi 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr 3 17:24:16 BST 2023 aarch64 GNU/Linux
却没有/lib/modules/6.1.21-v8+/build目录。
此时可以在/boot/config.txt中添加arm_64bit=0然后重启,切换回32bit模式。
1.7.2 2. 安装对应的raspberrypi-kernel-header的deb包。
从这个链接中查找到对应当前的版本的deb安装包并安装。
tag请根据本机piOS版本与raspberrypi OS tags确定。
1.7.3 3. 使用rpi-source
使用rpi-source工具,它会设置好构建自己内核所需的一切(默认情况下是从当前运行的内核构建)。
2 安装编译后的驱动
编译完成后,就得到了指定版本的驱动和dtbo文件。
参考安装驱动步骤,
wget https://github.com/veyeimaging/raspberrypi_v4l2/releases/latest/download/raspberrypi_v4l2.tgz
tar -xzvf raspberrypi_v4l2.tgz
cd raspberrypi_v4l2/release/
mkdir driver_bin/$(uname -r)
将编译得到的驱动的驱动和dtbo放到此目录下。
然后执行安装命令即可。
chmod +x *
sudo ./install_driver.sh [camera module]
camera module:可以是veye327,csimx307,cssc132,veyecam2m,veye_mvcam等。
3 参考资料
- 树莓派的piOS编译方案:
https://www.raspberrypi.org/documentation/linux/kernel/building.md
4 本文修改记录
- 20230326
完善找不到build目录错误的处理方法。
- 20230326
增加找不到build目录错误的描述和处理方法。
- 20220424
增加在树莓派本地编译的支持方法。
- 20220411
独立成篇,增加MV系列的描述。