无法编译内核模块:没有 .ko 文件输出

发布于 2025-01-10 11:58:24 字数 1784 浏览 0 评论 0原文

我已经构建了一个 android 内核(源代码),现在我我正在尝试为其交叉编译内核模块,准确地说是v4l2loopback。我使用这个工具链来构建内核(内核版本为4.9)。

在github上你可以看到有人确实成功编译了该模块,我一直在尝试自己复制他们的成功。但在实际构建内核模块的最后阶段,我没有得到 .ko 文件输出。这是我得到的:

# setting up
$ export ARCH=arm64
$ export CROSS_COMPILE=aarch64-linux-android-
$ export PATH=/home/username/redmi_7a/aarch64-linux-android-4.9-kernel/bin:$PATH
# go to the source code directory
$ cd v4l2loopback
$ export M="$PWD" 
# I have the compiled kernel at /home/username/redmi_7a/kernel
make -C ../kernel
make: entering catalogue «/home/username/redmi_7a/kernel»
  CHK     include/config/kernel.release
  CHK     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  CHK     include/generated/bounds.h
  CHK     include/generated/timeconst.h
  CHK     include/generated/asm-offsets.h
  CALL    scripts/checksyscalls.sh
  CHK     scripts/mod/devicetable-offsets.h
  Building modules, stage 2.
  MODPOST 4 modules
make: exiting catalogue «/home/username/redmi_7a/kernel»

看起来没有错误,什么也没有,但我得到的只是一个 v4l2loopback.o 文件,而不是 v4l2loopback.ko 文件,如 < a href="https://github.com/umlaeute/v4l2loopback#build" rel="nofollow noreferrer">v4l2loopback github 页面。

我尝试 find 。 -name "*.ko",但它没有返回任何内容。

我可能在内核编译过程中搞砸了一些东西,所以它可能不是模块的错。我真的不知道该去哪里看,我对此很陌生。

也许我需要在内核 .config 文件中设置一些标志并重新编译?

我真正问的只是一个方向,我可能做错了什么?

I've built an android kernel (source code), now I'm trying to cross-compile a kernel module for it, v4l2loopback to be precise. I've used this toolchain to build the kernel (kernel version is 4.9).

Here on github you can see that someone actually succeeded in compiling the module, and I've been trying to replicate their success myself. But in the last stage of actually building the kernel module I don't get a .ko file output. Here is what I get:

# setting up
$ export ARCH=arm64
$ export CROSS_COMPILE=aarch64-linux-android-
$ export PATH=/home/username/redmi_7a/aarch64-linux-android-4.9-kernel/bin:$PATH
# go to the source code directory
$ cd v4l2loopback
$ export M="$PWD" 
# I have the compiled kernel at /home/username/redmi_7a/kernel
make -C ../kernel
make: entering catalogue «/home/username/redmi_7a/kernel»
  CHK     include/config/kernel.release
  CHK     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  CHK     include/generated/bounds.h
  CHK     include/generated/timeconst.h
  CHK     include/generated/asm-offsets.h
  CALL    scripts/checksyscalls.sh
  CHK     scripts/mod/devicetable-offsets.h
  Building modules, stage 2.
  MODPOST 4 modules
make: exiting catalogue «/home/username/redmi_7a/kernel»

Seems like no errors, no nothing, but all I get is a v4l2loopback.o file, instead of v4l2loopback.ko file, as mentioned per v4l2loopback github page.

I tried find . -name "*.ko", but it didn't return anything.

I might've screwed something up during the kernel compilation, so it might not module's fault. I don't really know where to look, I'm really new to this.

Maybe I need to set some flag in the kernel .config file and recompile?

All I really ask is a direction, what are the things I might've done wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲娇萝莉攻 2025-01-17 11:58:24

您似乎构建不正确。使用 make -C ../kernel 您完全忽略了您尝试构建并使用内核 Makefile< 的模块存储库中的 Makefile /code> 单独。您应该查看 v4l2loopback 内的 Makefile 并注意文件开头的以下几行:

include Kbuild
ifeq ($(KBUILD_MODULES),)

KERNELRELEASE   ?= `uname -r`
KERNEL_DIR      ?= /lib/modules/$(KERNELRELEASE)/build
PWD             := $(shell pwd)
...

因此 PWD 和内核目录是已经为你设置好了。您应该只覆盖 KERNEL_DIR 和所需的交叉编译变量:

export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-android-
export PATH=/home/username/redmi_7a/aarch64-linux-android-4.9-kernel/bin:$PATH
export KERNEL_DIR=/home/username/redmi_7a/kernel

cd v4l2loopback
make

上面的代码在我的机器上运行并正确生成 v4l2loopback.ko。当然,在执行此操作之前请确保您已经构建了内核。

You seem to be building incorrectly. With make -C ../kernel you are completely ignoring the Makefile that is in the repository of the module you are trying to build and using the kernel Makefile alone. You should take a look at the Makefile inside v4l2loopback and notice the following lines at the beginning of the file:

include Kbuild
ifeq ($(KBUILD_MODULES),)

KERNELRELEASE   ?= `uname -r`
KERNEL_DIR      ?= /lib/modules/$(KERNELRELEASE)/build
PWD             := $(shell pwd)
...

So the PWD and kernel dir are already set for you. You should just override KERNEL_DIR and the needed cross-compilation variables:

export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-android-
export PATH=/home/username/redmi_7a/aarch64-linux-android-4.9-kernel/bin:$PATH
export KERNEL_DIR=/home/username/redmi_7a/kernel

cd v4l2loopback
make

The above works on my machine and correctly produces v4l2loopback.ko. Make sure you have built the kernel before doing this of course.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文