Yocto环境下如何添加树外设备驱动?
Hey there! Since you're new to Yocto and already have a working build environment for uboot+kernel+rootfs, let's break down how to integrate that bcmdhd driver properly—we'll take it step by step, no jargon overload.
1. Stick to Out-of-Tree Module Best Practices
Your driver is built separately from the mainline kernel, so we'll create a dedicated Yocto recipe for it. This keeps your kernel source clean and aligns with Yocto's modular workflow.
2. Set Up Your Custom Layer (Recommended)
First, create a custom layer to house your driver recipe—this avoids messing with Yocto's core layers:
- Make a directory like
meta-my-drivers - Add the standard layer structure inside:
meta-my-drivers/ ├── conf/ │ └── layer.conf └── recipes-kernel/ └── bcmdhd/ ├── bcmdhd/ │ └── [drop your full bcmdhd driver source here] └── bcmdhd_%.bb
Pro tip: If your driver lives in a git repo, you can use SRC_URI to pull it directly instead of copying files—we'll cover that in the recipe.
3. Write the BCMDHD Recipe (bcmdhd_%.bb)
Here's a tailored recipe that mimics your native build command. Adjust placeholders to match your setup:
DESCRIPTION = "Broadcom BCMDHD WiFi Driver (BCM4359 PCIe)" LICENSE = "Proprietary" LIC_FILES_CHKSUM = "file://LICENSE;md5=[replace-with-actual-md5-of-your-license-file]" # Use this if your driver is local, or swap for git://your-repo-url.git if using a repo SRC_URI = "file://bcmdhd/" S = "${WORKDIR}/bcmdhd" # Pull in kernel build dependencies DEPENDS = "virtual/kernel" inherit module # Pass your exact CONFIG flags to the make command EXTRA_OEMAKE += " \ CONFIG_BCMDHD_PCIE=y \ CONFIG_BCMDHD=m \ CONFIG_BCM4359=y \ " # Install the module to the correct kernel module directory do_install() { install -d ${D}${base_libdir}/modules/${KERNEL_VERSION}/kernel/drivers/net/wireless/ install -m 0644 ${S}/bcmdhd.ko ${D}${base_libdir}/modules/${KERNEL_VERSION}/kernel/drivers/net/wireless/ } # Ensure the module is included in your image and dependencies are met FILES_${PN} += "${base_libdir}/modules/${KERNEL_VERSION}/kernel/drivers/net/wireless/bcmdhd.ko" RDEPENDS_${PN} = "kernel-module-bcmdhd"
Key details:
- The
inherit moduleline handles all the tedious stuff like pointing to the correct kernel build directory (no more manual-CorM=parameters!). EXTRA_OEMAKEinjects your custom CONFIG flags directly into the build—exactly like your native make command.- If your driver needs firmware files, add them via
SRC_URIand install them to${D}/lib/firmware/in thedo_installsection.
4. Enable Your Layer and Recipe
- Add your new layer to
conf/bblayers.confin your build directory:BBLAYERS += "${TOPDIR}/../meta-my-drivers" - Add the driver to your image's package list in
local.conf:
UseIMAGE_INSTALL:append = " bcmdhd"IMAGE_INSTALL += " bcmdhd"if you're on an older Yocto version.
5. Build and Verify
Run your build as usual:
bitbake your-target-image-name
Once the build finishes, flash the image to your target. Test if the module loads with:
modprobe bcmdhd lsmod | grep bcmdhd
Quick Troubleshooting
- Kernel version mismatch: Double-check that your Yocto kernel version matches what you used for native compilation. Use
uname -ron the target or checkKERNEL_VERSIONin your build logs. - Build errors: Check the detailed log at
tmp/work/[your-target-arch]/bcmdhd/[version]/temp/log.do_compile—most issues are missing dependencies or typos in CONFIG flags. - Firmware not found: If the driver complains about missing firmware, add those files to your recipe and install them to
/lib/firmware/.
内容的提问来源于stack exchange,提问作者ZioByte

