Error compiling very simple Kernel module

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error compiling very simple Kernel module

15,045 Views
Matteo
Contributor II

Hi,

I'm trying to compile a kernel test module by means of the below line in i.mx28EVK board.

make CROSS_COMPILE=/opt/freescale/usr/local/gcc-4.4.4-glibc-2.11.1-multilib-1.0/arm-fsl-linux-gnueabi/bin/arm-fsl-linux-gnueabi- -C /home/mydir/imx28/ltib/rpm/BUILD/linux-2.6.35.3 ARCH=arm M=/home/mydir/Project/test modules

The code of test module is listed below.......

#include <linux/module.h>

#include <linux/init.h>
/* public domain */
MODULE_LICENSE("GPL and additional rights");

static int test_init(void)
{
return 0;
}
static void test_exit(void)
{
}
module_init(test_init);
module_exit(test_exit);

.....and the result of the cross-compilation is lised below:

CC /home/mydir/Project/test/test.mod.o
/home/mydir/Project/test/test.mod.c:8: error: variable '__this_module' has initializer but incomplete type
/home/mydir/Project/test/test.mod.c:9: error: unknown field 'name' specified in initializer
/home/mydir/Project/test/test.mod.c:9: warning: excess elements in struct initializer
/home/mydir/Project/test/test.mod.c:9: warning: (near initialization for '__this_module')
/home/mydir/Project/test/test.mod.c:10: error: unknown field 'init' specified in initializer
/home/mydir/Project/test/test.mod.c:10: warning: excess elements in struct initializer
/home/mydir/Project/test/test.mod.c:10: warning: (near initialization for '__this_module')
/home/mydir/Project/test/test.mod.c:14: error: unknown field 'arch' specified in initializer
/home/mydir/Project/test/test.mod.c:14: error: 'MODULE_ARCH_INIT' undeclared here (not in a function)
/home/mydir/Project/test/test.mod.c:14: warning: excess elements in struct initializer
/home/mydir/Project/test/test.mod.c:14: warning: (near initialization for '__this_module')
make[1]: *** [/home/mydir/Project//test/test.mod.o] Error 1

Have you any suggestion??

Thank you very much!!

Tags (2)
0 Kudos
Reply
12 Replies

4,306 Views
yanhongfeiyan
Contributor I

Hello Matteo,

    I met the same problem,too!

     when I typed "insmod bq27501.ko",

     the result is:

     insmod: can't insert 'bq27501.ko': kernel does not support requested operation

     can you tell he how did you solve this problem ffinally?

thanks!!

0 Kudos
Reply

4,306 Views
Matteo
Contributor II

Hi,

the insmod problem is changed. Now when I type the command

insmod test.ko

the result is:

insmod: can't insert 'test.ko': invalid module format

Do you have any suggestion to solve my new problem?

Thanks to all!!

0 Kudos
Reply

4,306 Views
ecm_temp
Contributor I

..

0 Kudos
Reply

4,306 Views
yanhongfeiyan
Contributor I

Hello Matteo,

     I met the same problem,too!

     when I typed "insmod bq27501.ko",

     the result is:

     insmod: can't insert 'bq27501.ko': kernel does not support requested operation

     can you tell he how did you solve this problem ffinally?

thanks!!

0 Kudos
Reply

4,306 Views
Matteo
Contributor II

Hello Brilliantov,

yes, I rebuilt and update linux kernel.

0 Kudos
Reply

4,306 Views
BrilliantovKiri
Senior Contributor I
Hello, Matteo! You rebuild and update linux after change config?
0 Kudos
Reply

4,306 Views
Matteo
Contributor II

Hi.

I have solved my problem by following the suggestions of Alexander, whom I thank. I have set CONFIG_MODULES to y and I'm able to compile modules. Now I'm trying to run modules in the imx28EVK board through the insmod commad, but the result is this:

root@freescale /$ insmod test.ko
insmod: can't insert 'test.ko': kernel does not support requested operation

test.ko is present in the rootfs and it's executable. Do you have any suggestion to solve my new problem?

Thanks to all!!

0 Kudos
Reply

4,306 Views
BrilliantovKiri
Senior Contributor I

Hello, Alexander!

I use next Makefile:

OV2715 := ov2715

obj-m += $(OV2715).o

all:
        $(MAKE) --directory=$(LINUX_DIR) M=$(shell pwd) \
                ARCH=arm CROSS_COMPILE=$(CROSS) modules

clean:
        $(RM) --recursive .tmp_versions *.o Module.symvers *.mod.c .*.cmd \
                modules.order

cleanall: clean
        $(RM) *.ko

.PHONY: clean cleanall

0 Kudos
Reply

4,306 Views
Sasamy
Contributor IV

obj-m := prova.o

The kernel includes support modules? Check

$ grep "CONFIG_MODULES" /home/mydir/imx28/ltib/rpm/BUILD/linux-2.6.35.3/.config

CONFIG_MODULES=y

0 Kudos
Reply

4,306 Views
YS
Contributor IV

This is Makefile I've tested.

obj-m:=$(MODULES)
CROSS_COMPILE=arm-linux-
ARCH=arm

MAKEARCH=$(MAKE) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE)
all:
        $(MAKEARCH) -C $(KERNEL_SRC) SUBDIRS=$(BUILD_DIR) modules

0 Kudos
Reply

4,306 Views
Matteo
Contributor II

Hi and thanks for your reply.

I try to delete the header file module.h from directory /ltib/rpm/BUILD/linux/include and cross compile again. The compiler reports below error:

error: linux/modules.h: No such file or directory

I think that I include the proper file from linux kernel. It is possible that I wrong the make instruction or have a wrong Makefile? My Makefile is this:

obj-m := prova.o

When I installed LTIB I followed the freescale user guide and I'm able of build linux kernel and launch it in the i.mx28EVK.

0 Kudos
Reply

4,306 Views
YS
Contributor IV

I've tested exact same source code on my iMX28 environment and no trouble to build test.ko.

It seems like you failed to include proper header files (linux/module.h).

export KBUILD_VERBOSE=1 then make may help; it will dump full command line options of gcc. Check if correct Kernel path is specified in -I option.

0 Kudos
Reply