0
votes

I'm new to kernel compilation and am trying to cross-compile a userspace program for an existing kernel driver for an ARM board. Basically, I'm trying to access the ioctl facilities of the driver.

I'm using arm-linux-gnueabihf-gcc (4.9.2).

I can compile the kernel successfully. The userspace code looks like following

getefuse.c

#include <stdio.h>
#include <sys/types.h>
#include <string.h>
#include <sys/ioctl.h> 
#include <linux/amlogic/efuse.h> //The driver's header file
....

When I try to compile the userspace code, I get entangled in a mesh of 'include' file issues. The kernel source code resides at /home/cheema/boards/linux/

$ arm-linux-gnueabihf-gcc -I/home/cheema/boards/linux/include getefuse.c
In file included from getefuse.c:7:0:
/home/cheema/boards/linux/include/linux/amlogic/efuse.h:5:24: fatal   error: mach/efuse.h: No such file or directory
#include <mach/efuse.h>
                    ^
compilation terminated.

I try to add the missing 'include' file path. But every time I add another file path, the compiler gives the No such file or directory error for a different file.

I believe I have to use kernel's config files(Makefile??) to get out of this mess, but don't know how.

1
You need to add another -I option to tell the compiler where mach/efuse.h lives. You can try to include the kernel makefile in yours, and use the flags as defined there, but add yours to them. - ventsyv
@ventsyv - I already mentioned, its an every increasing mess. For every new -I that I add, the error shifts somewhere else. For ex: $ arm-linux-gnueabihf-gcc -I/home/cheema/boards/linux/include -I../../../arch/arm/mach-meson8/include getefuse.c .... .... from /home/cheema/boards/linux/include/linux/amlogic/efuse.h:75, from getefuse.c:7: /home/cheema/boards/linux/include/linux/atomic.h:4:24: fatal error: asm/atomic.h: No such file or directory #include <asm/atomic.h> ^ compilation terminated. - Neo
And then there is the problem of too many different directories where mach/efuse.h exists. So only the kernel config can identify and pick the correct mach/efuse.h. - Neo
Can you post the makefile for the kernel? - ventsyv
is amlogic your board ? - srd

1 Answers

1
votes

Looks like the file efuse.h includes mach/efuse.h. But mach is only defined under Kernel build system. It does not mean anything to cross-compiler at user-space.

You need to include only the file that has the ioclt number. If it is mach/efuse.h, then include only that file as #include <path_to_file>

You should be able to identify your mach, it depends on your board.