Compiling UVC kernel module out of source tree against running kernel - linux-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.

Related

Android x86 Kernel Compilation stops abruptly

I downloaded PrimeOS' kernel from https://github.com/primebook/android_kernel_common. I just need to replace a single .c file in /drivers/platform/x86. Here's what I tried doing:-
Replaced .c
make clean && make mrproper
Copied arch//configs/android-x86_deconfig to linux source root folder as .config
fakeroot make kernel -j4
The command runs but stops abruptly and the terminal shows the $ localhost as if the task is finished. Can you tell me where I went wrong.
Update
Here's the place where the issue comes:-
HOSTCC scripts/basic/fixdep
HOSTCC scripts/kconfig/conf.o
YACC scripts/kconfig/zconf.tab.c
LEX scripts/kconfig/zconf.lex.c
..............................................................
CC kernel/time/timeconv.o
In file included from ./arch/x86/include/asm/string.h:3,
from ./include/linux/string.h:20,
from ./arch/x86/include/asm/page_32.h:35,
from ./arch/x86/include/asm/page.h:14,
from ./arch/x86/include/asm/thread_info.h:12,
from ./include/linux/thread_info.h:38,
from ./arch/x86/include/asm/preempt.h:7,
from ./include/linux/preempt.h:81,
from ./include/linux/spinlock.h:51,
from ./include/linux/mmzone.h:8,
from ./include/linux/gfp.h:6,
from ./include/linux/mm.h:10,
from ./include/linux/ring_buffer.h:5,
from kernel/trace/trace.c:15:
In function ‘ftrace_dump’,
inlined from ‘ftrace_dump’ at kernel/trace/trace.c:8269:6:
./arch/x86/include/asm/string_32.h:325:29: warning: ‘__builtin_memset’ offset [8297, 8336] from the object at ‘iter’ is out of the bounds of referenced subobject ‘seq’ with type ‘struct trace_seq’ at offset 4176 [-Warray-bounds]
325 | #define memset(s, c, count) __builtin_memset(s, c, count)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kernel/trace/trace.c:8347:3: note: in expansion of macro ‘memset’
8347 | memset(&iter.seq, 0,
| ^~~~~~
CC kernel/time/timecounter.o
..............................................................
AR kernel/built-in.a
$
Full Log: https://pastebin.com/8T3G3Uyc
So, it just comes back to $ as if the process completed at kernel/built-in.a. This is the file where every time it stops. Even if I compile the kernel without any changes, it still stops at kernel/built-in.a
BTW, I am just using the source I downloaded from primebook and installed the necessary packages for recompiling the kernel. Should I be doing something else too.
UPDATE 1
I tried running make -j4 bzImage modules but this again stops at
AR drivers/video/built-in.a
AR drivers/built-in.a
Even this doesn't compile a bzImage
UPDATE 2
I tried running make kernel on a Linux source (5.4.0) and even that stops at built-in.a
UPDATE 3
I tried running make bzImage modules without -j4 and I get a new error now
sound/soc/codecs/es8316.c:766:1: note: in expansion of macro ‘module_i2c_driver’
766 | module_i2c_driver(es8316_i2c_driver);
| ^~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
make[3]: *** [scripts/Makefile.build:304: sound/soc/codecs/es8316.o] Error 1
make[2]: *** [scripts/Makefile.build:544: sound/soc/codecs] Error 2
make[1]: *** [scripts/Makefile.build:544: sound/soc] Error 2
make: *** [Makefile:1050: sound] Error 2
Full log: https://pastebin.com/JJeh4QTk
UPDATE 4
make bzImageworks and outputs the bzImage as expected.
Fix for kernel compilation stopping at make a built-in.a file
Use make bzImage or make bzImage modules instead of make kernel
Update - In my case the error was with the ES8316.c which was causing the compilation to stop. Go to your config file and delete the lines pertaining to ES8316 and the build went through successfully.
Fix for other Errors in the question
For the codec issue and for any other conflicting module, go to your config file and search for it, for eg:- i had issue with the module for ES8316. To fix it, remove the line corresponding to ES8316 in your config file or add a # infront of it. You may also try to debug the problem if you really need that driver.
Other things that you could try
I had gcc-9 installed and installing gcc-8 did help at times.

Buildroot plugin file is compiled for the target architecture altough used later in Makefile

I am trying to create an package for dietsplash for buildroot, and I've added the files
Config.in
config BR2_PACKAGE_DIETSPLASH
bool "dietsplash"
help
dietsplash is an simple splash screen service for
embedded devices. It has support for animations.
dietsplash.mk
################################################################################
#
# dietsplash
#
################################################################################
DIETSPLASH_VERSION = v0.3
DIETSPLASH_SOURCE = dietsplash-$(DIETSPLASH_VERSION).tar.gz
DIETSPLASH_SITE = git://github.com/lucasdemarchi/dietsplash.git
DIETSPLASH_AUTORECONF = YES
$(eval $(autotools-package))
The github repository is
https://github.com/lucasdemarchi/dietsplash
The output of make is:
>>> dietsplash v0.3 Building
PATH="/media/justus_fluegel/PROJECTS/buildroot/buildroot-2019.11.1/output/host/bin:/media/justus_fluegel/PROJECTS/buildroot/buildroot-2019.11.1/output/host/sbin:/home/justus_fluegel/.pub-cache/bin/:/usr/share/flutter/flutter/bin/cache/dart-sdk/bin/:/usr/share/flutter/flutter/bin/:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/sbin:/usr/sbin:/snap/bin:/usr/local/texlive/2019/bin/x86_64-linux" /usr/bin/make -j5 -C /media/justus_fluegel/PROJECTS/buildroot/buildroot-2019.11.1/output/build/dietsplash-v0.3/
make[1]: Entering directory '/media/justus_fluegel/PROJECTS/buildroot/buildroot-2019.11.1/output/build/dietsplash-v0.3'
/usr/bin/make all-am
make[2]: Entering directory '/media/justus_fluegel/PROJECTS/buildroot/buildroot-2019.11.1/output/build/dietsplash-v0.3'
GEN src/background.h
/bin/bash: src/genstaticlogo: cannot execute binary file: Exec format error
Makefile:1017: recipe for target 'src/background.h' failed
make[2]: *** [src/background.h] Error 126
make[2]: *** Waiting for unfinished jobs....
make[2]: Leaving directory '/media/justus_fluegel/PROJECTS/buildroot/buildroot-2019.11.1/output/build/dietsplash-v0.3'
Makefile:400: recipe for target 'all' failed
make[1]: *** [all] Error 2
make[1]: Leaving directory '/media/justus_fluegel/PROJECTS/buildroot/buildroot-2019.11.1/output/build/dietsplash-v0.3'
package/pkg-generic.mk:238: recipe for target '/media/justus_fluegel/PROJECTS/buildroot/buildroot-2019.11.1/output/build/dietsplash-v0.3/.stamp_built' failed
make: *** [/media/justus_fluegel/PROJECTS/buildroot/buildroot-2019.11.1/output/build/dietsplash-v0.3/.stamp_built] Error 2
And file of src/genstaticlogo
src/genstaticlogo: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 4.19.0, not stripped
I think the problem is that src/genstaticlogo is compiled for the target but executed by the Makefile.am during the build process. How do I tell make to compile src/genstaticlogo for the build machine and not for the target? Altough the repository is not my work, it's theoretically possible to modify the makefile after download.
Thank you for your help!
You will need to patch the Makefile.am to support cross-compilation. See this old answer for details. In short, you will need something like this in the Makefile.am:
$(genstaticlogo_OBJECTS): CC=$(CC_FOR_BUILD)
$(genstaticlogo_OBJECTS): CFLAGS=$(CFLAGS_FOR_BUILD)
$(genstaticlogo_OBJECTS): CPPFLAGS=$(CPPFLAGS_FOR_BUILD)
Since you will be patching Makefile.am, you will also need to set DIETSPLASH_AUTORECONF = YES in the Buildroot dietsplash.mk file.

How to compile tool and samples from within the kernel source tree? (e.g. bpftool, bpf samples)

GOAL: compile samples/bpf, compile bpf/bpftool and use them.
PROBLEM: on a VM with Ubuntu 18.04 bionic with a kernel 4.18.0-25-generic I've installed kernel src code executing apt install linux-source-4.18.0.
Now I cd into /usr/src/linux-source-4.18.0/linux-source-4.18.0/samples/bpf and I run make and the result is
make -C ../../ /usr/src/linux-source-4.18.0/linux-source-4.18.0/samples/bpf/ BPF_SAMPLES_PATH=/usr/src/linux-source-4.18.0/linux-source-4.18.0/samples/bpf
make[1]: Entering directory '/usr/src/linux-source-4.18.0/linux-source-4.18.0'
scripts/kconfig/conf --syncconfig Kconfig
***
*** Configuration file ".config" not found!
***
*** Please run some configurator (e.g. "make oldconfig" or
*** "make menuconfig" or "make xconfig").
***
scripts/kconfig/Makefile:40: recipe for target 'syncconfig' failed
make[3]: *** [syncconfig] Error 1
Makefile:562: recipe for target 'syncconfig' failed
make[2]: *** [syncconfig] Error 2
make[1]: *** No rule to make target 'include/config/auto.conf', needed by 'include/config/kernel.release'. Stop.
make[1]: Leaving directory '/usr/src/linux-source-4.18.0/linux-source-4.18.0'
Makefile:203: recipe for target 'all' failed
make: *** [all] Error 2
If I cd into ../samples/bpf and I run sudo make the result is
Auto-detecting system features:
... libbfd: [ OFF ]
... disassembler-four-args: [ OFF ]
CC map_perf_ring.o
CC xlated_dumper.o
CC perf.o
CC cfg.o
CC common.o
CC cgroup.o
CC main.o
main.c:36:10: fatal error: bfd.h: No such file or directory
#include <bfd.h>
^~~~~~~
compilation terminated.
Makefile:92: recipe for target 'main.o' failed
make: *** [main.o] Error 1
QUESTIONS: what am I missing? After I compile them if I want to write a program which, for example, needs to use bpftool I have to write the program inside the source kernel directory or I can write it everywhere?
Build errors
The first case (Makefile:562: recipe for target 'syncconfig' failed) fails because you run make from the top of the linux kernel repository, and before trying to compile the samples, the build system tries to load a config file to use for your system (but does not find one).
Before trying to build the samples (make -C samples/bpf), you can create a .config file from your current kernel configuration like this:
$ cp /usr/src/linux-headers-$(uname -r)/.config <path to repo>/.config
$ make olddefconfig
Or even simply generate a default config file from scratch:
$ make defconfig
See make help from top directory to see the available make options.
Your second error, regarding bfd.h not found, is that you miss a library. Libbfd on Ubuntu comes with binutils-dev, so apt install binutils-dev should do the trick.
Compiling the programs
Finally, regarding your question on compiling the programs:
You can write and build program from the kernel repository, just by creating a new sample and reusing the existing Makefiles.
You can also write and compile programs outside of the kernel tree. The basic clang (v4.0 or above, if possible v6.0 or above) command to compile them usually looks something like this:
$ clang -O2 -emit-llvm -c my_bpf_prog.c -o - | \
llc -march=bpf -filetype=obj -o my_bpf_prog.o
You can find examples of programs compiled out of the kernel tree in that repository (disclaimer: by my company) or in the XDP tutorial repo.

Trying to compile kernel module in Windows Subsystem for Linux error

When I run make after creating this makefile from this website
http://www.tldp.org/LDP/lkmpg/2.6/html/x181.html
When I run make in WSL I get make -C /lib/modules/4.4.0-17134-Microsoft/build M=/mnt/c/Users/tdwil/OneDrive/code/Documents/cfiles/systems/linuxkernel modules
make[1]: *** /lib/modules/4.4.0-17134-Microsoft/build: No such file or directory. Stop.
Makefile:5: recipe for target 'all' failed
make: *** [all] Error 2
Is this because make isn't possible in WSL? Or am I typing some directory wrong?
First of all, you do not have Linux header on WSL.
Another problem with Windows that Linux kernel have several file names which are differ in case.
It is better to compile kernel or kenel modules on Linux machines or VM.

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

Resources