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.

Error in building driver for am-1808

Other Parts Discussed in Thread: OMAPL138, AM1808

HI !

I am trying to make a simple "helloworld" driver for am-1808, the am-1808 (evm zoom kit) which i am having has kernel 2.6.33.rc-4, here are the steps which i performed:

1. download the DaVinci-PSP-SDK-03.20.00.13 from here: (which contains the kernel version 2.6.33.rc-4), [path of kernel is /home/user/Desktop/linux-03.20.00.13/]

2. Installed CodeSourcery, [installation path : /home/user/CodeSourcery]

3. Compiled the kernel by following commands:

export CROSS_COMPILE=/home/user/CodeSourcery/Sourcery_G++_Lite/bin/:$CROSS_COMPILE

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

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

[Kernel compiles successfully , zimage + uimage are created as a result of compilation ]

4. Compile the driver, which results in error:

hello.c file contains :

/*                                                     
 * $Id: hello.c,v 1.5 2004/10/26 03:32:21 corbet Exp $
 */                                                    
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void)
{
    printk(KERN_ALERT "Hello, world\n");
    return 0;
}

static void hello_exit(void)
{
    printk(KERN_ALERT "Goodbye, cruel world\n");
}

module_init(hello_init);
module_exit(hello_exit);

Makefile contains this:

# If KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
ifneq ($(KERNELRELEASE),)
obj-m := hello.o
# Otherwise we were called directly from the command
# line; invoke the kernel build system.
else
KERNELDIR ?= /home/user/Desktop/linux-03.20.00.13/
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif

Compiled the module using following command;

make -C /home/user/Desktop/linux-03.20.00.13/ M=`pwd` modules

After this i got these errors:

make: Entering directory `/home/user/Desktop/linux-03.20.00.13'
  CC [M]  /home/user/Desktop/drivers/hello.o
In file included from include/linux/prefetch.h:14,
                 from include/linux/list.h:6,
                 from include/linux/module.h:9,
                 from /home/user/Desktop/drivers/hello.c:5:
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/processor.h:117: error: 'CONFIG_X86_L1_CACHE_SHIFT' undeclared here (not in a function)
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/processor.h:117: error: requested alignment is not a constant
In file included from include/linux/prefetch.h:14,
                 from include/linux/list.h:6,
                 from include/linux/module.h:9,
                 from /home/user/Desktop/drivers/hello.c:5:
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/processor.h:163:1: warning: "cache_line_size" redefined
In file included from /home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/processor.h:28,
                 from include/linux/prefetch.h:14,
                 from include/linux/list.h:6,
                 from include/linux/module.h:9,
                 from /home/user/Desktop/drivers/hello.c:5:
include/linux/cache.h:64:1: warning: this is the location of the previous definition
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/processor.h:243: error: requested alignment is not a constant
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/processor.h:274: error: requested alignment is not a constant
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/processor.h: In function 'native_get_debugreg':
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/processor.h:504: error: invalid application of 'sizeof' to incomplete type 'struct bug_entry'
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/processor.h: In function 'native_set_debugreg':
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/processor.h:531: error: invalid application of 'sizeof' to incomplete type 'struct bug_entry'
In file included from /home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic.h:4,
                 from /home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/thread_info.h:24,
                 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/user/Desktop/drivers/hello.c:5:
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h: At top level:
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:201: warning: type defaults to 'int' in declaration of 'atomic64_t'
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:201: error: expected ';', ',' or ')' before '*' token
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:213: error: expected ')' before '*' token
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:225: error: expected declaration specifiers or '...' before 'atomic64_t'
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h: In function 'atomic64_add':
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:228: error: 'v' undeclared (first use in this function)
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:228: error: (Each undeclared identifier is reported only once
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:228: error: for each function it appears in.)
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:227: error: invalid lvalue in asm output 0
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:227: error: memory input 2 is not directly addressable
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h: At top level:
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:239: error: expected declaration specifiers or '...' before 'atomic64_t'
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h: In function 'atomic64_sub':
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:242: error: 'v' undeclared (first use in this function)
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:241: error: invalid lvalue in asm output 0
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:241: error: memory input 2 is not directly addressable
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h: At top level:
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:255: error: expected declaration specifiers or '...' before 'atomic64_t'
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h: In function 'atomic64_sub_and_test':
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:260: error: 'v' undeclared (first use in this function)
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:259: error: invalid lvalue in asm output 0
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:259: error: memory input 3 is not directly addressable
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h: At top level:
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:271: error: expected ')' before '*' token
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:284: error: expected ')' before '*' token
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:299: error: expected ')' before '*' token
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:317: error: expected ')' before '*' token
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:336: error: expected declaration specifiers or '...' before 'atomic64_t'
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h: In function 'atomic64_add_negative':
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:341: error: 'v' undeclared (first use in this function)
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:340: error: invalid lvalue in asm output 0
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:340: error: memory input 3 is not directly addressable
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h: At top level:
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:353: error: expected declaration specifiers or '...' before 'atomic64_t'
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h: In function 'atomic64_add_return':
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:357: error: 'v' undeclared (first use in this function)
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:356: error: invalid lvalue in asm output 1
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:356: error: memory input 3 is not directly addressable
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h: At top level:
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:362: error: expected declaration specifiers or '...' before 'atomic64_t'
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h: In function 'atomic64_sub_return':
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:364: error: 'v' undeclared (first use in this function)
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:364: error: too many arguments to function 'atomic64_add_return'
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h: At top level:
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:370: error: expected ')' before '*' token
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:375: error: expected ')' before '*' token
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/atomic_64.h:425: error: expected ')' before '*' token
In file included from include/linux/mmzone.h:16,
                 from include/linux/gfp.h:4,
                 from include/linux/kmod.h:22,
                 from include/linux/module.h:13,
                 from /home/user/Desktop/drivers/hello.c:5:
include/linux/nodemask.h: In function '__first_node':
include/linux/nodemask.h:239: error: implicit declaration of function 'find_first_bit'
include/linux/nodemask.h: In function '__next_node':
include/linux/nodemask.h:245: error: implicit declaration of function 'find_next_bit'
include/linux/nodemask.h: In function '__first_unset_node':
include/linux/nodemask.h:268: error: implicit declaration of function 'find_first_zero_bit'
In file included from include/linux/elf.h:7,
                 from include/linux/module.h:14,
                 from /home/user/Desktop/drivers/hello.c:5:
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/elf.h: In function 'elf_common_init':
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/elf.h:167: error: 'struct thread_struct' has no member named 'fs'
In file included from include/linux/module.h:21,
                 from /home/user/Desktop/drivers/hello.c:5:
/home/user/Desktop/linux-03.20.00.13/arch/x86/include/asm/module.h:59:2: error: #error unknown processor family
make[1]: *** [/home/user/Desktop/drivers/hello.o] Error 1
make: *** [_module_/home/user/Desktop/drivers] Error 2
make: Leaving directory `/home/user/Desktop/linux-03.20.00.13'

Can anyone tell, how to resolve these errors:

regards

usama

  • I think you need to specify the ARCH and CROSS_COMPILE on the module make just like your kernel make. I usually just use the module makefile to invoke the make on the kernel directory. Add the ARCH and CROSS_COMPILE variables to the module makefile. Something like this:

    # If KERNELRELEASE is defined, we've been invoked from the
    # kernel build system and can use its language.
    ifneq ($(KERNELRELEASE),)
    obj-m := hello.o
    # Otherwise we were called directly from the command
    # line; invoke the kernel build system.
    else
    ARCH=arm
    CROSS_COMPILE=/home/user/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-
    KERNELDIR := /home/user/Desktop/linux-03.20.00.13/
    PWD := $(shell pwd)
    default:
    $(MAKE) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KERNELDIR) M=$(PWD) modules
    endif

    You could shorten CROSS_COMPILE to arm-none-linux-gnueabi- if your cross compiler is in your PATH env variable. Compile your module with just 'make' on the command line. That will do the long kernel make invocation for you on the first pass and hello.ko on the second pass.

  • Hi Norman,

    Thanks for your reply, i used your Makefile and now When i type "make"
    in the terminal, i got this error :
    "make: Nothing to be done for `default'."

    and if i type this :"make -C /home/user/Desktop/linux-03.20.00.13/ M=`pwd` modules ", i got the same previous error.

    These errors show that there are errors in the kernel source file, but
    this is not possible because kernel compiles successfully , this is really
    strange, any clue what could be the issue ?

    can it be related to ubuntu version which i am using to compile the kernel ?

    And can u provide links of official ti tutorials which explain making kernel modules for am1808 or any other board ?

    And one more thing, to build a module is compiling a kernel necessary ?

    (i know a module can be loaded only to a compiled kernel, but to generate .ko file is compiling kernel necessary or not ? )

  • I was using your original post as a basis for my makefile example. I did not notice that make line lost it's indent. All rules have to be indented.

    # If KERNELRELEASE is defined, we've been invoked from the
    # kernel build system and can use its language.
    ifneq ($(KERNELRELEASE),)
    obj-m := hello.o
    # Otherwise we were called directly from the command
    # line; invoke the kernel build system.
    else
    .PHONY:    default
    ARCH=arm
    CROSS_COMPILE=/home/user/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-
    KERNELDIR := /home/user/Desktop/linux-03.20.00.13/
    PWD := $(shell pwd)
    default:
        $(MAKE) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KERNELDIR) M=$(PWD) modules
    endif

    Note the tab indent on the $(MAKE) line. I added a .PHONY directive just in case your version of make is extra picky.

    There's a lot a info around. Check TI's http://processor.wiki.ti.com or the book http://lwn.net/Kernel/LDD3/

    I've seen other say that  you should be able to build modules without compiling the kernel. I not quite sure how that is quite possible. The module needs to know what exported symbols to "link" to.

  • Adding the ".phony" in the Makefile doesn't help, i am getting the same error.

    But besides the Makefile do u have any idea why are we getting the remaining errors i.e errors in source file of kernel ?

  • In your first post, the errors from the command line:

    make -C /home/user/Desktop/linux-03.20.00.13/ M=`pwd` modules

    are probably because ARCH and CROSS_COMPILE are not defined. The errors hint at that the host compiler, probably Intel X86, is being used. The CROSS_COMPILE and ARCH can be obtained from the shell environment. Your export line

    export CROSS_COMPILE=/home/user/CodeSourcery/Sourcery_G++_Lite/bin/:$CROSS_COMPILE

    does not make sense to me unless it is some sort of makefile magic. It should be

    export CROSS_COMPILE=/home/user/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-

    Your kernel compile uses the command line "CROSS_COMPILE=arm-none-linux-gnueabi-" instead the shell environment's CROSS_COMPILE. Since no absolute path is specified, "/home/user/CodeSourcery/Sourcery_G++_Lite/bin" must be in your $PATH. I don't know why your makefile does not work. The indent on the $(MAKE) line should have solved the make error. You should be able try it directly on the command line:

    make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi-  -C /home/user/Desktop/linux-03.20.00.13  M=`pwd` modules

    Assumes that the compiler is pathed in.

  • The issue was with the CROSS_COMPILE

    After this,

    export CROSS_COMPILE=/home/user/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-

    i am able to make "hello.ko" file, and also load module in the kernel.

    Thanks alot for your support .