#1601 closed enhancement (wontfix)

USB stack port from FreeBSD 8.0

Reported by: Sebastian Huber Owned by: Sebastian Huber
Priority: normal Milestone: 4.11
Component: unspecified Version: 4.10
Severity: minor Keywords:
Cc: joel.sherrill@… Blocked By:
Blocking:

Description

This is a port of parts of the FreeBSD USB stack released with version 8.0.
The code is based on trunk revision 209644.

HOWTO USE IT WITH YOUR BSP:

  1. Update to RTEMS 4.10 or CVS HEAD.
  1. Verify that a supported BSP works with you local installation

(ARM/lpc24xx_ncs_ram):

2.1. Install the ARM/lpc24xx_ncs_ram BSP:

${RTEMS_SOURCE}/configure --target=arm-rtems4.10 --enable-rtemsbsp=lpc24xx_ncs_ram --enable-posix

2.2. Install the media library (attached):

cd libmedia && make clean install

2.3. Install the USB library (attached):

cd libusb && make clean install

2.4. Build the demo application (attached):

cd usb-demo && make clean all

2.5. If you have problems with the steps above please report the errors.

  1. Build the demo application with your BSP: 3.1. Install the media library (attached):

cd libmedia && make clean install

3.2. Install the USB library (attached):

cd libusb && make clean install

3.3. If you have problems with steps 3.1 or 3.2 please report the errors.
3.4. Build the demo application (attached):

cd usb-demo && make clean all

3.5. You will likely encounter errors from the linker. Your BSP must support

the following linker set:

.rodata : {

start_set_modmetadata_set = .;
*(set_modmetadata_set);
stop_set_modmetadata_set = .;

}

Your BSP must implement the interrupt server API:

http://www.rtems.org/onlinedocs/doxygen/cpukit/html/group__rtems__interrupt__extension.html

Support files:

c/src/lib/libbsp/shared/include/irq-generic.h
c/src/lib/libbsp/shared/include/irq-info.h
c/src/lib/libbsp/shared/src/irq-generic.c
c/src/lib/libbsp/shared/src/irq-info.c
c/src/lib/libbsp/shared/src/irq-legacy.c
c/src/lib/libbsp/shared/src/irq-server.c
c/src/lib/libbsp/shared/src/irq-shell.c

  1. Add support for your USB controller Examples:

libusb/rtems/freebsd/dev/usb/controller/ehci_mpc83xx.c
libusb/rtems/freebsd/dev/usb/controller/ohci_lpc24xx.c
libusb/rtems/freebsd/dev/usb/controller/ohci_lpc32xx.c

IMPLEMENTATION NOTES:

There are different ways to port subsystems from FreeBSD to RTEMS. You can
replace locking and synchronization primitives from FreeBSD with dummy
functionality or provide a mapping to the RTEMS directives.

The current FreeBSD is capable to run on a SMP machine. If you run the FreeBSD
kernel within different RTEMS tasks this is like running FreeBSD on a SMP
machine. Thus if you provide a proper mapping of the locking and
synchronization primitives of FreeBSD to RTEMS you can use FreeBSD code without
much modification. The current TCP/IP port uses a different approach. It
introduces a giant lock outside the FreeBSD kernel and ensures that the FreeBSD
kernel will be executed through defined entry and exit points which are
protected by this giant lock (this is not the Giant lock, it is the network
semaphore).

With the current SMP aware FreeBSD system it is possible to avoid the
introduction of external giant locks and use only the native FreeBSD locking
and synchronization means. This requires that RTEMS provides some core APIs
from FreeBSD. The work with the USB stack from current FreeBSD showed that the
following APIs are important. You can obtain a man page for each API at

http://www.freebsd.org/cgi/man.cgi?query=signal&apropos=0&sektion=9&manpath=FreeBSD+8-current&format=html

Each name matches the man page entry. A proposed implementation with RTEMS
directives is given.

sx (Shared/exclusive locks):

Binary semaphores (this neglects the ability to allow shared access).

mutex (Mutual exclusion):

Binary semaphores (not recursive mutexes are not supported this way).

condvar (Condition variables):

POSIX condition variables with modifications (hack).

callout (Timer functions):

Timer server.

kthread, kproc (Tasks):

Tasks.

devfs (Device file system):

Dummy, IMFS or new implementation (currently dummy).

psignal (Signals):

TBD. Seems to be not needed.

poll, select:

TBD. Seems to be not needed.

rman (Resource management):

TBD. Seems to be not needed.

devclass, device, driver, make_dev (Device management):

Use FreeBSD implementation as far as possible. FreeBSD has a nice API
for dynamic device handling. It may be interesting for RTEMS to use
this API internally in the future.

bus_space, bus_dma (Bus and DMA access):

Likely BSP dependent. A default implementation for memory mapped
linear access is easy to provide. The current heap implementation
supports all properties demanded by bus_dma (including the boundary
constraint).

Interrupt handlers can use some kind of blocking calls in FreeBSD. We can use
an interrupt handler server for this purpose.

All files for the USB port are generated through a Python script from modified
FreeBSD sources. The generated files are placed into an own directory
hierarchy. The script changes include paths and adds a special RTEMS
configuration include file to the top of the include list. The header guards
are also modfied. The modifications done by the script are reversible. All
modifications of the original FreeBSD sources are within preprocessor sections
guarded by the rtems define. So you can update with a low chance for
conflicts. This is useful for synchronization with the FreeBSD development.
Suppose we used revision X for our USB port and want to synchronize with
revision Y. We can do this in the following steps:

  1. Check-out FreeBSD at revision X.
  2. Make the changes done for revision X (through a script).
  3. Update to revision Y.
  4. Resolve conflicts.
  5. Use script to generate USB port.

The FreeBSD kernel is not designed to be a library. It is incorporated as a
bunch of object files. The linker generates so called linker sets of special
objects (the BSP linker command file must support this). At runtime these sets
are evaluated for example to do the system startup. We cannot use this method
instead we have to use for example an explicit table instead of the linker set
to resolve all dependencies.

TODO:

o Tests for FreeBSD API implementations.
o Proper bus space implementation.
o More robust unmount(). This requires thorough file system changes.

Attachments (6)

libmedia.tar.bz2 (6.2 KB) - added by Sebastian Huber on Jul 5, 2010 at 9:34:07 AM.
Media library.
libusb.tar.bz2 (516.5 KB) - added by Sebastian Huber on Jul 5, 2010 at 9:34:43 AM.
USB library.
usb-demo.tar.bz2 (5.9 KB) - added by Sebastian Huber on Jul 5, 2010 at 9:35:10 AM.
Demo application.
usb-demo.tar_v1.bz2 (5.9 KB) - added by Sebastian Huber on Aug 13, 2010 at 11:57:35 AM.
Demo application.
libusb.tar_v1.bz2 (524.3 KB) - added by Sebastian Huber on Nov 19, 2010 at 6:59:06 AM.
USB library.
usb-demo.tar_v2.bz2 (5.7 KB) - added by Sebastian Huber on Nov 19, 2010 at 7:05:47 AM.
Demo application.

Download all attachments as: .zip

Change History (13)

Changed on Jul 5, 2010 at 9:34:07 AM by Sebastian Huber

Attachment: libmedia.tar.bz2 added

Media library.

Changed on Jul 5, 2010 at 9:34:43 AM by Sebastian Huber

Attachment: libusb.tar.bz2 added

USB library.

Changed on Jul 5, 2010 at 9:35:10 AM by Sebastian Huber

Attachment: usb-demo.tar.bz2 added

Demo application.

comment:1 Changed on Jul 5, 2010 at 9:35:27 AM by Sebastian Huber

Owner: changed from Joel Sherrill to Sebastian Huber

Changed on Aug 13, 2010 at 11:57:35 AM by Sebastian Huber

Attachment: usb-demo.tar_v1.bz2 added

Demo application.

comment:2 Changed on Aug 13, 2010 at 11:57:35 AM by Sebastian Huber

attachments.isobsolete: 01, 1

Changed on Nov 19, 2010 at 6:59:06 AM by Sebastian Huber

Attachment: libusb.tar_v1.bz2 added

USB library.

comment:3 Changed on Nov 19, 2010 at 6:59:06 AM by Sebastian Huber

attachments.isobsolete: 01

Changed on Nov 19, 2010 at 7:05:47 AM by Sebastian Huber

Attachment: usb-demo.tar_v2.bz2 added

Demo application.

comment:4 Changed on Nov 19, 2010 at 7:05:47 AM by Sebastian Huber

attachments.isobsolete: 01

comment:5 Changed on Mar 13, 2014 at 5:24:07 PM by Joel Sherrill

Cc: Joel Sherrill added

comment:6 Changed on Mar 14, 2014 at 7:12:15 AM by Sebastian Huber

Resolution: wontfix
Status: newclosed

USB support is now included in the libbsd:

http://git.rtems.org/rtems-libbsd

comment:7 Changed on Oct 10, 2017 at 6:35:44 AM by Sebastian Huber

Component: miscunspecified
Note: See TracTickets for help on using tickets.