首页 > 解决方案 > Yocto layer for ADIS16475

问题描述

Context

Lately I've had trouble including an adis driver in my Yocto build. I've asked the question on the adis forum but found the solution before anyone answered it. The adis forum not being very user friendly and the answer being quiet long, I've decided to answer my question here and link it in the forum.

The question

I'm building my OS with yocto and I'd like to add a driver for IMU ADIS1607 (anything but the ease of use is a plus) as part of this build.

I'm building a prototype on a raspberryPi4. My application uses an ADIS IMU (ADIS16507). Since the board for the final product is not fixed I'm building my OS with Yocto.

I'm currently trying to add a driver for ADIS16507. Ideally I'd like to add ADIS16475, but I could do with something else provided it works nicely.

First off I have checked that I'm able to build the whole ADIS linux kernel for RaspberryPi as specified in the doc. With that kernel the driver works nicely.

However the ADIS linux kernel is too heavy for what I intend to do. Hence I'm trying to build a lighter OS with yocto (also, as aforementioned, I'll likely need to port my work on different platforms).

I have a few ideas on how to do it, however none of them worked easily and I'm not sure which one to pursue.

Any pointer on which method I should use (maybe I've missed an obvious easy one) is welcome.

标签: linuxraspberry-pidriveryoctobitbake

解决方案


所以这是我找到的解决方案。我们将使用 ADIS16475,它是自 5.10 版以来标准libc的一部分。然后我们将从 ADIS 获取相应的设备树覆盖并添加相关变量以使其与其他设备树覆盖一起编译。

获取正确的版本

为此,我们需要libc 5.10 或更高版本,因为早期版本不包含 adis16475.c 源文件。然而,只有最新的 yocto 版本 Hardknott 使用 5.10 版本。所以最简单的事情就是切换到 Yocto 的 Hardknott 分支。请记住,如果您使用其他层,出于兼容性原因,您可能还必须更改版本。

配置内核以编译内置的 ADIS16475 驱动程序

在这里,我们将进入内核编译,所以有一些事情要知道

短而近似的理论

如果您对内核编译不太了解,请不要担心,我也不用担心。但这里有一个大致的快速解释,以便您了解我们在做什么:内核 makefile 包含必须编译的文件列表。对于司机来说,有两个重要的。obj-y它包含将被内置obj-m的文件,以及将被编译为可加载模块的文件。为了使这些列表可配置,它们在 makefile 中使用如下语句定义:

obj-${CONFIG_MYDRIVER} += my_driver.o

这个想法是您可以CONFIG_MYDRIVER在外部文件中设置为“m”或“y”。如果您将其设置为其他任何内容,makefile 中的行将被忽略,并且您的文件将不会被编译。所以基本上我们所要做的就是将正确的变量设置为正确的值,以便 yocto 编译我们的驱动程序。

自定义内核配置

基本上我们要做的是创建我们自己的配置片段文件。为此,您需要设置 yocto 层(如果您正在阅读这篇文章,我假设您知道如何操作)。在您的图层中,您应该添加以下文件夹:

meta-my-layer
|
- recipe-kernel
  |
  - linux
    |
    - linux-raspberrypi_5.10.bbappend
    |
    -linux-raspberrypi
     |
     -adis16475.cfg

(请注意,我们附加了 linux-raspberrypi_5.10,因为它是 meta-raspberrypi 中负责 libc 编译的那个。如果您正在为另一台机器编译,请查看 recipe-kernel/linux 中的文件。您的 BSP 甚至可能实际上使用 poky/meta/recipe-kernel/linux 中的那些)

现在剩下要做的就是通过在 linux-raspberrypi_5.10.bbappend 中添加以下行来将 adis16475.cfg 添加到我们的源代码中:

FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
SRC_URI += "file://adis16475.cfg"

并通过添加到文件中来实际设置 adis16475.cfg 中的配置:

CONFIG_SPI_MASTER=y
CONFIG_IIO=y
CONFIG_ADIS16475=y
CONFIG_IIO_KFIFO_BUF=y
CONFIG_SPI_BCM2835=y

据我所知和经验,这是您必须构建的最少驱动程序才能使其工作。

完成此操作后,您将内置驱动程序,但不会对 Pi 产生任何影响。那是因为我们缺少正确的覆盖。

构建 adis16475-overlay.dts

为了解决这个问题,我受到这篇文章的广泛启发,所以如果你遇到问题,你可能想看看。这里的问题是,据我所知,libc 不提供与驱动程序对应的叠加层,至少 5.10 版本不提供。所以我们必须有点狡猾。首先从adis获取覆盖并将其复制到recipe-kernel/linux/linux-raspberrypi.

完成此操作后,我们将通过修改为 yocto 来查找它,recipe-kernel/linux/linux-raspberrypi_5.10.bbappend如下所示:

FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
SRC_URI += "file://adis16475.cfg \
            file://adis16475-overlay.dts;subdir=git/arch/${ARCH}/boot/dts/overlays"

我们添加的最后一行告诉 yocto 从哪里获取我们的 .dts 文件以及将它放在哪里(与其他覆盖)。

最后,我们要做的是将我们的叠加层添加到要编译的叠加层和设备树列表中。为此我们将机器配置文件raspberrypi4-64.conf。更多细节在这里

首先在您的层 conf 文件夹中,创建machine/raspberrypi4-64-extra.conf. 该文件将包含我们要为此驱动程序进行的所有其他配置。在其中首先添加:

# Create the device trees and overlay list with necessary drivers
KERNEL_DEVICETREE =  " \
                      ${RPI_KERNEL_DEVICETREE} \
                      ${RPI_KERNEL_DEVICETREE_OVERLAYS} \
                      overlays/adis16475.dtbo \
                     "

这将设置要编译的设备树列表。它添加了 pi(两个第一个变量)和我们的 adis16475 覆盖所需的 RPI 设备树和覆盖。

然后我们将利用这个文件来启用一些必要的 raspberrypi 特定配置选项。添加:

# Enable RPI specific options in config.txt
ENABLE_SPI_BUS = "1"
RPI_EXTRA_CONFIG = '\ndtoverlay=adis16475\n'

最后你需要告诉 yocto 使用这个额外的配置。最通用的方法是在您的 中添加以下行local/local.conf

# Enables the DIP hardware support
require conf/machine/${MACHINE}-dip-extra.conf

完成此操作后,如果您确实将图层添加到 bblayers.conf 文件,并且您的机器在 local.con 文件中设置为 raspberrypi4-64,那么其他一切都应该正常工作。

机器类型注意事项

在这里,我使用设置为 raspberrypi4-64 的机器,因为它是我拥有的机器。此过程没有理由不与 meta-raspberrypi 层中的任何其他机器一起使用。只要记住在我放置 raspberrypi4-64 的任何地方都替换你的机器名称,你应该没问题。

希望这会帮助一些迷失在 Yoctoverse 中的其他人

干杯


推荐阅读