How to build an additional kernel module?

I keep working with banana pi bpi-r2. Successfully launched a openwrt snapshot of it. I want to add a hw-nat kernel module. I have a patch that I put in target/linux/mediatek/patches-4.19 . I also created a file in package / kernel / linux / modules of the following content

define KernelPackage/nat-hw-mtk
TITLE:= MediaTek's hardware NAT module
AUTOLOAD:=$(call AutoLoad,90,mtkhnat)

define KernelPackage/nat-hw-mtk/description
MediaTek's hardware NAT driver.

$(eval $(call KernelPackage,nat-hw-mtk))

This added a menu item "kmod-nat-hw-mtk" to the kernel module configuration.

$ make target/linux/compile
The patch is applied successfully. Everything is built without errors, but there is no file mkthnat.ko .
What did I not do?

Where are you looking for this file? You should have kmod-nat-hw-mtk.ipk with that file in your bin/packages. The mkthnat.ko is inside.

It is actually bin/target/xxxxxx/packages

I'm looking for it in build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-mediatek_mt7623/linux-4.19.106/drivers/net/ethernet/mediatek/mtk_hnat.
I watched it work make target/linux/compile V=s
There is no activity in this folder

So did the ipk appear?

And so

$ make package/kernel/linux/compile V=s /
make[1]: Entering directory '/var/opt/vanessa/router/bpi-r2/openwrt'
make[2]: Entering directory '/var/opt/vanessa/router/bpi-r2/openwrt/package/libs/toolchain'
echo "libc" >> /var/opt/vanessa/router/bpi-r2/openwrt/staging_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/pkginfo/toolchain.default.install
echo "libgcc" >> /var/opt/vanessa/router/bpi-r2/openwrt/staging_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/pkginfo/toolchain.default.install
echo "libpthread" >> /var/opt/vanessa/router/bpi-r2/openwrt/staging_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/pkginfo/toolchain.default.install
make[2]: Leaving directory '/var/opt/vanessa/router/bpi-r2/openwrt/package/libs/toolchain'
time: package/libs/toolchain/compile#0.13#0.03#0.16
make[2]: Entering directory '/var/opt/vanessa/router/bpi-r2/openwrt/package/firmware/linux-firmware'
make[2]: Leaving directory '/var/opt/vanessa/router/bpi-r2/openwrt/package/firmware/linux-firmware'
time: package/firmware/linux-firmware/compile#0.24#0.03#0.25
make[2]: Entering directory '/var/opt/vanessa/router/bpi-r2/openwrt/package/firmware/prism54-firmware'
make[2]: Leaving directory '/var/opt/vanessa/router/bpi-r2/openwrt/package/firmware/prism54-firmware'
time: package/firmware/prism54-firmware/compile#0.17#0.04#0.19
make[2]: Entering directory '/var/opt/vanessa/router/bpi-r2/openwrt/package/kernel/linux'
ERROR: module '/var/opt/vanessa/router/bpi-r2/openwrt/build_dir/target-arm_cortex-a7+neon-vfpv4_musl_eabi/linux-mediatek_mt7623/linux-4.19.106/drivers/net/ethernet/mediatek/mtk_hnat/mtkh
nat.ko' is missing.
make[2]: *** [modules/ /var/opt/vanessa/router/bpi-r2/openwrt/bin/targets/mediatek/mt7623/packages/kmod-nat-hw-mtk_4.19.106-1_arm_cortex-a7_neon-vfpv4.ipk] Error 1
make[2]: Leaving directory '/var/opt/vanessa/router/bpi-r2/openwrt/package/kernel/linux'
time: package/kernel/linux/compile#2.26#0.16#2.41
make[1]: *** [package/Makefile:113: package/kernel/linux/compile] Error 2
make[1]: Leaving directory '/var/opt/vanessa/router/bpi-r2/openwrt'
make: *** [/var/opt/vanessa/router/bpi-r2/openwrt/include/ package/kernel/linux/compile] Error 2

The compiler bypasses it

Maybe try a clean first (check dependency issue)

make target/linux/{clean,compile} V=s

maybe add a grep to look for something of interest.

So I did too, the make doesn't go in drivers/net/ethernet/mediatek/mtk_hnat folder

Doing a quick google, this driver seems to depend on a number of additional kernel symbols. Look at the KConfig in the patch you created to see which.

	tristate "MediaTek MT7623 hardware NAT support"

These need to be added to your Makefile KCONFIG line or defined indirectly through the DEPENDS:= line if the relevant kmod- is part of the Openwrt packages so that it compiles the relevant dependent modules and defines the kernel symbols. So, if none of the dependent symbols are already packaged by other kmod- packages (which is not the case for the netfilter ones), the line would look thus:


But, as I mentioned, some of those kernel symbols above are set by other kmod- packages. Most of the netfilter ones are set in openwrt/include/, so you'd need to check yourself which ones and then put the associated kmods in the DEPENDS line (for example DEPENDS=+kmod_nf_conntrack) instead of explicitly putting those symbols in the KCONFIG line, as the kmod- packages will then build the required dependent kmods and define the kernel symbols.

I'm trying to move this patch from here
Had to modify it for work with the kernel 4.19. But the compiler bypasses it. In the kernel .config file by eliasmagn is present a line


what i am doing does not add such a line in .config file

You're compiling it as a module. Go back and read what I wrote again. Have you actually tried this?

If you just want to get it to work, don't try and create a kmod package for it if it's causing you trouble. Just compile it directly into the kernel.

make kernel_menuconfig CONFIG_TARGET=subtarget

Toggle the option for that driver on, then remove your package Makefile and it should compile the patched driver directly into the kernel.

But frankly, just try what I suggested in the previous post before you do that.

Yes, I tried - it didn't help

This driver is not there ...

make kernel_menuconfig CONFIG_TARGET=subtarget

I worked on the problem again.
Found the following: The scripts/kconfig/conf program removes a CONFIG_NET_MEDIATEK_HNAT=m parameter from a .config file

1 Like

Im trying to learn how to do this but im not having success. Im new to both linux and openwrt but ive learned some over the past week.
Im not sure how to do this though.

I want to add
into kernel. I have no clue if that works? Any pointers appriciated!
Trying to get 2.5gbit to work


EDIT: Would adding kmod-usb-net-rtl8152 with an asterisk, instead of a module make a difference when making the firmware?
Installing kmod-usb-net-rtl8152 on 19.07.3 x86_64 after the fact does not work with my 2.5gbit usb ethernet