Saturday, 8 February 2014

Bootloader for Embedded Linux !!

Hi all...

I hope you all are doing well. Today I'll discus about boot loader in general, we will discuss how boot loader works.. and also we'll try to build boot loader for our board(I am using beagle bone black... ).


BOOTLOADER :  In my uClinux posts(January's posts) we already have discussed about basic information of boot loader. New viewers click here to know about an introduction of boot loader.
 

Building U-boot for our target :  My target board is Beagle Bone black and i am building u-boot loader for this board. Below are the steps to build u-boot image for our target. In case you have other development board the steps will be same but at the time of configuration we have to build config file according to our board which i'll specify at that time. So lets begin... :)

Steps:Follow these steps on linux platform, I m doing these on Ubuntu 12.04

1)Download all these packages:
 -u-boot-2013.10 Its a u-boot source code for latest version
 -0001-arm-omap-i2c-don-t-zero-cnt-in-i2c_write.patch This is a patch file for Beagle bone board. In case you are using other board you have to search for patch specific to your board.

2) Go where you downloaded all u-boot tar packages
   $ cd /home/<user>/download 

3) untar U-boot package in the same folder
   $ tar –xjvf  u-boot-2013.10.tar.bz2

4) Change directory to the u-boot directory.
   $ cd u-boot-2013.10

5) Apply the u-boot patch
   $ cat   ../0001-arm-omap-i2c-don-t-zero-cnt-in-i2c_write.patch | patch –p1

6) Set ARCH and CROSS_COMPILE variable to your current terminal...
  $ export ARCH=arm
  $ export CROSS_COMPILE=arm-linux-

7) Select board configuration. In this example I am selecting the configuration for the Beagle bone board.
   $ make omap3_beagle_config 


In case you have different board,  first see on to the kernel Is there any config file is present or not which  matches to your board :)

For seeing config file present in kernel type..

$ make help


It'll give you all pre-configured architecture if it matches to your board then select it :)


8) Now it is time to compile the u-boot.
   $ make

9) When the build has finished successfully a binary file named u-boot.bin will be
available in the u-boot-1.1.6 directory.

10) Convert the bin file to a hex file.
   $ arm-linux-objcopy –I binary –O ihex u-boot.bin u-boot.hex

This u-boot.hex is a final image of u-boot loader... yes we got it !!

In my next post i'll show you how to flash this u-boot.hex file into your target machine and how to run....

That's all... njoy!!

Abhishek Mourya

Thursday, 6 February 2014

Cross-compiling Toolchain !!

Hi friends...

Today we'll go little bit deeper to understand the tools which are very essential to build embedded Linux kernel for your device...

We'll first try to understand the need of these tools and then we'll learn how to get these tools... :)

Toolchain : If you will see towards the tools such as GCC, GDB, Strace, Ltrace etc which are present in your UBUNTU workstation  is a native toolchain.  That means this toolchain  will run on your workstation and generates code for your workstation( example for x86 processor on your syytem)

For embedded systems (Boards like Beagle bone or other...), we can not use this native toolchain, because the target is little different in terms of storage, memory and in the terms of architecture. Target may not support executable created by native toolchain..

So cross-compiling toolchains are generally used. This cross compiling toolchain will  run on your workstation but it will generate code for your target(according to your target processor architecture..).






Components inside the toolchain :

Binutils : Binutils is a set of tools to generate and manipulate binaries for a given CPU architecture.
ex : as, ld, ar, ranlib etc...

Kernel headers : The C library and compiled programs needs to interact with the kernel. For example to get available system calls and their
numbers or for available data structures, etc.

Thats why compiling the C library requires kernel headers, and many applications also require them.

GCC : GNU Compiler Collection, the famous free software compiler . Can compile C, C++, Ada, Fortran, Java, Objective-C, Objective-C++, and generate code for a large number of CPU architectures, including ARM, AVR, Black n, CRIS, FRV, M32, MIPS, MN10300, PowerPC, SH, v850, i386, x86 64, IA64, Xtensa, etc.

C library : The C library is a very important component of a Linux system Interface between the applications andthe kernel.  It provides the well-known standard C API to ease application development

Several C libraries are available: glibc, uClibc, eglibc, dietlibc, newlib, etc. The choice of the C library for ousr tool chain must be made at the time of the cross-compiling toolchain generation.

We will use uLibc in our toolchain because the Size of uLibc is 4 times smaller than glibc...


Obtaining a Toolchain : 

Now we got enough information about cross-compile tool chain... So before getting our own toolchain for our target which is arm processor, lets see how to get toolchain...

So basically there are two ways to getting our own tool chain...

1) Get a pre-compiled toolchain : Building your own  cross-compiling toolchain by yourself is a di fficult task. It Can take days or weeks, because of omplicated con guration.Lots of component we need like kernel headers and C library source etc...
Thats why people use to install pre-compiled toolchain available in the internet. 

Determine what toolchain you need: CPU, endianism, C library, component versions, ABI, soft oat or hard
flooat, etc.Possible choices for pre-compiled toolchain are Sourcery CodeBench toolchains, Linaro toolchains etc...
For more information about tool chains click here.

For Ubuntu 12.04 you can install a prebuilt toolchain like this very easily follo below steps...

sudo apt-get install gcc-arm-linux-gnueabi
 
Now find out the path and name of the cross-compiler executable by looking at the contents of the package:

dpkg -L gcc-arm-linux-gnueabi 
 
Now u can use your installed toolchain.... :)


2) Build our own toolchain : Its a complicated process which may take few week or few days to understand and to do successfully, because for building toolchain we need to integrate all components of tool chai like c-library, GCC, kernel  headres etc ando also we have to configure it and build it... which is little complecated but more interesting... 

So lets try to build our own toolchain for ARM processor, follow below steps....

a) Install the packages needed for building toolchain, Embedded Linux and u-boot:
sudo apt-get install autoconf automake libtool libexpat1-dev \ libncurses5-dev bison flex patch curl cvs texinfo  build-essential subversion gawk python-dev gperf

b) Download source code of the latest version of toolchain from crosstool-ng website click here to download( which is crosstool-ng-1.19.0.tar.bz2)....

c) Extract toolchain 

 $ tar -jxvf crosstool-ng-1.19.0.bz2 

d) It will give one directory name as crosstool-ng-1.19.0

$cd crosstool-ng-1.19.0

e) Install toolchain using...

$./configure --enable-local 
$make 
$make install

f) Configure the toolchain using...

$./ct-ng arm-unknown-linux-uclibcgnueabi

Then, to refine the configuration, let’s run the menuconfig interface:

$./ct-ng menuconfig

g) In Path and misc options: 
• Change Prefix directory to /usr/local/xtools/${CT_TARGET}. This is the place where the toolchain will be installed. 
• Change Maximum log level to see to DEBUG so that we can have more details on what happened during the build in case something went wrong. 

In Toolchain options: 

• Set Tuple’s alias to arm-linux. This way, we will be able to use the compiler as arm-linux-gcc instead of arm-unknown-linux-uclibcgnueabi-gcc, which is much longer to type. In Debug facilities:
• Enable gdb, strace and ltrace. 
• Remove the other options (dmalloc and duma). 
• In gdb options: – Make sure that the Cross-gdb and Build a static gdbserver options are enabled; the other options are not needed. – Set gdb version to 7.4.1.

h) Produce the toolchain...

$./ct-ng build

And wait...

This 8 steps must be done under non-root user... In super user login it will not work...

So i told building our own toolchain is a complicated... why ? because when you will build tool chai by above step you'll get make error several time that is...  "Source archives not found on the Internet"

 It is frequent that Crosstool-ng aborts because it can’t find a source archive on the Internet, when such an archive has moved or has been replaced by more recent versions. New Crosstoolng versions ship with updated URLs, but in the same time we have do our work... :)

So, If this happens to you, what you can do is search for the source archive by yourself on the Internet, and copy such an archive to the same directory where it is unable to find archive. Then, all you have to do is run ./ct-ng build again, and it will use the source archive that you downloaded.


So this is how we can play with tool chain... I hope you will do it successfully... keep trying n dont ever give up !!

Thats it for today !!
Gud Bye :)

Abhishek Mourya

Tuesday, 4 February 2014

Embedded Linux Development Environment !!

Hi guys...


I hope you like the introduction of Embedded Linux... if you'll search more about LINUX or Open source community for LINUX you'll get to know so many genius Linux system hackers and programmers are working for enhancement  of LINUX every day every minute... and they are not paid by anybody or any company.

They love to play with Linux kernel, they love to write drivers and services for new hardware... they njoy it !!
They respect and understand the simplicity and robust architecture of Linux kernel which is UNIX...
Hats off for Dennis Ritchie and Ken Thompson for this great invention, and we all who will be the part of Open Source Community in the near future have proud to be a part of LINUX....

Okay !! So today we will explore the environment useful for developing Embedded Linux on our device...


Embedded Linux :
There are two ways to switch to embedded Linux...
1) We can use solutions provided and supported by vendors like Embedded Artist, Monavista etc.... These solutions come with their own development tools and environment. They use a mix of open-source components and proprietary tools.
2)  Use community solutions. They are completely open, supported by the community.

Here we'll use community solutions because knowing the concepts will be easy to switch to vendor solutions.


Host OS for Linux development :
We'll use Linux as the desktop operating system to embedded Linux development because...


1)All tools which are necessary to build embedded Linux are developed and designed to run on Linux. If we'll try to use them on other operating systems (Windows, Mac etc) will lead to trouble.
DIAG
2) Any good and recent Linux desktop distribution can be used for the development workstation
Example : Ubuntu, Debian, Fedora, openSUSE, Red Hat, etc
We'll choose Ubuntu, because it is a widely used and easy to use desktop Linux distribution.


Host Vs Target :
While doing embedded development we need to computers one is  HOST which is a development workstation and which is typically a powerful PC, second one is  TARGET, which is the embedded system board under development. 
They can be connected by various means such as almost through a serial line for debugging purposes, Ethernet connection for frequently access and a JTAG interface for low-level debugging.


For a embedded Linux developer or a device driver developer Ethernet connection (TFTP server) is most suitable... becouse of frequent communication between target and host.
 

Serial line communication program :
An essential tool for embedded development is a serial line communication program, like HyperTerminal in Windows.
There are multiple options available in Linux: Minicom, Picocom, Gtkterm, Putty, etc.

We will use Picocom program for terminal application because it is easy to use...
PICOCOM instalation on UBUNTU...

sudo apt-get install picocom


How to use it.. we'll see while lab practice.... (update you soon...)

In my first post of embedded Linux i told we can use any of the processor architecture which supports Embedded Linux... and better to use processor which is defined in the arch directory inside the kernel source code.. because for that processor kernel configuration is already present in kernel source tree... :).

So I am going to use Beaglebone black which is up to1-GHz Sitara™ ARM® Cortex™

For beagle bone black,  configuration file is already present in kernel name as omap2_deconfig which i am going to use....



Beagle bone board support... http://circuitco.com/support/index.php?title=BeagleBoneBlack

board System Reference Manual found at
https://github.com/CircuitCo/BeagleBone-Black/blob/master/BBB_SRM.pdf?raw=true

This is the ultimate reference about the board, giving all the details about the design of the board and the components which were chosen....

People who have this Beagle bone black board can start with same and  people who have other ARM board can start with their board if that board architecture is supported by LINUX's recent version... :)


Thats it !!
Good Bye

Abhishek Mourya