如何使用 Yocto SDK 构建 Linux 内核模块?

tan*_*ect 5 linux-device-driver linux-kernel

我正在尝试使用 Yocto SDK 构建 Linux 内核模块。但是,我遇到了编译错误,它抱怨

./include/uapi/asm-generic/int-ll64.h:12:10: fatal error: asm/bitsperlong.h: No such file or directory
 #include <asm/bitsperlong.h>
Run Code Online (Sandbox Code Playgroud)

这是我的 Makefile

ARCH ?= arm
CROSS_COMPILE ?= arm-poky-linux-gnueabi-
KERNELDIR ?= /opt/poky/2.7.3/sysroots/cortexa9t2hf-neon-poky-linux-gnueabi/usr/src/kernel/
PWD := $(shell pwd)

.PHONY: build clean

build:
    $(MAKE) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KERNELDIR) M=$(PWD) modules

clean:
    rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c modules.order  Module.symvers

# Incorporate modules into a multi-part driver
my-objs := hello.o    


$(info Building with KERNELRELEASE = ${KERNELRELEASE})
EXTRA_CFLAGS+=-I$(PWD)/../include
obj-m := hello.o
Run Code Online (Sandbox Code Playgroud)

在调用 make 之前,我要设置源环境。

$source /opt/poky/2.7.3/environment-setup-cortexa9t2hf-neon-poky-linux-gnueabi     
$make
Run Code Online (Sandbox Code Playgroud)

Mar*_* H. 8

由于现在编译的“@tannoy connect”的注释,树外内核模块也遇到了类似的问题。以下是基本步骤:

  1. 通过您的镜像配方在 SDK 中启用 kernel-devsrc(请参阅Yocto Kernel Dev Manual
    TOOLCHAIN_TARGET_TASK += "kernel-devsrc"
Run Code Online (Sandbox Code Playgroud)
  1. 将 SDK 安装到您的主机,然后运行内核 src makefile(感谢“@tannoy connect”):
    source path/to/sdk/environment-setup-aarch64-linux
    cd -P path/to/sdk/sysroots/aarch64-linux/usr/src/kernel
    # Note the -P argument: kernel is a symlink, in my case:
    # path/to/sdk/sysroots/aarch64-linux/lib/modules/5.4.0-xilinx-v2020.1/build
    make scripts
    make prepare
Run Code Online (Sandbox Code Playgroud)
  1. 编译树外内核模块(注意:我的 Makefile 使用 KERNEL_SRC,因此与原始问题不同,因为它通常是通过 yocto module.bbclass 编译的):
    export KERNEL_SRC=path/to/sdk/sysroots/aarch64-linux/usr/src/kernel/
    make
Run Code Online (Sandbox Code Playgroud)