insmod: init_module 'hello.ko' failed (Exec format error)

在经过重新编译的goldfish内核上,已经运行了安卓模拟器,正在动态添加自己编译的内核。

一开始的时候我从网上找了个hello.c文件,按照他的方式写了Makefile文件,但是当运行命令insmod的时候,会报错:

insmod: init_module 'hello.ko' failed (Exec format error)

期间,查了好多资料依然没有解决,然后又重新按照这篇博客的方式试了一下,竟然成功了,连接地址:http://blog.csdn.net/yf210yf/article/details/9901375

下面我把他的Makefie文件贴出来,hello.c文件没有问题,问题就出在Makefile上,按照他的方式写Makefile,便可以动态插入自己编译的内核了。下面贴代码:

    obj-m := hello-yf.o        
    hello-yf-objs := hello.o       
            
    KID :=~/android-kernel/goldfish  
    PWD := $(shell pwd)  
    ARCH=arm    
    CROSS_COMPILE=arm-eabi-  
    CC=$(CROSS_COMPILE)gcc  
    LD=$(CROSS_COMPILE)ld     
            
    all:  
    make -C $(KID) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) M=${PWD} modules  
            
    clean:  
    rm -rf *.o .cmd *.ko *.mod.c .tmp_versions
但是,我现在不知道为什么他这样写是正确的,我在研究研究。等把原理弄清楚了,在更新这篇博客,不过这个问题已经解决了。

我大概明白是为什么了,大家看这个代码:

   all:  
    make -C $(KID) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) M=${PWD} modules  
           
我觉得这段代码是解决这个问题的关键,首先通过make -C $(KID),将当前的goldfish内核源码的本地路径指定为编译环境,然后分别给ARCH  和交叉编译的环境变量分别赋值,这样的话就不会在出现上面的问题了。如果大家想要自己编译自己的内核按照,这种方式去写makefile文件的话,应该是没有问题的。

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

在更新一下,“M=”选项的作用是,当用户需要以某个内核为基础编译一个外部模块的话,需要在make modules 命令中加入“M=dir”,程序会自动到你所指定的dir目录中查找模块源码,将其编译,生成KO文件。这样一来生成的ko文件才能动态插入到内核中。

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
This bundle contains a modified CP210x driver for the 4.10.0 kernel (Ubuntu 17.04). It contains: - Support for the CP2102N NOTE: This driver is an example of how to perform GPIO operations within the CP210x driver since the driver on kernel.org does not support GPIO at this time. This driver has only been written and tested on the Linux 3.13.0 kernel on Ubuntu 14.04. This driver is a modified version of the existing driver in the Linux 3.13.0 kernel, which is maintained at kernel.org. It is recommened to use the driver there that matches your specific kernel version: www.kernel.org Build instrutions: Ubuntu: 1. make ( your cp210x driver ) 2. cp cp210x.ko to /lib/modules//kernel/drivers/usb/serial 3. insmod /lib/modules/<kernel-version/kernel/drivers/usb/serial/usbserial.ko 4. insmod cp210x.ko RedHat: 1. yum update kernel* //need to update the kernel first otherwise your header won't match 2. yum install kernel-devel kernel-headers //get the devel and header packages. 3. reboot //your build link should be fixed after your system come back 4. make ( your cp210x driver ) // should be able to build successfully at this point 5. cp cp210x.ko to /lib/modules//kernel/drivers/usb/serial 6a. insmod /lib/modules/<kernel-version/kernel/drivers/usb/serial/usbserial.ko 6. insmod cp210x.ko 7. sudo chmod 666 /dev/ttyUSB0 8. sudo chmod 666 /dev/ttyUSB1 GPIO example: This shows how to use the two IOCTLs to set GPIO state. Build instructions: 1. g++ cp210x_gpio_example.c -o cp210x_gpio_example 2. ./cp210x_gpio_example

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值