YOCTO how to add own driver to the Linux and build it

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

YOCTO how to add own driver to the Linux and build it

Jump to solution
4,785 Views
btarnowski
Contributor III

Hi all,

Im working with driver for camera, I found all components like source code and recipes. The linux has not this driver by default (it is too new, new component, Linux doesn't know that it exist), I have to add it locally. Before I used URL and already existing drivers in the Linux sources. What I have to do to add new driver to yocto build project from my hard drive?

post NXP comunity.png

0 Kudos
1 Solution
4,779 Views
khang_letruong
Senior Contributor III

Hi @btarnowski ,

There's some ways :

1. Commit your driver source code into your own linux-imx repository then update the URL and commit HASH of your linux & driver in the following recipe :  <path-to-yocto-bsp>/sources/meta-imx/meta-bsp/recipes-kernel/linux/linux-imx_%.bbappend

 

KERNEL_src="git://git@gitlab.com:/company-name/linux-imx.git;protocol=ssh" # The repository of your company, cloned and modified from https://source.codeaurora.org/external/imx/linux-imx/

SRCBRANCH = "lf-5.10.y"
SRCREV = "a11753a89ec610768301d4070e10b8bd60fde8cd" # The commit that you added your driver

FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"

 

or,

2. Add local patches to the default NXP's source (downloaded from https://source.codeaurora.org/external/imx/linux-imx/) :

a. Add patches and .bbappend :

 

$ tree <path-to-yocto-bsp>/sources/meta-imx/meta-bsp/recipes-kernel/linux/
<path-to-yocto-bsp>/sources/meta-imx/meta-bsp/recipes-kernel/linux/
├── linux-imx
│   ├── 0001-dts-imx8mp-evk-Add-DTS-with-AR0234-sensor-nodes.patch
│   ├── 0002-dts-imx8mp-evk-Add-camera-SYNC-signals.patch
│   ├── 0011-defconfig-Enable-PRINTK-and-set-LOGLEVEL.patch
│   └── 0012-Enable-debugging-of-MIPI-CSI2-interface.patch
├── linux-imx_5.10.bb
├── linux-imx_%.bbappend
├── linux-imx-headers_5.10.bb
└── linux-imx-headers_%.bbappend

 

b. Modify <path-to-yocto-bsp>/sources/meta-imx/meta-bsp/recipes-kernel/linux/linux-imx_%.bbappend to add patches' location :

 

SRC_URI_append_mx8 = " \
    file://0001-dts-imx8mp-evk-Add-DTS-with-AR0234-sensor-nodes.patch \
    file://0002-dts-imx8mp-evk-Add-camera-SYNC-signals.patch \
    file://0011-defconfig-Enable-PRINTK-and-set-LOGLEVEL.patch \
    file://0012-Enable-debugging-of-MIPI-CSI2-interface.patch \

 

After that, you will need to re-bitbake your kernel  : bitbake virtual/kernel -c cleansstate &&  bitbake virtual/kernel -c compile && bitbake <image-name>

Regards,
K.

View solution in original post

9 Replies
4,780 Views
khang_letruong
Senior Contributor III

Hi @btarnowski ,

There's some ways :

1. Commit your driver source code into your own linux-imx repository then update the URL and commit HASH of your linux & driver in the following recipe :  <path-to-yocto-bsp>/sources/meta-imx/meta-bsp/recipes-kernel/linux/linux-imx_%.bbappend

 

KERNEL_src="git://git@gitlab.com:/company-name/linux-imx.git;protocol=ssh" # The repository of your company, cloned and modified from https://source.codeaurora.org/external/imx/linux-imx/

SRCBRANCH = "lf-5.10.y"
SRCREV = "a11753a89ec610768301d4070e10b8bd60fde8cd" # The commit that you added your driver

FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"

 

or,

2. Add local patches to the default NXP's source (downloaded from https://source.codeaurora.org/external/imx/linux-imx/) :

a. Add patches and .bbappend :

 

$ tree <path-to-yocto-bsp>/sources/meta-imx/meta-bsp/recipes-kernel/linux/
<path-to-yocto-bsp>/sources/meta-imx/meta-bsp/recipes-kernel/linux/
├── linux-imx
│   ├── 0001-dts-imx8mp-evk-Add-DTS-with-AR0234-sensor-nodes.patch
│   ├── 0002-dts-imx8mp-evk-Add-camera-SYNC-signals.patch
│   ├── 0011-defconfig-Enable-PRINTK-and-set-LOGLEVEL.patch
│   └── 0012-Enable-debugging-of-MIPI-CSI2-interface.patch
├── linux-imx_5.10.bb
├── linux-imx_%.bbappend
├── linux-imx-headers_5.10.bb
└── linux-imx-headers_%.bbappend

 

b. Modify <path-to-yocto-bsp>/sources/meta-imx/meta-bsp/recipes-kernel/linux/linux-imx_%.bbappend to add patches' location :

 

SRC_URI_append_mx8 = " \
    file://0001-dts-imx8mp-evk-Add-DTS-with-AR0234-sensor-nodes.patch \
    file://0002-dts-imx8mp-evk-Add-camera-SYNC-signals.patch \
    file://0011-defconfig-Enable-PRINTK-and-set-LOGLEVEL.patch \
    file://0012-Enable-debugging-of-MIPI-CSI2-interface.patch \

 

After that, you will need to re-bitbake your kernel  : bitbake virtual/kernel -c cleansstate &&  bitbake virtual/kernel -c compile && bitbake <image-name>

Regards,
K.

4,754 Views
btarnowski
Contributor III

Thank you for your help @khang_letruong , I appreciate it.

For me the second solution is suitable. I made some tests, I assume that I have to see the object file after kernel rebuild. Below on the picture I described 5 steps I made. (additional I modified DeviceTree).

I have other hint and I made that one hint as the first and now Im going to combine your hint with this one. What Im missing that I can not obtain the os02g10.o file after bitbake linux-imx -c compile -f  ?

 

btarnowski_0-1657406759517.png

 

0 Kudos
4,743 Views
khang_letruong
Senior Contributor III

Hi @btarnowski 

Did you add your own kernel's configuration to DELTA_KERNEL_DEFCONFIG ? Also, I wonder if DELTA_KERNEL_DEFCONFIG_append exist ?

Regards,
Khang

 

 

0 Kudos
4,738 Views
btarnowski
Contributor III

In my project there is only DELTA_KERNEL_DEFCONFIG_append
I added 
os02g10.cfg but still not see os02g10.o after build.
So now I need to study the use of DELTA_KERNEL_DEFCONFIG and why other functionalities works only with DELTA_KERNEL_DEFCONFIG_append

btarnowski_1-1657489851968.png

0 Kudos
4,731 Views
khang_letruong
Senior Contributor III

Hi @btarnowski ,

Are os02g10.c and the modified Makefile committed to the repository or added as patches ? Btw, you can do bitbake virtual/kernel -c menuconfig to ensure that the CONFIG_VIDEO_OS02G10 is available and selected.

Regards,
K

4,729 Views
btarnowski
Contributor III

Looks like I need to generate patches for all added files: all header files and one source file os02g10.c

regarding menucofig tool:

1. bitbake virtual/kernel -c menuconfig - is not working as below on the picture
2. make menuconfig - works but I see 4 git repositories, I added os02g10.c and other files only to one of them - yocto/build/tmp/work/cortexa53-crypto-mx8mm-poky-linux/linux-imx-headers/5.10-r0/git

for these I did not add

yocto/build/tmp/work/imx8mmevk-poky-linux/linux-imx/5.10.72+gitAUTOINC+a68e31b63f-r0/git

yocto/build/tmp/work/imx8mmevk-poky-linux/linux-imx/5.10.72+gitAUTOINC+a68e31b63f-r0/build/source

yocto/build/tmp/work-shared/imx8mmevk/kernel-source

Im confused that there are 4 git source repositories

btarnowski_1-1657529348632.png

 

 

0 Kudos
4,720 Views
khang_letruong
Senior Contributor III

Hi @btarnowski 

So now I need to study the use of DELTA_KERNEL_DEFCONFIG and why other functionalities works only with DELTA_KERNEL_DEFCONFIG_append

There's also DELTA_KERNEL_DEFCONFIG_mx8 in the following example : https://github.com/SolidRun/meta-solidrun-arm-imx8/blob/hardknott-imx8mp/recipes-kernel/linux/linux-...

 

Looks like I need to generate patches for all added files: all header files and one source file os02g10.c

Yes, you should. That is the proper way for Yocto build system.

1. bitbake virtual/kernel -c menuconfig - is not working as below on the picture

It might be due to the fact that you ran the command within Docker.

Regards,

K

0 Kudos
4,714 Views
btarnowski
Contributor III

I got it to build, I had to add 2 patches, there was additional dependency in the driver so after the first patch I got build error.

btarnowski_1-1657551597091.png

 

The second thing I need to do is adding the i2c-tools to my kernel build, it is challenge for me as well

https://git.yoctoproject.org/poky/plain/meta/recipes-devtools/i2c-tools/i2c-tools_4.3.bb

 

 

0 Kudos
4,691 Views
khang_letruong
Senior Contributor III

Hi,

The second thing I need to do is adding the i2c-tools to my kernel build, it is challenge for me as well

You can populate the Yocto SDK then cross-build i2c-tools on host machine and copy the binaries into the board.

 

0 Kudos