I'm trying to modify the libcomposite module in a way that it prints the functions of which are loaded to the log file.

I'm using an Raspberry Pi Zero W with the 4.9.20+ Kernel. I updated everything with the rpi-source then edited the composite.c file in drivers/usb/gadget folder to print with printk(..).

And recompiled everything with make modules SUBDIR=drivers/usb/gadget and the installed everything with make modules_install SUBDIR=drivers/usb/gadget.

The libcomposite is loaded with modprobe libcomposite in a systemd service and then the functions are appended.

But the problem is that the messages of printk(..) are neither shown in dmesg nor any log files.

Thanks for your help!


This works for me, but there are many pitfalls that you could have stumbled on.

  • Correct install path: I cross-compiled from a PC so had to make sure INSTALL_MOD_PATH was specified properly. It sounds like you're building on the Pi itself so that this may not be an issue, but to double-check, confirm that the timestamp on /lib/modules/4.9.56+/kernel/drivers/usb/gadget/libcomposite.ko (or newer kernel version) has been updated.

  • Correct kernel.img: Make sure kernel.img is updated as well. If you run the old kernel it'll pull libcomposite.ko out of /lib/modules/4.9.35+/ (or whatever your original kernel version is). You could nuke the old modules directory to be certain.

  • kernel message level: KERN_INFO (6) is too high for messages to land in dmesg by default. Try printk(KERN_WARNING ...) for level 4 initially. pr_info() may be preferable for modules and does not have this complication.

  • Which part of composite.c are you putting your printout in? If usb_add_function(), note that this won't be called until you've fully configured a gadget and do the ls /sys/class/udc > UDC step.

By the way, I find the SUBDIR variable having no effect, but it doesn't hurt.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.