Can't compile LKM for custom sensor driver

Hello,

I am trying to compile my imaging sensor driver as a module with the command:

make ARCH="arm64" O=$TEGRA_KERNEL_OUT -j$(nproc)

Yet, the compiler throws out this error:

rm drivers/misc/mods/mods.dtb drivers/misc/mods/mods.dtb.S
  Building modules, stage 2.
  MODPOST 656 modules
WARNING: could not open drivers/misc/mods/mods.dtb.S: No such file or directory
FATAL: modpost: GPL-incompatible module imx392.ko uses GPL-only symbol 'tegracam_v4l2subdev_register'
/home/ubuntu/repositories/Stereo-Vision_TX2/build/Linux_for_Tegra/sources/kernel/kernel-4.9/scripts/Makefile.modpost:107: recipe for target '__modpost' failed
make[2]: *** [__modpost] Error 1
/home/ubuntu/repositories/Stereo-Vision_TX2/build/Linux_for_Tegra/sources/kernel/kernel-4.9/Makefile:1333: recipe for target 'modules' failed
make[1]: *** [modules] Error 2
make[1]: Leaving directory '/home/ubuntu/repositories/Stereo-Vision_TX2/build/Linux_for_Tegra/images'
Makefile:171: recipe for target 'sub-make' failed
make: *** [sub-make] Error 2

I wrote my driver almost like the IMX185 (v2) driver. It compiles correctly if the driver is set to “y” in tegra_defconfig.
Any idea how I can solve this issue?

I tried following the building of EKM and got as far as just the preparation of the sources. The docs specify to change the directory to <path_to_module_source>. I looked around, tried different paths but I can’t find which path is meant by “module_source”.

Furthermore, since I updated the sources to 32.4.2, I get these errors while compiling:

dpkg: error processing package ... (--install):
   dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of ...:
Package ... is not configured yet

Errors were encountered while processing:
 nvidia-l4t-init
 nvidia-l4t-x11
 nvidia-l4t-3d-core
 nvidia-l4t-camera
 nvidia-l4t-cuda
 nvidia-l4t-graphics-demos
 nvidia-l4t-gstreamer
 nvidia-l4t-multimedia

Did you build the r32.3.1 or r32.4.x ?
These version are build imx185 as LKM without problem.

I’m building 32.4.2. The IMX185 and IMX274 build fine as a module, but not my custom driver (IMX392).

I believe I found a temporarily workaround for building here.
The comment states to change MODULE_LICENSE("Proprietary"); to MODULE_LICENSE("GPL"); in order to build the kernel modules. This should of course only be used for internal development due to legal reasons.

I tried this and it works. Oddly enough setting the license to “GPL V2” like the IMX185 driver doesn’t allow the module to be built.

I hope to see a clarification regarding the restriction of proprietary drivers and maybe a more permanent workaround/fix.

Regarding my second issue, installing the kernel modules “breaks” the use of ./apply_binaries.sh:
$ sudo make ARCH=${ARCH} O=$TEGRA_KERNEL_OUT modules_install INSTALL_MOD_PATH=$DEVDIR/rootfs

The output (first post) shows not configured dependencies.

Edit:
This second problem seems to be fixed in L4T 32.4.3. I believe it’s related to issue 200612061 from the release notes.

I managed to build the LKM, but I can’t load it on the system. This is the output:

ubuntu@ubuntu-desktop:~/Downloads$ sudo insmod imx392.ko
insmod: ERROR: could not insert module imx392.ko: Invalid parameters
ubuntu@ubuntu-desktop:~/Downloads$ dmesg | tail
[  173.726472] imx392: disagrees about version of symbol tegracam_v4l2subdev_register
[  173.734113] imx392: Unknown symbol tegracam_v4l2subdev_register (err -22)
[  173.740966] imx392: disagrees about version of symbol tegracam_device_unregister
[  173.748450] imx392: Unknown symbol tegracam_device_unregister (err -22)
[  173.755121] imx392: disagrees about version of symbol tegracam_get_privdata
[  173.762183] imx392: Unknown symbol tegracam_get_privdata (err -22)
[  173.768515] imx392: disagrees about version of symbol tegracam_set_privdata
[  173.775579] imx392: Unknown symbol tegracam_set_privdata (err -22)
[  173.781986] imx392: disagrees about version of symbol tegracam_device_register
[  173.789308] imx392: Unknown symbol tegracam_device_register (err -22)

These functions are GPL functions from what I’ve seen previously when I was trying to compile it as a module.

It looks like the preinstalled kernel modules have different modversions:

ubuntu@ubuntu-desktop:~$ sudo modprobe --dump-modversions /lib/modules/4.9.140-tegra/kernel/drivers/media/i2c/imx185.ko | grep tegra
0x81a72767      tegracam_v4l2subdev_register
0xec53576e      tegracam_set_privdata
0xa12366ce      tegracam_device_register
0x7c98b75d      tegracam_get_privdata
0xc94b262b      tegracam_device_unregister
0x8758372d      tegracam_v4l2subdev_unregister
ubuntu@ubuntu-desktop:~$ sudo modprobe --dump-modversions /lib/modules/4.9.140-tegra/kernel/drivers/media/i2c/imx392.ko | grep tegra
0x0a2dfa4e      tegracam_v4l2subdev_register
0x4f8b6305      tegracam_set_privdata
0x9dbb7fc6      tegracam_device_register
0x5ab54b52      tegracam_get_privdata
0xdd714459      tegracam_device_unregister
0x6e32e8e3      tegracam_v4l2subdev_unregister

I compiled the driver with L4T 32.4.2 sources and the Jetson is using the BSP for the Connect Tech Orbitty, which is also L4T version 32.4.2

Edit:
Looks like the provided kernel from Connect Tech is different. I flashed my build kernel and the driver is loaded!

[   54.768463] imx392 2-0036: probing v4l2 sensor.
[   54.768521] imx392 2-0036: mclk not in DT
[   54.774709] imx392 2-0036: inck-gpios not found -22
[   54.781688] imx392 2-0036: slamode1-gpios not found -22
[   54.794000] imx392 2-0036: slamode2-gpios not found -22
[   54.810072] imx392 2-0036: mode-gpios not found -22
[   54.948364] imx392 2-0036: trigger-gpios not found -22
[   54.967450] imx392 2-0036: pwr-gpios not found -22
[   54.979757] imx392 2-0036: unable to get clock extperiph1
[   54.993082] imx392 2-0036: unable to power get
[   54.997726] imx392 2-0036: tegra camera driver registration failed
[   55.004053] imx392: probe of 2-0036 failed with error -14