Serial debugging/Serial Gadget

For devices where getting a physical UART cable is not possible, or not feasible, the kernels USB serial gadget can be a good option for debugging when you know that the kernel is booting.

Enabling serial gadget
Turn on the following config options: CONFIG_USB_G_SERIAL=y CONFIG_U_SERIAL_CONSOLE=y CONFIG_USB_U_SERIAL=y

Add the following to your kernel cmdline to enable logging to the gadget console: console=ttyGS0,115200

Using the gadget
Now when booting your device, you should see a new serial device appear on your host, usually it's. This one liner can make sure you don't miss anything (although usually the output is buffered until you open the device). Sometimes the gadget buffer breaks down and it sends a lot of the same few characters over and over, when this includes newlines it can cause you to lose a lot of the logs, hence the grep below.

Leave this running in a console and the boot logs will be printed every boot. while true; do test -e /dev/ttyACM0 && sleep 0.1 && cat /dev/ttyACM0 | grep -vE "^\s?\n$"; done