SlideShare a Scribd company logo
1 of 35
Download to read offline
1Gary Bisson - ELC 2012
Useful USB Gadgets on Linux
February, 2012
Gary Bisson
Adeneo Embedded
Embedded Linux Conference 2012
2Gary Bisson - ELC 2012
Agenda
● Introduction to USB
● USB Gadget API
● Existing Gadgets
● Design your own Gadget
● Demo
● Conclusion
3Gary Bisson - ELC 2012
Who am I?
● Software engineer at Adeneo Embedded
(Bellevue, WA)
● Linux, Android
● Main activities:
– BSP adaptation
– Driver development
– System integration
4Gary Bisson - ELC 2012
Context and objectives
● General knowledge of the API
● Focused on USB not general driver development
● Nothing on the host side
● Case study
● Using a generic embedded device, see how we can
create a USB Gadget
● Show potential
● How to fulfill every need
5Gary Bisson - ELC 2012
Universal Serial Bus
● Industry standard developed in the mid-1990s
● Defines the cables, connectors and protocols used for
connection, communication and power supply
between computers and electronic devices
● 2 billion USB devices were sold each year (as of
2008)
6Gary Bisson - ELC 2012
Universal Serial Bus
● Benefits:
● Replace lots of old buses
● Automatic configuration
● Multiple speeds
● Reliable
● Limits:
● Distance
● Peer-To-Peer
● Broadcasting
7Gary Bisson - ELC 2012
Universal Serial Bus
● Architecture:
● Master-Slave protocol
● Up to 127 devices addressable
● Can be hot-plugged
● Identification to the host
● Supports high speeds
● Multifunction device possibility
8Gary Bisson - ELC 2012
Universal Serial Bus
● Description:
9Gary Bisson - ELC 2012
Universal Serial Bus
● Endpoints
● Source and Sink of data
● Uniquely identifiable
● Unique direction (except setup)
10Gary Bisson - ELC 2012
Universal Serial Bus
● 4 transfer types:
● Control
● Configuration and control information
● Interrupt
● Small quantities time-sensitive data
● Bulk
● Large quantities time-insensitive data
● Isochronous
● Real-time data at predictable bit rates
11Gary Bisson - ELC 2012
Typical Device Driver
● Device Firmware Driver
● Hardware specific routines
● USB interrupts/events
● Chapter 9
● Enumeration process
● Transfer data to upper layer
● USB Class Driver
● Defines the behavior
● Provides configuration
12Gary Bisson - ELC 2012
Gadget API
● Provides essential infrastructure
● Similar to Chapter 9 in typical USB device software
● Handles USB protocol specific requirements
● Flexible enough to expose more complex USB device
capabilities
13Gary Bisson - ELC 2012
Gadget API
Lower boundary:
● handling setup requests (ep0 protocol responses)
possibly including class-specific functionality
● returning configuration and string descriptors
● (re)setting configurations and interface altsettings,
including enabling and configuring endpoints
● handling life cycle events, such as managing bindings
to hardware, USB suspend/resume, remote wakeup,
and disconnection from the USB host
● managing IN and OUT transfers on all currently
enabled endpoints
14Gary Bisson - ELC 2012
Gadget API
Upper layer:
● user mode code, using generic (gadgetfs) or application
specific files in /dev
● networking subsystem (for network gadgets, like the
CDC Ethernet Model gadget driver)
● data capture drivers, perhaps video4Linux or a scanner
driver; or test and measurement hardware
● input subsystem (for HID gadgets)
● sound subsystem (for audio gadgets)
● file system (for PTP gadgets)
● block i/o subsystem (for usb-storage gadgets)
15Gary Bisson - ELC 2012
Gadget API vs. Linux-USB API
● Similarities
● Share common definitions for the standard USB messages,
structures and constants
● Use queues of request objects to package I/O buffers
● Both APIs bind and unbind drivers to devices
● Differences
● Control transfers
● Configuration management
=> Thanks to similarities, Gadget API supports OTG
16Gary Bisson - ELC 2012
Gadget API – Main structures
struct usb_gadget – represents a gadget device
➢ usb_gadget_ops – contains callbacks for hardware operations
struct usb_ep – device hardware management
➢ usb_ep_ops – contains callbacks for endpoints operations
struct usb_gadget_driver – device functions
management (bind, unbind, suspend etc...)
struct usb_request – USB transfers management
17Gary Bisson - ELC 2012
Gadget API – Main functions
General operations (usb_gadget_x()):
● probe_driver / unregister_driver
● set_selfpowered / clear_selfpowered
● vbus_connect / vbus_disconnect
● connect / disconnect
● frame_number
Endpoint operations (usb_ep_x()):
● autoconf / autoconf_reset
● enable / disable
● alloc / free
● queue / dequeue
● set_halt / clear_halt
● fifo_status / fifo_flush
Decriptor operations:
● usb_descriptor_fillbuf
● usb_gadget_config_buf
18Gary Bisson - ELC 2012
Gadget API
Driver life cycle:
● Register driver for a particular device controller
● Register gadget driver (bind)
● Hardware powered, enumeration starts
● Gadget driver returns descriptors (setup)
● Gadget driver returns interfaces configuration
● Do real work (data transfer) until disconnect
● Gadget driver unloaded (unbind)
19Gary Bisson - ELC 2012
Existing Gadgets
● Ethernet
● Enumerate to the host as an Ethernet device
● Can easily be bridging, routing, or firewalling
access to other networks
● Interoperability with hosts running Linux, MS-
Windows among others
● Possibility to set parameters such as MAC address,
IP configuration or DHCP use thanks to the
bootargs if using a boot firmware like U-Boot
20Gary Bisson - ELC 2012
Existing Gadgets
● GadgetFS
● Provides User-Mode API
● Each endpoint presented as single I/O file
descriptor
● Normal read() and write() calls
● Async I/O supported
● Configuration and descriptors written into files
Note that user mode gadget drivers do not necesarily need to
be licensed according to the GPL.
21Gary Bisson - ELC 2012
Existing Gadgets
● File-backed Storage
● Implements the USB Mass Storage Class
● Up to 8 disk drives can be set
● Store file or block device is called the “backing
storage”
● Backing storage requires preparation
– If a file is used, it must created with its desired size before
launching the driver
– If a block device, it must match host reaquirements (DOS
partition for MS-Windows host)
● The backing storage must not change while FBS is
running, only the host should access it
22Gary Bisson - ELC 2012
Existing Gadgets
● Webcam
● Acts as a composite USB Audio and Video Class
device
● Provides a userspace API to process UVC control
requests and stream video data
● Serial Gadget
● Useful for TTY style operation
● Supports a CDC-ACM module option
23Gary Bisson - ELC 2012
Existing Gadgets
● MIDI
● Exposes an ALSA MIDI interface
● Both recording and playback support
● GadgetZero
● Useful to test device controller driver
● Helps verify that the driver stack pass USB-IF (for
USB branding)
● On the host side, useful to test USB stack
24Gary Bisson - ELC 2012
Design your own Gadget
● 3 main operations to consider
● Hardware
● Functional
● Endpoints
25Gary Bisson - ELC 2012
Design your own Gadget
● First implement the register/unregister functions
● usb_gadget_probe_driver
– Resgistration of the usb_gadget_driver
– Responsible for binding the gadget driver and powering up
the device
● usb_gadget_unregister_driver
– Responsible for unbinding the gadget from the functional
driver and powering down the device
● Then define callbacks hardware related
● Fill usb_ep_ops and usb_gadget_ops
● Not necessary to support all functions
26Gary Bisson - ELC 2012
Design your own Gadget
● Implement the control request handles (ep0)
● Gadget driver handles only a part of it
● The rest is routed to the class driver
27Gary Bisson - ELC 2012
Design your own Gadget
● Power Management requests
● Comes from the PDC to the Gadget
● The Gadget must pass the events to the class driver
● Once enumeration is done, class driver requests
usb_request structure for IN/OUT transfers
● Gadget receives data in interrupt routine (OUT)
– Only when the expected amount is received the Gadget
calls the complete function
● Gadget sends data to the PDC (IN)
– Wait send completion to inform the class driver
28Gary Bisson - ELC 2012
Design your own Gadget
29Gary Bisson - ELC 2012
Demo: Hardware
BeagleBoard xM
● ARM™ Cortex™-A8 1000 MHz
● USB connectivity:
● 4 host ports
● 1 OTG port (used as device)
30Gary Bisson - ELC 2012
Demo: Software
● Bootloader
● U-boot 2011.12 r4
● Kernel
● 3.0.17 r115c
● Root filesystem
● Console image
– Custom recipe (lighttpd)
● Additional modules
31Gary Bisson - ELC 2012
Conclusion
● Easy to implement
● Hardware independent
● Scalability
● Large panel of existing gadgets
● Awareness of limitations
32Gary Bisson - ELC 2012
Questions?
33Gary Bisson - ELC 2012
Appendix: Files
The files used for this experiment should be
attached with the presentation
● Rootfs:
● Custom recipe provided if rebuild is necessary
● Additional modules:
● Instructions to recompile them
● Demo script
● Lighttpd configuration file
34Gary Bisson - ELC 2012
Appendix: References
● Linux-USB Gadget API Framework: General
presentation.
● USB Gadget API for Linux: Full description of the API.
● Essential Linux Device Drivers (Sreekrishnan
Venkateswaran) : General device driver book
containing a useful USB section.
● Bootstrap Yourself with Linux-USB Stack (Rajaram
Regupathy): Very detailed and easy-to-read book about
Linux-USB.
Useful USB Gadgets on Linux

More Related Content

What's hot

Linux internal
Linux internalLinux internal
Linux internalmcganesh
 
Build your own embedded linux distributions by yocto project
Build your own embedded linux distributions by yocto projectBuild your own embedded linux distributions by yocto project
Build your own embedded linux distributions by yocto projectYen-Chin Lee
 
Android Security Internals
Android Security InternalsAndroid Security Internals
Android Security InternalsOpersys inc.
 
Embedded Android Workshop
Embedded Android WorkshopEmbedded Android Workshop
Embedded Android WorkshopOpersys inc.
 
Process and Threads in Linux - PPT
Process and Threads in Linux - PPTProcess and Threads in Linux - PPT
Process and Threads in Linux - PPTQUONTRASOLUTIONS
 
Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013Opersys inc.
 
Course 102: Lecture 4: Using Wild Cards
Course 102: Lecture 4: Using Wild CardsCourse 102: Lecture 4: Using Wild Cards
Course 102: Lecture 4: Using Wild CardsAhmed El-Arabawy
 
Course 102: Lecture 16: Process Management (Part 2)
Course 102: Lecture 16: Process Management (Part 2) Course 102: Lecture 16: Process Management (Part 2)
Course 102: Lecture 16: Process Management (Part 2) Ahmed El-Arabawy
 
Androidへのdebianインストール奮闘記
Androidへのdebianインストール奮闘記Androidへのdebianインストール奮闘記
Androidへのdebianインストール奮闘記Tomoya Kawanishi
 
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Opersys inc.
 
Q4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsQ4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsLinaro
 
U-boot and Android Verified Boot 2.0
U-boot and Android Verified Boot 2.0U-boot and Android Verified Boot 2.0
U-boot and Android Verified Boot 2.0GlobalLogic Ukraine
 
Building your own embedded system with Yocto
Building your own embedded system with YoctoBuilding your own embedded system with Yocto
Building your own embedded system with Yoctommeisenzahl
 
Android Treble: Blessing or Trouble?
Android Treble: Blessing or Trouble?Android Treble: Blessing or Trouble?
Android Treble: Blessing or Trouble?Opersys inc.
 

What's hot (20)

Linux internal
Linux internalLinux internal
Linux internal
 
Build your own embedded linux distributions by yocto project
Build your own embedded linux distributions by yocto projectBuild your own embedded linux distributions by yocto project
Build your own embedded linux distributions by yocto project
 
Linux Internals - Part II
Linux Internals - Part IILinux Internals - Part II
Linux Internals - Part II
 
Logging system of Android
Logging system of AndroidLogging system of Android
Logging system of Android
 
Android Security Internals
Android Security InternalsAndroid Security Internals
Android Security Internals
 
Android Internals
Android InternalsAndroid Internals
Android Internals
 
Advanced C
Advanced C Advanced C
Advanced C
 
Embedded Android Workshop
Embedded Android WorkshopEmbedded Android Workshop
Embedded Android Workshop
 
Process and Threads in Linux - PPT
Process and Threads in Linux - PPTProcess and Threads in Linux - PPT
Process and Threads in Linux - PPT
 
Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013
 
Android Things : Building Embedded Devices
Android Things : Building Embedded DevicesAndroid Things : Building Embedded Devices
Android Things : Building Embedded Devices
 
Course 102: Lecture 4: Using Wild Cards
Course 102: Lecture 4: Using Wild CardsCourse 102: Lecture 4: Using Wild Cards
Course 102: Lecture 4: Using Wild Cards
 
Course 102: Lecture 16: Process Management (Part 2)
Course 102: Lecture 16: Process Management (Part 2) Course 102: Lecture 16: Process Management (Part 2)
Course 102: Lecture 16: Process Management (Part 2)
 
Androidへのdebianインストール奮闘記
Androidへのdebianインストール奮闘記Androidへのdebianインストール奮闘記
Androidへのdebianインストール奮闘記
 
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
 
Mesa and Its Debugging
Mesa and Its DebuggingMesa and Its Debugging
Mesa and Its Debugging
 
Q4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsQ4.11: Porting Android to new Platforms
Q4.11: Porting Android to new Platforms
 
U-boot and Android Verified Boot 2.0
U-boot and Android Verified Boot 2.0U-boot and Android Verified Boot 2.0
U-boot and Android Verified Boot 2.0
 
Building your own embedded system with Yocto
Building your own embedded system with YoctoBuilding your own embedded system with Yocto
Building your own embedded system with Yocto
 
Android Treble: Blessing or Trouble?
Android Treble: Blessing or Trouble?Android Treble: Blessing or Trouble?
Android Treble: Blessing or Trouble?
 

Viewers also liked

Viewers also liked (10)

Linux Usb overview
Linux Usb  overviewLinux Usb  overview
Linux Usb overview
 
Headless Android Strikes Back!
Headless Android Strikes Back!Headless Android Strikes Back!
Headless Android Strikes Back!
 
Leveraging the Android Open Accessory Protocol
Leveraging the Android Open Accessory ProtocolLeveraging the Android Open Accessory Protocol
Leveraging the Android Open Accessory Protocol
 
Quickboot on i.MX6
Quickboot on i.MX6Quickboot on i.MX6
Quickboot on i.MX6
 
Android OTA updates
Android OTA updatesAndroid OTA updates
Android OTA updates
 
Accessing Hardware on Android
Accessing Hardware on AndroidAccessing Hardware on Android
Accessing Hardware on Android
 
Embedded Android : System Development - Part III
Embedded Android : System Development - Part IIIEmbedded Android : System Development - Part III
Embedded Android : System Development - Part III
 
Embedded Android : System Development - Part IV
Embedded Android : System Development - Part IVEmbedded Android : System Development - Part IV
Embedded Android : System Development - Part IV
 
Embedded Android : System Development - Part I
Embedded Android : System Development - Part IEmbedded Android : System Development - Part I
Embedded Android : System Development - Part I
 
USB Drivers
USB DriversUSB Drivers
USB Drivers
 

Similar to Useful USB Gadgets on Linux

Rapid SPi Device Driver Development over USB
Rapid SPi Device Driver Development over USBRapid SPi Device Driver Development over USB
Rapid SPi Device Driver Development over USBSamsung Open Source Group
 
Embedded Fest 2019. Игорь Опанюк. Das U-boot v2019: a look under the hood
Embedded Fest 2019. Игорь Опанюк. Das U-boot v2019: a look under the hoodEmbedded Fest 2019. Игорь Опанюк. Das U-boot v2019: a look under the hood
Embedded Fest 2019. Игорь Опанюк. Das U-boot v2019: a look under the hoodEmbeddedFest
 
Android Open Accessory Protocol - Turn Your Linux machine as ADK
Android Open Accessory Protocol - Turn Your Linux machine as ADKAndroid Open Accessory Protocol - Turn Your Linux machine as ADK
Android Open Accessory Protocol - Turn Your Linux machine as ADKRajesh Sola
 
aoa-adk-osidays-rajeshsola
aoa-adk-osidays-rajeshsolaaoa-adk-osidays-rajeshsola
aoa-adk-osidays-rajeshsolaRajesh Sola
 
The Deck by Phil Polstra GrrCON2012
The Deck by Phil Polstra GrrCON2012The Deck by Phil Polstra GrrCON2012
The Deck by Phil Polstra GrrCON2012Philip Polstra
 
Open Source Firmware - FrOSCon 2019
Open Source Firmware - FrOSCon 2019Open Source Firmware - FrOSCon 2019
Open Source Firmware - FrOSCon 2019Daniel Maslowski
 
Droidcon 2013 France - Android Platform Anatomy
Droidcon 2013 France - Android Platform AnatomyDroidcon 2013 France - Android Platform Anatomy
Droidcon 2013 France - Android Platform AnatomyBenjamin Zores
 
Elc Europe 2020 : u-boot- porting and maintaining a bootloader for a multimed...
Elc Europe 2020 : u-boot- porting and maintaining a bootloader for a multimed...Elc Europe 2020 : u-boot- porting and maintaining a bootloader for a multimed...
Elc Europe 2020 : u-boot- porting and maintaining a bootloader for a multimed...Neil Armstrong
 
Robot controlled car using Wireless Module
 Robot controlled car using Wireless Module Robot controlled car using Wireless Module
Robot controlled car using Wireless Moduleshreyaseksambe
 
XPDDS17: Keynote: Shared Coprocessor Framework on ARM - Oleksandr Andrushchen...
XPDDS17: Keynote: Shared Coprocessor Framework on ARM - Oleksandr Andrushchen...XPDDS17: Keynote: Shared Coprocessor Framework on ARM - Oleksandr Andrushchen...
XPDDS17: Keynote: Shared Coprocessor Framework on ARM - Oleksandr Andrushchen...The Linux Foundation
 
Embedded Linux Systems Basics
Embedded Linux Systems BasicsEmbedded Linux Systems Basics
Embedded Linux Systems BasicsMax Henery
 
Hacking and Forensics on the Go - 44CON 2012
Hacking and Forensics on the Go - 44CON 2012Hacking and Forensics on the Go - 44CON 2012
Hacking and Forensics on the Go - 44CON 201244CON
 
ITE v5.0 - Chapter 7
ITE v5.0 - Chapter 7ITE v5.0 - Chapter 7
ITE v5.0 - Chapter 7Irsandi Hasan
 
[HES2013] Hacking apple accessories to pown iDevices – Wake up Neo! Your phon...
[HES2013] Hacking apple accessories to pown iDevices – Wake up Neo! Your phon...[HES2013] Hacking apple accessories to pown iDevices – Wake up Neo! Your phon...
[HES2013] Hacking apple accessories to pown iDevices – Wake up Neo! Your phon...Hackito Ergo Sum
 
A War Story: Porting Android 4.0 to a Custom Board (ELCE 2012)
A War Story: Porting Android 4.0 to a Custom Board (ELCE 2012)A War Story: Porting Android 4.0 to a Custom Board (ELCE 2012)
A War Story: Porting Android 4.0 to a Custom Board (ELCE 2012)Matthias Brugger
 

Similar to Useful USB Gadgets on Linux (20)

Rapid SPi Device Driver Development over USB
Rapid SPi Device Driver Development over USBRapid SPi Device Driver Development over USB
Rapid SPi Device Driver Development over USB
 
Embedded Fest 2019. Игорь Опанюк. Das U-boot v2019: a look under the hood
Embedded Fest 2019. Игорь Опанюк. Das U-boot v2019: a look under the hoodEmbedded Fest 2019. Игорь Опанюк. Das U-boot v2019: a look under the hood
Embedded Fest 2019. Игорь Опанюк. Das U-boot v2019: a look under the hood
 
How to Hack Edison
How to Hack EdisonHow to Hack Edison
How to Hack Edison
 
Android Open Accessory Protocol - Turn Your Linux machine as ADK
Android Open Accessory Protocol - Turn Your Linux machine as ADKAndroid Open Accessory Protocol - Turn Your Linux machine as ADK
Android Open Accessory Protocol - Turn Your Linux machine as ADK
 
aoa-adk-osidays-rajeshsola
aoa-adk-osidays-rajeshsolaaoa-adk-osidays-rajeshsola
aoa-adk-osidays-rajeshsola
 
The Deck by Phil Polstra GrrCON2012
The Deck by Phil Polstra GrrCON2012The Deck by Phil Polstra GrrCON2012
The Deck by Phil Polstra GrrCON2012
 
Open Source Firmware - FrOSCon 2019
Open Source Firmware - FrOSCon 2019Open Source Firmware - FrOSCon 2019
Open Source Firmware - FrOSCon 2019
 
Droidcon 2013 France - Android Platform Anatomy
Droidcon 2013 France - Android Platform AnatomyDroidcon 2013 France - Android Platform Anatomy
Droidcon 2013 France - Android Platform Anatomy
 
Elc Europe 2020 : u-boot- porting and maintaining a bootloader for a multimed...
Elc Europe 2020 : u-boot- porting and maintaining a bootloader for a multimed...Elc Europe 2020 : u-boot- porting and maintaining a bootloader for a multimed...
Elc Europe 2020 : u-boot- porting and maintaining a bootloader for a multimed...
 
Hardware hacking
Hardware hackingHardware hacking
Hardware hacking
 
Robot controlled car using Wireless Module
 Robot controlled car using Wireless Module Robot controlled car using Wireless Module
Robot controlled car using Wireless Module
 
XPDDS17: Keynote: Shared Coprocessor Framework on ARM - Oleksandr Andrushchen...
XPDDS17: Keynote: Shared Coprocessor Framework on ARM - Oleksandr Andrushchen...XPDDS17: Keynote: Shared Coprocessor Framework on ARM - Oleksandr Andrushchen...
XPDDS17: Keynote: Shared Coprocessor Framework on ARM - Oleksandr Andrushchen...
 
Introduction and course Details of Embedded Linux Platform Developer Training
Introduction and course Details of Embedded Linux Platform Developer TrainingIntroduction and course Details of Embedded Linux Platform Developer Training
Introduction and course Details of Embedded Linux Platform Developer Training
 
Android presentation
Android presentationAndroid presentation
Android presentation
 
Embedded Linux Systems Basics
Embedded Linux Systems BasicsEmbedded Linux Systems Basics
Embedded Linux Systems Basics
 
Polstra 44con2012
Polstra 44con2012Polstra 44con2012
Polstra 44con2012
 
Hacking and Forensics on the Go - 44CON 2012
Hacking and Forensics on the Go - 44CON 2012Hacking and Forensics on the Go - 44CON 2012
Hacking and Forensics on the Go - 44CON 2012
 
ITE v5.0 - Chapter 7
ITE v5.0 - Chapter 7ITE v5.0 - Chapter 7
ITE v5.0 - Chapter 7
 
[HES2013] Hacking apple accessories to pown iDevices – Wake up Neo! Your phon...
[HES2013] Hacking apple accessories to pown iDevices – Wake up Neo! Your phon...[HES2013] Hacking apple accessories to pown iDevices – Wake up Neo! Your phon...
[HES2013] Hacking apple accessories to pown iDevices – Wake up Neo! Your phon...
 
A War Story: Porting Android 4.0 to a Custom Board (ELCE 2012)
A War Story: Porting Android 4.0 to a Custom Board (ELCE 2012)A War Story: Porting Android 4.0 to a Custom Board (ELCE 2012)
A War Story: Porting Android 4.0 to a Custom Board (ELCE 2012)
 

Recently uploaded

Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGSIVASHANKAR N
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 

Recently uploaded (20)

Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 

Useful USB Gadgets on Linux

  • 1. 1Gary Bisson - ELC 2012 Useful USB Gadgets on Linux February, 2012 Gary Bisson Adeneo Embedded Embedded Linux Conference 2012
  • 2. 2Gary Bisson - ELC 2012 Agenda ● Introduction to USB ● USB Gadget API ● Existing Gadgets ● Design your own Gadget ● Demo ● Conclusion
  • 3. 3Gary Bisson - ELC 2012 Who am I? ● Software engineer at Adeneo Embedded (Bellevue, WA) ● Linux, Android ● Main activities: – BSP adaptation – Driver development – System integration
  • 4. 4Gary Bisson - ELC 2012 Context and objectives ● General knowledge of the API ● Focused on USB not general driver development ● Nothing on the host side ● Case study ● Using a generic embedded device, see how we can create a USB Gadget ● Show potential ● How to fulfill every need
  • 5. 5Gary Bisson - ELC 2012 Universal Serial Bus ● Industry standard developed in the mid-1990s ● Defines the cables, connectors and protocols used for connection, communication and power supply between computers and electronic devices ● 2 billion USB devices were sold each year (as of 2008)
  • 6. 6Gary Bisson - ELC 2012 Universal Serial Bus ● Benefits: ● Replace lots of old buses ● Automatic configuration ● Multiple speeds ● Reliable ● Limits: ● Distance ● Peer-To-Peer ● Broadcasting
  • 7. 7Gary Bisson - ELC 2012 Universal Serial Bus ● Architecture: ● Master-Slave protocol ● Up to 127 devices addressable ● Can be hot-plugged ● Identification to the host ● Supports high speeds ● Multifunction device possibility
  • 8. 8Gary Bisson - ELC 2012 Universal Serial Bus ● Description:
  • 9. 9Gary Bisson - ELC 2012 Universal Serial Bus ● Endpoints ● Source and Sink of data ● Uniquely identifiable ● Unique direction (except setup)
  • 10. 10Gary Bisson - ELC 2012 Universal Serial Bus ● 4 transfer types: ● Control ● Configuration and control information ● Interrupt ● Small quantities time-sensitive data ● Bulk ● Large quantities time-insensitive data ● Isochronous ● Real-time data at predictable bit rates
  • 11. 11Gary Bisson - ELC 2012 Typical Device Driver ● Device Firmware Driver ● Hardware specific routines ● USB interrupts/events ● Chapter 9 ● Enumeration process ● Transfer data to upper layer ● USB Class Driver ● Defines the behavior ● Provides configuration
  • 12. 12Gary Bisson - ELC 2012 Gadget API ● Provides essential infrastructure ● Similar to Chapter 9 in typical USB device software ● Handles USB protocol specific requirements ● Flexible enough to expose more complex USB device capabilities
  • 13. 13Gary Bisson - ELC 2012 Gadget API Lower boundary: ● handling setup requests (ep0 protocol responses) possibly including class-specific functionality ● returning configuration and string descriptors ● (re)setting configurations and interface altsettings, including enabling and configuring endpoints ● handling life cycle events, such as managing bindings to hardware, USB suspend/resume, remote wakeup, and disconnection from the USB host ● managing IN and OUT transfers on all currently enabled endpoints
  • 14. 14Gary Bisson - ELC 2012 Gadget API Upper layer: ● user mode code, using generic (gadgetfs) or application specific files in /dev ● networking subsystem (for network gadgets, like the CDC Ethernet Model gadget driver) ● data capture drivers, perhaps video4Linux or a scanner driver; or test and measurement hardware ● input subsystem (for HID gadgets) ● sound subsystem (for audio gadgets) ● file system (for PTP gadgets) ● block i/o subsystem (for usb-storage gadgets)
  • 15. 15Gary Bisson - ELC 2012 Gadget API vs. Linux-USB API ● Similarities ● Share common definitions for the standard USB messages, structures and constants ● Use queues of request objects to package I/O buffers ● Both APIs bind and unbind drivers to devices ● Differences ● Control transfers ● Configuration management => Thanks to similarities, Gadget API supports OTG
  • 16. 16Gary Bisson - ELC 2012 Gadget API – Main structures struct usb_gadget – represents a gadget device ➢ usb_gadget_ops – contains callbacks for hardware operations struct usb_ep – device hardware management ➢ usb_ep_ops – contains callbacks for endpoints operations struct usb_gadget_driver – device functions management (bind, unbind, suspend etc...) struct usb_request – USB transfers management
  • 17. 17Gary Bisson - ELC 2012 Gadget API – Main functions General operations (usb_gadget_x()): ● probe_driver / unregister_driver ● set_selfpowered / clear_selfpowered ● vbus_connect / vbus_disconnect ● connect / disconnect ● frame_number Endpoint operations (usb_ep_x()): ● autoconf / autoconf_reset ● enable / disable ● alloc / free ● queue / dequeue ● set_halt / clear_halt ● fifo_status / fifo_flush Decriptor operations: ● usb_descriptor_fillbuf ● usb_gadget_config_buf
  • 18. 18Gary Bisson - ELC 2012 Gadget API Driver life cycle: ● Register driver for a particular device controller ● Register gadget driver (bind) ● Hardware powered, enumeration starts ● Gadget driver returns descriptors (setup) ● Gadget driver returns interfaces configuration ● Do real work (data transfer) until disconnect ● Gadget driver unloaded (unbind)
  • 19. 19Gary Bisson - ELC 2012 Existing Gadgets ● Ethernet ● Enumerate to the host as an Ethernet device ● Can easily be bridging, routing, or firewalling access to other networks ● Interoperability with hosts running Linux, MS- Windows among others ● Possibility to set parameters such as MAC address, IP configuration or DHCP use thanks to the bootargs if using a boot firmware like U-Boot
  • 20. 20Gary Bisson - ELC 2012 Existing Gadgets ● GadgetFS ● Provides User-Mode API ● Each endpoint presented as single I/O file descriptor ● Normal read() and write() calls ● Async I/O supported ● Configuration and descriptors written into files Note that user mode gadget drivers do not necesarily need to be licensed according to the GPL.
  • 21. 21Gary Bisson - ELC 2012 Existing Gadgets ● File-backed Storage ● Implements the USB Mass Storage Class ● Up to 8 disk drives can be set ● Store file or block device is called the “backing storage” ● Backing storage requires preparation – If a file is used, it must created with its desired size before launching the driver – If a block device, it must match host reaquirements (DOS partition for MS-Windows host) ● The backing storage must not change while FBS is running, only the host should access it
  • 22. 22Gary Bisson - ELC 2012 Existing Gadgets ● Webcam ● Acts as a composite USB Audio and Video Class device ● Provides a userspace API to process UVC control requests and stream video data ● Serial Gadget ● Useful for TTY style operation ● Supports a CDC-ACM module option
  • 23. 23Gary Bisson - ELC 2012 Existing Gadgets ● MIDI ● Exposes an ALSA MIDI interface ● Both recording and playback support ● GadgetZero ● Useful to test device controller driver ● Helps verify that the driver stack pass USB-IF (for USB branding) ● On the host side, useful to test USB stack
  • 24. 24Gary Bisson - ELC 2012 Design your own Gadget ● 3 main operations to consider ● Hardware ● Functional ● Endpoints
  • 25. 25Gary Bisson - ELC 2012 Design your own Gadget ● First implement the register/unregister functions ● usb_gadget_probe_driver – Resgistration of the usb_gadget_driver – Responsible for binding the gadget driver and powering up the device ● usb_gadget_unregister_driver – Responsible for unbinding the gadget from the functional driver and powering down the device ● Then define callbacks hardware related ● Fill usb_ep_ops and usb_gadget_ops ● Not necessary to support all functions
  • 26. 26Gary Bisson - ELC 2012 Design your own Gadget ● Implement the control request handles (ep0) ● Gadget driver handles only a part of it ● The rest is routed to the class driver
  • 27. 27Gary Bisson - ELC 2012 Design your own Gadget ● Power Management requests ● Comes from the PDC to the Gadget ● The Gadget must pass the events to the class driver ● Once enumeration is done, class driver requests usb_request structure for IN/OUT transfers ● Gadget receives data in interrupt routine (OUT) – Only when the expected amount is received the Gadget calls the complete function ● Gadget sends data to the PDC (IN) – Wait send completion to inform the class driver
  • 28. 28Gary Bisson - ELC 2012 Design your own Gadget
  • 29. 29Gary Bisson - ELC 2012 Demo: Hardware BeagleBoard xM ● ARM™ Cortex™-A8 1000 MHz ● USB connectivity: ● 4 host ports ● 1 OTG port (used as device)
  • 30. 30Gary Bisson - ELC 2012 Demo: Software ● Bootloader ● U-boot 2011.12 r4 ● Kernel ● 3.0.17 r115c ● Root filesystem ● Console image – Custom recipe (lighttpd) ● Additional modules
  • 31. 31Gary Bisson - ELC 2012 Conclusion ● Easy to implement ● Hardware independent ● Scalability ● Large panel of existing gadgets ● Awareness of limitations
  • 32. 32Gary Bisson - ELC 2012 Questions?
  • 33. 33Gary Bisson - ELC 2012 Appendix: Files The files used for this experiment should be attached with the presentation ● Rootfs: ● Custom recipe provided if rebuild is necessary ● Additional modules: ● Instructions to recompile them ● Demo script ● Lighttpd configuration file
  • 34. 34Gary Bisson - ELC 2012 Appendix: References ● Linux-USB Gadget API Framework: General presentation. ● USB Gadget API for Linux: Full description of the API. ● Essential Linux Device Drivers (Sreekrishnan Venkateswaran) : General device driver book containing a useful USB section. ● Bootstrap Yourself with Linux-USB Stack (Rajaram Regupathy): Very detailed and easy-to-read book about Linux-USB.