You are not logged in.

#1 2023-03-09 23:44:36

jenia
Member
Registered: 2014-07-12
Posts: 43

[SOLVED] Cannot compile kernel module

Hello.

I need to compile this kernel module: https://bugs.launchpad.net/ubuntu/+sour … ug/2000947

But when I run the make command:

    make -j4 -C /lib/modules/$(uname -r)/build M=$(pwd) modules

I get

    scripts/Makefile.build:41: /home/jenia/Documents/kernel-modules/camera/Makefile: No such file or directory
    make[1]: *** No rule to make target '/home/jenia/Documents/kernel-modules/camera/Makefile'.  Stop.
    make: *** [Makefile:2021: /home/jenia/Documents/kernel-modules/camera] Error 2

Notice that I have the -C flag there pointing the make program to the directory `/lib/modules/$(uname -r)/build` where the makefile is located.

How do I correctly point the make to `/lib/modules/$(uname -r)/build`?

It's also note worthy if I remove all other flag other than the -C flag: `make -C /lib/modules/$(uname -r)/build modules`

I get:

    mkdir: cannot create directory ‘.tmp_17624’: Permission denied

Can someone please tell me, how do I compile correctly that kernel module?

Last edited by jenia (2023-04-23 18:42:41)

Offline

#2 2023-03-09 23:57:43

loqs
Member
Registered: 2014-03-06
Posts: 17,369

Re: [SOLVED] Cannot compile kernel module

/home/jenia/Documents/kernel-modules/camera/Makefile which is missing is the Makefile for the module.  /lib/modules/$(uname -r)/build/Makefile is the Makefile for the kernel build system which calls the module Makefile in the directory passed via M=$(pwd)
Edit:
See also https://docs.kernel.org/kbuild/modules.html
Edit2:
https://patchwork.kernel.org/project/li … board.com/

Last edited by loqs (2023-03-10 00:23:01)

Offline

#3 2023-03-10 00:55:56

jenia
Member
Registered: 2014-07-12
Posts: 43

Re: [SOLVED] Cannot compile kernel module

Hello loqs. Thanks kindly for the help. I have a follow up question, where do I find the makefile that should be in /home/jenia/Documents/kernel-modules/camera/Makefile ?
Its not in the original launchpad thread.
?
Should I write one myself to simply compile that .c file?

Offline

#4 2023-03-10 01:17:09

loqs
Member
Registered: 2014-03-06
Posts: 17,369

Re: [SOLVED] Cannot compile kernel module

$ git clone https://github.com/archlinux/svntogit-packages --single-branch --branch 'packages/linux' linux # get the current PKGBUILD for Arch's kernel package
$ gpg --import keys/pgp/* # import the signing keys it uses
$ makepkg -Codd --noprepare # get the kernel source
$ curl -o media-uvcvideo-Force-UVC-version-to-1.0a-for-0408-4035.diff https://patchwork.kernel.org/project/linux-media/patch/20230115205210.20077-1-laurent.pinchart@ideasonboard.com/raw/ #get the patch
$ cd src/archlinux-linux/
$ git apply -v ../../media-uvcvideo-Force-UVC-version-to-1.0a-for-0408-4035.diff # apply the patch
$ cd drivers/media/usb/uvc/
$ make -C /lib/modules/$(uname -r)/build M=$PWD
# make -C /lib/modules/$(uname -r)/build M=$PWD modules_install # install the module ( I have not tested this last command )

Last edited by loqs (2023-03-10 01:19:23)

Offline

#5 2023-04-23 01:12:11

jenia
Member
Registered: 2014-07-12
Posts: 43

Re: [SOLVED] Cannot compile kernel module

ok. I finally had time to do this and it ran flawlessly. I suggest to keep this page open for anyone consulting the instruction above: https://wiki.archlinux.org/title/Kernel_module

Offline

#6 2023-04-23 01:13:27

jenia
Member
Registered: 2014-07-12
Posts: 43

Re: [SOLVED] Cannot compile kernel module

Thank you loqs!!

Offline

#7 2023-04-23 06:22:00

seth
Member
Registered: 2012-09-03
Posts: 51,165

Re: [SOLVED] Cannot compile kernel module

Please always remember to mark resolved threads by editing your initial posts subject - so others will know that there's no task left, but maybe a solution to find.
Thanks.

Offline

#8 2023-04-23 15:00:42

jenia
Member
Registered: 2014-07-12
Posts: 43

Re: [SOLVED] Cannot compile kernel module

One more critical instruction to anyone trying to replicate this, change the device IDs in the patch with the ones outputted from lsusb on your machine.

Last edited by jenia (2023-04-23 15:02:01)

Offline

#9 2023-04-23 15:01:40

jenia
Member
Registered: 2014-07-12
Posts: 43

Re: [SOLVED] Cannot compile kernel module

seth: I can't see the option to edit the title only the messages I posted.

Offline

#10 2023-04-23 15:25:18

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,785

Re: [SOLVED] Cannot compile kernel module

jenia wrote:

seth: I can't see the option to edit the title only the messages I posted.

You have to edit the first post in the thread to have the option to edit the title.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#11 2024-03-02 17:59:58

gchamon
Member
Registered: 2018-08-07
Posts: 5

Re: [SOLVED] Cannot compile kernel module

I am really sorry if this comment might be considered necro-bumping, but I found that while this post really solves the issue, the solution isn't complete in which every kernel upgrade or re-installation will overwrite the patch.

I wanted to create a pacman hook to re-run the steps provided by loqs, but redownloading the entire kernel source before applying the patch each time I upgrade the linux kernel isn't practical.

I found that https://github.com/Kvalme/uvc is supposed to solve the same issue, but I wasn't convinced that applying a random kernel module patch on github is safe, so I combined both approaches, added audit and precaution instructions and created another repo to automate the process using pacman hooks: https://github.com/gchamon/uvc

Hope this helps other people with this issue, and sorry if my approach is too involved and there are other simpler ways to solve this, but I was battling this problem for the last couple of days and I think this is the best solution so far.

Offline

#12 2024-03-03 19:16:30

loqs
Member
Registered: 2014-03-06
Posts: 17,369

Re: [SOLVED] Cannot compile kernel module

@gchamon have you considered working with the kernel developers to resolve the issue?  https://patchwork.kernel.org/project/li … board.com/ ended with a request for information from someone with the hardware to which there was no response.  You could also check if the issue is still present in mainline and the linux-media tree.

Offline

#13 2024-03-06 21:13:25

gchamon
Member
Registered: 2018-08-07
Posts: 5

Re: [SOLVED] Cannot compile kernel module

@loqs nice, I didn't see they were in need of testers with the required hardware. I am going to reach out. I just assumed these things take long. Thanks!

Offline

Board footer

Powered by FluxBB