# rpi-ov9281-driver **Repository Path**: qCwCp/rpi-ov9281-driver ## Basic Information - **Project Name**: rpi-ov9281-driver - **Description**: 本仓库是基于 InnoMaker 官方驱动 ([INNO-MAKER/CAM-OV9281RAW-V2.git](https://github.com/INNO-MAKER/CAM-OV9281RAW-V2.git)) 修改的轻量版本,适用于树莓派(Pi5/CM5)平台源码方式安装 OV9281 相机驱动。 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-06-13 - **Last Updated**: 2025-06-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: driver ## README # rpi-ov9281-driver 本仓库是基于 InnoMaker 官方驱动 ([INNO-MAKER/CAM-OV9281RAW-V2.git](https://github.com/INNO-MAKER/CAM-OV9281RAW-V2.git)) 修改的轻量版本,适用于树莓派(Pi5/CM5)平台源码方式安装 OV9281 相机驱动。 ## 文件结构 ``` ./ ├── autoinstall.sh # 一键自动安装脚本,支持参数化选择 CSI 通道 ├── uninstall.sh # 一键卸载脚本,支持参数化选择 CSI 通道 ├── setmode.sh # 运行时模式选择与初始化脚本 ├── initial.sh # 单独初始化 CSI 通道链路与格式的脚本 ├── driver/ # 驱动源码与 Makefile,仅负责 .ko 的编译/安装/卸载 │ ├── Makefile │ └── src/ │ └── inno_mipi_ov9281.c ├── dts/ # Device tree 源文件与 overlay 编译安装脚本 │ ├── build_install_dtbo.sh │ ├── inno_mipi_ov9281_csi0.dts │ └── inno_mipi_ov9281_csi1.dts ├── txt/ # config.txt/cmdline.txt 自动化管理脚本 │ ├── update_config.sh │ └── update_cmdline.sh ├── docs/ # inno官方相关文档与资料 │ ├── CAM-MIPI9281V2-Compile Driver Source Code.pdf │ ├── CAM-MIPIOV9281 V2 User Manual V1.2.pdf │ └── Lens drawing/ │ ├── Lens Mount.png │ └── Lens.png ├── LICENSE.md └── README.md ``` ## 安装步骤 首先进入根目录 ```sh cd rpi-ov9281-driver ``` 可以直接使用autoinstall.sh ```sh sudo ./autoinstall.sh [0|1|all] ``` 也可手动安装,步骤如下 1. 添加权限 ```sh sudo chmod -R a+rwx * ``` 2. 编译并安装驱动 ```sh cd driver sudo make clean sudo make sudo make install cd .. ``` 3. 编译并安装 dtbo(以 CSI0 为例,CSI1 同理) ```sh cd dts sudo ./build_install_dtbo.sh inno_mipi_ov9281_csi0.dts inno_mipi_ov9281_csi0.dtbo # or sudo ./build_install_dtbo.sh inno_mipi_ov9281_csi1.dts inno_mipi_ov9281_csi1.dtbo cd .. ``` 4. 更新 config.txt(以 CSI0 为例,CSI1 同理) ```sh cd txt # 添加 dtoverlay=inno_mipi_ov9281_csix 和 dtparam=i2c_vc=on sudo ./update_config.sh 0 add # or sudo ./update_config.sh 1 add cd .. ``` 5. 重启树莓派 ```sh sudo reboot ``` :exclamation: 针对pi5,每次重启后,运行 setmode.sh 选择工作模式并初始化(本质上目的是执行原仓库中的initial脚本) ```sh sudo ./setmode.sh [csi_num] ``` ## 测试程序 仅使用csi0时,mipi挂载在`/dev/video0`上,i2c挂载在`/dev/v4l-subdev2`上,可在执行initial或setmode脚本时查看输出信息 应用层程序详见[OV9281_API](https://gitee.com/qCwCp/OV9281_API.git) ## 卸载驱动 如需彻底卸载所有驱动、overlay 及相关配置,可一键执行: ```sh sudo ./uninstall.sh [0|1|all] ``` 也可以参考 `uninstall.sh` 脚本内容,按需手动卸载。 --- ## 其他说明 - csi0 和 csi1 overlay 可同时存在于 config.txt,但目前共用同一驱动,setmode会同时更改两个通道。 - 推荐使用脚本 `txt/update_config.sh` 自动管理 overlay。 - overlay 支持参数化,例如 `i2c_pins_0_1` 是一个参数名,用户可以在 config.txt 里写 `dtoverlay=xxx,i2c_pins_0_1=1` 来激活 GPIO 0/1 作为 I2C0(而不是 44/45),以适配不同硬件需求。 - 针对pi5(CM5),重启或切换模式后,必须初始化方能拍照。 ```sh sudo ./initial.sh [0|1] # 0: csi0 (默认), 1: csi1 ``` ​ 或使用`setmode.sh` 选择模式后自动初始化对应csi。 ​ 如果需要同时使用两个相机,setmode后csi0和csi1都要初始化 - 可使用`v4l2-ctl --device=/dev/video0 --stream-mmap`查看video0帧率 - 将 dtbo 文件反编译为 dts 文件的指令: ```sh dtc -I dtb -O dts -o output.dts input.dtbo ``` - :exclamation: cmdline.txt中cma=128M根据情况添加,一定要加在console...的同一行 :exclamation::exclamation: CM5实测直接添加会导致系统无法启动 p.s. 查看系统内存信息文件(Pi5默认64M): ```sh cat /proc/meminfo | grep Cma ``` - 重新安装kernel headers以修复内核文件缺失问题 ```sh sudo apt reinstall linux-headers-$(uname -r) ```