ubuntu下hello world kernel Module:MODPOST 0 modules


Hello World Kernel Module: MODPOST 0 modules

[root@localhost]~/kernel-stu/hello-1# make              
make -C /lib/modules/2.6.23.1-42.fc8/build M=/root/kernel-stu/hello-1 modules
make[1]: Entering directory `/usr/src/kernels/2.6.23.1-42.fc8-i686'
Building modules, stage 2.
MODPOST 0 modules
make[1]: Leaving directory `/usr/src/kernels/2.6.23.1-42.fc8-i686'

Solution: review the Makefile of the source code, any of the following can get this error:
First:
[root@localhost]~/kernel-stu/hello-1# cat Makefile 
bj-m += hello-1.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
Second:
[root@localhost]~/kernel-stu/hello-1# cat Makefile 
obj-m += hello-1.c
all:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

The right content of Makefile is:
[root@localhost]~/kernel-stu/hello-1# cat Makefile 
obj-m += hello-1.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

The content of hello-1.c:
[root@localhost]~/kernel-stu/hello-1# cat hello-1.c 

#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");
      return 0;
      }

module_init(hello_init);
module_exit(hello_exit);

Make:

[root@localhost]~/kernel-stu/hello-1# make
make -C /lib/modules/2.6.23.1-42.fc8/build M=/root/kernel-stu/hello-1 modules
make[1]: Entering directory `/usr/src/kernels/2.6.23.1-42.fc8-i686'
CC [M] /root/kernel-stu/hello-1/hello-1.o
/root/kernel-stu/hello-1/hello-1.c: In function ‘hello_exit’:
/root/kernel-stu/hello-1/hello-1.c:13: warning: ‘return’ with a value, in function returning void
Building modules, stage 2.
MODPOST 1 modules
CC      /root/kernel-stu/hello-1/hello-1.mod.o
LD [M] /root/kernel-stu/hello-1/hello-1.ko
make[1]: Leaving directory `/usr/src/kernels/2.6.23.1-42.fc8-i686'

-------------------------------------------------------------
the kernel build system (kbuild) allows to compile modules whose sources
live outside the kernel source tree by setting SUBDIRS as follows (from
the module sources's directory):

$ make -C /lib/modules/$(uname -r)/build modules SUBDIRS=$(pwd)

people use this mechanism to compile kernel modules that are missing in
their kernel sources, or have been updated/fixed in the meantime.

Currently there are a number of deficiencies for building such modules:

(1) symbol versioning (MODVERSIONS) is not properly supported, and

(2) only the `modules' make target is supported.

Problem (1) did not exist in the 2.4 kernel series. The current
situation has lead authors of several external modules to implement some
of the kbuild functionality in their own makefiles, which can only lead
to problems later on.

During the kernel compile, a list of all files that export symbols is
created in .tmp_versions/ of the kernel source tree. After everything is
compiled, the module versions of all these object files are resolved
with modpost. When an external module is compiled, it ends up being the
only file in .tmp_versions/, and so symbols in other modules would not
be found.

An additional problem is that resolving symbol versions requires all
module files plus vmlinux to be in the kernel source tree, so modules
cannot be build against a clean kernel source tree. Reference :
lwn.net/Articles/69148/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Linux设备驱动程序学习(0)-Hello, world!模块 Linux设备驱动程序学习(0) -Hello, world!模块 一个学习Linux设备驱动程序都会碰到的第一个例程: #include #include MODULE_LICENSE("Dual BSD/GPL"); static int hello_init(void) { printk(KERN_ALERT "Hello, Tekkaman Ninja !\n"); return 0; } static void hello_exit(void) { printk(KERN_ALERT "Goodbye, Tekkaman Ninja !\n Love Linux !Love ARM ! Love KeKe !\n"); } module_init(hello_init); module_exit(hello_exit); 我将其复制到我的工作目录,并编写了一个简单的Makefile文件: KERNELDIR = /home/tekkaman/working/SBC2440/linux-2.6.22.2 # The current directory is passed to sub-makes as argument PWD := $(shell pwd) INSTALLDIR = /home/tekkaman/working/rootfs/lib/modules CROSS_COMPILE =/home/tekkaman/working/crosstool-gcc410-k26222/gcc-4.1.0-glibc-2.3.2/arm-9tdmi-linux-gnu/bin/arm-9tdmi-linux-gnu- CC = $(CROSS_COMPILE)gcc obj-m := hello.o modules: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules modules_install: cp hello.ko $(INSTALLDIR) clean: rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions .PHONY: modules modules_install clean 说实话,以上是我参考了《Linux设备驱动程序(第3版)》的Makefile源码修改得来的。我对Makefile不是很了解,是该好好学习学习了! 然后就是make modules 、 make modules_install 。 [root@Tekkaman-Ninja Helloworld]# make modules make -C /home/tekkaman/working/SBC2440/linux-2.6.22.2 M=/home/tekkaman/working/Linuxdriver/Helloworld modules make[1]: Entering directory `/home/tekkaman/working/SBC2440/linux-2.6.22.2' CC [M] /home/tekkaman/working/Linuxdriver/Helloworld/hello.o Building modules, stage 2. MODPOST 1 modules CC /home/tekkaman/working/Linuxdriver/Helloworld/hello.mod.o LD [M] /home/tekkaman/working/Linuxdriver/Helloworld/hello.ko make[1]: Leaving directory `/home/tekkaman/working/SBC2440/linux-2.6.22.2' [root@Tekkaman-Ninja Helloworld]# make modules_install cp hello.ko /home/tekkaman/working/rootfs/lib/modules [root@Tekkaman-Ninja Helloworld]# 在我的开发板上的操作: [Tekkaman2440@SBC2440V4]#cd /lib/modules/ [Tekkaman2440@SBC2440V4]#ls cs89x0.ko hello.

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值