How to set dependency in kernel module package?

Hello all,
i created a new hwmon driver package which needs CONFIG_REGMAP set in kernel config.
But this variable is not set bydefault in my target config.

When i add another kernel module which requires these settings with
make menuconfig (e.g. kmod-hwmon-lm75) , also my driver compiles without error.
But without this workaround CONFIG_REMAP is not set and compilation fails.

What i've done so far:

What am i missing?

It looks like the lantiq atm packages do this with kmod-atm, so it should be possible: https://github.com/openwrt/openwrt/blob/f0445746f6fd96fc7c5394b238153bd2ff22bc5b/package/kernel/lantiq/ltq-atm/Makefile#L24

Some suggestions:

  • Check tmp/.config-package.in to see that your package dependencies are being parsed correctly. Sometimes, I need to manually remove this tmp folder to get config to update correctly.
  • don't include in KCONFIG Kconfigs that you depend on packages for (HWMON I2C REGMAP_I2C)
  • You should be able to use KERNEL_MAKE
  • Might be easier to remove the Kconfig your driver defines: https://github.com/openwrt/openwrt/commit/24bf94ecb728d47d45ec9a419b92bb8440eb64ce
  • I think, because you are not building this driver as part of the kernel build, the KernelPackage KCONFIG should be empty—this is what the other src kernel packages do, see: git grep KCONFIG -- 'package/kernel/**Makefile' ':!package/kernel/linux'
  • Check other examples of KernelPackage build from source: find package/kernel/ -maxdepth 2 -type d -iname src -printf '%h\n'

Thanks for your suggestions, but meanwhile i think it is not possible to add an required kernel config for a package which is not part of the kernel tree.

It looks like the lantiq atm packages do this with kmod-atm , so it should be possible:

Promising, but i think the kmod-atm dependecy is already set in the target configs,
as these packages can't be added to other targets.

  • Check tmp/.config-package.in to see that your package dependencies are being parsed correctly.

It looks good, all dependencies are here, but in kernel config CONFIG_REGMAP_I2C is missing.

  • don't include in KCONFIG Kconfigs that you depend on packages for (HWMON I2C REGMAP_I2C)

Removed it, but no change.

  • You should be able to use KERNEL_MAKE

Still no success.

  • Might be easier to remove the Kconfig your driver defines:

Also no change.

  • I think, because you are not building this driver as part of the kernel build, the KernelPackage KCONFIG should be empty

O.k., but the dependency is still missing.

  • Check other examples of KernelPackage build from source: find package/kernel/ -maxdepth 2 -type d -iname src -printf '%h\n'

I didn't find a good example here, they have either no dependencies or are target depended, so all dependcies are set already be the target.

Meanwhile i think i should move my driver to the kernel tree like ubnt-ledbar, see:
target/linux/generic/hack-5.xx/800-ubnt-ledbar-driver-patch and
target/linux/generic/files/drivers/leds/leds_ubnt-ledbar.c

Or better add patches under package/kernel/hwmon-isl28022 ?
Any thoughts on it?

It is not (directly). There may be something that select or depends on it:

git grep CONFIG_ATM -- target/linux/lantiq/
git grep kmod-atm -- target/linux/lantiq

This is due to the DEPENDS on @TARGET_lantiq_$ part of the KernelPackage

These packages are included in DEVICE_PACKAGES of the images, which might help getting this to work.

kmod-ovpn-dco is another example: https://github.com/openwrt/packages/blob/master/kernel/ovpn-dco/Makefile

Just making sure that you are checking the kernel config after it has been parsed, under build_dir/target-*/linux-*/linux-*/.config*

Yes, building this within kernel means let Makefile complexity. That driver was moved out to a package though: https://github.com/openwrt/openwrt/commit/4363faef8a8c975410f001858b010170942aacfc

The patches under package modify the source defined by the package, so that will not help here.

kmod-ovpn-dco is another example

Very interesting exampe, this package does exactly what i want.
I enabled 'kmod-ovpn-dco', the dependecies are set correctly and the build succeeds.

But i don't see yet what's the difference to my package.

Just making sure that you are checking the kernel config after it has been parsed, under build_dir/target-/linux-/linux-/.config

I have

  • .config.set, .config.prev and .config.old with the identical content and CONFIG_REGMAP_I2C=m set as needed.
  • .config.override with CONFIG_REGMAP_I2C=m (smaller content compared to .config.set)
  • .config and .config.modules.save which are identical and
    # CONFIG_REGMAP_I2C is not set which causes the trouble

For kmod-ovpn-dco the dependency CONFIG_NET_UDP_TUNNEL=m is set in all .config* files.

From the timestamps, .config is the newest one, but i need a make with V=sc to see what happens.

Good information. This means that Openwrt is correctly setting the Kconfig options https://github.com/openwrt/openwrt/blob/9a5b1af670185f07a797920f861a6033e61c5c61/include/kernel-defaults.mk#L114, but then configure run by the kernel is dropping them.
I think this could be because REGMAP_I2C is hidden option (no prompt text), so kernel configure will drop it unless something else select or depends on it (from kernel .config). If that is the case, I think you will need to move your driver into the kernel build. I saw something similar (hidden .config option dropped) with kmod-sfp (not) being built by itself.

I think this could be because REGMAP_I2C is hidden option (no prompt text)

I removed the HIDDEN flag from both regmap-i2c and regmap, but build still fails.

kmod-ovpn-dco depends on udptunnel4 and udptunnel6 which both are hidden too.
Therefore i think the HIDDEN flag is not the reason.

HIDDEN at OpenWrt level does not matter (relevant for OpenWrt make menuconfig)
We are looking at something that happens within the kernel build process: I think that no prompt text in kernel Kconfig does matter does matter here. Example:

config REGMAP_I2C
	tristate
	depends on I2C

vs.

config I2C
	tristate "I2C support"

The way to test this is to patch it in kernel, example:

config REGMAP_I2C
	tristate "REGMAP I2C support"
	depends on I2C

This can be done in-place, under build_dir/target-*/linux-*/linux-*/drivers/i2c/Kconfig, then rebuild kernel via make target/linux/install, but it is easy to make mistakes, and you will lose changes when a clean happens.

O.k. this works, i think i have to create a patch similar to
target/linux/generic/hack-5.15/261-lib-arc4-unhide.patch

Can i add such a patch to my PR, or is it better to create separate PRs?

PR created

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