This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Cross-Compiling Kernel Modules for PSP Kernel BeagleBoard

I am able to cross-compile simple c programs using the command :
/home/sumanta/scratchbox/

compilers/arm-linux-cs2009q3-67/bin/arm-none-linux-gnueabi-gcc -Wall -o hello hello1.c

for loadable modules i have a make file :
----------------------------------------------------------
obj-m +=hello-1.o
obj-m +=hello-2.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


This makefile works on PC for compiling modules to .ko files
But for cross compiling I use the command

make ARCH=arm CROSS_COMPILE=/home/sumanta/scratchbox/compilers/arm-linux-cs2009q3-67/bin/arm-none-linux-gnueabi-

it gives errors :
--------------------
make -C /lib/modules/2.6.38-8-generic/build M=/home/sumanta/programs/c_programs/es2_mini_project/cross_compile modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.38-8-generic'
  CC [M]  /home/sumanta/programs/c_programs/es2_mini_project/cross_compile/hello-1.o
In file included from include/linux/prefetch.h:14,
                 from include/linux/list.h:7,
                 from include/linux/module.h:9,
                 from /home/sumanta/programs/c_programs/es2_mini_project/cross_compile/hello-1.c:1:
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/processor.h:98: warning: "__LINUX_ARM_ARCH__" is not defined
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/processor.h:118: warning: "__LINUX_ARM_ARCH__" is not defined
In file included from include/linux/module.h:9,
                 from /home/sumanta/programs/c_programs/es2_mini_project/cross_compile/hello-1.c:1:
include/linux/list.h: In function 'list_del':
include/linux/list.h:107: error: implicit declaration of function '_AC'
include/linux/list.h:107: error: 'UL' undeclared (first use in this function)
include/linux/list.h:107: error: (Each undeclared identifier is reported only once
include/linux/list.h:107: error: for each function it appears in.)
include/linux/list.h: In function 'hlist_del':
include/linux/list.h:602: error: 'UL' undeclared (first use in this function)
In file included from include/linux/irqflags.h:15,
                 from /usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/system.h:61,
                 from /usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/bitops.h:27,
                 from include/linux/bitops.h:22,
                 from include/linux/kernel.h:17,
                 from include/linux/cache.h:4,
                 from include/linux/time.h:7,
                 from include/linux/stat.h:60,
                 from include/linux/module.h:10,
                 from /home/sumanta/programs/c_programs/es2_mini_project/cross_compile/hello-1.c:1:
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/irqflags.h: At top level:
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/irqflags.h:11: warning: "__LINUX_ARM_ARCH__" is not defined
In file included from /usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/bitops.h:27,
                 from include/linux/bitops.h:22,
                 from include/linux/kernel.h:17,
                 from include/linux/cache.h:4,
                 from include/linux/time.h:7,
                 from include/linux/stat.h:60,
                 from include/linux/module.h:10,
                 from /home/sumanta/programs/c_programs/es2_mini_project/cross_compile/hello-1.c:1:
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/system.h:121: warning: "__LINUX_ARM_ARCH__" is not defined
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/system.h:127: warning: "__LINUX_ARM_ARCH__" is not defined
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/system.h:128: warning: "__LINUX_ARM_ARCH__" is not defined
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/system.h:134: warning: "__LINUX_ARM_ARCH__" is not defined
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/system.h:138: warning: "__LINUX_ARM_ARCH__" is not defined
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/system.h: In function '__xchg':
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/system.h:272: warning: "__LINUX_ARM_ARCH__" is not defined
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/system.h:279: warning: "__LINUX_ARM_ARCH__" is not defined
In file included from /usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/bitops.h:27,
                 from include/linux/bitops.h:22,
                 from include/linux/kernel.h:17,
                 from include/linux/cache.h:4,
                 from include/linux/time.h:7,
                 from include/linux/stat.h:60,
                 from include/linux/module.h:10,
                 from /home/sumanta/programs/c_programs/es2_mini_project/cross_compile/hello-1.c:1:
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/system.h: At top level:
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/system.h:349: warning: "__LINUX_ARM_ARCH__" is not defined
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/system.h:352: error: #error "SMP is not supported on this platform"
In file included from include/linux/bitops.h:22,
                 from include/linux/kernel.h:17,
                 from include/linux/cache.h:4,
                 from include/linux/time.h:7,
                 from include/linux/stat.h:60,
                 from include/linux/module.h:10,
                 from /home/sumanta/programs/c_programs/es2_mini_project/cross_compile/hello-1.c:1:
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/bitops.h:237: warning: "__LINUX_ARM_ARCH__" is not defined
In file included from include/linux/swab.h:6,
                 from include/linux/byteorder/little_endian.h:12,
                 from /usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/byteorder.h:21,
                 from include/linux/kernel.h:22,
                 from include/linux/cache.h:4,
                 from include/linux/time.h:7,
                 from include/linux/stat.h:60,
                 from include/linux/module.h:10,
                 from /home/sumanta/programs/c_programs/es2_mini_project/cross_compile/hello-1.c:1:
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/swab.h:25: warning: "__LINUX_ARM_ARCH__" is not defined
In file included from /usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/thread_info.h:16,
                 from include/linux/thread_info.h:56,
                 from include/linux/preempt.h:9,
                 from include/linux/spinlock.h:50,
                 from include/linux/seqlock.h:29,
                 from include/linux/time.h:8,
                 from include/linux/stat.h:60,
                 from include/linux/module.h:10,
                 from /home/sumanta/programs/c_programs/es2_mini_project/cross_compile/hello-1.c:1:
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/fpstate.h:32: warning: "__LINUX_ARM_ARCH__" is not defined
In file included from include/linux/spinlock.h:87,
                 from include/linux/seqlock.h:29,
                 from include/linux/time.h:8,
                 from include/linux/stat.h:60,
                 from include/linux/module.h:10,
                 from /home/sumanta/programs/c_programs/es2_mini_project/cross_compile/hello-1.c:1:
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/spinlock.h:4: warning: "__LINUX_ARM_ARCH__" is not defined
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/spinlock.h:5: error: #error SMP not supported on pre-ARMv6 CPUs
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/spinlock.h: In function 'dsb_sev':
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/spinlock.h:10: warning: "__LINUX_ARM_ARCH__" is not defined
In file included from include/linux/spinlock.h:387,
                 from include/linux/seqlock.h:29,
                 from include/linux/time.h:8,
                 from include/linux/stat.h:60,
                 from include/linux/module.h:10,
                 from /home/sumanta/programs/c_programs/es2_mini_project/cross_compile/hello-1.c:1:
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/atomic.h: At top level:
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/atomic.h:30: warning: "__LINUX_ARM_ARCH__" is not defined
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/atomic.h:153: error: #error SMP not supported on pre-ARMv6 CPUs
In file included from include/linux/time.h:9,
                 from include/linux/stat.h:60,
                 from include/linux/module.h:10,
                 from /home/sumanta/programs/c_programs/es2_mini_project/cross_compile/hello-1.c:1:
include/linux/math64.h: In function 'div_u64_rem':
include/linux/math64.h:51: error: '__LINUX_ARM_ARCH__' undeclared (first use in this function)
In file included from /usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/page.h:26,
                 from include/linux/mmzone.h:20,
                 from include/linux/gfp.h:4,
                 from include/linux/kmod.h:22,
                 from include/linux/module.h:13,
                 from /home/sumanta/programs/c_programs/es2_mini_project/cross_compile/hello-1.c:1:
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/glue.h: At top level:
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/glue.h:119: error: #error Unknown data abort handler type
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/glue.h:160: error: #error Unknown prefetch abort handler type
In file included from include/linux/mmzone.h:20,
                 from include/linux/gfp.h:4,
                 from include/linux/kmod.h:22,
                 from include/linux/module.h:13,
                 from /home/sumanta/programs/c_programs/es2_mini_project/cross_compile/hello-1.c:1:
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/page.h:116: error: #error Unknown user operations model
In file included from /usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/page.h:204,
                 from include/linux/mmzone.h:20,
                 from include/linux/gfp.h:4,
                 from include/linux/kmod.h:22,
                 from include/linux/module.h:13,
                 from /home/sumanta/programs/c_programs/es2_mini_project/cross_compile/hello-1.c:1:
/usr/src/linux-headers-2.6.38-8-generic/arch/arm/include/asm/memory.h:18: fatal error: mach/memory.h: No such file or directory
compilation terminated.
make[2]: *** [/home/sumanta/programs/c_programs/es2_mini_project/cross_compile/hello-1.o] Error 1
make[1]: *** [_module_/home/sumanta/programs/c_programs/es2_mini_project/cross_compile] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.38-8-generic'
make: *** [all] Error 2
  • I think you are mixing your host and target Linux versions. And I have doubts the ARCH and CROSS_COMPILE defines are automatically passed down to the sub-make. Your makefile maybe should look like:

    obj-m +=hello-1.o
    obj-m +=hello-2.o

    all:
        make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C KERNEL M=$(PWD) modules

    clean:
        make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C KERNEL M=$(PWD) clean

    where KERNEL is the path to where you built the target kernel. Using "uname" on will get you the host Linux version. Cross compiling into /lib/modules/2.6.38-8-generic runs the risk of overwriting your host's module libraries. You might want stay away from "/".