Introduction to Ethernet TSN on Embedded Linux
April 06, 2021
Part 1: Basics of Embedded Linux
This article series takes an in-depth look at the emerging deterministic Ethernet standard, Ethernet Time-Sensitive Networking (TSN), and how it can be implemented effectively on a variety of Linux-based embedded systems. Using a range of low-cost, off-the-shelf development board hardware, we will demonstrate how to configure a Raspberry Pi and MediaTek LinkIt Smart board for our use case and then use the real-time packet technology to communicate between the devices and control robotic peripherals.
First, a foundational understanding of the underlying components is required. In this article, we begin with embedded Linux.
Desktop Linux versus Embedded Linux
Embedded Linux is an adaptation of the Linux kernel for use in an embedded system. The most popular example of embedded Linux is the Android operating system.
However, a number of hardware resources are needed to support embedded Linux, especially if it will be deployed in use cases like the real-time machine-to-machine (M2M) communications, robotic control, or complex timing applications highlighted later in this series. At minimum, these resources include an embedded hardware platform (board or system-on-chip) that supports Ethernet and other basic interfaces, as well as ample NOR or NAND flash memory for housing the OS, libraries, file system, applications, bootloader, etc.
Just like regular Linux, embedded Linux is open source, modifiable, and written in C. Also just like desktop Linux, or any other operating system for that matter, the role of embedded Linux is to abstract the user and applications from the underlying processor, memory, and other hardware components; allocate and deliver system resources to various functions; manage multiple tasks and applications simultaneously, and so on. As such, an embedded Linux system stack looks just like your typical desktop.
Despite that, if you haven’t noticed by now, there are many significant differences between embedded Linux and traditional desktop Linux. These include such as the ability to boot directly from flash as opposed to a hard drive.
A chart comparing some of the major differences between embedded and desktop Linux is provided below.
Embedded Linux: Cross Compilers, Libraries & Bootloaders
Because embedded Linux is designed for specific applications, there are some specific development tools engineers must have at their disposal when starting out on a system design that calls for the open source operating system. The following is certainly not an exhaustive list, but a good place to start is with the right libraries, a robust cross compiler, and an efficient bootloader to pair with the Linux kernel.
For the unfamiliar, a cross-compiler is a compiler that executes code written to run in other machines than the one the compiler is on. For example, a cross-compiler running on your PC or laptop is able to generate code written for an embedded system like an Android smartphone.
Cross-compilers are needed for embedded Linux systems because these devices often don’t have the resources required to compile the code locally, so it must be compiled elsewhere then delivered to the target.
There are several options when it comes to cross-compilers that offer features such as size optimization, characteristics that support control processing, and so on. But some of the most common cross-compilers are listed here:
The C library provides an interface between the kernel and applications, and therefore must be part of the cross-compilation process. Any program in the embedded Linux system, whether its written in python, java, or another language will have to call the C library at runtime in order to access hardware resources via the Linux kernel.
Here are some of the popular C libraries for use in an embedded Linux system.
- glibc – The standard GNU C library is full of features, but that comes at the expense of a large memory footprint. It also doesn’t have any configuration options.
- uClibc – The “u” indicates that uClibc is a microcontroller C library that is small in size for use in embedded system.
- musl – musl is also small and a good choice in systems with a limited amount of RAM and storage.
- eglibc – eglibc is the same as glibc but with modifications that make it more suitable for use in embedded devices, such as support for configuration.
The embedded Linux kernel has limited features, and therefore requires specific libraries. We of course can’t list them all, but some more popular ones are listed below. Some of these will be used later on in this series.
- libgpiod – The standard command line isn’t the only way to interact with Linux device files these days. The libgpiod is used to interact with GPIO hardware in Linux devices.
- libusb – libusb is a C library that provides drivers for all generic USB devices from a single platform.
- Socket – The socket library connects nodes on a network.
- serdisplib – This library can drive several displays like OLEDs, USB displays, or displays with built-in controllers.
- Pigpio – The Pigpio library caann be used to control Raspberry Pi GPIOs.
- opc-ua – The opc-ua protocol is a protocol that works on time sensitive networks.
- lockdev – Lock and unlock devices
- libxls – This library is used to read and convert excel files.
- libstroke – A library used to recognize mouse strokes and gestures.
- libserialport – Abstracts OS-specific details when writing software that uses a serial port
- hidapi – A library for communicating with USB and Bluetooth HID devices. hb
- mjpg_streamer – For capturing JPEG frames from one or more inputs and streaming them over an IP network
- cheese – cheese helps you to take videos, photos, etc. with your webcam.
- Elisa – it is a simple music player so you can play any of the audio.
The bootloader is the first code to run after a system powers on, and handles basic hardware initialization and loads the operating system from bootable devices like the hard drive or an SD card or flash memory in an embedded Linux system. Once the bootloader sets up the executable environment for the Linux kernel and the kernel starts to execute, the bootloader is no longer needed.
Bootloaders come in various shapes and sizes, and can be customized according to user or system needs. In fact, some embedded boards come packaged with a bootloader.
Here some of commonly-used bootloaders and the processor architectures they support.
ARC, ARM, Blackfin, Microblaze, MIPS, Nios II, OpenRice, PowerPC, SuperH
ARM, MIPS, PowerPC, SuperH
ARM, Blackfin, MIPS, Nios II, PowerPC
These are the key building blocks behind a wide range of embedded Linux-based systems you probably use every day perhaps without even knowing they run Linux, such as smart TVs, wireless routers, and network attached storage devices.
Now that those fundamentals are out of the way, in part 2 we’ll take a closer look at the ins and outs of embedded hardware targets we’ll run embedded Linux on that will later support our Ethernet Time-Sensitive Networking (TSN) stack.