linux - How to compile Linux kernel module without kernel Makefile?
问题描述
I have an ARM Linux device, but I don't have the Makefile
of the kernel to build a kernel module.
I have GCC cross compiler to this arch.
How can I compile a kernel module without the Makefile
of the kernel?
解决方案
如何在没有内核 Makefile 的情况下编译内核模块?
你不能。您需要内核Makefile
来编译模块,以及预构建的内核源代码树。在大多数发行版上,您可以通过包获取构建模块的内核源代码,例如linux-headers-xxx
where xxx
should be output of uname -r
.
例如,在 Debian 或 Ubuntu 上:
sudo apt-get install linux-headers-$(uanme -r)
然后,您将在 中找到构建模块所需的文件/lib/modules/$(uname -r)/build
,并且您可以使用Makefile
如下所示构建模块:
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
obj-m := mymodule.o # same name as the .c file of your module
default:
$(MAKE) -C $(KDIR) M=$(PWD) modules
这基本上是调用内核Makefile
告诉它在当前目录中构建模块。
另外,我不确定你为什么说你在 ARM Linux 设备上,并且你有一个交叉编译器。如果您在设备本身上,则根本不需要交叉编译器。如果您在不同的设备上,那么您需要使用适合uname -r
目标设备的设备才能获得正确的源并进行构建。您可能需要手动执行此操作,因为 的输出uname -r
并不总是有帮助。
您还需要在模块中指定架构和交叉编译工具链前缀Makefile
,例如:
default:
$(MAKE) -C $(KDIR) M=$(PWD) ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- modules
推荐阅读
- vue.js - Nuxt SSR - 我无法检查用户是否经过身份验证
- python - 在熊猫中转换出生日期
- express - 尝试从移动浏览器使用 mediaDevices 时出现问题
- java - 如何在 BorderLayout.SOUTH 中添加一个矩形?
- r - 将列与另一列分开而不对其进行硬编码
- reactjs - 如何在 Firebase 中注册用户后立即将 displayName 添加到用户?
- flutter - 如何使用颤振在 Firestore 中编写嵌套数组
- python - 通过 docker-compose 文件创建的 django 超级用户不起作用
- r - 如何在 R data.table 中进行移位操作,同时为最后一个比较附加一行?
- html - 如何使用 css flex 保持一个盒子为空