OV5693 as module. Not working

I have built the image with the OV5693 driver as a module. Here is the “.config” file I used to build the image.

#
# Automatically generated file; DO NOT EDIT.
# Linux/arm64 4.9.140 Kernel Configuration
#
CONFIG_ARM64=y
CONFIG_64BIT=y
CONFIG_ARCH_PHYS_ADDR_T_64BIT=y
CONFIG_MMU=y
CONFIG_DEBUG_RODATA=y
CONFIG_ARM64_PAGE_SHIFT=12
CONFIG_ARM64_CONT_SHIFT=4
CONFIG_ARCH_MMAP_RND_BITS_MIN=18
CONFIG_ARCH_MMAP_RND_BITS_MAX=24
CONFIG_ARCH_MMAP_RND_COMPAT_BITS_MIN=11
CONFIG_ARCH_MMAP_RND_COMPAT_BITS_MAX=16
CONFIG_STACKTRACE_SUPPORT=y
CONFIG_ILLEGAL_POINTER_VALUE=0xdead000000000000
CONFIG_LOCKDEP_SUPPORT=y
CONFIG_TRACE_IRQFLAGS_SUPPORT=y
CONFIG_FIQ_GLUE=y
CONFIG_RWSEM_XCHGADD_ALGORITHM=y
CONFIG_GENERIC_BUG=y
CONFIG_GENERIC_BUG_RELATIVE_POINTERS=y
CONFIG_GENERIC_HWEIGHT=y
CONFIG_GENERIC_CSUM=y
CONFIG_GENERIC_CALIBRATE_DELAY=y
CONFIG_ZONE_DMA=y
CONFIG_HAVE_GENERIC_RCU_GUP=y
CONFIG_ARCH_DMA_ADDR_T_64BIT=y
CONFIG_NEED_DMA_MAP_STATE=y
CONFIG_NEED_SG_DMA_LENGTH=y
CONFIG_SMP=y
# CONFIG_IOMMU_HELPER is not set
CONFIG_KERNEL_MODE_NEON=y
CONFIG_FIX_EARLYCON_MEM=y
CONFIG_PGTABLE_LEVELS=3
# CONFIG_ARM64_NON_SHARED_TLBI is not set
CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
CONFIG_IRQ_WORK=y
CONFIG_BUILDTIME_EXTABLE_SORT=y
CONFIG_THREAD_INFO_IN_TASK=y

#
# General setup
#
CONFIG_INIT_ENV_ARG_LIMIT=32
CONFIG_CROSS_COMPILE=""
# CONFIG_COMPILE_TEST is not set
CONFIG_LOCALVERSION="-tegra"
# CONFIG_LOCALVERSION_AUTO is not set
CONFIG_DEFAULT_HOSTNAME="(none)"
CONFIG_SWAP=y
CONFIG_SYSVIPC=y
CONFIG_SYSVIPC_SYSCTL=y
CONFIG_POSIX_MQUEUE=y
CONFIG_POSIX_MQUEUE_SYSCTL=y
CONFIG_CROSS_MEMORY_ATTACH=y
CONFIG_FHANDLE=y
# CONFIG_USELIB is not set
CONFIG_AUDIT=y
CONFIG_HAVE_ARCH_AUDITSYSCALL=y
CONFIG_AUDITSYSCALL=y
CONFIG_AUDIT_WATCH=y
CONFIG_AUDIT_TREE=y

...

#
# Sensors used on soc_camera driver
#

#
# NVIDIA overlay Encoders, decoders, sensors and other helper chips
#
CONFIG_VIDEO_IMX185=y
CONFIG_VIDEO_IMX219=y
CONFIG_VIDEO_IMX268=y
CONFIG_VIDEO_IMX274=y
CONFIG_VIDEO_IMX318=y
CONFIG_VIDEO_LC898212=y
CONFIG_VIDEO_OV5693=m
CONFIG_VIDEO_OV9281=y
CONFIG_VIDEO_OV10823=y
CONFIG_VIDEO_OV23850=y
CONFIG_I2C_IOEXPANDER_PCA9570=y
CONFIG_VIDEO_TC358840=y
CONFIG_I2C_IOEXPANDER_SER_MAX9295=y
CONFIG_I2C_IOEXPANDER_DESER_MAX9296=y
CONFIG_VIDEO_IMX390=y

...

#
# Tegra BPMP Driver
#
CONFIG_ARCH_TEGRA_18x_SOC=y
CONFIG_ARCH_TEGRA_19x_SOC=y
CONFIG_ARCH_TEGRA_23x_SOC=y

Up until this point, everything correct. The fact is that, once I load the module, I cannot remove it. This is what I do to generate and load the module:

  1. Generate the .ko binary with the following makefile:
ifneq ($(KERNELRELEASE),)
obj-m	:= ov5693.o
else
KDIR	:= /lib/modules/$(shell uname -r)/build
PWD	:= $(shell pwd)
all:
	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
install:
	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules_install
%:
	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) $@
endif
  1. Load the module
sudo insmod ov5693.ko
  1. I check the module is correctly loaded by capturing some images via Gstreamer. Works fine.

  2. Remove the module

sudo rmmod ov5693.ko

In this last step, I get the error “Module ov5693 is builtin”. Why is this happening?

hello euskadi,

it seems you’re working with kernel-4.9, may I also know which JetPack release you’re used.
FYI,
JetPack-4.2 (l4t-r32.1) is not support loadable camera kernel module.
thanks

It seems the post got unformatted for no reason. I’ve fixed that.

Yes, I’m using JetPack 4.2, but setting the OV5693 as loadable module instead of builtin. Why is that feature not available? Is there any way to work with it as loadable? I tried to remove the c and header files (also the entry from the .config file, and the entries in the Makefile and Kconfig files) from the kernel source, and load it the same way, with the .ko file, but still giving the same “builtin” error.

@euskadi

Is the module listed in

cat /lib/modules/$(uname -r)/modules.builtin

?

Hi @arne.caspari,

Yes, it is. This is how it’s shown.

kernel/drivers/media/i2c/ov5693.ko

However, lsmod doesn’t show the ov5693 entry, only when I manually load the module.

Is there any way to delete that entry from modules.builtin?

Thanks!

AFAIK, if it is in modules.builtin, the module is statically linked in the kernel and thus could not be unloaded. This also means that the camera should also already work before you “modprobe” the module. Does it?

No, it doesn’t, at least with Gstreamer. I see no /dev/video0 entry anyways. I use the following pipeline, which works after manually loading the module.

gst-launch-1.0 nvarguscamerasrc ! 'video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)NV12, framerate=(fraction)30/1' ! nvoverlaysink -e

@euskadi

Try:

make clean
make Image
make modules.builtin

@euskadi

I tested it with my IMX290 driver on my system and I could build the driver as a module this way. However doing so is not very useful since if the driver gets successfully probed during boot time, the tegracam infrastructure will hold a reference to it. This means that the module can not get unloaded anyway.

@arne.caspari

And would it work to change the compatible field of the OV5693 driver included in the kernel (i.e. change <<.compatible = “nvidia,ov5693”>> to <<.compatible = “fail,ov5693”>> for example), so that the sensor doesn’t get successfully probed, and after that, build the .ko binary with the correct compatible field and load/unload it whenever I want?

@euskadi

I do not think this would work but go ahead and try it. Why do you want this functionality?

@euskadi

I tested it by not installing the module in /lib/modules/… in the first place.

This allows you to load the module later on but as expected, tegracam still holds a reference then so once the module is loaded, you can not unload it.

@arne.caspari

Okey, thanks! I’ll test it asap, and I’ll let you know if it works. The reason is because I want to try the module without some functionalities or modifying them, and I don’t want to generate a new kernel image every time I change the driver.

It is still not working. Regardless the change I do in the ov5693.c file located in kernel/nvidia/drivers/media/i2c/, the driver keeps appearing in modules.builtin. I’ll keep trying different things, will update if I get something.