0

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.

Eliah Kagan
  • 116,445
  • 54
  • 318
  • 493
JosephCenk
  • 103
  • 1
  • 3

1 Answers1

0

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).

pim
  • 3,240
  • 3
  • 20
  • 37
  • Still I am not sure, how to proceed with UpStream Kernel... Are you sure we cannot compile this Light Sensor module separately and integrate it with Ubuntu Kernel. Something like below link http://tldp.org/LDP/lkmpg/2.6/html/x121.html#AEN128 – JosephCenk Sep 26 '17 at 08:25
  • When try to compile opt3001.c, it generates below error ```opt3001.c:19:26: fatal error: linux/bitops.h: No such file or directory compilation terminated.``` – JosephCenk Sep 26 '17 at 09:56
  • please note I fixed the commands, but since `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
  • it did not install anything, please find below result `$ 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.` – JosephCenk Sep 26 '17 at 11:02
  • I just tested on a xubuntu 16.04 live-cd, nothing to install, works as expected. which version of ubuntu are you using? on which architecture? are you trying to cross-compile the module? – pim Sep 26 '17 at 11:07
  • I am using Ubuntu 16.04 LTS, amd64 `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
  • getting below error `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
  • Ok, so your kernel is too old for this driver, you can either modify the driver code or install the latest HWE kernel by using `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
  • Wow! thanks, I generated below files Makefile modules.order `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