如何在Yocto构建的Raspberry Pi CM3系统启动时自动加载内核模块?
Hey there! Let's sort out that kernel module auto-loading problem for your Raspberry Pi CM3 Yocto build. Since you already have the modules sitting in /lib/modules on your target device, we’ve got a couple of reliable approaches to get them loading automatically on boot—plus we’ll fix those dependency headaches at the same time.
Method 1: Configure Auto-Loading in Your Yocto Recipe (Recommended, Fix at Build Time)
If your drivers were added via a custom recipe or .bbappend, you can set this up directly in your Yocto build so the configuration ships with the image (no post-flash edits needed):
- For a single module:
Add this line to your.bbor.bbappendfile:
This variable tells Yocto to generate the necessary modprobe configs, which will auto-load the module on boot and handle dependencies automatically (modprobe is way smarter than insmod about resolving dependent modules).MODULES_AUTOLOAD += "your-module-name" - For multiple modules, just space-separate them:
MODULES_AUTOLOAD += "module1 module2 module3" - If your module needs load-time parameters, use
MODULES_CONFto add a custom config:
Then createMODULES_CONF += "your-module.conf"your-module.confin your recipe'sfilesdirectory with content like:
This ensures the parameters are applied automatically when the module loads.options your-module-name param1=value1 param2=value2
Method 2: Manually Configure on the Target System (Great for Testing or Post-Flash Edits)
If you don't want to rebuild your Yocto image, you can set this up directly on your Raspberry Pi CM3:
- First, stop using
insmod—switch tomodprobe your-module-nameinstead. It will automatically detect and load any dependent modules, which eliminates those dependency issues you were hitting. - To set up auto-load on boot:
- Create or edit a file in
/etc/modules-load.d/(e.g.,/etc/modules-load.d/my-drivers.conf), adding each module name on its own line:
Systemd reads all configs in this directory on boot and uses modprobe to load the listed modules.your-module-name another-dependent-module - For module parameters, create a file in
/etc/modprobe.d/(e.g.,/etc/modprobe.d/my-driver.conf):options your-module-name param1=value1
- Create or edit a file in
- To verify your setup works:
Usesystemctl status systemd-modules-load.serviceto check the status of the module-loading service, or reboot and runlsmod | grep your-module-nameto confirm the module is loaded.
Quick Notes to Avoid Headaches
- Double-check that your module matches your kernel version: Run
uname -ron the target, and make sure there's a matching directory in/lib/modules/(modules are stored per kernel version). - Ensure your Yocto kernel config has dynamic module support enabled (
CONFIG_MODULES=y)—this is usually default in meta-raspberrypi, but it's worth confirming if you've tweaked kernel settings. - If you built the module directly into the kernel (not as a dynamic module), you don't need to load it manually—it will be present on boot automatically. But since you're seeing it in
/lib/modules, you're using dynamic modules, so the above methods apply.
内容的提问来源于stack exchange,提问作者Asma Maaroufi
相关产品推荐
相关产品推荐

