Enable logs in kernel driver

Hello,

I would like to work on customizing a screen driver. I have identified the driver file: /drivers/gpu/drm/panel/panel-sitronix-st7701.c. I want to enable logs in this file and view them.

I have tried many solutions found online, but none have been successful.

For example, I tried adding the linux/module.h and linux/kernel.h libraries to the panel-sitronix-st7701.c file, along with printk(KERN_INFO "some thing\n") logs in several places.
I enabled the following options:

  • CONFIG_PRINTK=y
  • CONFIG_DYNAMIC_DEBUG=y
  • CONFIG_DEBUG_KERNEL=y

I also enabled the logs using the following command:

echo "module panel-sitronix-st7701 +p" > /sys/kernel/debug/dynamic_debug/control  

However, I don’t see anything new in dmesg.

Could you please guide me on how to enable logs in the driver and view them?

Best regards,

Arthur

Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Hello Arthur,

Thank you for reaching out with your question about enabling logs in your kernel driver. It sounds like you’re on the right track with using printk for logging. Here are some steps to help ensure your logging works as expected:

  1. Correct Use of printk:

    • Ensure your printk statements are correctly formatted, such as printk(KERN_INFO "Your message here\n");. The KERN_INFO level is suitable for informational messages.
  2. Dynamic Debug Configuration:

    • You’ve correctly enabled dynamic debug for your module. Make sure the command echo "module panel-sitronix-st7701 +p" > /sys/kernel/debug/dynamic_debug/control is executed after the module is loaded.
    • Verify that CONFIG_DYNAMIC_DEBUG=y is set in your kernel configuration.
  3. Kernel Boot Parameters:

    • Check that your kernel boot parameters do not suppress log levels. The loglevel parameter should be set to include KERN_INFO (e.g., loglevel=7).
  4. Review dmesg Settings:

    • Ensure dmesg is configured to display the log level you are using. You can adjust the dmesg log level with dmesg -n 7 to show all messages.
  5. Troubleshooting Tips:

    • If logs are still not visible, try using KERN_DEBUG instead of KERN_INFO for more verbosity.
    • Confirm that your changes to the driver file are compiled and loaded correctly. Adding a simple printk at the start of the driver’s initialization function can help verify that your changes are active.
    • Reboot the system after making changes to ensure all configurations are applied.

By following these steps, you should be able to see the logs from your driver in dmesg. If issues persist, double-check your kernel configuration and ensure the module is correctly loaded with the updated code.

Best regards,
Toradex AI Assistant

Please, also check if these links can help you solve your problem:

MCP3428 Kernel driver.

Hello @aforey,

The recommendations from the @ToradexAI are good, but I would also recommend that you take a look at the following resources that should help you debug this issue:

As the log level for your messages is just KERN_INFO, it is possible that the messages are being hidden, so the printk documentation is especially relevant here.

Best Regards,
Bruno

Hello @aforey,

Could you send me your image so I can check if there was a misconfiguration that may lead to the driver not being loaded?

If possible, please upload it to share.toradex.com and send an email with the link to support.eu@toradex.com.

Best Regards,
Bruno

Hello Bruno,

Thank you for checking in. I tried adding logs to the tc358768 driver following the instructions you provided, and it was a success!

However, I applied the same method to the st7701 driver, but I don’t see any logs in dmesg or when running the commands rmmod panel_sitronix_st7701 and modprobe panel_sitronix_st7701.

I have attached the source code of the driver I used. I am also sending you the link to the BSP I used.

Best regards,

Arthur

panel-sitronix-st7701.c (25.9 KB)

Hello @aforey,

Thanks for the additional information.

I had a look at your image and was able to conclude the following:

  • The correct device tree is configured on the device
  • The custom module for the st7701 is being built and has your changes
  • The device tree is correctly configured to load the st7701 driver
  • The st7701 driver is being loaded by default on your image

The above leads me to believe that the overall configuration is correct.
What may be missing is some initialization step that is specific to this configuration.

I recommend that you enable the CONFIG_FTRACE config on your kernel to be able to use the ftrace functionality.
With that, you should be able to see more clearly which functions are being called when the kernel module is loaded.
For more information on how to use ftrace, please refer to the following page: Introduction to kernel tracing with ftrace - devkernel.io
The most useful part at least initially would be to use the function tracer.

Best Regards,
Bruno

Hello @bruno.tx ,

I have enabled the following kernel modules:

CONFIG_FTRACE=y  
CONFIG_FUNCTION_TRACER=y  
CONFIG_FUNCTION_GRAPH_TRACER=y  
CONFIG_DYNAMIC_FTRACE=y  

I added some traces in the ST7701 driver:

trace_printk("st7701: Test\n");

We do have the /sys/kernel/tracing/ directory, and we execute the following commands:

  1. echo > trace
  2. echo function > current_tracer
  3. echo 1 > tracing_on
  4. rmmod panel_sitronix_st7701
  5. modprobe panel_sitronix_st7701
  6. echo 0 > tracing_on

When I check the “trace” file, I don’t see the ST7701 log. However, I do see other logs.

I don’t see what else I can do…

Best regards,

Arthur

Hello @bruno.tx ,

Here is the modified driver file attached: panel-sitronix-st7701.c.

It uses two functions to initialize and remove it: st7701_dsi_probe and st7701_dsi_remove.

As you can see in the file, there is a log: trace_printk("st7701: Test\n");

panel-sitronix-st7701.c (25.8 KB)

However, I don’t even see the log from the st7701_dsi_probe function. Yet, the driver seems to be properly loaded when we check with lsmod.

I am also attaching the DTS files so you can verify the screen declaration.

k3-am62-verdin.dtsi (43.8 KB)
k3-am62-verdin-dev.dtsi (5.4 KB)
k3-am625-verdin-wifi-dev.dts (613 Bytes)
rfa6400e-awh-mnn.dtsi (804 Bytes)

I inserted logs into the tc358768 driver, and I can see them.

Best regards,
Arthur

Hello @aforey,

Thanks for the additional information.

I will have a look at it and get back to you next week.

Best Regards,
Bruno

1 Like

Hello @bruno.tx ,

Sorry to bother you again, have you had a chance to take a look?

Best regards,

Arthur

Hello @aforey,

Sorry for the delay here.

I would recommend that you try to change the compatible string for your panel in your device tree to the following one:

compatible = "techstar,ts8550b";

Your device tree seems to be correct, but this change would be recommended in order to avoid any possible misconfigurations.

With that in place, please check if the status of the panel is expected in the image:

find /sys/firmware/ -name "*panel*" 
# In the directory you find verify that the status is either okay or not there
cat <directory>/status

Besides that it would be important to know if the init function is called.
For that, can you set the following ftrace filter?

echo "*st77*" > /sys/kernel/tracing/set_ftrace_filter

With this configuration, do you see the init function being called?

Best Regards,
Bruno