Linux Kernel driver modpost missing MODULE_LICENSE - linux-kernel

My Linux Kernel driver (platform driver) contains MODULE_LICENSE ("GPL v2");, but during compilation following warning is printed:
make[1]: Entering directory '/home/me/buildroot/output/build/linux-4.15.16'
LD [M] /home/me/dir/driver_xy.o
Building modules, stage 2.
MODPOST 1 modules
WARNING: modpost: missing MODULE_LICENSE() in /home/me/dir/driver_xy.o
Whats the problem?

The Makefile was incorrect:
The module name was equal the source file name. So following works:
#Makefile
obj-m += mymodule.o
mymodule-y := mymodule_main.o driver_xy.o
before/incorrect:
obj-m += mymodule.o
mymodule-y := driver_xy.o

I had to add MODULE_LICENSE("GPL"); at the end of my module.c file and it worked. See also this GitHub issue.

Related

Compiling UVC kernel module out of source tree against running kernel

I am trying to make modifications to the UVC kernel module and then insert it into my running kernel. To do this, I performed these steps:
Install linux-headers with sudo apt install linux-headers-$(uname -r)
Checkout the UVC drivers folder from the Linux kernel GitHub repository
Enter directory and try to compile with make -C /lib/modules/`uname -r`/build M=$PWD as specified by Building External Modules from the kernel.org docs.
But I get this error from Make, complaining that it can't find an include from the tree above (which I do not have checked out)
me#bionic:~/src/media/usb/uvc$ make -C /lib/modules/`uname -r`/build M=$PWD
make: Entering directory '/usr/src/linux-headers-5.4.0-131-generic'
CC [M] /home/me/src/media/usb/uvc/uvc_driver.o
/home/me/src/media/usb/uvc/uvc_driver.c:23:10: fatal error: media/v4l2-uvc.h: No such file or directory
#include <media/v4l2-uvc.h>
^~~~~~~~~~~~~~~~~~
compilation terminated.
scripts/Makefile.build:270: recipe for target '/home/me/src/media/usb/uvc/uvc_driver.o' failed
make[1]: *** [/home/me/src/media/usb/uvc/uvc_driver.o] Error 1
Makefile:1762: recipe for target '/home/me/src/media/usb/uvc' failed
make: *** [/home/me/src/media/usb/uvc] Error 2
make: Leaving directory '/usr/src/linux-headers-5.4.0-131-generic'
But shouldn't it be able to find this include from my running kernel (given by -C /lib/modules/`uname -r`/build)? How can I compile this kernel module?
The Makefile from inside the UVC folder contains:
# SPDX-License-Identifier: GPL-2.0
uvcvideo-objs := uvc_driver.o uvc_queue.o uvc_v4l2.o uvc_video.o uvc_ctrl.o \
uvc_status.o uvc_isight.o uvc_debugfs.o uvc_metadata.o
ifeq ($(CONFIG_MEDIA_CONTROLLER),y)
uvcvideo-objs += uvc_entity.o
endif
obj-$(CONFIG_USB_VIDEO_CLASS) += uvcvideo.o
and the Kconfig file contains:
config USB_VIDEO_CLASS
tristate "USB Video Class (UVC)"
depends on VIDEO_V4L2
select VIDEOBUF2_VMALLOC
---help---
Support for the USB Video Class (UVC). Currently only video
input devices, such as webcams, are supported.
For more information see: <http://linux-uvc.berlios.de/>
config USB_VIDEO_CLASS_INPUT_EVDEV
bool "UVC input events device support"
default y
depends on USB_VIDEO_CLASS
depends on USB_VIDEO_CLASS=INPUT || INPUT=y
---help---
This option makes USB Video Class devices register an input device
to report button events.
If you are in doubt, say Y.

How to specify and use a locally installed package in a makefile?

I'm trying make a program which requires Armadillo as a dependency. I've installed Armadillo in a local directory (I'm working on a cluster without root privileges), but am unable to install the program because it can't find armadillo. How would I specify that? Thanks in advance for the help!
What I'm doing & seeing:
$ make
g++ -O3 -o ancestry_hmm ancestry_hmm.cpp -larmadillo
ancestry_hmm.cpp:22:21: fatal error: armadillo: No such file or directory
#include <armadillo>
^
compilation terminated.
make: *** [all] Error 1
The current Make file:
TCFLAGS = -ltcmalloc
ARMAFLAGS = -larmadillo
all:
$(LINK.cc) -O3 -o ancestry_hmm ancestry_hmm.cpp $(ARMAFLAGS)
Path to armadillo:
/{user}/Programs/Anaconda/*.so
/{user}/Programs/Anaconda/
Answer was provided by Claes Rolen in the comments. I had to also add -lgfortran, but it works, thanks!

Cross-compilation (ARM) 'VFP register arguments' error

I want to build a DDS 'perftest' application to do some tests between a x64 Kubuntu 15.10 and RaspberryPi 1 B, but in /rtiperftest.5.2.4/perftest_cpp directory there isn't a makefile for armv6 architecture.
I have installed crosstool-ng 1.22 to build application for target armv6 architecture following this HOWTO (Section 4 and 5) but I didn't know how to write the makefile for build 'perftest_cpp' using crosscompiler to run it on RaspberryPi.
Now I have got a makefile (attached) for build 'perftest_cpp' but I get 'uses VFP register arguments' error (with hundred of files) that I can't understand (I only paste one error for make it readable)
/home/ampu/x-tools/armv6-rpi-linux-gnueabi/lib/gcc/armv6-rpi-linux-gnueabi/5.2.0/../../../../armv6-rpi-linux-gnueabi/bin/ld.bfd: error: /opt/rti_connext_dds-5.2.3//lib/armv6vfphLinux3.xgcc4.7.2/libnddscorez.a(SkiplistInfo.o) uses VFP register arguments, ../bin/armv6vfphLinux3.xgcc4.7.2/Release/perftest_cpp does not
/home/ampu/x-tools/armv6-rpi-linux-gnueabi/lib/gcc/armv6-rpi-linux-gnueabi/5.2.0/../../../../armv6-rpi-linux-gnueabi/bin/ld.bfd: failed to merge target specific data of file /opt/rti_connext_dds-5.2.3//lib/armv6vfphLinux3.xgcc4.7.2/libnddscorez.a(SkiplistInfo.o)
collect2: error: ld returned 1 exit status
common2.mk:86: recipe for target '../bin/armv6vfphLinux3.xgcc4.7.2/Release/perftest_cpp' failed
make: *** [../bin/armv6vfphLinux3.xgcc4.7.2/Release/perftest_cpp] Error 1
Here is my Makefile.RPi
ARCH := armv6vfphLinux3.xgcc4.7.2
DEBUG_FLAG := -O4
#DEBUG_FLAG := -g
#DEFINES_ARCH_SPECIFIC := -DRTI_LINUX
cxx_cc := armv6-rpi-linux-gnueabi-g++
cxx_ld := armv6-rpi-linux-gnueabi-g++
cxx_ld_flags := -static-libgcc -ldl -lnsl -lm -L/usr/lib/nptl -lpthread -lrt
include common2.mk
Any idea?
Thank you.
Attached files:
Makefile.RPi
common2.mk

Cross-compilation of rtl8192cu driver fails

I 'm trying to cross-compile rtl8192cu Driver in my Linux x86 machine for an ARM machine. I downloaded driver from Realtek website. Compilation guide refers editing Makefile as follows:
Ensure that the $PATH variable includes the location of the toolchain that you will be using to cross-compile the module. Refer to the setup instructions for the location of this directory.
Set the KSRC environment variable is set to the location of your Beagleboard's kernel source (see cross-compilation environment setup instructions for this directory path).
Set the KVER environment variable to your beagleboard's kernel version.
For this reson, I edited:
KVER := 2.6.32 (2.6.32. is BB's kernel version)
KSRC ?= /home/demetres/linux-2.6.32.61 (compiled kernel sources, taken from BB, stored on home/demetres/linux-2.6.32.61 location)
My question is:
What do I have to edit on Makefile's field CROSS_COMPILE:? I edited the path /home/demetres/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/bin but
make fails with these errors:
make ARCH=arm CROSS_COMPILE=/home/demetres/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/bin -C /home/demetres/linux-2.6.32.61 M=/home/demetres/Downloads/rtl8188C_8192C_usb_linux_v4.0.2_9000.20130911 modules
make[1]: /home/demetres/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/bingcc: Command not found
make[1]: Entering directory `/home/demetres/linux-2.6.32.61'
CC [M] /home/demetres/Downloads/rtl8188C_8192C_usb_linux_v4.0.2_9000.20130911/core/rtw_cmd.o
/bin/sh: /home/demetres/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/bingcc: No such file or directory
make[2]: *** [/home/demetres/Downloads/rtl8188C_8192C_usb_linux_v4.0.2_9000.20130911/core/rtw_cmd.o] Error 1
make[1]: *** [_module_/home/demetres/Downloads/rtl8188C_8192C_usb_linux_v4.0.2_9000.20130911] Error 2
make[1]: Leaving directory `/home/demetres/linux-2.6.32.61'
make: *** [modules] Error 2
INFO: Cross-toolchain on x86 machine is from CodeSourcery. I cross-compiled a helloworld.c for BB, by running arm-none-linux-gnueabi-gcc helloworld.c –o helloworld, on CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/bin location.
_CodeBench_Lite_for_ARM_GNU_Linux/bingcc: Command not found
This error is due to you are not passing correct parameter
pass arm-none-linux-gnueabi-
where ever it finds {CROSS_COMPILE}gcc {CROSS_COMPILE}ld ...etc
this will be replaced with arm-none-linux-gnueabi-gcc arm-none-linux-gnueabi-ld
Edit
make ARCH=arm CROSS_COMPILE=/home/demetres/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/bin/arm-none-linux-gnueabi- -C /home/demetres/linux-2.6.32.61 M=/home/demetres/Downloads/rtl8188C_8192C_usb_linux_v4.0.2_9000.20130911 modules
If your cross-toolchain exported then try this
make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- -C /home/demetres/linux-2.6.32.61 M=/home/demetres/Downloads/rtl8188C_8192C_usb_linux_v4.0.2_9000.20130911 modules

Linux driver phys_mem_access_prot undefined

I have a loadable module that is throwing a warning about phys_mem_access_prot when built under Ubuntu 9.10 (Linux 2.6.31-22-server).
[664] make -C /lib/modules/`uname -r`/build M=`pwd`
make: Entering directory `/usr/src/linux-headers-2.6.31-22-server'
LD /home/chuck/dev/svd/built-in.o
CC [M] /home/chuck/dev/svd/svd.o
LD [M] /home/chuck/dev/svd/svd_drv.o
Building modules, stage 2.
MODPOST 1 modules
WARNING: "phys_mem_access_prot" [/home/chuck/dev/svd/svd_drv.ko] undefined!
CC /home/chuck/dev/svd/svd_drv.mod.o
LD [M] /home/chuck/dev/svd/svd_drv.ko
make: Leaving directory `/usr/src/linux-headers-2.6.31-22-server'
The function does show up in the System.map-2.6.31-22-server file
[667] grep phys_mem_access_prot /boot/System.map-2.6.31-22-server
ffffffff8103fb40 T phys_mem_access_prot
ffffffff8103fb50 T phys_mem_access_prot_allowed
and the driver loads, so I'm confused as to why modpost is unhappy. Is this a problem because the kernel doesn't export the function with EXPORT_SYMBOL()?
You've answered you own question! Any kernel function used by a module needs to be exported by one of the various EXPORT_SYMBOL() macros.
You'll also see problems if non-GPL modules need to use functions exported by EXPORT_SYMBOL_GPL.

Resources