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.

how to insmod a simple module



Hi guys,

I'm writting a simple hello driver from my laptop(ubuntu). I had write a simple makefile to compile the hello.c and i copy the hello.ko to dm816x-evm at directory:/home/root/hello.ko.

When i type insmod command.It will appear this error.Do you all have any idea regards to this error?Do i need to do any kernel compilation/configuration?Do you all have simple tutorial regarding how to write a simple driver and implement in dm816x-evm.Thank you.

root@dm816x-evm:~# insmod hello.ko                                             
insmod: error inserting 'hello.ko': -1 Invalid module forma
t

This is my makefile script

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

This is my hello.c
/* 
 *  hello-3.c - Illustrating the __init, __initdata and __exit macros.
 */
#include <linux/module.h>    /* Needed by all modules */
#include <linux/kernel.h>    /* Needed for KERN_INFO */
#include <linux/init.h>        /* Needed for the macros */

static int hello3_data __initdata = 3;

static int __init hello_3_init(void)
{
    printk(KERN_INFO "Hello, world %d\n", hello3_data);
    return 0;
}

static void __exit hello_3_exit(void)
{
    printk(KERN_INFO "Goodbye, world 3\n");
}

module_init(hello_3_init);
module_exit(hello_3_exit);
  • Hi,

     

      I think the module(hello.ko) you made is for laptop Linux, not the board.

      You need the cross compile tools for arm when you make it for the board.

     

      I think your Makefile should like this:

    -----------------------------------------------------------------------------------------------------

    include $(EZSDK)/Rules.make

     

    obj-m := hello.o

    PWD := $(shell pwd)

     

    modules:

    $(MAKE) -C $(LINUXKERNEL_INSTALL_DIR) ARCH=arm CROSS_COMPILE=$(CSTOOL_PREFIX) M=$(PWD) modules

     

    clean:

    rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions

    --------------------------------------------------------------------------------------------------------

    Good luck.

     

    Regards,

    lei

  • Hi Lei,

    Thanks for your help.It does help me to solve the problem.

     

    Regards,

    Chei Siang