Before we start, let us get an appreciation of the terms bare metal and programming and how these are related to each other.
Table of Contents
Believe it or not, this is an actual term in programming. Techopedia defines this as: a computer system without a base operating system or installed applications. It is a computer’s hardware assembly, structure and components that is installed with either the firmware or basic input/output system software utility or no software at all.
Computer programming can be defined as the process of designing and developing a set of instructions that the target computer will use to accomplish a specific task. This set of instructions is referred to as the computer program. The source code of the program is written in one or more languages that are later translated into machine code, which is the language that the Central Processing Unit (CPU) understands.
Programming languages are divided into two, and these are:
Low level programming languages – these are easier for the machine to “understand,” and harder for the programmer to understand.
High level programming languages – these are easier for the programmer to understand, but are harder for the machine to “understand.”
Bringing it together
Bare metal programming is writing a set of instructions that runs directly on computer hardware which has no operating system installed on it. It is considered to be a low level method of programming that is specific to the hardware used in the computer system.
Bare metal programming is often used for optimizing software and applications for a computer or a small group of systems, or for the design of basic tools that would be used on a new system to perform actions such as bypassing the Basic Input Output System (BIOS) or the operating system interface.
The need for safety and security has grown in the recent years. This need has been seen across various sectors such as automotive, industrial and in the cloud. An option that is currently being explored is building security and safety into both the hardware and software. This is being implemented by performing bare metal programming directly on a chip. This kind of bare metal programming includes everything, from real time operating systems and drivers right up to type 1 virtual machines.
Since bare metal programming is a low level method of software programming, it is extremely fast and it is very reliable. This is due to the fact that it does not have to go through various software abstraction layers. While this may look quite promising, bare metal programming is quite difficult to develop for modern chips. Here’s why.
When embedded systems development was still new, software was minimal. The engineers who had designed the hardware would frequently take part in the software development. They knew their electronics very well. They understood all the nuances of the hardware’s behaviour so bare metal programming was not a challenge at all.
The systems became more complicated. This lead to the recruitment of software specialists. These specialists were frequently engineers with a significant knowledge and understanding of hardware. As a result they were quite happy to perform the bare metal programming. The rising complexity, however, made this bare metal programming a lot more difficult.
As the complexity increased, the single software engineer turned into a team. This resulted in a huge mix of people with different types of expertise. The developers responsible for bare metal programming would develop software programs that we now know as drivers.
With the rise in the processing power of the microcontrollers and microprocessors, there was a drive for the adoption of Real Time Operating Systems, and the drivers made by developers responsible for bare metal programming became part of the Real Time Operating systems.
Bare metal programming use case scenarios
- When a low end system is designed with a microcontroller and the code is run in one loop. There will not be enough CPU bandwidth and enough memory to run and load operating systems. Bare metal programming will be the best (and the only) option in such a scenario.
- When your boot time of the system is stringent and you cannot achieve this using the OS based system. The OS based system’s boot up time is in seconds, and therefore is not feasible when you want deterministic boot time.
- When there is a need to have direct control over every piece of hardware and registers to meet the timing requirements present.
- When there is a need to eliminate the Operating System overhead.
- When there is a need to implement control loops where acquiring data from an Analogue to Digital Converter and processing it to trigger Pulse Width Modulation in the feedback needs hard time performance.
- When there is a need to own and control every piece of the code and external modules present cannot be used due to licensing issues or third party royalty issues.
Disadvantages of Bare metal programming
- You do not get the luxury of having an operating system which abstracts the user from the underlying hardware. You are forced to write device drivers, manage schedulers, perform memory management, thread management, etc. As a result, the process of bare metal programming will be much slower than when using a high level programming language.
- There are no tools to reuse. You create everything from scratch.
- You have to hang onto JTAG for memory dump analysis.
- You get very limited tools, and if they are there, then they will definitely be expensive.
- Vulnerabilities present in a chip may be found and exploited if such vulnerabilities leak. This could potentially defeat the whole purpose of implementing the bare metal programming in applications that use bare metal programming to improve the security present.
Bare metal programming is a complicated, time consuming method of programming, which would be recommended if there is a real need for it. Its applications in security are still being investigated. Who knows? Maybe very soon bare metal programmers will be in demand.
Thanks for reading!