Makefile error when building an out-of-tree kernel module on Resin OS


#1

Hi,

I’ve been attempting to get an external USB Wi-Fi adapter(D-Link DWA-171) working on a Raspberry Pi 3, running Resin OS(started with v1.24.1, but then switched to v2.0.0-beta.7 as suggested by @craig due to missing headers/scripts in previous versions).

I’m using a Dockerfile and build script from the resin.io playground https://github.com/craig-mulligan/kernel-module-build
which seems to execute correctly, except that I run into the following error during the make process:

[Build]      HOSTCC  scripts/conmakehash
[Build]      HOSTCC  scripts/recordmcount
[Build]      HOSTCC  scripts/sortextable
[Build]    scripts/Makefile.build:44: init/Makefile: No such file or directory
[Build]    make[1]: *** No rule to make target 'init/Makefile'.  Stop.
[Build]    Makefile:947: recipe for target 'init' failed
[Build]    make: *** [init] Error 2
[Build]    make: Leaving directory '/tmp/tmp.RX8KBNR5MS'
[Build]     ---> d339f47e07c8
[Build]    Removing intermediate container 82f56278f78a

Any idea why this is happening?

Note: I have verified that the Makefile works perfectly on a regular Raspbian installation.

Cheers,
Bjorn.


Using rtl88au module to connect to 5Gz wifi network on Raspberry Pi 3 Model B
#2

Hey Bjorn,

Could you post the link to the kernel module that you are trying to build?

Cheers,
Cameron


#3

Hey Cameron,
You can find it here


#4

Would it be possible to post your repository? I’m having trouble recreating the issues you’re having.


#5

I’ve built that same module, albeit for a different platform. Based on my experience with the huge range of versions of the rtl8812au drivers out there, I’d recommend starting by pulling the resin headers down for your architecture (you can see how to get them by following the code in the kernel-module-build project) and just build it yourself outside of the resin / docker environment to start with. I had to mangle the makefile quite a bit to get everything to compile properly. If I remember correctly, the particular issue you’re having there is related to the way the kernel sources are brought in on this line:

$(MAKE) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KSRC) M=$(shell pwd)  modules

#6

Thanks for the tips @cmoss that’s very handy! Is there a repo you can share with complete example, or something that can be adapted into a working base project / boilerplate? There’s indeed a lot of variation out there, and kernel modules will be just more important later.


#7

I’m unable to post the link. It’s being automatically flagged.


#8

Hi @bjorn, that was an over-eager spam filter on the forums, reinstated your posts, and whitelisted github.com, so it won’t happen again with that domain. :black_joker: Hope it didn’t cause too much inconvenience!


#9

thanks! :slight_smile:


#10

@cameron You can find my repo here: https://github.com/bjorn-sminq/rtl8812-resin-module


#11

@cameron @cmoss Any update on this?


#12

Hey @bjorn,

I’ve been looking at this when I get the time, but I havn’t been able to make it build yet either. It’s not really my area of expertise but I’ll keep looking, and update if I reach anything meaningful. At the moment I’m also just failing on Makefile errors. Sorry I’ve not been more help :confused:


#13

Hi Bjorn,

Unfortunately I don’t have anything ARM here right now to test with, nor do I have the cross compile toolchain setup (we’re doing everything resin with x86), however here’s what I noticed when I tried building your repo:

A). Build with a standard git push resin master:
Failed - like you said:

    [Build]    scripts/Makefile.build:44: init/Makefile: No such file or directory
[Build]    make[1]: *** No rule to make target 'init/Makefile'.  Stop.
[Build]    Makefile:947: recipe for target 'init' failed
[Build]    make: *** [init] Error 2
[Build]    make: Leaving directory '/tmp/tmp.mQsAYtBAoq'

B) Build locally, using the standard Makefile:

  1. Pull down the kernel headers:
    wget https://files.resinstaging.io/images/raspberrypi3/2.0.0-beta.7/kernel_modules_headers.tar.gz

  2. Compile from within the module directory:
    make ARCH=arm CROSS_COMPILE= -C /lib/modules/3.14.0/build M=/home/cmoss/Development/rtl8812-resin-module/rtl8812au_rtl8821au modules
    make[1]: *** /lib/modules/3.14.0/build: No such file or directory. Stop.
    Makefile:1680: recipe for target ‘modules’ failed
    make: *** [modules] Error 2

No surprise there, shouldn’t work anway.

  1. Hack the KSRC directory, to point to the headers that we downloaded:

    (vivid)cmoss@localhost:~/Development/rtl8812-resin-module/rtl8812au_rtl8821au$ make
    make ARCH=arm CROSS_COMPILE= -C /home/cmoss/Development/rtl8812-resin-module/kernel_modules_headers M=/home/cmoss/Development/rtl8812-resin-module/rtl8812au_rtl8821au modules
    make[1]: Entering directory '/home/cmoss/Development/rtl8812-resin-module/kernel_modules_headers’
    CC [M] /home/cmoss/Development/rtl8812-resin-module/rtl8812au_rtl8821au/core/rtw_cmd.o
    gcc: error: unrecognized argument in option '-mabi=aapcs-linux’
    gcc: note: valid arguments to ‘-mabi=’ are: ms sysv
    gcc: error: unrecognized command line option '-mlittle-endian’
    gcc: error: unrecognized command line option '-mapcs’
    gcc: error: unrecognized command line option '-mno-sched-prolog’
    gcc: error: unrecognized command line option '-mno-thumb-interwork’
    gcc: error: unrecognized command line option '-mfpu=vfp’
    scripts/Makefile.build:258: recipe for target ‘/home/cmoss/Development/rtl8812-resin-module/rtl8812au_rtl8821au/core/rtw_cmd.o’ failed
    make[2]: *** [/home/cmoss/Development/rtl8812-resin-module/rtl8812au_rtl8821au/core/rtw_cmd.o] Error 1
    Makefile:1384: recipe for target ‘module/home/cmoss/Development/rtl8812-resin-module/rtl8812au_rtl8821au’ failed
    make[1]: *** [module/home/cmoss/Development/rtl8812-resin-module/rtl8812au_rtl8821au] Error 2
    make[1]: Leaving directory '/home/cmoss/Development/rtl8812-resin-module/kernel_modules_headers’
    Makefile:1680: recipe for target ‘modules’ failed
    make: *** [modules] Error 2

Tries to compile, fails, because I don’t have any of the ARM cross compile stuff here - but at least it knows what it has to do.

I’m 99.9% sure if you do this either directly on the ARM system, or on a rig with the ARM toolchain, then it will compile properly.

I’ve not had a chance to dig much into the Makefile, but if you look at the top there are any number of switches based on architecture, which then use a different definition of KSRC. The build.sh you’re using expects the makefile to play nicely with the kernel headers it gets given which that Makefile really doesn’t do. Basically, although you have the right headers, your Makefile is ignoring them.


#14

Ok, so I couldn’t let that evil Makefile get its way. If you want a quick and very dirty way to get your module compiled, using the resin toolchain, here you go:

  1. Modify your Makefile on line 1680:

change:

$(MAKE) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KSRC) M=$(shell pwd)  modules

to this:

    $(MAKE) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C /tmp/headers M=$(shell pwd)  modules

Then change build.sh in a couple of places:

This:

tmp_path=$(mktemp --directory)
push $tmp_path

to this:

    mkdir -p /tmp/headers
    tmp_path="/tmp/headers/"
    push $tmp_path

And this:

	cp -R "$module_dir"/* "$output_dir"

	push "$output_dir"
	make -C "$tmp_path"
	pop

to this:

cp -R “$module_dir”/* “$output_dir”

#push "$output_dir"
#make -C "$tmp_path"
make -C "$output_dir"
#pop

rm -rf "$tmp_path"

And your module will compile.

There is certainly a much cleaner way to get this working (I haven’t checked how many files build artifacts are left hanging around after this) - but at least this way you’ll get the module compiled, and I don’t have to spend any more time looking at that horrible Makefile :wink:


#15

Thanks a ton @cmoss, the hacky solution worked perfectly! :smiley:
This issue was a blocker for the project I’m working on… At least now I’ll be able to get a move on with things. I’ll try and work out a cleaner solution eventually, now that I know what the problem was. :slight_smile: