Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I've been trying to build a basic hello world device driver on my Virtual Box installation of Ubuntu 13.10 for a development board running an ARMv5 processor. I know I need to cross compile the driver and I've set-up my local environment in the following fashion:

1) Clean install of 13.10. 2) sudo apt-get install gcc-arm-linux-gnueabi 3) export PATH=$PATH:/usr/arm-linux-gnueabi/bin 4) Create my hello.c and Makefile

hello.c

#include <linux/module.h>
#include <linux/kernel.h>

int init_module(void)
{
    printk(KERN_INFO "Hello Erich!\n");
    return 0;
}

void cleanup_module(void)
{
    printk(KERN_INFO "Goodbye Erich.\n");
}

Makefile obj-m += hello.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

5) To run this for a cross compile I then do:

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-

This fails with:

make -C /lib/modules/3.11.0-12-generic/build M=/home/erich/dd modules make[1]: Entering directory /usr/src/linux-headers-3.11.0-12-generic' CC [M] /home/erich/dd/hello.o In file included from include/linux/types.h:5:0, from include/linux/list.h:4, from include/linux/module.h:9, from /home/erich/dd/hello.c:1: include/uapi/linux/types.h:4:23: fatal error: asm/types.h: No such file or directory compilation terminated. make[2]: *** [/home/erich/dd/hello.o] Error 1 make[1]: *** [_module_/home/erich/dd] Error 2 make[1]: Leaving directory/usr/src/linux-headers-3.11.0-12-generic' make: * [all] Error 2

6) If I attempt to fix this issue by linking asm-generic to asm in the following fashion: sudo ln -s /usr/src/linux-headers-3.11.0-12-generic/include/uapi/asm-generic /usr/src/linux-headers-3.11.0-12-generic/include/uapi/asm

It then fails in the new different fashion:

make -C /lib/modules/3.11.0-12-generic/build M=/home/erich/dd modules make[1]: Entering directory /usr/src/linux-headers-3.11.0-12-generic' CC [M] /home/erich/dd/hello.o In file included from include/linux/irqflags.h:15:0, from /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/bitops.h:27, from include/linux/bitops.h:22, from include/linux/kernel.h:10, from include/linux/cache.h:4, from include/linux/time.h:4, from include/linux/stat.h:18, from include/linux/module.h:10, from /home/erich/dd/hello.c:1: /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/irqflags.h:21:5: warning: "__LINUX_ARM_ARCH__" is not defined [-Wundef] In file included from /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/bitops.h:124:0, from include/linux/bitops.h:22, from include/linux/kernel.h:10, from include/linux/cache.h:4, from include/linux/time.h:4, from include/linux/stat.h:18, from include/linux/module.h:10, from /home/erich/dd/hello.c:1: include/asm-generic/bitops/non-atomic.h: In function ‘__set_bit’: include/asm-generic/bitops/non-atomic.h:17:23: error: ‘BITS_PER_LONG’ undeclared (first use in this function) include/asm-generic/bitops/non-atomic.h:17:23: note: each undeclared identifier is reported only once for each function it appears in include/asm-generic/bitops/non-atomic.h: In function ‘__clear_bit’: include/asm-generic/bitops/non-atomic.h:25:23: error: ‘BITS_PER_LONG’ undeclared (first use in this function) include/asm-generic/bitops/non-atomic.h: In function ‘__change_bit’: include/asm-generic/bitops/non-atomic.h:42:23: error: ‘BITS_PER_LONG’ undeclared (first use in this function) include/asm-generic/bitops/non-atomic.h: In function ‘__test_and_set_bit’: include/asm-generic/bitops/non-atomic.h:59:23: error: ‘BITS_PER_LONG’ undeclared (first use in this function) include/asm-generic/bitops/non-atomic.h: In function ‘__test_and_clear_bit’: include/asm-generic/bitops/non-atomic.h:78:23: error: ‘BITS_PER_LONG’ undeclared (first use in this function) include/asm-generic/bitops/non-atomic.h: In function ‘__test_and_change_bit’: include/asm-generic/bitops/non-atomic.h:90:23: error: ‘BITS_PER_LONG’ undeclared (first use in this function) include/asm-generic/bitops/non-atomic.h: In function ‘test_bit’: include/asm-generic/bitops/non-atomic.h:105:21: error: ‘BITS_PER_LONG’ undeclared (first use in this function) In file included from include/linux/bitops.h:22:0, from include/linux/kernel.h:10, from include/linux/cache.h:4, from include/linux/time.h:4, from include/linux/stat.h:18, from include/linux/module.h:10, from /home/erich/dd/hello.c:1: /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/bitops.h: At top level: /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/bitops.h:217:5: warning: "__LINUX_ARM_ARCH__" is not defined [-Wundef] In file included from /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/bitops.h:220:0, from include/linux/bitops.h:22, from include/linux/kernel.h:10, from include/linux/cache.h:4, from include/linux/time.h:4, from include/linux/stat.h:18, from include/linux/module.h:10, from /home/erich/dd/hello.c:1: include/asm-generic/bitops/__fls.h: In function ‘__fls’: include/asm-generic/bitops/__fls.h:14:12: error: ‘BITS_PER_LONG’ undeclared (first use in this function) include/asm-generic/bitops/__fls.h:16:5: warning: "BITS_PER_LONG" is not defined [-Wundef] In file included from /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/bitops.h:221:0, from include/linux/bitops.h:22, from include/linux/kernel.h:10, from include/linux/cache.h:4, from include/linux/time.h:4, from include/linux/stat.h:18, from include/linux/module.h:10, from /home/erich/dd/hello.c:1: include/asm-generic/bitops/__ffs.h: In function ‘__ffs’: include/asm-generic/bitops/__ffs.h:16:5: warning: "BITS_PER_LONG" is not defined [-Wundef] In file included from /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/bitops.h:280:0, from include/linux/bitops.h:22, from include/linux/kernel.h:10, from include/linux/cache.h:4, from include/linux/time.h:4, from include/linux/stat.h:18, from include/linux/module.h:10, from /home/erich/dd/hello.c:1: include/asm-generic/bitops/fls64.h: At top level: include/asm-generic/bitops/fls64.h:17:5: warning: "BITS_PER_LONG" is not defined [-Wundef] include/asm-generic/bitops/fls64.h:25:7: warning: "BITS_PER_LONG" is not defined [-Wundef] include/asm-generic/bitops/fls64.h:33:2: error: #error BITS_PER_LONG not 32 or 64 In file included from /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/bitops.h:282:0, from include/linux/bitops.h:22, from include/linux/kernel.h:10, from include/linux/cache.h:4, from include/linux/time.h:4, from include/linux/stat.h:18, from include/linux/module.h:10, from /home/erich/dd/hello.c:1: include/asm-generic/bitops/sched.h: In function ‘sched_find_first_bit’: include/asm-generic/bitops/sched.h:14:5: warning: "BITS_PER_LONG" is not defined [-Wundef] include/asm-generic/bitops/sched.h:18:7: warning: "BITS_PER_LONG" is not defined [-Wundef] include/asm-generic/bitops/sched.h:27:2: error: #error BITS_PER_LONG not defined include/asm-generic/bitops/sched.h:29:1: warning: no return statement in function returning non-void [-Wreturn-type] In file included from /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/swab.h:18:0, from include/uapi/linux/swab.h:6, from include/linux/swab.h:4, from include/uapi/linux/byteorder/little_endian.h:12, from include/linux/byteorder/little_endian.h:4, from /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/uapi/asm/byteorder.h:21, from include/asm-generic/bitops/le.h:5, from /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/bitops.h:308, from include/linux/bitops.h:22, from include/linux/kernel.h:10, from include/linux/cache.h:4, from include/linux/time.h:4, from include/linux/stat.h:18, from include/linux/module.h:10, from /home/erich/dd/hello.c:1: /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/uapi/asm/swab.h: At top level: /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/uapi/asm/swab.h:26:29: warning: "__LINUX_ARM_ARCH__" is not defined [-Wundef] In file included from include/uapi/linux/swab.h:6:0, from include/linux/swab.h:4, from include/uapi/linux/byteorder/little_endian.h:12, from include/linux/byteorder/little_endian.h:4, from /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/uapi/asm/byteorder.h:21, from include/asm-generic/bitops/le.h:5, from /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/bitops.h:308, from include/linux/bitops.h:22, from include/linux/kernel.h:10, from include/linux/cache.h:4, from include/linux/time.h:4, from include/linux/stat.h:18, from include/linux/module.h:10, from /home/erich/dd/hello.c:1: /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/swab.h:20:5: warning: "__LINUX_ARM_ARCH__" is not defined [-Wundef] In file included from include/linux/kernel.h:10:0, from include/linux/cache.h:4, from include/linux/time.h:4, from include/linux/stat.h:18, from include/linux/module.h:10, from /home/erich/dd/hello.c:1: include/linux/bitops.h: In function ‘fls_long’: include/linux/bitops.h:164:2: error: implicit declaration of function ‘fls64’ [-Werror=implicit-function-declaration] include/linux/bitops.h: In function ‘__ffs64’: include/linux/bitops.h:177:5: warning: "BITS_PER_LONG" is not defined [-Wundef] include/linux/bitops.h:180:7: warning: "BITS_PER_LONG" is not defined [-Wundef] include/linux/bitops.h:181:2: error: #error BITS_PER_LONG not 32 or 64 In file included from include/linux/cache.h:4:0, from include/linux/time.h:4, from include/linux/stat.h:18, from include/linux/module.h:10, from /home/erich/dd/hello.c:1: include/linux/kernel.h: At top level: include/linux/kernel.h:58:5: warning: "BITS_PER_LONG" is not defined [-Wundef] In file included from /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/thread_info.h:16:0, from include/linux/thread_info.h:54, from include/linux/preempt.h:9, from include/linux/spinlock.h:50, from include/linux/seqlock.h:29, from include/linux/time.h:5, from include/linux/stat.h:18, from include/linux/module.h:10, from /home/erich/dd/hello.c:1: /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/fpstate.h:32:5: warning: "__LINUX_ARM_ARCH__" is not defined [-Wundef] In file included from /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/domain.h:14:0, from /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/thread_info.h:28, from include/linux/thread_info.h:54, from include/linux/preempt.h:9, from include/linux/spinlock.h:50, from include/linux/seqlock.h:29, from include/linux/time.h:5, from include/linux/stat.h:18, from include/linux/module.h:10, from /home/erich/dd/hello.c:1: /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/barrier.h:9:5: warning: "__LINUX_ARM_ARCH__" is not defined [-Wundef] /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/barrier.h:10:3: warning: "__LINUX_ARM_ARCH__" is not defined [-Wundef] /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/barrier.h:16:5: warning: "__LINUX_ARM_ARCH__" is not defined [-Wundef] /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/barrier.h:20:35: warning: "__LINUX_ARM_ARCH__" is not defined [-Wundef] In file included from include/linux/spinlock.h:87:0, from include/linux/seqlock.h:29, from include/linux/time.h:5, from include/linux/stat.h:18, from include/linux/module.h:10, from /home/erich/dd/hello.c:1: /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/spinlock.h:4:5: warning: "__LINUX_ARM_ARCH__" is not defined [-Wundef] /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/spinlock.h:5:2: error: #error SMP not supported on pre-ARMv6 CPUs In file included from /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/spinlock.h:8:0, from include/linux/spinlock.h:87, from include/linux/seqlock.h:29, from include/linux/time.h:5, from include/linux/stat.h:18, from include/linux/module.h:10, from /home/erich/dd/hello.c:1: /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/processor.h:78:5: warning: "__LINUX_ARM_ARCH__" is not defined [-Wundef] /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/processor.h:93:5: warning: "__LINUX_ARM_ARCH__" is not defined [-Wundef] In file included from include/linux/spinlock.h:87:0, from include/linux/seqlock.h:29, from include/linux/time.h:5, from include/linux/stat.h:18, from include/linux/module.h:10, from /home/erich/dd/hello.c:1: /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/spinlock.h: In function ‘dsb_sev’: /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/spinlock.h:47:5: warning: "__LINUX_ARM_ARCH__" is not defined [-Wundef] /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/spinlock.h: In function ‘arch_spin_lock’: /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/spinlock.h:91:3: error: implicit declaration of function ‘wfe’ [-Werror=implicit-function-declaration] In file included from /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/atomic.h:18:0, from include/linux/atomic.h:4, from include/linux/spinlock.h:392, from include/linux/seqlock.h:29, from include/linux/time.h:5, from include/linux/stat.h:18, from include/linux/module.h:10, from /home/erich/dd/hello.c:1: /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/cmpxchg.h: In function ‘__xchg’: /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/cmpxchg.h:33:5: warning: "__LINUX_ARM_ARCH__" is not defined [-Wundef] /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/cmpxchg.h:40:5: warning: "__LINUX_ARM_ARCH__" is not defined [-Wundef] In file included from /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/atomic.h:18:0, from include/linux/atomic.h:4, from include/linux/spinlock.h:392, from include/linux/seqlock.h:29, from include/linux/time.h:5, from include/linux/stat.h:18, from include/linux/module.h:10, from /home/erich/dd/hello.c:1: /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/cmpxchg.h: At top level: /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/cmpxchg.h:108:5: warning: "__LINUX_ARM_ARCH__" is not defined [-Wundef] /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/cmpxchg.h:112:2: error: #error "SMP is not supported on this platform" In file included from include/linux/atomic.h:4:0, from include/linux/spinlock.h:392, from include/linux/seqlock.h:29, from include/linux/time.h:5, from include/linux/stat.h:18, from include/linux/module.h:10, from /home/erich/dd/hello.c:1: /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/atomic.h:32:5: warning: "__LINUX_ARM_ARCH__" is not defined [-Wundef] /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/atomic.h:155:2: error: #error SMP not supported on pre-ARMv6 CPUs /usr/src/linux-headers-3.11.0-12-generic/arch/arm/include/asm/atomic.h:242:3: error: conflicting types for ‘atomic64_t’ In file included from include/linux/list.h:4:0, from include/linux/module.h:9, from /home/erich/dd/hello.c:1: include/linux/types.h:182:3: note: previous declaration of ‘atomic64_t’ was here In file included from include/linux/atomic.h:127:0, from include/linux/spinlock.h:392, from include/linux/seqlock.h:29, from include/linux/time.h:5, from include/linux/stat.h:18, from include/linux/module.h:10, from /home/erich/dd/hello.c:1: include/asm-generic/atomic-long.h:21:5: warning: "BITS_PER_LONG" is not defined [-Wundef] In file included from include/linux/time.h:6:0, from include/linux/stat.h:18, from include/linux/module.h:10, from /home/erich/dd/hello.c:1: include/linux/math64.h:7:5: warning: "BITS_PER_LONG" is not defined [-Wundef] include/linux/math64.h:49:7: warning: "BITS_PER_LONG" is not defined [-Wundef] include/linux/math64.h: In function ‘div_u64’: include/linux/math64.h:87:2: error: implicit declaration of function ‘div_u64_rem’ [-Werror=implicit-function-declaration] include/linux/math64.h: In function ‘div_s64’: include/linux/math64.h:98:2: error: implicit declaration of function ‘div_s64_rem’ [-Werror=implicit-function-declaration] In file included from include/linux/stat.h:18:0, from include/linux/module.h:10, from /home/erich/dd/hello.c:1: include/linux/time.h: At top level: include/linux/time.h:88:6: warning: "BITS_PER_LONG" is not defined [-Wundef] In file included from include/linux/mmzone.h:9:0, from include/linux/gfp.h:4, from include/linux/kmod.h:22, from include/linux/module.h:13, from /home/erich/dd/hello.c:1: include/linux/wait.h:8:25: fatal error: asm/current.h: No such file or directory cc1: some warnings being treated as errors compilation terminated. make[2]: *** [/home/erich/dd/hello.o] Error 1 make[1]: *** [_module_/home/erich/dd] Error 2 make[1]: Leaving directory/usr/src/linux-headers-3.11.0-12-generic' make: * [all] Error 2

I thought this would be rather straight forward with the cross compiler package being easy to pick up, but it doesn't work at all. Please help.

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.