如何在不重命名传递给insmod的.ko的情况下重命名内核模块名称? [英] How to rename a kernel module name without renaming the .ko passed to insmod?

查看:188
本文介绍了如何在不重命名传递给insmod的.ko的情况下重命名内核模块名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要重命名已经存在的驱动程序的内核模块(使用lsmod显示的名称),而无需更改源文件的名称.

I need to rename a kernel module (the name that get displayed with lsmod) of an already existing driver without changing the name of the source file.

例如

# insmod xxx.ko
<<module loads successfully>>
# lsmod
Module                  Size  Used by    Tainted: P
xxx                   191527  0
#

  • 我想将 xxx 重命名为 yyy .

    • I want to rename xxx to yyy.

      现在,我知道更改驱动程序源文件的名称(当它涉及单个文件时)会更改模块的名称.

      Now I know that changing the name of the driver source file (when it involves a single file) changes the name of the module.

      但是我不想更改源文件的名称.

      But I don't want to change the name of a source file.

      推荐答案

      在Makefile中重命名obj-m并将obj-m的依赖项设置为原始模块.

      Rename your obj-m in Makefile and set dependency of obj-m to original module.

      例如,我有一个包含所有源代码的文件hello.c.但我希望模块为mynewname.

      For example, I have file hello.c that contain all of my source code. But I want module to be mynewname.

      这是执行此操作的整个Makefile:

      Here is whole Makefile that does this:

      obj-m := mynewname.o 
      mynewname-objs := hello.o
      
      KERNELDIR ?= /lib/modules/$(shell uname -r)/build
      PWD  := $(shell pwd)
      
      default:
          $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
      
      clean:
          $(MAKE) -C $(KERNELDIR) M=$(PWD) clean
      

      我将obj-m设置为mynewname.o,并使mynewname.o依赖于hello.o.调用make后,您将获得mynewname.ko.

      I set obj-m to mynewname.o and make mynewname.o dependant on hello.o. After invoking make you'll get mynewname.ko.

      这篇关于如何在不重命名传递给insmod的.ko的情况下重命名内核模块名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆