Search code examples
yocto

Out-of-tree module and dt-bindings in yocto


I have built a new kernel module out-of-tree in a separate kernel recipe - see folder structure below. As part of this driver there is a header that is to be used by the device tree compiler when generating the final device tree (i.e. it has constants) as well as my driver.

The normal place to install these files is dt-bindings/clock/clk-driver.h I have created a new header file that is to be used in the compilation of the device tree; however, if copy it to the kernel source during the configure stage of the module it is too late for the device tree compiler.

I worked around this by adding a new configure_prepend to the device tree recipe (device-tree.bbappend) to copy it to the work-shared kernel sources. However, this feels wrong as my header now is in a different recipe to the kernel module that it refers to. I tried adding a dependency so that the device tree compiler runs after the kernel build but this created an error of a circular dependency.

What is the correct method for adding an out-of-tree module header to be used by the device tree compiler into the kernel source at the correct stage?

Folder structure:

meta-mylayer/
├── conf
│   └── layer.conf
│       └── status-report.bb
├── recipes-bsp
│   ├── device-tree
│   │   ├── device-tree.bbappend
│   │   └── files
│   │       └── dt-clock.h
└── recipes-modules
    └── clock
        ├── files
        │   ├── clock.c
        │   ├── COPYING
        │   ├── Makefile
        │   └── clock.h
        ├── README
        └── clock.bb


Solution

  • I found my own solution to this.

    The following three steps were what I did to get it to work. Note that essentially this delays the device tree recipe until after the kernel modules are compiled (from my understanding).

    1. Added a depend in kernel module recipe on the kernel created the shared work directory (i.e. extracting kernel sources
    2. Added a configure step in kernel module recipe to copy across the files into the correct place in the kernel sources.
    3. Added a step to the device tree recipe adding a dependency on the compiling of kernel modules.

    Device tree (.bbappend file)

    do_configure[depends] += "virtual/kernel:do_compile_kernelmodules"
    

    Kernel Module Recipe (.bb file)

    do_configure[depends] += "virtual/kernel:do_shared_workdir"
    do_configure_append() {
            cp ${S}/clk.h ${TMPDIR}/work-shared/${MACHINE}/kernel-source/include/linux/platform_data/clk.h
            cp ${S}/clk-dts.h ${TMPDIR}/work-shared/${MACHINE}/kernel-source/include/dt-bindings/clock/clk-dts.h    
    }