简体   繁体   English

在启动时加载linux内核模块

[英]Load linux kernel module at boot

I have written a kernel module for a study research project that is a driver for seven segment displays connected to a Raspberry Pi (I am pretty new to kernel development). 我已经为一个研究项目编写了一个内核模块,该模块是连接到Raspberry Pi的七个分段显示器的驱动程序(我对内核开发还很陌生)。 I would like to permanently install the module and load it at boot time when it is compiled, so I added the install target to my Makefile which allows the user to directly compile and install it. 我想永久安装模块并在编译时在引导时加载它,因此我将install目标添加到了我的Makefile中,该Makefile允许用户直接编译并安装它。

I found out that all kernel modules are located somewhere inside /lib/modules/<kernel version>/kernel , so I thought I just had to copy the compiled module into a subdirectory and list the module in the modules.order and modules.dep files. 我发现所有内核模块都位于/lib/modules/<kernel version>/kernel内的某个位置,所以我想我只需要将编译后的模块复制到一个子目录中,并在modules.ordermodules.dep列出该模块。文件。 However, this approach did not work and since I could not find any resources to that topic, I am a little desperate. 但是,这种方法行不通,并且由于我找不到该主题的任何资源,所以我有些绝望。

This is what my Makefile currently looks like: 这是我的Makefile当前的样子:

# All source files are inside the src directory
obj-m := src/sevenseg.o

all:
    make -C /lib/modules/$(shell uname -r)/build EXTRA_CFLAGS=-I$(PWD)/src M=$(PWD) modules
    mv src/sevenseg.ko .

install:
    make -C /lib/modules/$(shell uname -r)/build EXTRA_CFLAGS=-I$(PWD)/src M=$(PWD) modules
    mkdir -p /lib/modules/$(shell uname -r)/kernel/drivers/sevenseg
    cp src/sevenseg.ko /lib/modules/$(shell uname -r)/kernel/drivers/sevenseg
    echo "kernel/drivers/sevenseg/sevenseg.ko:" >> /lib/modules/$(shell uname -r)/modules.dep
    echo "kernel/drivers/sevenseg/sevenseg.ko" >> /lib/modules/$(shell uname -r)/modules.order
    insmod src/sevenseg.ko
    make clean

clean:
    rm -rf src

How do I tell the kernel that it should load the module sevenseg.ko at boot time? 我如何告诉内核它应该在引导时加载模块sevenseg.ko

tldr; tldr;

# echo 'my-module-name' >> /etc/modules

Longer explanation: 更长的解释:

Consult the documentation on insmod , modprobe , and modprobe.conf . 请查阅有关insmodmodprobemodprobe.conf的文档。

Here's a decent tutorial: https://www.cyberciti.biz/faq/linux-how-to-load-a-kernel-module-automatically-at-boot-time/ 这是一个不错的教程: https : //www.cyberciti.biz/faq/linux-how-to-load-a-kernel-module-automatically-at-boot-time/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM