In current project, I focused on replacing the existing outdated WiFi driver with an updated version driver provided by NXP. The target machine for this task is the STM32MP1, which utilises an ARM-based architecture. The challenge arose because the instructions in the driver’s README file were created for use on the target machine. They were specifically designed for building the driver directly there. However, due to the limited size and dependencies of my target system, this approach was not possible.
After considering various options, I chose to use Buildroot for this task. Previously, I wrote an article on a similar topic. It was about compiling a kernel module using Buildroot, and you can find it here. For this project, I followed the same principles, but this time I used the actual NXP driver. Here, I will elaborate on the steps I took to successfully replace and update the WiFi driver on the STM32MP1.
In this blog, I won’t delve into the Buildroot setup, as it diverges from the main purpose of this post. Instead, I’ll assume you already have an existing Buildroot system. The focus here will be on leveraging that Buildroot system to build the driver for the target STM32MP1 platform.
Get hold of the NXP WiFi driver (mwifiex) source code
I am using an updated NXP WiFi driver source code that is compatible with the Linux kernel version 5.15.67 on my target. The closest driver version I found is lf-5.15.71_2.2.0. To obtain this driver, visit the NXP Git repository. You can find the driver here unless it has been moved recently. Change the branch to lf-5.15.71_2.2.0 or another preferred version. Download the source code using the following Git command:
git clone git@github.com:nxp-imx/mwifiex.git
Alternatively, you can download the ZIP version of the NXP WiFi driver source code. Once downloaded, you will have a folder named mwifiex, which holds the source of the WiFi driver. My product is based on an STM32MP1, and it does not support PCIe. Thus, it is necessary to turn off PCIe-based Wi-Fi chipsets in the Makefile. To do this, modify the settings in mwifiex/mxm_wifiex/wlan_src/Makefile as follows:
CONFIG_PCIE8897=n
CONFIG_PCIE8997=n
CONFIG_PCIE9097=n
CONFIG_PCIE9098=n
CONFIG_PCIEIW624=n
CONFIG_PCIEAW693=n
Now, we’re ready to compile our local driver directory for offline use. Let’s start by preparing the source code. Next, we’ll create a Buildroot package to integrate this source code into the Buildroot build system.
Create a Buildroot Package for Integrating Local Drivers
To create the Buildroot package, follow the steps outlined in the earlier post. For completeness, I’ll reiterate the process here. Start by creating a placeholder for the package using the following steps:
mkdir package/xxx/xyz/
Create the package within the package folder according to your hosting preference. In my scenario, I’m using the folder ‘xxx,’ which is customer-specific. Your folder structure differ slightly, but it’s not crucial. Within the ‘package/xxx/xyz/’ folder, create two files: the package configuration file ‘Config.in’ and the package makefile ‘xyz.mk.’ Typically, I follow this structure:
touch package/xyz/Config.in
touch package/xyz/xyz.mk
I have chosen a more meaningful name for the package. But, using ‘xyz’ emphasises that the package name can be anything. It does not need to adhere to strict naming conventions.
Write the Config.in File for Your Buildroot Package
For writing the Config.in I will borrow the code I have in this post. Here is the listing that I have written for this purposes:
config BR2_PACKAGE_XYZ
bool "xyz"
help
This is sample package.
Again, very simple config file without much ado.
Write the xyz.mk Makefile for Your Buildroot Package
Similarly, I will write a very simple makefile for this activity. The listing is again very much like the one in this post. The listing for this activity is as follows:
XYZ_MODULE_VERSION = 1.0
XYZ_SITE = /home/vivekb/WIFI_INTEGRATION/mwifiex/mxm_wifiex/wlan_src
XYZ_SITE_METHOD = local
XYZ_LICENSE = GPLv2
XYZ_LICENSE_FILES = COPYING
define KERNEL_MODULE_BUILD_CMDS
$(MAKE) -C '$(@D)' LINUX_DIR='$(LINUX_DIR)' CC='$(TARGET_CC)' LD='$(TARGET_LD)' modules
endef
$(eval $(kernel-module))
$(eval $(generic-package))
Incorporate Package Configuration in the Upper-Level Config in Buildroot
Now you need to add the package in the upper level package config file. In my case I have placed the package under package/xxx/. Hence I have to include this package config in the following config file:
package/xxx/Config.in
It will a one line addition which is as follows:
source "package/xxx/xyz/Config.in"
Activate the Package in the Buildroot defconfig File
In the defconfig file add the following line to enable the package you just created:
BR2_PACKAGE_XYZ=y
Recreate the .config File for Buildroot
In a typical buildroot the config files are usually located under the config/ folder. Lets say your board’s device config file name is mydevice_dev_defconfig. Now you need to recreate the .config file using your device config file as below:
make mydevice_dev_defconfig
This should recreate the .config file in the buildroot top level directory.
Verify the Package Configuration in the .config File
Open the .config file and double check if your package config is there in it, there should be a line like the below:
BR2_PACKAGE_XYZ=y
Compiling and Verifying Kernel Module Build Status in Buildroot
Now we are all set to compile the buildroot:
make
Once the build finishes you should be capable of checking the following .kos in the output directory:
find output/ -iname moal.ko 2>/dev/null
output/build/xyz/moal.ko
output/target/lib/modules/5.15.67/extra/moal.ko
find output/ -iname mlan.ko 2>/dev/null
output/build/xyz/mlan.ko
output/target/lib/modules/5.15.67/extra/mlan.ko
All we care are these two files in the final root file system:
target/lib/modules/5.15.67/extra/moal.ko
target/lib/modules/5.15.67/extra/mlan.ko
And there you have it. You now have a freshly compiled NXP WiFi kernel module. It is ready to be loaded onto your target device for testing!

Leave a Reply