Linux新版OpenWrt自动编译加载ko

旧版的OpenWrt系统下,编译出的ko模块,需要自己手写启动脚本加载ko,这种方法比较繁琐,好在新版的OpenWrt能实现自动加载ko操作。

需求

把PCIE的驱动编译成ko自动加载

配置

package/kernel/linux/modules/usb.mk

XHCI_MODULES := xhci-hcd xhci-pci xhci-plat-hcd
ifdef CONFIG_TARGET_ramips_mt7621
  XHCI_MODULES += xhci-mtk
endif
XHCI_FILES := $(wildcard $(patsubst %,$(LINUX_DIR)/drivers/usb/host/%.ko,$(XHCI_MODULES)))
XHCI_AUTOLOAD := $(patsubst $(LINUX_DIR)/drivers/usb/host/%.ko,%,$(XHCI_FILES))

define KernelPackage/usb3
  TITLE:=Support for USB3 controllers
  DEPENDS:= \
    +TARGET_bcm53xx:kmod-usb-bcma \
    +TARGET_bcm53xx:kmod-phy-bcm-ns-usb3
  KCONFIG:= \
    CONFIG_USB_PCI=y \
    CONFIG_USB_XHCI_HCD \
    CONFIG_USB_XHCI_PCI \
    CONFIG_USB_XHCI_PLATFORM \
    CONFIG_USB_XHCI_MTK \
    CONFIG_USB_XHCI_HCD_DEBUGGING=n
  FILES:= \
    $(XHCI_FILES)
  AUTOLOAD:=$(call AutoLoad,54,$(XHCI_AUTOLOAD),1)
  $(call AddDepends/usb)
endef

配置选择

Kernel modules  --->
	USB Support  --->
		<*> kmod-usb3. Support for USB3 controllers

Linux新版OpenWrt自动编译加载ko_第1张图片

Makefile

obj-$(CONFIG_USB_XHCI_HCD)  += xhci-hcd.o
obj-$(CONFIG_USB_XHCI_PCI)  += xhci-pci.o
obj-$(CONFIG_USB_XHCI_PLATFORM) += xhci-plat-hcd.o

 Kconfig

config USB_XHCI_HCD
    tristate "xHCI HCD (USB 3.0) support"
    depends on HAS_DMA && HAS_IOMEM
    ---help---
      The eXtensible Host Controller Interface (xHCI) is standard for USB 3.0
      "SuperSpeed" host controller hardware.

      To compile this driver as a module, choose M here: the
      module will be called xhci-hcd.

if USB_XHCI_HCD

config USB_XHCI_PCI
       tristate
       depends on USB_PCI
       default y

config USB_XHCI_PLATFORM
    tristate "Generic xHCI driver for a platform device"
    select USB_XHCI_RCAR if ARCH_RENESAS
    ---help---
      Adds an xHCI host driver for a generic platform device, which
      provides a memory space and an irq.
      It is also a prerequisite for platform specific drivers that
      implement some extra quirks.

      If unsure, say N.
endif # USB_XHCI_HCD

编译

只需要在openwrt里面把kmod选择,不用配置内核选项。

root@OpenWrt:/# ls /lib/modules/4.14.98/xhci-*
/lib/modules/4.14.98/xhci-hcd.ko       /lib/modules/4.14.98/xhci-plat-hcd.ko
/lib/modules/4.14.98/xhci-pci.ko

启动加载

root@OpenWrt:/# cat /etc/modules.d/54-usb3 
xhci-hcd
xhci-pci
xhci-plat-hcd

加载效果 

xhci_hcd              131072  2 xhci_plat_hcd,xhci_pci
xhci_pci               16384  0 
xhci_plat_hcd          16384  0 

 

你可能感兴趣的:(NXP/TI)