We want to integrate a light sensor driver with Ubuntu's kernel. Please advise how can we do it.
The light sensor code given in opt3001.c
here.
We want to integrate a light sensor driver with Ubuntu's kernel. Please advise how can we do it.
The light sensor code given in opt3001.c
here.
It seems this is the mainline upstream kernel, so please have a look at MainlineBuilds, you can probably find the kernel suiting your needs here.
On ubuntu 16.04 , the default kernel (4.4) is too old for compiling this driver. But you can install a more recent kernel HWE using this command : sudo apt-get install --install-recommends linux-generic-hwe-16.04
.
Manual compiling, tested on 16.04 with kernel 4.10.0-35-generic
mkdir opt3001 && cd opt3001
wget https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/drivers/iio/light/opt3001.c
echo 'obj-$(CONFIG_OPT3001) += opt3001.o' > Makefile
make -C /lib/modules/$(uname -r)/build M=$(pwd) modules
Some packages may be necessary (build-essential
, linux-headers-$(uname -r)
, ...).
And you may have a look at this answer if you have troubles with secure boot (insmod: ERROR: could not insert module opt3001.ko: Required key not available
).
compilation terminated.```
– JosephCenk
Sep 26 '17 at 09:56
linux/bitops.h
is the first include, maybe sudo apt-get install linux-headers-$(uname -r)
should do.
– pim
Sep 26 '17 at 10:49
$ sudo apt-get install linux-headers-$(uname -r) Reading package lists... Done Building dependency tree Reading state information... Done linux-headers-4.4.0-96-generic is already the newest version (4.4.0-96.119). The following packages were automatically installed and are no longer required: ... zlib1g-dev:i386 Use 'sudo apt autoremove' to remove them. 0 upgraded, 0 newly installed, 0 to remove and 178 not upgraded.
uname -a Linux VirtualBox 4.4.0-96-generic #119-Ubuntu SMP Tue Sep 12 14:59:54 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
– JosephCenk
Sep 26 '17 at 11:24
make -C /lib/modules/$(uname -r)/build M=$(pwd) modules make: Entering directory '/usr/src/linux-headers-4.4.0-96-generic CC [M] /opt3001/opt3001.o /opt3001/opt3001.c: In function ‘opt3001_irq: /opt3001/opt3001.c:716:6: error: too many arguments to function ‘iio_get_time_ns’ In file included from /opt3001/opt3001.c:32:0: include/linux/iio/iio.h:287:19: note: declared here /opt3001/opt3001.c:722:6: error: too many arguments to function ‘iio_get_time_ns’ In file included from /opt3001/opt3001.c:32:0: include/linux/iio/iio.h:287:19: note: declared here
– JosephCenk
Sep 26 '17 at 11:39
sudo apt-get install --install-recommends linux-generic-hwe-16.04
, after a reboot you will be able to compile this driver (I just tested that in a VM).
– pim
Sep 26 '17 at 11:47
Module.symvers opt3001.c opt3001.ko opt3001.mod.c opt3001.mod.o opt3001.o
Add Module using below command to Kernel
sudo modprobe --all opt3001
please confirm that it?
– JosephCenk Sep 26 '17 at 12:35
opt3001
is a single in-tree kernel module and you want to build it. – David Foerster Sep 26 '17 at 13:19