1

I'm following the first example of a Hello World LKM and now I need to compile it.

According to the book, the Makefile needs to be like this:

obj-m+=hello_world.o

all:
        make -C /lib/modules/$(shell uname -r)/build/ M=$(pwd) modules
clean:
        make -C /lib/modules/$(shell uname -r)/build/ M=$(pwd) clean

And then you need to run make (and it says that you souldn't run sudo make or you'll recompile all Linux kernel headers).

By running this it outputs:

make -C /lib/modules/5.10.63+/build/ M= modules
make[1]: Entering directory '/usr/src/rpi-5.10.y'
/bin/sh: 1: cannot create include/generated/uapi/linux/.version.h.tmp: Permission denied
  UPD     include/generated/uapi/linux/version.h
mv: cannot stat 'include/generated/uapi/linux/.version.h.tmp': No such file or directory
make[1]: *** [Makefile:1277: include/generated/uapi/linux/version.h] Error 1
make[1]: Leaving directory '/usr/src/rpi-5.10.y'
make: *** [Makefile:4: all] Error 2

And if I run sudo make or change the Makefile commands by sudo make -C ... it never ends (>2h and still waiting).

I couldn't run sudo apt install linux-headers-'uname -r' (ignore the ', they are ` but I can't place it here) because the kernel it's the last one (5.10.63+), but I have followed all the steps on the book that tells how to manually compile all Linux kernel headers, so I should have them.

Any idea? If you need some extra information just tell me what command I need to run and I'll attach the output.

Thanks!

3
  • 1
    The value for M= is empty. This chooses the directory in which the module you are building is found. When empty, it will try and build the Makefile in your /lib/modules directory, which you do not have write access to. Hence, when make tries to create a file, it fails.
    – galexite
    Commented Oct 2, 2021 at 18:02
  • 2
    +1 ... it likely should be M=$(PWD) not M=$(pwd) Commented Oct 2, 2021 at 18:03
  • 1
    You're right, I should've used M=$(PWD) Commented Oct 2, 2021 at 18:07

0

You must log in to answer this question.

Browse other questions tagged .