Building USB kernel module for Sierra EM9191

First, I have't built/cross-compiled any external kernel module for OpenWrt before. So, I might be doing something wrong which is trivial to others.

I am trying to build Sierra's latest USB drivers (for EM9191) from source downloaded from here.

The directory structure, containing the driver source, which I created under /package/kernel/ looks like this:

        MBPL_Drivers_USB_R23
               | -- Makefile
               | -- src
                      | -- Makefile
                      | -- qcserial.c
                      | -- qmi_wwan.c
                      | -- usb-wwan.h
                      | -- usb_wwan.c

My MBPL_Drivers_USB_R23/Makefile is as follows:

include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk

PKG_NAME:=Sierra_MBPL_USB_R23
PKG_RELEASE:=23

PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/$(PKG_NAME)

include $(INCLUDE_DIR)/package.mk

define KernelPackage/$(PKG_NAME)
        SUBMENU:=USB Support
        TITLE:=Sierra MBPL USB Driver R23
        DEPENDS:=+kmod-usb-core kmod-usb-serial
        FILES:= \
                $(PKG_BUILD_DIR)/qcserial.ko \
                $(PKG_BUILD_DIR)/usb_wwan.ko \
                $(PKG_BUILD_DIR)/qmi_wwan.ko
        KCONFIG:=
endef

MAKE_OPTS:= \
            ARCH="$(LINUX_KARCH)" \
            CROSS_COMPILE="$(TARGET_CROSS)" \
            SUBDIRS="$(PKG_BUILD_DIR)" \
            EXTRA_CFLAGS="$(EXTRA_CFLAGS)" \
            $(EXTRA_KCONFIG)

define KernelPackage/$(PKG_NAME)/description
        Sierra MBPL USB R23 kernel module
endef

define Build/Prepare
        mkdir -p $(PKG_BUILD_DIR)
        $(CP) ./src/* $(PKG_BUILD_DIR)/
endef

define Build/Compile
        $(MAKE) -C "$(LINUX_DIR)" \
                $(MAKE_OPTS) \
                modules
endef

define KernelPackage/$(PKG_NAME)/install
        $(INSTALL_DIR) $(1)/lib/modules/$(LINUX_VERSION)
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/qcserial.ko $(1)/lib/modules/$(LINUX_VERSION)
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/usb_wwan.ko $(1)/lib/modules/$(LINUX_VERSION)
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/qmi_wwan.ko $(1)/lib/modules/$(LINUX_VERSION)
endef

$(eval $(call KernelPackage,$(PKG_NAME)))

The MBPL_Drivers_USB_R23/src/Makefile is one line:

obj-m := qcserial.o usb_wwan.o qmi_wwan.o

With the above settings, I am getting following error:

for subdir in .; do realdir=$(readlink -f /root/mylab/openwrt/source/ow_buildroot/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/Sierra_MBPL_USB_R23); grep -F /root/mylab/openwrt/source/ow_buildroot/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/Sierra_MBPL_USB_R23 /root/mylab/openwrt/source/ow_buildroot/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/Sierra_MBPL_USB_R23/$subdir/Module.symvers >> /root/mylab/openwrt/source/ow_buildroot/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/Sierra_MBPL_USB_R23/Module.symvers.tmp; [ "/root/mylab/openwrt/source/ow_buildroot/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/Sierra_MBPL_USB_R23" = "$realdir" ] || grep -F $realdir /root/mylab/openwrt/source/ow_buildroot/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/Sierra_MBPL_USB_R23/$subdir/Module.symvers >> /root/mylab/openwrt/source/ow_buildroot/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/Sierra_MBPL_USB_R23/Module.symvers.tmp; done; sort -u /root/mylab/openwrt/source/ow_buildroot/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/Sierra_MBPL_USB_R23/Module.symvers.tmp > /root/mylab/openwrt/source/ow_buildroot/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/Sierra_MBPL_USB_R23/Module.symvers; mkdir -p /root/mylab/openwrt/source/ow_buildroot/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/symvers; mv /root/mylab/openwrt/source/ow_buildroot/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/Sierra_MBPL_USB_R23/Module.symvers /root/mylab/openwrt/source/ow_buildroot/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/symvers/Sierra_MBPL_USB_R23.symvers
grep: /root/mylab/openwrt/source/ow_buildroot/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/Sierra_MBPL_USB_R23/./Module.symvers: No such file or directory
touch /root/mylab/openwrt/source/ow_buildroot/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/Sierra_MBPL_USB_R23/.built
rm -rf /root/mylab/openwrt/source/ow_buildroot/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/Sierra_MBPL_USB_R23/.pkgdir/kmod-Sierra_MBPL_USB_R23.installed /root/mylab/openwrt/source/ow_buildroot/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/Sierra_MBPL_USB_R23/.pkgdir/kmod-Sierra_MBPL_USB_R23
mkdir -p /root/mylab/openwrt/source/ow_buildroot/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/Sierra_MBPL_USB_R23/.pkgdir/kmod-Sierra_MBPL_USB_R23
ERROR: module '/root/mylab/openwrt/source/ow_buildroot/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/Sierra_MBPL_USB_R23/qcserial.ko' is missing.
make[3]: *** [Makefile:53: /root/mylab/openwrt/source/ow_buildroot/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/Sierra_MBPL_USB_R23/.pkgdir/kmod-Sierra_MBPL_USB_R23.installed] Error 1
make[3]: Leaving directory '/root/mylab/openwrt/source/ow_buildroot/package/kernel/MBPL_Drivers_USB_R23'
time: package/kernel/MBPL_Drivers_USB_R23/compile#80.44#8.58#87.70
    ERROR: package/kernel/MBPL_Drivers_USB_R23 failed to build.

Can anyone help on why it is failing to build?

Don't know what's wrong. But I wonder why you want to build those files from some untrusted external source? They are part of the Linux kernel and are built as OpenWrt packages already. Whatever changes you need are better pushed upstream to the kernel and imported back through the stable process.

1 Like