Linux OS Porting Best Practices for Embedded Systems

Linux OS Porting Best Practices for Embedded Systems

Linux is an exceedingly versatile operating system that has been deployed in a wide range of devices – large and small. It supports a huge variety of chip architectures and has hence, found utility in data centers of large enterprises, connected devices powered by the Internet of Things (IoT), personal systems and consumer electronics.

For embedded system development, there are several popular choices for operating systems. And over the years, Linux has evolved to be one of the most preferred operating systems for embedded applications.

In this article, we explore the many advantages of using Linux for embedded systems and some of the best practices to follow while developing Linux based IoT applications.

malachi-brooks

Advantages of Linux over Other OS

The widespread popularity of Linux arises from the following benefits it offers for embedded application development:

  • Open Source –Linux is open source and royalty-free. It should be noted that there are several costs associated with configuring it to develop full-fledged embedded applications. However, the fact that open source Linux enables easy bug fixes (without having to approach a vendor), makes it an attractive option. Another perk of using Linux is the easy availability of features and add-ons developed by the talent pool of an open source community.
  • Extensive Support – Linux supports almost all libraries, tools, and programming languages for embedded systems. It provides a web server, communication protocols for USB devices, graphical toolkit, and much more! An important point to note here is that Linux also supports a wide range of hardware platforms (SoC, SoM, etc.). You may, however, have to develop specific Linux drivers to support custom hardware. But this feat can also be accomplished effortlessly with Linux.
  • Standards – The Linux OS adheres to several standards, including BSD, POSIX, FHS, etc. You can easily migrate to other operating systems, in case there is a need to do so.
  • Quick Booting – When compared to other leading operating systems for embedded applications, Linux has a quick boot time and smaller footprint. In some use cases, the multitude of features offered by an OS such as Android is not needed at all. In this scenario, a simple Linux platform can perform the required tasks efficiently.
  • Developer Access – Hiring engineers for embedded Linux development is also not a stressful task, as there is a vast community of experienced developers around the world
  • Hypervisor – Hypervisor is basically a software that runs virtual machines. Linux has an in-built open source virtualization technology, Kernel-based Virtual Machine (KVM) that enables you to convert Linux into a hypervisor. This facilitates a host system to run multiple individual virtual environments called guests, on a single workstation. Large enterprises can benefit from these virtual environments as they simplify resource administration and streamline operations.

Choosing the Right Version of Linux

The ready-to-deploy Enterprise version of Linux is not considered to be suitable for embedded systems. So, embedded system developers tend to create their own customized versions. This is usually referred to as Roll-Your-Own (RYO) Linux.

An embedded system engineer can select just the relevant components from the community distribution for their specific use case. Then, they can add features to the stripped-down version of Linux, based on their requirements.

RYO Linux, however, is not suitable for embedded systems with low-resource environments or low-end hardware, i.e., hardware that is underpowered to execute multiple tasks with a scheduler.

Commercially supported Linux for embedded applications is similar to off-the-shelf Enterprise Linux in many ways. Commercially supported Linux has a compact core that supports low-resource environments effectively. This core framework is offered by Yocto Project and Open Embedded communities. This version of Linux is cost-effective and offers long-term support/maintenance and faster time to market.

When designing an embedded system application, it is crucial to analyse the Linux OS options available and decide on a suitable framework.

Best Practices for Linux OS Porting Projects

Listed below are some best practices that should be followed by embedded system engineers while undertaking a Linux porting project.

  1. Hardware Requirements – The first step is to identify the type of hardware to be used for the application. Decide on the type of processor and interfaces to be incorporated. For instance, if Linux OS porting is done for an automotive application, it is imperative that the CAN interface is included. There is also a need to assess the memory requirements.

    The decision on the type of hardware, RAM and interfaces predominantly depends on the project BOM cost and associated criteria.

  2. HMI Components – HMI components run in the application layer and interact with the hardware. Linux requires HMI components that offer rich GUI features. It is necessary to employ third-party products to build a hardware- and OS-agnostic user interface for Linux based applications. Product offerings from Elektrobit, Qt, CGI Studio and OpenGL are widely used for HMI development in the industry.

    There are products that provide customized GUIs with 2D and 3D support, effects and animations, specifically suited for automotive applications as well.

    The HMI can be configured to have basic or advanced features, depending on the use case. The user interface design should also include all elements required by the operator and eliminate the ones that are not needed. The system efficiency pivots around the layout of the GUI, the size of the buttons and the navigation loops. It is imperative that an easy-to-use navigation menu is in place so that the operator can access the critical functions quickly.

  3. Security Considerations – Security aspects at the hardware and software level should be given due attention while developing connected devices. Technologies such as Trust Execution Environment (TEE) help address security issues for embedded systems.

    TEE is a secure spot inside a processor in an isolated environment. This runs in parallel to the OS and ensures that the code and data in the TEE are secure, with respect to integrity and confidentiality. Applications that run in the TEE can access the main processor and memory of the device. However, hardware and software isolations protect the various contained applications from each other.

    Some of the hardware technologies that support TEE implementations are:

    • SGX from Intel
    • TrustZone from ARM

    ARM TrustZone facilitates embedded system security starting at the hardware level, by enabling two environments to run together on a single core – a secure and a non-secure world. The non-secure software is blocked from accessing the resources in the secure world.

    Another concept is Secure Boot, a process in which the operating system boot images and code are verified against the hardware before being used in the actual booting process. The hardware is pre-configured to authenticate code using trusted security credentials.

  4. Library and API Development – APIs are developed to enable various peripheral functionalities. For instance, lighting up a part of the application’s GUI can be accomplished through an API.

    Generic API development that does not restrict porting of the application across multiple platforms should be considered seriously. Similarly, software library development for various functionalities should also be analyzed during the design phase.

  5. Device Tree (DT) – It is recommended to use a hardware discovery solution such as Device Tree in Linux applications. DT is essentially a data structure and language that describes the hardware and can be read by an operating system. Usage of DT ensures that there is no need to hard code machine details in the program. Linux OS uses DT data to find and register the various devices in the system.

    The device tree images can be statistically passed to the kernel at boot time. It can also be expanded to a kernel internal data structure for easy access after system booting.

  6. Board Bring-up – Board bring-up is a planned activity in which the embedded electronics application (including hardware, firmware, assembly and low-level software elements) are tested and validated in an iterative manner to ensure readiness for manufacturing. This activity consists of a set of repeatable steps that will be performed on a prototype to ensure that all functionalities are working as expected.

    The main phases in a board bring-up activity includes:

    • Checking if the board has been assembled accurately
    • Testing of the hardware
    • Testing firmware and low-level software
    • Evaluating memory and signal integrity
    • Loading OS and checking embedded software

    There should be adequate planning for board bring-up activities during the initial phases of the product development life cycle.

  7. Boot Time Optimization – Boot time is basically the sequence of steps a system performs from the time it is switched on till it is ready to be used (after loading of applications). Boot sequence follows several steps.

    Complex embedded systems based on Linux, Android or Windows may have long boot times that can adversely affect user experience. With increase in complexity of devices, several new challenges arise in getting these applications to boot-up quickly.

    However, it is possible to optimize boot time significantly through methods such as cold boot optimization, suspend and resume, and hibernation boot-up. The selection of an appropriate boot time optimization method depends on the application itself, the underlying platform and the use case.

  8. Power Management – The overall power management of a device depends on two criteria – power consumption while the device is idle and while it is being used. Power management can be efficiently performed through software techniques and hardware techniques.

    Software power management techniques should be considered during the design phase itself. Power measurement and analysis can be performed using third-party software such as PowerScope.

    Hardware power management can be classified into two types – static and dynamic. Static power management (SPM) is done during the design phase and this is used for optimization of both hardware and software. Dynamic power management uses runtime behavioural changes to minimize power consumption.

  9. Testing and Validation – This involves the creation of testing frameworks for the validation of BSP, APIs, libraries, interfaces, hardware, etc. It is advisable to incorporate a Validation and Verification (V&V) methodology early in the development phase itself. This ensures that errors are detected and eliminated in the early stages and hence, resolution costs are minimized.

Conclusion

One of the quickest ways to build components for an IoT ecosystem is by using embedded Linux. You can enhance the capabilities of existing connected devices or design a new system from scratch, without too many hassles. Linux has the power to future-proof and also provide IP gateway services for an IoT infrastructure. Following the best practices listed above, it is possible to build a robust IoT application through Linux OS porting.

×

Happy to Help!