I'm trying to build an old linux driver in my system (Kubuntu 21.10) with make -C ...
.
The driver is declaring static struct timeval frame_timestamp;
If I try to build it with something like
make -C /lib/modules/`uname -r`/build M=`pwd` V=1 modules
I'm getting ... has an incomplete type ‘struct timeval’
error and some other related errors.
So I believe I must include sys/time.h with #include <sys/time.h>
into the code.
But in this case I'm getting fatal error: sys/time.h: No such file or directory
. And I cant't find a way to resolve this. (The code already had some includes but none from sys/, they are all from linux/ and media/)
I ended up with a following Makefile
:
obj-m := mydriver.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) M=$(PWD) V=1 modules
The KDIR
resolves into /lib/modules/5.13.0-21-generic/build
which links to /usr/src/linux-headers-5.13.0-21-generic
. There is no sys/time.h
.
locate sys/time.h
returns:
/usr/include/i386-linux-gnu/sys/time.h
/usr/include/sys/time.h
/usr/include/x86_64-linux-gnu/sys/time.h
which belongs to libc6-dev
and libc6-dev-i386:
.
dpkg -l *5.13.0-21*
gives:
ii linux-headers-5.13.0-21 5.13.0-21.21 all Header files related to Linux kernel version 5.13.0
ii linux-headers-5.13.0-21-generic 5.13.0-21.21 amd64 Linux kernel headers for version 5.13.0 on 64 bit x86 SMP
ii linux-image-5.13.0-21-generic 5.13.0-21.21 amd64 Signed kernel image generic
un linux-image-unsigned-5.13.0-21-generic <нет> <нет> (описание недоступно)
ii linux-modules-5.13.0-21-generic 5.13.0-21.21 amd64 Linux kernel extra modules for version 5.13.0 on 64 bit x86 >
ii linux-modules-extra-5.13.0-21-generic 5.13.0-21.21 amd64 Linux kernel extra modules for version 5.13.0 on 64 bit x86
I was trying to hardcode -I /usr/include/x86_64-linux-gnu/
into make -C
- this has no effect.
I also tried to download a vanilla kernel from kernel.org: https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.13.tar.xz
and hardcode it as KDIR
- that doesn't help and it's not containing sys/time.h
either.
The question is: how to force my module build process to see the sys/time.h
?
Does linux module allowed to link to libc? If it's not a part of the kernel, how to make it available for module buildprocess?
Ok, it seems one can't use
sys/time.h
in kernel module.I have taken a look at definition of
struct v4l2_buffer
inlinux/videodev2.h
where thestruct timeval
is supposed to be used by the driver to initialize itstimestamp
field and found there:The
__KERNEL__
is defined automatically somewhere inmake -C
process, so up-to-date kernel expects to get__kernel_v4l2_timeval
. Replacingstruct timeval
withstruct __kernel_v4l2_timeval
among with some other tricks allowed me to compile this old driver.