Difference between revisions of "Build drivers from source for rpi/zh"

From wiki_veye
Jump to navigation Jump to search
Line 1: Line 1:
 
[[Build drivers from source for rpi|English]]
 
[[Build drivers from source for rpi|English]]
  
本文主要参考资料为[https://www.raspberrypi.org/documentation/linux/kernel/building.md 官方piOS编译方法]。我们采用交叉编译的方法。
+
本文主要参考资料为[https://www.raspberrypi.org/documentation/linux/kernel/building.md 官方piOS编译方法]
  
 +
我们提供了在树莓派上本地编译和在PC上交叉编译的方法。建议使用树莓派本地编译,这更简单,也更快捷。
 +
 +
=== 树莓派本地编译 ===
 +
 +
=== PC机上交叉编译 ===
 
以下操作均在ubuntu PC上进行。
 
以下操作均在ubuntu PC上进行。
===开发环境准备===
+
====开发环境准备====
 
<code>sudo apt install git bc bison flex libssl-dev make libc6-dev libncurses5-dev</code>
 
<code>sudo apt install git bc bison flex libssl-dev make libc6-dev libncurses5-dev</code>
  
Line 14: Line 19:
  
 
<code>sudo apt install crossbuild-essential-arm64</code>
 
<code>sudo apt install crossbuild-essential-arm64</code>
===下载标准版本===
+
====下载标准版本====
 
=====首先,请确认自己的树莓派上的piOS版本:=====
 
=====首先,请确认自己的树莓派上的piOS版本:=====
  
Line 61: Line 66:
  
 
修改同路径下的Makefile,增加对应dts编译选项。
 
修改同路径下的Makefile,增加对应dts编译选项。
===编译===
+
====编译====
 
=====编译准备=====
 
=====编译准备=====
 
不同树莓派的编译选项不同,区别如下:
 
不同树莓派的编译选项不同,区别如下:
Line 110: Line 115:
  
 
<code>make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Image modules dtbs -j4</code>
 
<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。
 
 
===参考资料===
 
===参考资料===
  

Revision as of 17:16, 24 April 2022

English

本文主要参考资料为官方piOS编译方法

我们提供了在树莓派上本地编译和在PC上交叉编译的方法。建议使用树莓派本地编译,这更简单,也更快捷。

1 树莓派本地编译

2 PC机上交叉编译

以下操作均在ubuntu PC上进行。

2.1 开发环境准备

sudo apt install git bc bison flex libssl-dev make libc6-dev libncurses5-dev

  • 32-bit piOS target version

sudo apt install crossbuild-essential-armhf

  • 64-bit piOS target version

sudo apt install crossbuild-essential-arm64

2.2 下载标准版本

2.2.1 首先,请确认自己的树莓派上的piOS版本:
  • Release version

$ uname -a

Linux raspberrypi 5.4.72-v7l+ #1356 SMP Thu Oct 22 13:57:51 BST 2020 armv7l GNU/Linux

  • Code tag

$ cp /usr/share/doc/raspberrypi-bootloader/changelog.Debian.gz ./

gunzip changelog.Debian.gz

查看最上面一条,确定代码tag。

2.2.2 有两种方法可以得到自己想要的版本的源码:

在PC上:

1. 采用git获取到对应branch上的对应tag版本代码

git clone --branch rpi-5.4.y https://github.com/raspberrypi/linux

git checkout raspberrypi-kernel_1.20201022-1

PS:以上两条命令请替换为自己对应的版本。

2. 直接从如下链接手动下载对应tag的版本代码

https://github.com/raspberrypi/linux/tags

2.3 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编译选项。

2.4 编译

2.4.1 编译准备

不同树莓派的编译选项不同,区别如下:

  • For Raspberry Pi 1, Zero and Zero W, and Raspberry Pi Compute Module 1 default (32-bit only) build configuration

KERNEL=kernel

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcmrpi_defconfig

  • For Raspberry Pi 2, 3, 3+ and Zero 2 W, and Raspberry Pi Compute Modules 3 and 3+ default 32-bit build configuration

KERNEL=kernel7

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig

  • For Raspberry Pi 4 and 400, and Raspberry Pi Compute Module 4 default 32-bit build configuration

KERNEL=kernel7l

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2711_defconfig

  • 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

KERNEL=kernel8

make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcm2711_defconfig

2.4.2 增加编译选项
  • 32-bit version

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig

  • 64-bit version

make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfig

增加对应camera模块驱动的编译选项,linux5.4版本路径为driver-->multimedia-->i2c;

5.10版本kernel的路径是Device Drivers --> Multimedia Support --> Media ancillary drivers --> Camera sensor devices。

2.4.3 编译输出
  • 32-bit version

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs -j4

  • 64-bit version

make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Image modules dtbs -j4

3 参考资料

  • 树莓派的piOS编译方案:

https://www.raspberrypi.org/documentation/linux/kernel/building.md

4 本文修改记录

  • 20220411

独立成篇,增加MV系列的描述。