The end of the phase one of GSoC 2021 is here. This report summarizes the work I have done in the phase one.

Intro:

As per the proposed plan for the phase one I have imported the USB Template driver to the RTEMS LibBSD. As the first device template the CDC Ethernet template is imported and it is enabled for the Beagle BSP.

Background:

LibBSD is the new networking stack of RTEMS starting from RTEMS 5. It gets the name from FreeBSD as the stack is ported from FreeBSD. LibBSD has more than just the networking code such as WiFi, USB, Mass storage and etc.

Currently RTEMS LibBSD doesn’t have a documentation in the RTEMS Documentation Project. I have initiated a small effort to start a documentation for LibBSD by documenting the USB Template driver and adding a quick start guide. You can view the current progress in my repo.

Implementation:

The driver is imported and configured in 4 steps.

Commit 1 : Import The Code

The driver is in sys/dev/usb/template. Import the template driver and the ethernet template. The freebsd-to-rtems.py script is used to import the files. Instructions are given here. (You need to apply the changes made to libbsd.py file in commit 4 to import the code.)

NOTE: The implementation order slightly differs here from the commit order to prevent having a commit that doesn’t build.

Commit 2 : Configure

We are only importing the Ethernet template for now. So we should exclude the reference of the other templates in the driver. We can use the __rtems__ macro and add a preprocessor guard for this. Refer the Rules for Modifying FreeBSD Source.

The correct template is initialized based on the value of hw.usb.template sysctl variable. The Each template has a value associated with it. For CDC Ethernet the value is 1. Temlate Values

You can learn more about the template initialization here.

The usb_devices.c has the function calls for initializing the hw.usb.template sysctl varible. You might have noticed the RTEMS_BSD_MODULE_DEV_USB_TEMPLATE macro. The waf build system genarates a module.h header which has definitions for the enabled modules. We use that macro to exclude those functions when the usb template module is disabled.

Commit 3 : Create the Module and Add it to the Buildset

Still the LibBSD is not aware of the code we have imported. The libbsd.py is used to keep track of the FreeBSD sources and to manage them. We should create the module dev_usb_template and add the module to the buildset. If you don’t add the module to the buildset, the files won’t build.

The Waf wscript uses the libbsd.py to generate the build.

Commit 4 : Enable the Module in Beagle

Now we have the files imported and ready to be built. Our target is to run the drivers on the Beaglebone Black. So we’ll include the driver in the Beagle BSP.

Documentation: Github Repo

Conclusion:

Work Env

The driver is imported from FreeBSD 13 to the current rtems-libbsd master. The driver was tested on the Beaglebone Black with a RPi 3B+ running Rasbian Buster (kernel: 5.10.17-v7+) as the host.

RPi dmesg: dmesg

USB Ethernet interface showing up in the RPi: USB Ethernet Interface

Next I’m planning to do a TTCP Benchmark for the CDC Ethernet.

The phase two of the project is to add USB Serial and Mass storage support.