Difference between Bare Metal vs. Embedded Linux

5/5 - (19 votes)

What is better, an embedded Linux program running in a board or a bare metal application?

What are the advantages or drawbacks of embedded Linux?

Nowadays embedded Linux systems are everywhere, literally EVERYWHERE. For example, smartphones (Android), TVs, vending machines, dataphones, GPSs, domotic houses, photo cameras, cars, etc But…

Is embedded Linux always the best option?

Bare Metal

First, let’s define what is “bare metal” application.

Bare metal refers to run a program or a software directly on the hardware level without the support of any operating system.

In other words, program a microcontroller directly with a bunch of lines of C or Assembler-code, as it was traditionally made in electronics and we learnt it.

It is a low-level method of programming and it is specific to the hardware used. For example, the GPIO, ADCs, hardware multipliers or adders, memories, communication modules (SPI, I2C, UART…), PWMs, DACs, etc

All the small microcontrollers or the classical Arduinos use bare metal programming.

Normally, most of the bare-metal projects do not start from scratch (at all). It would cost a lot to start every project from zero again and again. We use instead some already tested libraries.

We can consider this hybrid modality: “bare-metal + libraries”. These libraries contain basic functions and they could be developed by the same programmer (or team) or by a third-party. The use of libraries boost the developing time, because the debugging is reduced –> better time-to-market.

Embedded Linux

In embedded Linux, applications run over or supported by the kernel, acting as an operating system (OS). The "kernel" is the nucleus or core of the operating system controlling almost everything in the system. So, every iteration between hardware and software goes through the kernel.

Normal user-defined applications are called “User Space Applications” and they have intermediate layers until they access the hardware. For that purpose, they need to go through the kernel space to access to the HW.  In User space is just a chunk of memory and over the kernel.

The bigger difference (and advantage) is that the user space applications are hardware-independent.

Layer between user application and HW in Linux OS

What does the Linux “Kernel”?

The kernel of Linux consists of various modules, which interact directly with the underlying hardware.

It provides the required abstraction to hide low-level hardware details to system or application programs and therefore made it hardware-independent.

The kernel major activities or responsibilities are: Process management, memory management, timers, inter-process-communications (IPC), device drivers for all hardware resources or power management among others.

An application running in userspace can have scheduling and threading managed by the kernel (multi-threading advantage), but on the other hand, also can be interrupted any time when the OS needs to manage other calls and processes. Therefore, applications with timing-sensitive access to GPIO are not suitable or need special treatments.

Real-time in Linux?

Linux is generally not suitable for Hard Real-time tasks because user-space applications can always be interrupted by the kernel.

Linux has the possibility of using hard real-time extensions for this task, which add an extra layer between the hardware and the kernel. For example, RTLinux, RTAI or Xenomai. But it has also limits, and therefore any aeroplane or nuclear plant are based on Linux.

Conclusions

Bare Metal advantages:

  • Better performance with the same HW (100 to 1.000 faster than w. Linux)
  • Easy and fast for small applications
  • Reliability

Bare Metal drawbacks:

  • Complexity increase exponentially with the system size and functionalities
  • Basic and standard functions have to be programmed and adapted to the specific HW
  • No multi-threading possibilities in one core

Linux advantages:

  • Easily scalable
  • HW-independent (Portability)
  • Multi-threading and priorities
  • Free prebuilt drivers available (faster development)
  • Less bugs (mature OS code rather than new own code)
  • Community support

Linux drawbacks:

  • Complex for small applications
  • Steeper learning curve than bare metal
  • Require a minimum (powerful) hardware to run the Kernel
  • Security protection needed
  • Updates of the system may be needed

1 thought on “Difference between Bare Metal vs. Embedded Linux”

Leave a Comment

Your email address will not be published. Required fields are marked *