TorizonCore Builder - Kernel Module Compiling error

Hello,

I am using an Apalis imx8x module on a custom carrier board. On this carrier we have a M41T81 RTC. I a m trying to compile the rtc-m41-t80.c module from the llinux/drivers/rtc folder. For this i am using the TC Builder and the configured script.

kernel:
    modules:
      - source-dir: modules/m41t81/
        autoload: yes

When the build start i get following errors:

/workdir/modules/m41t81/m41t80.c: In function ‘m41t80_handle_irq’:
/workdir/modules/m41t81/m41t80.c:164:2: error: implicit declaration of function ‘rtc_lock’ [-Werror=implicit-function-declaration]
  164 |  rtc_lock(m41t80->rtc);
      |  ^~~~~~~~
/workdir/modules/m41t81/m41t80.c:168:3: error: implicit declaration of function ‘rtc_unlock’; did you mean ‘osq_unlock’? [-Werror=implicit-function-declaration]
  168 |   rtc_unlock(m41t80->rtc);
      |   ^~~~~~~~~~
      |   osq_unlock
/workdir/modules/m41t81/m41t80.c: In function ‘m41t80_probe’:
/workdir/modules/m41t81/m41t80.c:929:13: error: ‘RTC_FEATURE_ALARM’ undeclared (first use in this function)
  929 |   clear_bit(RTC_FEATURE_ALARM, m41t80_data->rtc->features);
      |             ^~~~~~~~~~~~~~~~~
/workdir/modules/m41t81/m41t80.c:929:13: note: each undeclared identifier is reported only once for each function it appears in
/workdir/modules/m41t81/m41t80.c:929:48: error: ‘struct rtc_device’ has no member named ‘features’
  929 |   clear_bit(RTC_FEATURE_ALARM, m41t80_data->rtc->features);
      |                                                ^~
/workdir/modules/m41t81/m41t80.c:987:7: error: implicit declaration of function ‘devm_rtc_register_device’; did you mean ‘rtc_register_device’? [-Werror=implicit-function-declaration]
  987 |  rc = devm_rtc_register_device(m41t80_data->rtc);
      |       ^~~~~~~~~~~~~~~~~~~~~~~~
      |       rtc_register_device
cc1: some warnings being treated as errors

What extra files do i need to add to the module directory tog et it to build?
Is there another driver that i can use for the m41t81?

Thanks.

Greetings @c.gantner,

Please take note of the article: Building External Kernel Modules With Torizon | Toradex Developer Center

The torizoncore-builder tool can only strictly build “out-of-tree” kernel modules, or put simply modules that don’t exist in the Linux kernel. Trying to build a module like rtc-m41t80.c, which does exist in the Linux kernel will generally not work and lead to very strange behaviors.

The only proper way to build an in-tree kernel module. Would be create a customized TorizonCore image with a recompiled kernel that has this kernel module enabled.

Best Regards,
Jeremias

Hello Jeremias,

I did not know that. Thank you for clarification.
I already read the article about building external kernel modules and also built one with success.
The issue was with the one “in-the-tree”. As far as i understand i need to build a custom image with Yocto? This would be the next point on my to do list. At the moment i am testing/setting everything up with the Builder.

Regards,
Cristian.

Glad I could clarify this.

This would be the ideal approach to avoid any unforeseen issues with adding this driver/module.

Best Regards,
Jeremias

Hi @c.gantner,

The Torizon team might be able to enable the device driver as a module in TorizonCore. I’m saying “might” because a few requisites must be met:

  • It shall not break any existing functionality.
  • The device driver must be included in the mainline/upstream.
  • You must provide the kernel configuration that must be enabled to make it work (e.g. CONFIG_XXX, CONFIG_RTC_DRV_M41T80=m, and so on).

If this would help you, and you have the required kernel configs, please provide them so we can evaluate if inclusion is possible.

Hello Leo,

Thank you for the help. In the mean time i managed to build a custom image with yocto and apply my customization with the torizon builder.

One of the last open topics is how i can add my own service files via the builder so that when i flash a new module i already have the files inside in the correct location.

Thank you again.

Hi @c.gantner, we’re happy to hear you have made progress.

Would you please open a new question about the service configuration files, providing more details? Meanwhile, the article Capturing Changes in the Configuration of a Board on TorizonCore | Toradex Developer Center may help you.