Debugging kernel driver?

I’m trying to add debug prints and custom sysfs entries a custom led driver I have created.

It is running early in the boot sequence so it can control the RGB power led.
the driver operates as intended but I can’t get any debug prints to show driver status.

I have also tried to load custom sysfs entries to debug the driver under the led class but I can’t get them to show up.

I think the led class system is not initialised and the just get ignored or something and I can’t unload or reload my module from bash without the system rebooting.

it also seems the led system is a few steps behind the kernel version like there is stuff in the same version of the main linux kernel but not in OpenWrt, and making the driver able to pass upstream review means it won’t compile under OpenWrt.

Does any one have any ideas?, i admit I’m a little lost.

It is running early in the boot sequence so it can control the RGB power led.
the driver operates as intended but I can’t get any debug prints to show driver status.

If you're looking for output on a UART you might need to enable early console on your platform. That should only be necessary if you're working in the low level platform init though.

What log level are you trying to print at? dev_dbg/KERN_DEBUG doesn't print at the default console_loglevel.

I have also tried to load custom sysfs entries to debug the driver under the led class but I can’t get them to show up.

I think the led class system is not initialised and the just get ignored or something and I can’t unload or reload my module from bash without the system rebooting.

How are you loading the module? If you're setting the driver to be built as a module in the kernel config it won't be included in the firmware image unless it's been defined as a package (see examples here). If you need to control the LED early at boot then the driver should be built into the kernel anyways.

The CONFIG_DEBUG_DRIVER kernel option can also give you a lot of information about how devices/drviers/systems are loaded.

it also seems the led system is a few steps behind the kernel version like there is stuff in the same version of the main linux kernel but not in OpenWrt, and making the driver able to pass upstream review means it won’t compile under OpenWrt.

Unfortunately there's no easy way to deal with this. Ideally you would upstream your code and then back port it to the openwrt kernel, or wait for openwrt to use the newer kernel.

What platform and LED are you working with? If you can modify the bootloader then configuring the LED behaviour there might work better.

I have built my driver with dynamic debug and enabled printk() in kernelconfig but I can’t seem to get it to show any logs or in debugfs.

The driver is loaded with autoload at 65 so the gpio sybsystem is up but I don’t think logging is up until 99 where logd is.

my driver loads and works as intended but is there some way to show or capture debug messages during preinit or reliably ring buffer them until the system is fully up, I’m guessing preinit runs in a seperate process and all is squashed.?

AUTOLOAD:=$(call AutoLoad,65,leds-group-virtualcolor,1)

I can’t really load it later on as it won’t be able to control the LEDs during early boot.
I tried to get it to show debug items in the led/class but that failed for the same reason I believe
I tried to use modbprobe to unload and load the driver but it causes the router to reboot so I’m kind of lost.

I’m wanting to test dynamic debug under OpenWrt so I can verify it working before pushing another upstream patch.

[PATCH v2 0/4] leds: Add a virtual LED driver for groups of

There seems to be a preinit interface but I don’t know how that works and gave up trying.

Even after enabling dynamic debug and kernel debugging etc... I still don't get the control file or the dynamic debug directory:
and i have run a target make clean to make sure the kernel is rebuilt and did the same with my driver, my driver has the debug symbols in it.
It is all pointing to dynamic debug is broken or I'm missing something really silly?

root@OpenWrt:/sys/kernel/debug# ls
ath11k              cpr3-regulator      dmaengine           ieee80211           memblock            pinctrl             regmap              tsens
bdi                 debug_enabled       extfrag             iio                 msm-apm             pm_genpd            regulator           ubi
block               device_component    fault_around_bytes  interconnect        mtd                 psci                remoteproc          ubifs
clear_warn_once     devices_deferred    gpio                lru_gen             opp                 qcom_socinfo        sleep_time          usb
clk                 dma_pools           i2c                 lru_gen_full        phy                 ras                 swiotlb
root@OpenWrt:/sys/kernel/debug# mount | grep debugfs debugfs on /sys/kernel/debug type debugfs (rw,nosuid,nodev,noexec,noatime) root@OpenWrt:/sys/kernel/debug# echo 'module leds-group-virtualcolor +p' > /sys/kernel/debug/dynamic_debug/control -ash: can't create /sys/kernel/debug/dynamic_debug/control: nonexistent directory
CONFIG_DYNAMIC_DEBUG=y
CONFIG_DYNAMIC_DEBUG_CORE=y
CONFIG_SYMBOLIC_ERRNAME=y
CONFIG_DEBUG_BUGVERBOSE=y
CONFIG_DEBUG_KERNEL=y
CONFIG_DEBUG_MISC=y
CONFIG_KERNEL_DEBUG_FS=y
CONFIG_IKCONFIG_PROC=y

It would seem I need to patch the driver in openwrt as the kernel config has stripped out CONFIG_MODULE_PARAM_SYSFS

it woulds seem logic in my driver around the debugfs never succeeds so the whole debugfs code path (controller_create_debugfs()) never runs.

something gracefull like this would be upstream acceptable:

#ifdef CONFIG_MODULE_PARAM_SYSFS
module_param_named(debug, enable_debugfs, bool, 0644);
MODULE_PARM_DESC(debug, "Enable debugfs support");
#else

/* For systems like OpenWrt that strip module_param sysfs */
static int __init leds_virtualcolor_force_debugfs(void)
{
	enable_debugfs = true;
	pr_info("leds-group-virtualcolor: forcing debugfs on (no MODULE_PARAM_SYSFS)\n");
	return 0;
}
late_initcall(leds_virtualcolor_force_debugfs);
#endif

Dam I still get no debug or logs so I'm a lost now

what I don't get is why gpio fan is getting console output on probe but my driver is not, is there something I have to enable to debug the led sybsystem?