MISC-AN-003: How to use an USB device port as Linux console

From DAVE Developer's Wiki
Jump to: navigation, search
Info Box


History
Date Version
2026/02/17 USB device console


Introduction[edit | edit source]

On standard Linux Embedded devices, the Linux console is available on a serial port connected to the one SoC UART port: this lets the user to access the Linux console - typically with a user/password-protected access - and manage and control the device using Linux commands.

Using a USB OTG port - configured a USB device - and the proper kernel module, it is possible to create a virtual console.

Physical connection[edit | edit source]

As an example, it is possible to use the AURA EVK as an Embedded Linux device: the USB port used is the J18 USB OTG port.

  • use a standard USB Type-A male to Micro B male (like this one)
  • connect the micro USB side to J18
  • connect the Type-A side to your PC
  • open a serial terminal (like Teraterm) - for example - on your Windows PC

kernel driver[edit | edit source]

The kernel driver used for emulating a serial device is the g_serial USB gadget driver. In the serial console, start the module in the following way:

root@desk-mx93-rev1:~# modprobe g_serial
[  116.831356] g_serial gadget.0: Gadget Serial v2.4
[  116.841683] g_serial gadget.0: g_serial ready
[  116.849924] remoteproc remoteproc0: releasing imx-rproc
root@desk-mx93-rev1:~#

This create a virtual device /dev/ttyGS0 in the Linux root file system.

root@desk-mx93-rev1:~# ls -la /dev/ttyGS0
crw-rw---- 1 root dialout 235, 0 Feb 27 17:26 /dev/ttyGS0
root@desk-mx93-rev1:~#

Windows terminal[edit | edit source]

  • open the Teraterm application and check for the available serial port
new COM port available in the Serial port list

systemd: automatic loading[edit | edit source]

For automatically starting the kernel module and then let the serial port-over-USB device available, it is possible to create a systemd service

root@desk-mx93-rev1:~# cat /lib/systemd/system/g-serial.service
[Unit]
Description=Load USB Gadget Serial (g_serial)
DefaultDependencies=no
After=systemd-modules-load.service
ConditionPathExists=/sys/module

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/sbin/modprobe g_serial
ExecStop=/sbin/modprobe -r g_serial

[Install]
WantedBy=multi-user.target
root@desk-mx93-rev1:~#

and then enable it:

systemctl enable g-serial

Furthermore, for enabling a getty login in the created serial device, it is enough to use the getty@.service with the associated device:

systemctl enable serial-getty@ttyGS0.service

login on the serial-to-USB console[edit | edit source]

At the end, once rebooted, if the serial terminal is already open, it is possible to see the getty login in the USB console:

getty on ttyGS0 serial port over USB