From bare-metal to embedded Linux

A little heads up for the people who are just moving from micro-controller to a processor board.

When I started my work on controllers like AVR,PIC16 series, their datasheet was all I needed.
But the story in case of a processor is completely changed.
As we are talking about embedded Linux and not a full blown desktop system, the processors considered here is a SOC like the one in a raspberry pi.

Different SOC’s vendors and the problem with proprietary code.

As there are a lot of player in the market, each of them is having there own set of tools and process by which one can work with the SOC processors provided by them.
There’s no generic way but the procedure followed is pretty similar but without the support from the vendor, its very hard for one to play with a particular processor. Vendors like Qualcomm, Nvidia, Broadcom release their processors and software tools needed to build things on top of them. Those software possess a huge amount of proprietary things that one has to take care of. The easiest way is to buy a development board from these vendors and get started with it which by the way is pretty costly if one is talking about a SOC development board.

How working on a SOC is different from a micro-controller based boards ?
There are many advantages for a SOC board over a controller based board. Many are in terms of easy of code and a more integrated solution.

Software : In terms of code, the SOC mostly will run a linux distribution or may be some other OS like android or windows. The bare metal coding concept is lost in case of a SOC. Concepts of OS are more used than the standard C/C++/Assembly coding in a micro-controller. The SOC vendors will always provide a SDK that does all of the work of building a kernel or android system for the particular processor.
When building custom a SOC boards, the corresponding purchased SOC development board is tweaked according to the requirements and are also added with others functionalities like addition of a custom hardware that connects the processor over some bus like USB or I2C and for such additions , one needs to tweak the software SDK also to support the same. Such activity comes under the field of linux Board Support Packaging and is itself is sometimes a tiresome activity.

So mainly the software will have a OS layer generally a linux kernel based.

Hardware : In terms of hardware, there are a lot of peripheral inside the SOC chip only like WiFi, Bluetooth, Ethernet, USB and many other peripheral are mostly inside the SOC. Though ram and storage chips needs to be connected to the processor. Some SOC vendors may include the ram and storage inside the SOC die only. Again, this thing is vendor specific. So hardware of a SOC chip will always a variety of options one can select. Programming the board though can be costly as the processors may or may not have support for different boot types. Like if the processor can’t boot from media like SD-card or USB ( the easy ones ), then one might need a JTAG debugger to flash the firmware inside the ROM used in the board.

To summarise one needs to know three ares to start working with a SOC board and these are :

  1. The purchased SOC boot sequence ( this is provided by the vendor ).
  2. The SDK ( whetherLinux or android based and this is provided by the vendor or may be an opensource one like buildroot/yocto/openembedded ). One needs to know the directory structure/compilation/configuration of the SDK so as to make modifications or additions to the code.
  3. The boards hardware schematic. I am suggesting this as one should know at least basic connections for the board to boot properly like the power,gnd,boot-straping pins , ram/rom connections to the processor and other pins like gpios and some bus pins like i2c or spi. This stuff is very basic and one should have knowledge of such things as only then one can tweak the software to produce a working code.

Few SOC development boards 
The famous raspberry pi dev board with a broadcom SOC.

The qualcomm’s dragaon series SOC board

New in the game recently launched Nvidia’s Jetson Nano dev board. 

RaspberryPi-The most famous SOC development board.

What is Raspberry Pi ?
Raspberry Pi is a heavily contributed SOC development board with a pretty powerful processor that is sufficient enough to run OS like Linux on it.
It’s having a very large community support and developers all over the word use it to make wonderful projects. It’s actually a single board computer if someone talks about how powerful it can be.

What to do next after purchasing a raspberry pi ?
OK so you got motivated enough to shift your development efforts to a SOC board from a micro-controller one ( a big and wise decision. Give yourself a big tap on your back. ) to learn how things work on a SOC board and purchased one raspberry pi for yourself. But what next ?
There are few things one should focus on after buying a SOC board like raspberry Pi.

Development Efforts : The starting point is to choose an operating system layer. As the platform is an SOC, bare metal approach is now lost ( for people coming from micro-controller background will really feel the pain but after some time they will enjoy this. ). Instead everything will be OS governed.
So there are two ways to achieve this layer and official and custom build environment.

Official support : One can choose variety of OS that one can run on the raspberry pi. The famous ones are the one supported by the raspberry pi community. The famous among all of them is the “raspbian“.
The pros with this approach is that one can install the readily available OS without worrying much.
The cons are that if someone willing to learn the actual process and the one who really want to go a little more into the cycle of building kernel and other stuffs can’t do with official supported OS as they are already built and has readily available things.

Custom build environment : To really learn the process of building a kernel and related things for an OS, one can use the build utilities like Yocto, open-embedded and buildroot.
These tools actually gives a lot of control on the process of building a kernel and is very well documented and the support is also very good.

So for people who just want to boot the board and then readily do the development can go with the officially supported OS and people who actually want to learn more basics should definitely go with the buildroot or similar tools. However the second method can be sometimes tiresome to get things working but it offers a really good learning curve if it interests one.

Link for official supported OS :
Link for buildroot :

In the next post I’ll show how to build and flash the OS using both the official and the one built using buildroot method and also the methods to access the board using HDMI, serial and Ethernet. Both methods are similar in some sense.