Line 1: |
Line 1: |
| [[Build drivers from source for rpi|English]] | | [[Build drivers from source for rpi|English]] |
| | | |
− | <br /> | + | 本文主要参考资料为[https://www.raspberrypi.org/documentation/linux/kernel/building.md 官方piOS编译方法]。我们采用交叉编译的方法,5.4.72版本32bitOS为例进行说明。 |
| + | |
| + | 以下操作均在ubuntu PC上进行。 |
| + | ====开发环境准备==== |
| + | <code>sudo apt install git bc bison flex libssl-dev make libc6-dev libncurses5-dev</code> |
| + | |
| + | *32-bit piOS target version |
| + | |
| + | <code>sudo apt install crossbuild-essential-armhf</code> |
| + | |
| + | *64-bit piOS target version |
| + | |
| + | <code>sudo apt install crossbuild-essential-arm64</code> |
| + | ====下载标准版本==== |
| + | =====首先,请确认自己的树莓派上的piOS版本:===== |
| + | |
| + | *Release version |
| + | |
| + | <code>$ uname -a</code> |
| + | |
| + | <code>Linux raspberrypi 5.4.72-v7l+ #1356 SMP Thu Oct 22 13:57:51 BST 2020 armv7l GNU/Linux</code> |
| + | |
| + | *Code tag |
| + | |
| + | <code>$ cp /usr/share/doc/raspberrypi-bootloader/changelog.Debian.gz ./</code> |
| + | |
| + | <code>gunzip changelog.Debian.gz</code> |
| + | |
| + | 查看最上面一条,确定代码tag。 |
| + | =====有两种方法可以得到自己想要的版本的源码:===== |
| + | 在PC上: |
| + | |
| + | 1. 采用git获取到对应branch上的对应tag版本代码 |
| + | |
| + | <code>git clone --branch rpi-5.4.y <nowiki>https://github.com/raspberrypi/linux</nowiki></code> |
| + | |
| + | <code>git checkout raspberrypi-kernel_1.20201022-1</code> |
| + | |
| + | PS:以上两条命令请替换为自己对应的版本。 |
| + | |
| + | 2. 直接从如下链接手动下载对应tag的版本代码 |
| + | |
| + | https://github.com/raspberrypi/linux/tags |
| + | ====patch我们的驱动代码==== |
| + | |
| + | *Driver source code |
| + | |
| + | camera驱动源码路径为: linux/drivers/media/i2c,将camera驱动的源码放到对应目录。 |
| + | |
| + | *Modify the the Makefile and Kconfig files |
| + | |
| + | 修改同路径下的Config和Makefile,增加对应camera驱动。 |
| + | |
| + | *dts file |
| + | |
| + | dts文件路径为:linux/arch/arm/boot/dts/overlays,将[camera]-overlay.dts文件放到此路径。 |
| + | |
| + | *Modify dts Makefile |
| + | |
| + | 修改同路径下的Makefile,增加对应dts编译选项。 |
| + | ====编译==== |
| + | =====编译准备===== |
| + | 不同树莓派的编译选项不同,区别如下: |
| + | |
| + | *For Raspberry Pi 1, Zero and Zero W, and Raspberry Pi Compute Module 1 default (32-bit only) build configuration |
| + | |
| + | <code>KERNEL=kernel</code> |
| + | |
| + | <code>make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcmrpi_defconfig</code> |
| + | |
| + | *For Raspberry Pi 2, 3, 3+ and Zero 2 W, and Raspberry Pi Compute Modules 3 and 3+ default 32-bit build configuration |
| + | |
| + | <code>KERNEL=kernel7</code> |
| + | |
| + | <code>make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig</code> |
| + | |
| + | *For Raspberry Pi 4 and 400, and Raspberry Pi Compute Module 4 default 32-bit build configuration |
| + | |
| + | <code>KERNEL=kernel7l</code> |
| + | |
| + | <code>make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2711_defconfig</code> |
| + | |
| + | *For Raspberry Pi 3, 3+, 4, 400 and Zero 2 W, and Raspberry Pi Compute Modules 3, 3+ and 4 default 64-bit build configuration |
| + | |
| + | <code>KERNEL=kernel8</code> |
| + | |
| + | <code>make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcm2711_defconfig</code> |
| + | =====增加编译选项===== |
| + | |
| + | *32-bit version |
| + | |
| + | <code>make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig</code> |
| + | |
| + | *64-bit version |
| + | |
| + | <code>make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfig</code> |
| + | |
| + | 增加对应camera模块驱动的编译选项,linux5.4版本路径为driver-->multimedia-->i2c; |
| + | |
| + | 5.10版本kernel的路径是Device Drivers --> Multimedia Support --> Media ancillary drivers --> Camera sensor devices。 |
| + | =====编译输出===== |
| + | |
| + | *32-bit version |
| + | |
| + | <code>make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs -j4</code> |
| + | |
| + | *64-bit version |
| + | |
| + | <code>make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Image modules dtbs -j4</code> |
| + | ===常见问题=== |
| + | |
| + | *disagrees about version of symbol module_layout |
| + | |
| + | 系统启动过后,dmesg可以看到camera的驱动加载的时候报这个错误。由于板子上原有的piOS版本与编译后的camera驱动版本不匹配导致。 |
| + | |
| + | 建议参考这个[https://www.raspberrypi.com/documentation/computers/linux_kernel.html#cross-compiling-the-kernel 链接],从代码重新编译,并整体安装Image、dtb、modules。 |
| + | ===参考资料=== |
| + | |
| + | *树莓派的piOS编译方案: |
| + | |
| + | https://www.raspberrypi.org/documentation/linux/kernel/building.md<br /> |