We help IT Professionals succeed at work.

How to study USB Host source code implemented in Ubuntu distribution in my linux laptop?

naseeam
naseeam used Ask the Experts™
on
I have Ubuntu 18.04 LTS (64-bit) laptop.  I need to study USB Host implementation in linux distribution installed in my linux laptop?  Is it possible to open USB source code in vim editor?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

Commented:
the source code will be with a .c or a .cpp extension.
Are you trying to create a driver?

Author

Commented:
>> Are you trying to create a driver?
Yes

My end goal is to implement USB host in embedded system.  My evaluation embedded board comes with some default linux distribution.  When I connect usb stick to the board, it gets detected, something like Mass Storage Device Detected.
When I connect my usb device to the board, it doesn't get detected.  I believe the board is unable to identify a driver for my device because it's USB Class 0xFF, vendor defined.  So, I'll need to write a driver.

Before I write driver in embedded system, I need to learn USB Host implementation in my linux laptop running Ubuntu 18.04 LTS (64-bit).

How do I read the source code for USB Host implemented in linux distribution in my laptop?
David FavorFractional CTO
Distinguished Expert 2018

Commented:
Tips...

1) If your embedded system already contains USB hardware, then this hardware is likely compatible with existing Linux drivers.

2) Writing your own USB driver is similar to hunting horseflies with howitzers. Overkill.

3) Your best first step will be to contact the company producing your SBC (single board computer) + asking them how to resolve the problem.

4) Also, best to start with the latest version of Linux. You never mentioned what exact SBC you're using or the version of Linux installed. And whether you installed Linux or the SBC came preinstalled.

5) Be clear. If you study the Bionic (18.04) USB implementation, then be sure you have Bionic installed on your SBC to ensure code is the same.

6)  Is it possible to open USB source code in vim editor?

Yes. You'll have to look at USB implementation. My guess is this is a Kernel module, so you'll download the source for the Kernel module or might be a driver. USB might be slightly different than normal block devices. You'll just have to dig into the source to determine how to proceed.

Author

Commented:
>> If your embedded system already contains USB hardware, then this hardware is likely compatible with existing Linux drivers.
Yes, it already contains USB hardware but the test shows that it isn't compatible with existing Linux drivers.  Because it doesn't detect my device.  My device is USB Class Vendor Defined (0xFF).  Popular devices like usb stick are getting detected.

>> Your best first step will be to contact the company producing your SBC (single board computer) + asking them how to resolve the problem.
It looks like FAE(Field Application Engineer) can support me if it was a simpler USB device, such as HID(Human Interface Device).
They are talking about paid support.


>> Also, best to start with the latest version of Linux.
will do.  It'll take some time to build Yocto Project.

>> You never mentioned what exact SBC you're using or the version of Linux installed.
https://www.nxp.com/design/development-boards/i.mx-evaluation-and-development-boards/i.mx-8quadmax-multisensory-enablement-kit-mek:MCIMX8QM-CPU
It comes with Android Linux Distribution

>> Yes. You'll have to look at USB implementation. My guess is this is a Kernel module, so you'll download the source for the Kernel module or might be a driver.
Why download source code?  I want to look at kernel or driver source code that is in Ubuntu 18.04 distribution installed in my Linux laptop.  How do I do that?
linux distributions come with binaries. source code is generally not available unless you download it.

apt is normally configured with sources repositories as well so you can easily download kernel sources. if not, the deb-src lines are sometimes commented

the source code is also easily available online

and writing drivers is documented : this should get you started
https://kernel.readthedocs.io/en/sphinx-samples/writing_usb_driver.html

feel free to post back your own findings and possibly sample code. some of us will be interested

Author

Commented:
>> this should get you started
thank you for the good link

My Linux laptop has Ubuntu 18.04 LTS 64-bit distribution.  Is it possible to load USB Subsystem from these binaries into GNU Debugger (gdb) and step through the code?
i do not think so : running a driver in a debugger would probably crash the system soon enough.

you could use an emulator such as qemu and activate kernel debugging, but then, i do not develop drivers so there may be better tools i am not aware of to do the job.

Author

Commented:
Thank you!