Unable to cross-compile for mips
Clash Royale CLAN TAG#URR8PPP
Unable to cross-compile for mips
I tried to cross compile the simple hello.c using mips cross compiler which throws me error.
Below is the error
satya@satya-dev:~/Test/kernel/check$ make ARCH=mips CROSS_COMPILE=mips-buildroot-linux-uclib-
make -C /opt/toolchains/crosstools-mips-gcc-5.3-linux-4.1-uclibc-1.0.12-binutils-2.25-NPTL/usr/bin/ M=/home/satya/Test/kernel/check modules
make[1]: Entering directory '/opt/toolchains/crosstools-mips-gcc-5.3-linux-4.1-uclibc-1.0.12-binutils-2.25-NPTL/usr/bin'
make[1]: *** No rule to make target 'modules'. Stop.
make[1]: Leaving directory '/opt/toolchains/crosstools-mips-gcc-5.3-linux-4.1-uclibc-1.0.12-binutils-2.25-NPTL/usr/bin'
Makefile:7: recipe for target 'all' failed
make: *** [all] Error 2
My Makefile is:
obj-m := hello.o
#KDIR := /lib/modules/$(shell uname -r)/build/
KDIR := /opt/toolchains/crosstools-mips-gcc-5.3-linux-4.1-uclibc-1.0.12-binutils-2.25-NPTL/usr/bin/
#PWD = $(shell pwd)
all:
$(MAKE) -C $(KDIR) M=$(shell pwd) modules
clean:
$(MAKE) -C $(KDIR) M=$(shell pwd) clean
I added the compiler path to /bin also
satya@satya-dev:~/Test/kernel/check$ echo $PATH
/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/sbin:/opt/toolchains/crosstools-mips-gcc-5.3-linux-4.1-uclibc-1.0.12-binutils-2.25-NPTL:/opt/toolchains/crosstools-mips-gcc-5.3-linux-4.1-uclibc-1.0.12-binutils-2.25-NPTL/usr/bin
Even compiler works fine without makefile
satya@satya-dev:~/Test/kernel/check$ /opt/toolchains/crosstools-mips-gcc-5.3-linux-4.1-uclibc-1.0.12-binutils-2.25-NPTL/usr/bin/mips-buildroot-linux-uclibc-gcc in.c -o temp
satya@satya-dev:~/Test/kernel/check$ ll
total 24
-rw-rw-r-- 1 satya satya 1135 Aug 10 05:06 hello.c
-rw-rw-r-- 1 satya satya 0 Aug 10 06:29 Module.symvers
-rw-rw-r-- 1 satya satya 52 Aug 10 07:48 modules.order
-rw-rw-r-- 1 satya satya 66 Aug 10 07:59 in.c
-rw-rw-r-- 1 satya satya 281 Aug 10 08:30 Makefile
-rwxrwxr-x 1 satya satya 5604 Aug 10 09:37 temp
I know I am doing some vague mistake, but I couldn't figure it out. Can anyone tell me where am I going wrong?
KDIR
Your makefile targets don't call your gcc to compile anything, and don't mention hello.c - they just run
make
in KDIR.– ewindes
Aug 10 at 14:22
make
1 Answer
1
I know I am doing some vague mistake, but I couldn't figure it out.
Can anyone tell me where am I going wrong?
No, it's no "vague mistake". Your Makefile has valid form, but the contents are pretty much non-sensical.
In your command-line make
invocation, you do not name a target, so make
chooses the default (first) one in your Makefile, 'all'. This is probably what you want, as far as it goes.
make
make
The recipe for target 'all' contains only one command:
$(MAKE) -C $(KDIR) M=$(shell pwd) modules
This runs a sub-make
in directory $(KDIR)
, which is surprising because it does not look like the value set for KDIR
is part of the project you are trying to build.
make
$(KDIR)
KDIR
The sub-make
is asked to build a target named 'modules', and the error message indicates that make
does not have any rule for how to do so. Probably it does not see a makefile (under any of the names it recognizes) in the build directory, but if it does see one, then it does not contain a rule for that target. I note that the Makefile
you present has no rule for such a target, either, so I have no idea where that comes from.
make
make
Makefile
Even compiler works fine without makefile
Well that's good news, at least.
The key to cross-compiling is to use the correct toolchain for the purpose. You can do this in several ways, but most of them start with defining some standard make variables appropriately. For example:
tooldir = /opt/toolchains/crosstools-mips-gcc-5.3-linux-4.1-uclibc-1.0.12-binutils-2.25-NPTL/usr/bin
CC = $(tooldir)/mips-buildroot-linux-uclibc-gcc
LD = $(CC)
The CC
variable names the C compiler, and the LD
variable names the linker. There are other variables you might want or need to set, too, such as CFLAGS
for any C compiler flags you want to use, and LDFLAGS
for any linker flags.
CC
LD
CFLAGS
LDFLAGS
There are several ways you could go from there, but the very simplest would be to name the default target "hello" instead of "all":
hello:
And that's probably all you need to build the "hello" program specifically.
I went to the directory "/opt/toolchains/crosstools-mips-gcc-5.3-linux-4.1-uclibc-1.0.12-binutils-2.25-NPTL/usr/bin". Here I have cross compiler like this $ ll | grep mips-buildroot-linux-uclibc-gcc lrwxrwxrwx 1 501 501 17 May 4 2017 mips-buildroot-linux-uclibc-gcc -> toolchain-wrapper But I dont have any make file. How can I proceed further
– satyaGolladi
Aug 10 at 14:47
No, @satyaGolladi, the whole point is that you shouldn't go to that directory. It contains tools that you must use, but you don't want to perform the build there. I already gave you a complete or nearly complete example of how to write a simple Makefile for building your "hello" program.
– John Bollinger
Aug 10 at 17:19
John, in my new make file with what I should replace the below line with? hello: $(KDIR) -C $(CC) M=$(shell pwd) module Note: I am new to driver development, please bear with me
– satyaGolladi
Aug 13 at 5:31
@satyaGolladi, for building a program named "hello" from a single source file named "hello.c", you can replace that line with nothing. A zero-line recipe. Just name the default target "hello", and set the variables I described in the answer. I meant you to take "that's probably all you need to build the "hello" program specifically" quite literally.
– John Bollinger
Aug 13 at 11:50
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
KDIR
is a path to part of the kernel sources, not the bin directory of a cross compiler. You need something more like this: blukat29.github.io/2017/12/cross-compile-arm-kernel-module– Dark Falcon
Aug 10 at 14:00