How to compile & add driver to Apalix iMX6?

What is the ideal way to add a driver to your images? I need to add a driver for an ethernet device that goes through PCI but have been unable to compile the source code for it (neither native or cross compilation seems to work) since I can’t find the linux-headers for the Kernel 4.9.67-+g1db9f06 (in the image the folder /lib/modules/4.9.67-+g1db9f06/build does not exists).

What am I missing? Can I use the image you provide as it is and install the driver? (I know native compilation is not encouraged, though). Do I need to compile the BSP and/or Kernel with the driver I intent to use?

I appreciate any help/tip you can provide.
Thanks for your time.

Yes, on target compilation is not encouraged, and we also do not ship with kernel headers. Also as far as I know, nowadays full kernel sources are necessary for proper kernel module compilation.

There are three ways you can go:

  1. Cross compile kernel & modules outside of OpenEmbedded
  2. Cross compile module using OpenEmbedded SDK which includes kernel sources
  3. Cross compile a complete image with kernel & module using OpenEmbedded

To start I would recommend variant 1. To have a reproduce-able build system for your system in the end, I would recommend going towards 3 during development…

  1. Cross compile kernel & modules outside of OpenEmbedded

    This is probably the quickest way to get the job done and does not require OpenEmbedded knowledge. First follow Build U-Boot and Linux Kernel from Source Code, to cross compile the regular kernel. Then follow the typical out of tree kernel module process using this environment.

  2. Cross compile module using OpenEmbedded SDK which includes kernel sources

    Currently, our SDK by default does not contain kernel sources, hence you cannot use our pre-built SDKs. However you can build a SDK yourself (see also Linux SDKs) and add TOOLCHAIN_TARGET_TASK_append = " kernel-devsrc" to your conf/local.conf file.

  3. Cross compile a complete image with kernel & module using OpenEmbedded

    This is typically not ideal during development of an external kernel module since it would require to always use bitbake to iterate through builds. However, if your external kernel module is already existing/tested, it might be worth directly use OpenEmbedded to build it. An example recipe of an external kernel module is for instance our kernel-module-atemsys reicpe. Once you have a recipe for your kernel module, add the package to your image using IMAGE_INSTALL_append and then build the image follow the OpenEmbedded (core) article.

Thanks!

We were able to compile the driver using method #1. For reference in case it’s useful for someone else, the driver we needed to compile is for the Intel Network Adapter Driver for 82575/6, 82580, I350, and I210/211

To compile the driver we used (while being on a shell session with the env variables configured to use the toolchain):

make KSRC=/path/to/linux-toradex

and then we copied the igb.ko file to the rootfs. We are using Ubuntu base 16.04 for the rootfs

Thanks for the update. I am glad it worked out!