如何在kernel模块中使用已经编译好的obj文件
2012-01-18 17:50
525 查看
这也是一时心血来潮,觉得好玩。 在Document/kbuild/modules.txt中看到这么一段
--- 3.3 Binary Blobs
Some external modules need to include an object file as a blob.
kbuild has support for this, but requires the blob file to be
named <filename>_shipped. When the kbuild rules kick in, a copy
of <filename>_shipped is created with _shipped stripped off,
giving us <filename>. This shortened filename can be used in
the assignment to the module.
Throughout this section, 8123_bin.o_shipped has been used to
build the kernel module 8123.ko; it has been included as
8123_bin.o.
8123-y := 8123_if.o 8123_pci.o 8123_bin.o
Although there is no distinction between the ordinary source
files and the binary file, kbuild will pick up different rules
when creating the object file for the module.
想着好玩,就自己试了一下,开始不成功,后来在高手的帮助下终于成功了。
1。 创建自己的obj文件
我最开始使用 gcc -c ex_obj.c -o ex_obj.o_shipped 来做的,结果链接后不能正常工作。
原来是一定要放在编译kernel的环境中编译这个obj。网上高手说了 要这么写
ifneq ($(KERNELRELEASE),)
obj-y := xxxx.o #your obj files goes here. 关键在这里,用obj-y 来指定要编译的,然后这个过程就在编译的时候停了,不会继续链接。
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD)
endif
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
depend .depend dep:
$(CC) $(CFLAGS) -M *.c > .depend
ifeq (.depend,$(wildcard .depend))
include .depend
endif
编译成功后,将这个拷贝到需要链接的模块目录。
记住要添加_shipped后缀
2。 然后在需要这个obj的模块中添加
scull-y := main.o pipe.o access.o ex_obj.o
然后在源代码中调用相应的函数,ok,可以了。
不过貌似没有啥实际用处。 :)
--- 3.3 Binary Blobs
Some external modules need to include an object file as a blob.
kbuild has support for this, but requires the blob file to be
named <filename>_shipped. When the kbuild rules kick in, a copy
of <filename>_shipped is created with _shipped stripped off,
giving us <filename>. This shortened filename can be used in
the assignment to the module.
Throughout this section, 8123_bin.o_shipped has been used to
build the kernel module 8123.ko; it has been included as
8123_bin.o.
8123-y := 8123_if.o 8123_pci.o 8123_bin.o
Although there is no distinction between the ordinary source
files and the binary file, kbuild will pick up different rules
when creating the object file for the module.
想着好玩,就自己试了一下,开始不成功,后来在高手的帮助下终于成功了。
1。 创建自己的obj文件
我最开始使用 gcc -c ex_obj.c -o ex_obj.o_shipped 来做的,结果链接后不能正常工作。
原来是一定要放在编译kernel的环境中编译这个obj。网上高手说了 要这么写
ifneq ($(KERNELRELEASE),)
obj-y := xxxx.o #your obj files goes here. 关键在这里,用obj-y 来指定要编译的,然后这个过程就在编译的时候停了,不会继续链接。
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD)
endif
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
depend .depend dep:
$(CC) $(CFLAGS) -M *.c > .depend
ifeq (.depend,$(wildcard .depend))
include .depend
endif
编译成功后,将这个拷贝到需要链接的模块目录。
记住要添加_shipped后缀
2。 然后在需要这个obj的模块中添加
scull-y := main.o pipe.o access.o ex_obj.o
然后在源代码中调用相应的函数,ok,可以了。
不过貌似没有啥实际用处。 :)
相关文章推荐
- 关于如何在Android源码目录中建立自己的C工程,并用mm命令单独进行该C工程模块的编译,以及Android.mk的使用介绍(1)
- 如何把rtl8188EUS驱动编译生成ko模块并且下载到rk平台Android4.2.2上使用
- 如何在android的mk文件添加依赖已经编译好的库
- 如何使用自己已经编译过的lamp安装cacti nagios zabbix
- 《未测试》如何使用自己已经编译过的lamp安装cacti nagios zabbix
- 如何判断.net编译好的dll文件的使用的.net版本
- 如何使用 Apache 控制命令检查它的模块是否已经启用或加载
- lein中如何使用已经编译好的class文件
- 关于如何在Android源码目录中建立自己的C工程,并用mm命令单独进行该C工程模块的编译,以及Android.mk的使用介绍(2)
- 如何使用automake来管理你的编译
- 如何使用指定版本的GCC/G++来编译autotools打包的程序
- 如何使用emacs编写c语言程序,并编译运行
- 如何快糙好猛地在Windows下编译CAFFE并使用其matlab和python接口
- 如何使用Python的logging模块
- ubuntu 12.04 64bit上使用32bit编译器编译kernel
- 如何使用Visual Studio 2005或Visual Studio 2008编译纯C语言程序!!【图文】
- Gentoo - 使用genkernel之后,修改了kernel,重新编译kernel和生成initramfs
- Linux学习笔记——如何在交叉编译时使用共享库
- android 如何使用jar替换java代码编译
- BOS如何修改已经创建好的单据 叙事薄名称 单据名称 以及列表名称