0

I have been reading about the Serial Console. So let us say I have an android phone and want to read its serial output from a computer. I can compile a kernel for the phone no problem.

I see things like /dev/ttyUSB0 in the article. Do I need to write my own driver for the devices that will make the console be seen on the computer?

2 Answers 2

1

So let us say I have an android phone and want to read its serial output from a computer.

If you want to do that, you need either serial hardware that is supported by the kernel drivers on your phone (and you are unlikely to find that, or if it has those, you'll need to open up your phone and solder lines to the motherboard), or

I see things like /dev/ttyUSB0 in the article

your kernel needs to put the USB port into host mode, and you'll have to connect an USB serial device as client to it. (And then in turn you have to connect the serial port of that device to some other serialport).

will make the console be seen on the computer?

There are simpler ways to do that, e.g. with netconsole (which then needs the USB configured for networking).

1
  • Alright Im guessing Turing my device into host mode is what I am looking for Dec 12, 2021 at 15:33
1

I'm seeing three options for accessing the console on an Android device by USB. USB-OTG, USB-C dual role port, and USB 3.x host-to-host communication.

USB-OTG is a spec that was made largely redundant and obsolete by use of USB-C and USB 3.x. This does appear to still be popular though on some Android systems. Technically USB-OTG requires use of USB micro-AB ports but it seems many Android device manufacturers violated this part of the spec and support USB-OTG on micro-B ports. This is popular because it allows use of "accessory charging adapters" that can provide power to the Android phone/tablet/whatever and also provide a standard USB-A port to plug in standard USB peripherals. Standard USB peripherals like a USB-to-serial adapter to provide a console debugging port. The manual for the device should specify if the Android device supports USB-OTG.

USB-C dual role ports means that the port can operate in host or peripheral mode. I believe all Android phones with USB-C will have dual role ports. The physical connection to a computer is trivial enough as any USB-C to USB-C cable, or USB-A to USB-C cable, should work. To get the Android device to present as a serial device to the computer will require the correct driver and configuration. I have not tried this myself but a quick search of the internet brought the driver to my attention: https://android.googlesource.com/kernel/msm/+/android-7.1.0_r0.2/drivers/usb/gadget/function/u_serial.c I'll leave discovery of the details on how to get this to work as an exercise for the reader.

USB 3.x allows for host-to-host communications. This capability has been supported in Linux for some time. I have not done this myself but I am aware of it being available. Again I'll provide a link giving some hints on how it works and leave the details for the reader: https://docs.kernel.org/driver-api/usb/usb3-debug-port.html

NOTE: Be very careful of the kinds of cables used if taking the USB host-to-host option. There are many USB-A to USB-A cables out there that do not adhere to the USB 3.x specification. A cable that complies with the specification will not connect Vbus, and will also leave the USB 2.0 D+/D- lines unconnected. Also confusing things are USB-A to USB-A cables that have electronics in them to make the cable appear as two serial or network adapters connected back-to-back. These are not technically USB cables but USB devices. They can be helpful in connecting an Android serial console to another computer but they will require different settings than a host-to-host USB 3.x debug cable. How can one tell they are getting the right kind of cable? That's complicated, would take a lot of time to explain, is beyond the scope of this question, and deserving of it's own separate discussion.

That covers the use of a USB serial console but there are other options. There's the option of a BlueTooth virtual serial port (using built-in Bluetooth or adding it by USB), a network console (by built-in Wi-Fi, USB-to-Wi-Fi adapter, or USB-to-Ethenet adapter), a console by use of a USB-C dock with DisplayPort and USB-A ports, and likely more.

I realize I'm quite possibly leaving more questions than answers. There's limited space here for describing how each works and the original question was is it possible. Yes, it is possible and I gave several options on how it is possible. How to get them working is another question.

3
  • thanks for the insight I am having USB-OTG and USB 3.0 so I will work on those Dec 12, 2021 at 21:42
  • @BretJoseph "I am having USB-OTG and USB 3.0 " Are you sure? USB-OTG and USB 3.x are rarely seen together, used only on "wide" micro-AB ports. USB-OTG came out in 2001 and was made obsolete by USB-C in 2014. USB 3.x, and the "wide" micro-AB ports to support the extra electrical contacts, came out in 2010. The window in which USB-OTG and USB 3.x coincided was very narrow and quite some time ago in terms of electronics. I'm not saying you are absolutely mistaken, only that if you are correct then you have a very rare piece of hardware.
    – MacGuffin
    Dec 12, 2021 at 22:43
  • I've bought a cable with two blue usb heads, for usb-3 to usb-3 serial. I haven't tried it yet, any chance of damaging hardware if cable is not right? also can this communication be bi-directional or is it one-way?
    – d9ngle
    May 2, 2023 at 7:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .