DornerWorks

Use FreeRTOS to Build a Lightweight Xen Virtual Machine

Posted on April 25, 2019 by Jeff Kubascik

What is FreeRTOS?

The FreeRTOS kernel is a market leading real-time operating system for embedded systems. As embedded applications grow in complexity, there is a growing need for a lightweight kernel capable of task scheduling. Task scheduling enables developers to segment their embedded applications into independent threads of execution. This reduces the complexity of the design and improves CPU utilization for applications dealing with many asynchronous inputs and outputs.

DornerWorks engineer Anna Little works with the Xilinx Zynq UltraScale+ MPSoC, which can run FreeRTOS alongside other operating systems using the Virtuosity Hypervisor.

Xilinx already provides support for FreeRTOS as part of the Xilinx Software Development Kit (XSDK). This integration makes developing FreeRTOS applications fast and easy for the Zynq® UltraScale+™ MPSoC, Zynq-7000 SoCs, and MicroBlaze™ soft-core microprocessor.

Why FreeRTOS?

The FreeRTOS kernel is simple, small, and lightweight. This enables embedded applications requiring a small memory footprint or needing low latency, deterministic responses to asynchronous interrupts. FreeRTOS provides a rich set of APIs to control executions of threads, such as semaphores, mutexes, queues, and software timers, to help developers design their applications.

Best of all, the FreeRTOS kernel is free to use for commercial applications, as the source code is provided under the permissive MIT license. There are no restrictive licensing fees or royalties to worry about. You own the code and are free to modify it.

FreeRTOS makes a great addition to the Xen hypervisor on the Zynq UltraScale+ MPSoC. It enables developers to develop small, low-level programs with direct access to hardware, perfect for real-time applications while providing the tools to take full advantage of the capable Arm® Cortex®-A53 processor.

Unfortunately, the FreeRTOS library in XSDK does not work with Xen out of the box. However, DornerWorks has developed a seamless solution that plugs directly into XSDK.

Enhancing FreeRTOS in the Xilinx Software Development Kit

To fill this gap, DornerWorks has developed a 3rd party repository for XSDK. The repository introduces a “Hypervisor Guest” option in the BSP project configuration menu that makes modifications to the Xilinx FreeRTOS library for Xen. This results in a seamless development flow, allowing you to build the application binary directly from the XSDK integrated development environment.

The plugin also adds a “libxen” library to XSDK. This library augments the hypervisor support by providing additional APIs for the following Xen features:

Figure 1. FreeRTOS in XSDK

Xen Virtual Console: Print to and read from the Xen console, eliminating the need for a dedicated serial port for the application.
XenStore: A standardized database for sharing configuration between virtual machines, commonly used with paravirtualized drivers.
Event Channels: Interface for sending and receiving asynchronous interrupts across virtual machines.
Grant Tables: Mechanism to share memory dynamically with other virtual machines.

Additionally, DornerWorks has developed a solution to share I/O pins of a GPIO controller across virtual machines. This virtual GPIO interface consists of a backend driver and a frontend driver. The backend driver resides in the Linux control domain, dom0, and works directly with the Linux GPIO subsystem. This results in a driver that is agnostic to the GPIO controller hardware, relying on existing GPIO drivers in Linux for the low-level control. The frontend driver relies on the “libxen” library to communicate with the backend driver and is available for Linux and FreeRTOS virtual machines.

The FreeRTOS kernel makes a great complement to the Zynq UltraScale+ MPSoC and Xen ecosystem, enabling you to build lightweight and deterministic applications, perfect for embedded systems. However, you cannot take advantage of it unless you take the first step and schedule a meeting with DornerWorks.

Jeff Kubascik
by Jeff Kubascik
Embedded Engineer
Jeff Kubascik is an embedded engineer at DornerWorks.