Building x86 image with custom drivers

Please bear with me as I am very inexperienced in git.
I am trying to build OpenWrt from source without using the image builder.
So far I have cloned the main repository, I have set up the build environment with all prerequisites, I have gone through all the settings in menuconfig, I have saved the config but for the life of me I cannot figure out why some drivers are not part of the main repo. The driver in question is the mt7915e, I want to try some changes before building the image but that driver is not located anywhere in the build dir.
I found it in the mt76 repo:

But I am unsure how to proceed with the build process, do I need to set up a different build directory solely for the driver, compile it, then somehow insert it in the image? That kind of defeats my purpose, I want this driver to be part of the kernel, but I also want to make some changes prior to building the image.
What am I missing here?

Did you run the feeds script to update and install all the packages into your build environment before running make menuconfig? If so, the mt7915 drivers should be visible at "Kernel modules" -> "Wireless Drivers". Just set them to M or Y (shows as *).

$ ./scripts/feeds update -a
...
$ ./scripts/feeds install -a
...
$ make menuconfig
...

I did all that, I even installed the optional feeds because I wanted to make sure I get no errors. I can see the mt7915e driver in Kernel modules -> Wireless drivers in menuconfig. What I am having trouble with, is locating them locally inside the building directory.
I mean to locally download the source code for the driver, edit it, then have it built alongside the rest of the system.

Driver is part of kernel.

Okay but then again, when building from source, isn't the kernel also compiled in the process? Isn't the 'git clone' command just downloading the source code locally so the build environment can compile it after going through make menuconfig?
Or are you saying I will need to first compile the kernel with the modified driver, then have that already compiled kernel be part of the new OpenWrt build from source where the process already takes the modified kernel?

Moreover, if it truly is part of the kernel, why do I have the option to add it in menuconfig? If it was part of the kernel, I wouldn't have to Y it in menuconfig

Aha, got it. I think you need to do this (I've never modified a driver/kmod, so this might have some holes).

  1. Clone a local copy of https://github.com/openwrt/mt76
  2. Read https://github.com/openwrt/openwrt/blob/main/config/Config-devel.in#L146 for background
  3. make menuconfig, "Advanced config..." -> "Enable package source tree..." (i.e., CONFIG_SRC_TREE_OVERRIDE=y in .config)
  4. Create a symlink in the package directory to point to your cloned repo
cd /my/repos/openwrt
ln -s /my/repos/mt76/.git/ package/kernel/mt76/git-src

Once you've got that in place, you then need to edit the code in the mt76 repo, commit it and update the hash in the package/kernel/mt76/Makefile to pull your changes. The FIXUP option might edit the hashes for this (again never done it for a kmod, but this works for regular packages).

make package/mt76/check V=s FIXUP=1
2 Likes

Thank you so much.
I ended up not actually editing the driver:

After some further digging into the issue, I have realized where the problem with my wifi adapter lies:

I have the exact same problem, with the randomness and all (my other thread) and as per the discussion in the github issue linked above, it is a missing quirks.c driver in the kernel:

I am now compiling from source, without actually making changes to the mt7915e driver, since I see that the OpenWrt currently supports the linux-6.6.68 kernel so it is included.

Fingers crossed this issue will finally be resolved.
I will report back.

1 Like