insmod error: inserting './hello.ko': -1 Invalid module format"

后端 未结 3 1277
失恋的感觉
失恋的感觉 2020-12-09 19:46

I have just made my first driver module, the hello world module following LDD3. However unfortunately encountered this error:

insmod: error inserting \'./hel         


        
3条回答
  •  Happy的楠姐
    2020-12-09 20:39

    Kernel from which you build your kernel module and to which you are inserting module should be of same version. If you do not want to take care of this thing you can use following Makefile.

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

    Now you can build and try to insert module.

    I suggest you to become root if possible before this line

    $sudo cp /boot/config-2.6.38-8-generic ./.config

    $su
    #cp /boot/config-2.6.38-8-generic ./.config
    #insmod hello_world.ko
    

    Alternatively you can also use following make file

    TARGET  := hello-world
    WARN    := -W -Wall -Wstrict-prototypes -Wmissing-prototypes
    INCLUDE := -isystem /lib/modules/`uname -r`/build/include
    CFLAGS  := -O2 -DMODULE -D__KERNEL__ ${WARN} ${INCLUDE}
    CC      := gcc-3.0
    
    ${TARGET}.o: ${TARGET}.c
    
    .PHONY: clean
    
    clean:
        rm -rf ${TARGET}.o
    

提交回复
热议问题