This write up aims to briefly discuss the build process or the steps involved in the generation of a binary image specifically for an embedded system.
Embedded System, unlike a conventional PC is very restricted in terms of both storage and processing capabilities. Keeping this in mind, the final image that sits in the system flash should be in line to the memory architecture of the system.
Thus, the build system is slightly different and more complicated when it comes to binary generation for a specific embedded device.
Table of Contents
Concepts covered in this write-up
- Compiling and Assembling.
- Linking.
- Relocation.
- Basics of bootloader and system start-up.
As mentioned in my previous articles on memory concepts in embedded system; (please give it a read if not already done 🙂 ) there are a few stages to undergo before an image can be generated.
Overview
Let us call it the 3 stage process
- Compiling/ assembling the source code in object files.
- Converting/ Merging all the object files into one object file ; commonly known as linking.
- Relocation/ Address Mapping.
These 3 stages will each be discussed in the course of this write up.
Compiling and Assembling
The process of converting the source code (codes) into an object file is termed as compiling. Similarly if the input is in processor specific assembly instructions; then converting that into an object file is termed as assembling. Both the processes are the same in terms of what they produce as outputs ultimately.
Let’s ponder over a few questions…
Why compiling? What other purpose do they serve? What are the compilers used for embedded systems? Are they all the same?
Let’s Find out…
Why Compiling?
In simple terms (not that you don’t know already 😉 ), the compiler converts the human readable code into a format that the machine can process; called the object code.
A compiler is a program that does this job for you. Having said this, there are many compilers out there and we will discuss some of the most common ones in the remaining course of this write-up.
What Other purpose do they serve?
Apart from doing the above mentioned task, the following responsibilities are undertaken
- Compilers check the syntactical correctness of the code. (Not the logic of the code)
- The settings of the compiler can be tweaked to increase the strictness of the compilation process e.g. Warnings can be treated as errors. ( For the sake of focus, we will not deep dive into this )
- Regroup data into text, data, .bss sections.
For an embedded system specifically, we use a cross compiler; a compiler that is used for a remote target executable generation.
What are the compilers used for Embedded Systems?
Most often the open source GCC compiler is used for cross compilation with appropriate target information already available as part of the compiler program.
The STM32 Microcontrollers using the ARM chip uses the GNU GCC compilers and assemblers to build its binaries as shown in the image below.
Please Note: this is entirely dependent on the capability of the compiler and linker to generate board specific binaries.
There are company specific compiler vendors for their boards ex
Keil, Vector, Code Composer etc.
A good article on how to choose compilers is in the below mentioned article
https://barrgroup.com/embedded-systems/how-to/c-cross-compilers
Are they all the same?
No, they are not one – to – one the same; they have some differences on how they execute group and run the code it receives. The ultimate outcome is same!
For the sake of keeping this article short; I intend on having a follow up post on the remaining concepts mentioned above.
Please read the continuation in the link below
As always thanks for reading!