0

I've built an android kernel (source code), now I'm trying to cross-compile a kernel module for it, v4l2loopback to be precise. I've used this toolchain to build the kernel (kernel version is 4.9).

Here on github you can see that someone actually succeeded in compiling the module, and I've been trying to replicate their success myself. But in the last stage of actually building the kernel module I don't get a .ko file output. Here is what I get:

# setting up
$ export ARCH=arm64
$ export CROSS_COMPILE=aarch64-linux-android-
$ export PATH=/home/username/redmi_7a/aarch64-linux-android-4.9-kernel/bin:$PATH
# go to the source code directory
$ cd v4l2loopback
$ export M="$PWD" 
# I have the compiled kernel at /home/username/redmi_7a/kernel
make -C ../kernel
make: entering catalogue «/home/username/redmi_7a/kernel»
  CHK     include/config/kernel.release
  CHK     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  CHK     include/generated/bounds.h
  CHK     include/generated/timeconst.h
  CHK     include/generated/asm-offsets.h
  CALL    scripts/checksyscalls.sh
  CHK     scripts/mod/devicetable-offsets.h
  Building modules, stage 2.
  MODPOST 4 modules
make: exiting catalogue «/home/username/redmi_7a/kernel»

Seems like no errors, no nothing, but all I get is a v4l2loopback.o file, instead of v4l2loopback.ko file, as mentioned per v4l2loopback github page.

I tried find . -name "*.ko", but it didn't return anything.

I might've screwed something up during the kernel compilation, so it might not module's fault. I don't really know where to look, I'm really new to this.

Maybe I need to set some flag in the kernel .config file and recompile?

All I really ask is a direction, what are the things I might've done wrong?

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
winwin
  • 958
  • 7
  • 25
  • You did `export M=$PWD` before you were in the correct directory. PWD is the current directory. – stark Feb 25 '22 at 16:09
  • @stark sorry, my bad, I did it correctly in fact, but written badly. `echo $M` returns `/home/username/redmi_7a/v4l2loopback`, so I guess it should be good. – winwin Feb 25 '22 at 16:26
  • 1
    Still wrong.$PWD in backticks will try to execute the directory name as a command. Lose the backticks. – stark Feb 25 '22 at 16:29
  • @stark ok, did it, thanks. But what other than that could there be? – winwin Feb 25 '22 at 16:31
  • As @stark says, this seems like a typo. Use `export M="$PWD"` instead and retry (maybe also clean the build before recompiling). Does that work? – Marco Bonelli Feb 25 '22 at 16:31
  • @MarcoBonelli `echo $M` returns `/home/username/redmi_7a/v4l2loopback`, so all should be good. I just mistyped it here on stackoverflow, but I guess I did it correctly in the terminal. Are there any other things to consider? – winwin Feb 25 '22 at 16:33
  • Hopefully, your code consists of exactly one C file named v4l2loopback.c? If there is more than one C file then this won't work. – stark Feb 25 '22 at 16:34
  • @stark I did not change anything in the code, I did `git clone https://github.com/umlaeute/v4l2loopback` and that's it. The codebase for the module itself should be very reliable, as it's an old kernel module (since 2.6.something). – winwin Feb 25 '22 at 16:37
  • @stark old meaning proven with time, not old as in ancient :) – winwin Feb 25 '22 at 16:37
  • You are creating an environment variable M, when you want to create a make variable M. `make -C M=$PWD` See https://elixir.bootlin.com/linux/v5.16.1/source/Documentation/kbuild/modules.rst#L77 – stark Feb 25 '22 at 16:45
  • @stark `make` takes vars from the environment too so that's not an issue really. – Marco Bonelli Feb 25 '22 at 16:46

1 Answers1

0

You seem to be building incorrectly. With make -C ../kernel you are completely ignoring the Makefile that is in the repository of the module you are trying to build and using the kernel Makefile alone. You should take a look at the Makefile inside v4l2loopback and notice the following lines at the beginning of the file:

include Kbuild
ifeq ($(KBUILD_MODULES),)

KERNELRELEASE   ?= `uname -r`
KERNEL_DIR      ?= /lib/modules/$(KERNELRELEASE)/build
PWD             := $(shell pwd)
...

So the PWD and kernel dir are already set for you. You should just override KERNEL_DIR and the needed cross-compilation variables:

export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-android-
export PATH=/home/username/redmi_7a/aarch64-linux-android-4.9-kernel/bin:$PATH
export KERNEL_DIR=/home/username/redmi_7a/kernel

cd v4l2loopback
make

The above works on my machine and correctly produces v4l2loopback.ko. Make sure you have built the kernel before doing this of course.

Marco Bonelli
  • 63,369
  • 21
  • 118
  • 128