Trying to compile Quectel qmi-wwan-q driver

Hello everyone, I have been trying to compile the qmi-wwan-q driver from Quectel since we are having some issues with the generic driver on a private 5G network.

We are using a RPi4 with the 22.03 version. I have downloaded the SDK and placed the source files in the folder /package/qmi_wwan_q including a Makefile I created based on some examples I found. The contents of the makefile are as following

include $(TOPDIR)/rules.mk

PKG_NAME:=qmi_wwan_q
PKG_VERSION:=1.2.2
PKG_RELEASE:=1

# Custom variable
SOURCE_DIR:=/home/crave/Documents/mypackages/qmi_wwan_q

PKG_MAINTAINER:=Quectel

include $(INCLUDE_DIR)/kernel.mk
include $(INCLUDE_DIR)/package.mk

define KernelPackage/qmi_wwan_q
    SUBMENU:=Network
    TITLE:=Quectel qmi_wwan driver
    DEPENDS:= \
        +kmod-mii \
        +kmod-usb-core \
        +kmod-usb-net-cdc-ether \
        +kmod-usb-net \
        +kmod-usb-net-qmi-wwan \
    FILES:=$(PKG_BUILD_DIR)/qmi_wwan_q.ko
	#AUTOLOAD:=$(call AutoLoad,50,qmi_wwan_q)
endef

define KernelPackage/qmi_wwan_q/description
	qmi_wwan driver by Quectel
endef

EXTRA_CFLAGS:= \
    $(patsubst CONFIG_%, -DCONFIG_%=1, $(patsubst %=m,%,$(filter %=m,$(EXTRA_KCONFIG)))) \
    $(patsubst CONFIG_%, -DCONFIG_%=1, $(patsubst %=y,%,$(filter %=y,$(EXTRA_KCONFIG)))) \
    
MAKE_OPTS:= \
	ARCH="$(LINUX_KARCH)" \
	CROSS_COMPILE="$(TARGET_CROSS)" \
	SUBDIRS="$(PKG_BUILD_DIR)" \
	EXTRA_CFLAGS="$(EXTRA_CFLAGS)" \
	$(EXTRA_KCONFIG)

define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)
	$(CP) $(SOURCE_DIR)/* $(PKG_BUILD_DIR)/
	$(Build/Patch)
endef


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

$(eval $(call KernelPackage,qmi_wwan_q))

In the folder, in addition to the Makefile I put qmi_wwan_q.c and rmnet_nss.c.

I do make menuconfig and select the module. Then I save the configuration and do make -1j V=sc and the process fails with the following errors:

make[4]: Entering directory '/home/crave/Documents/openWrt/openwrt-sdk-22.03.2-bcm27xx-bcm2711_gcc-11.2.0_musl.Linux-x86_64/build_dir/target-aarch64_cortex-a72_musl/linux-bcm27xx_bcm2711/linux-5.10.146'
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/dtc/dtc.o
  HOSTCC  scripts/dtc/flattree.o
  HOSTCC  scripts/dtc/fstree.o
  HOSTCC  scripts/dtc/data.o
  HOSTCC  scripts/dtc/livetree.o
  HOSTCC  scripts/dtc/treesource.o
  HOSTCC  scripts/dtc/srcpos.o
  HOSTCC  scripts/dtc/checks.o
  HOSTCC  scripts/dtc/util.o
  HOSTCC  scripts/dtc/dtc-lexer.lex.o
  HOSTCC  scripts/dtc/dtc-parser.tab.o
  HOSTLD  scripts/dtc/dtc
  HOSTCC  scripts/sorttable
scripts/sorttable.c:34:10: fatal error: tools/be_byteshift.h: No such file or directory
   34 | #include <tools/be_byteshift.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[5]: *** [scripts/Makefile.host:95: scripts/sorttable] Error 1
make[4]: *** [Makefile:1209: scripts] Error 2
make[4]: Leaving directory '/home/crave/Documents/openWrt/openwrt-sdk-22.03.2-bcm27xx-bcm2711_gcc-11.2.0_musl.Linux-x86_64/build_dir/target-aarch64_cortex-a72_musl/linux-bcm27xx_bcm2711/linux-5.10.146'
make[3]: *** [Makefile:53: /home/crave/Documents/openWrt/openwrt-sdk-22.03.2-bcm27xx-bcm2711_gcc-11.2.0_musl.Linux-x86_64/build_dir/target-aarch64_cortex-a72_musl/linux-bcm27xx_bcm2711/qmi_wwan_q-1.2.2/.built] Error 2
make[3]: Leaving directory '/home/crave/Documents/openWrt/openwrt-sdk-22.03.2-bcm27xx-bcm2711_gcc-11.2.0_musl.Linux-x86_64/package/qmi_wwan_q'
time: package/qmi_wwan_q/compile#2.43#0.35#2.78
    ERROR: package/qmi_wwan_q failed to build.

Do I need to include this header somehow? Is there anything else I need to do?

I appreciate any help

Take a look at gpio-button-hotplug package which is a good example for an out-of-tree kernel module build:

...
MAKE_OPTS:= \
        $(KERNEL_MAKE_FLAGS) \
        M="$(PKG_BUILD_DIR)"

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

mabie be_byteshift.h is not in the right directory

Thank you Daniel, based on the makefile from gpio-button-hotplug I modified mine and I change the file structure to follow the same pattern (/src dir for sources). The module was successfully compiled. Below I leave the final makefile.

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

PKG_NAME:=qmi-wwan-q
PKG_RELEASE:=1
PKG_VERSION:=1.2.2

include $(INCLUDE_DIR)/package.mk

define KernelPackage/qmi-wwan-q
  SUBMENU:=Network
  TITLE:=Quectel Driver for qmi wwan
  DEPENDS:= \
  	+kmod-usb-net \
  	+kmod-usb-net-qmi-wwan  		
  FILES:=$(PKG_BUILD_DIR)/qmi-wwan-q.ko
  AUTOLOAD:=$(call AutoLoad,30,qmi-wwan-q,1)
  KCONFIG:=
endef

define KernelPackage/qmi-wwan-q/description
 Driver from Quectel for qmi-wwan
endef

MAKE_OPTS:= \
	$(KERNEL_MAKE_FLAGS) \
	M="$(PKG_BUILD_DIR)"

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

$(eval $(call KernelPackage,qmi-wwan-q))

Thanks bricco1981, I think this error was not related to the driver itself but to an option in the menuconfig about signing the compiled packages. Once I unchecked that it didn't appear anymore.

Good, so that worked. The module sources are obviously under GPLv2 license (as they are linking against other GPLv2 licenced modules, such as usb-net, there is not much choice about that and every court in the world will confirm GPLv2 licence of the sources, even if stated otherwise)
So I think it would be nice to have this packaged officially in OpenWrt.
Edit: Or even better: extract the relevant bits and submit them to the upstream Linux driver...
Where to find the sources?

I got the sources emailed to me by Quectel support. I have not found them in an open repository. The same with other Quectel tools such as quectel-cm which I usually find only on other people's github because they uploaded it. I am not sure why they follow this policy...

For the tools it's up to Quectel to decide on licensing, they can do what they want: proprietary licenses, even NDAs. And while it may not be very smart to keep any software for hardware-support behind closed doors, in this case of user-space programs or tools it can be legal to do so and also enforceable in courts.

However: For a kernel module of this kind it is obvious that you have now received GPLv2 licensed code, they simply don't have any other choice than that, because it is obviously using and built-upon other GPLv2 code. So it's up to you to upload it somewhere :slight_smile:

Hi Daniel, I uploaded the code here: https://github.com/CarlosRaveloFivecomm/qmi-wwan-q.git

2 Likes

Not to mention that I have copyright on much of the code, and I have only licensed it as GPLv2. So yes, the qmi_wwan sources are definitely under GPL no matter what they did to it.

Your copyright is still at the top of the source file :slightly_smiling_face:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.