Search code examples
makefilelinux-kernelkernel-modulexilinx

Why does my kernel module Makefile build a .ko with kernel 4.14 but not 5.6?


I have a Makefile made by following this example: cross compile kernel module

I built a 4.14 Linux kernel from an older Xilinx source, and then built a out-of-kernel module with that script, pointing it to the said 4.14 kernel sources, and filling in the blanks for my particular platform architecture. That worked. (It's based on this code, if that matters: dma-proxy.c)

Now I need a newer version, and got Xilinx sources with a kernel named 5.6.0-rc1. (--branch "zynqmp-soc-for-v5.7" from here) Building that kernel also worked fine. If I now use a scrubbed clean directory (incl. hidden files) with my module source code and that Makefile again, pointing to the newer kernel sources, it does neither produce a .ko file nor an error message. All I get is:

make ARCH=arm64 CROSS_COMPILE="aarch64-linux-gnu-" -C /home/sk/src/XILINX/linux-xlnx SUBDIRS=/home/sk/src/XILINX/dma-proxy/driver modules
make[1]: Entering directory '/home/sk/src/XILINX/linux-xlnx'
CALL    scripts/checksyscalls.sh
CALL    scripts/atomic/check-atomics.sh
MODPOST 28 modules
make[1]: Leaving directory '/home/sk/src/XILINX/linux-xlnx'

No .ko file in my folder as it was before when building with 4.14, and it doesn't list actually compiling anything. I find it curious that it says "MODPOST 28 modules", whereas with pointing it to kernel 4.14, it expectedly says "1 modules" Has anything changed between 4.14 and 5.x that would cause this?


Solution

  • Mkay, here is the suggested makefile template by the tutorial I referenced in the question:

    PWD := $(shell pwd)
    obj-m += hello.o
    
    all:
            make ARCH=arm CROSS_COMPILE=$(CROSS) -C $(KERNEL) SUBDIRS=$(PWD) modules
    clean:
            make -C $(KERNEL) SUBDIRS=$(PWD) clean
    

    Turns out that if I replace SUBDIRS=$(PWD) with M=$(PWD), it works. Now if I google explicitly for that M variable in conjunction with building kernel modules, I do find text that show it that way. But the net is also littered with examples using SUBDIRS, and it worked for me with a fairly recent kernel (4.14).

    Then I did find references hinting at this being an old way of doing it, like from here:

    make -C $KDIR SUBDIRS=$PWD
        Same as M=. The SUBDIRS= syntax is kept for backwards compatibility.
    

    In fact, this seems to be really old, like, kernel 2.6.7 old. Unfortunately, fairly recent tutorials show the old way.