Tuesday, 25 February 2014

Linux kernel introduction

Hi guys...
    
    Today we'll try to gather information about Linux kernel source code... and then further we'll explore the Linux kernel and will cross compile Linux kernel source code for our ARM device (which i am using Beaglebone black... ).

The Linux kernel is one component of a system, which also requires libraries and applications to provide features to end users...

The Linux kernel was created  in 1991 by  Linus Torvalds.



Inside the Linux kernel :

The whole Linux sources are Free Software released under the GNU General Public License version 2.

Supported hardware architectures :  
See the arch/ directory in the kernel sources It support minimum 32 bit processors, with or without MMU, and gcc support... 
32 bit architectures (arch/ subdirectories) :
Examples: arm, avr32, blackfin, m68k, microblaze, mips, score, sparc, um
64 bit architectures:
Examples: alpha, arm64, ia64, sparc64 etc

Linux versioning scheme and development process : See in official kernel source code website which is maintained by Linus Torvald, You will get lots of Linux kernel Source code with different version... So here we need to understand the versioning system of linux kernel source...
Version of Linux kernel tells about two types of kernel one is stable kernel which is fully developed and ready to use and it is almost bugs free, and second one is unstable source which is under development...

So how to recognize...    One stable major branch comes in every 2 or 3 year which is identified  by an even middle number. examples: 1.0.x, 2.0.x, 2.2.x, 2.4.x 

One development branch(unstable kernel) to integrate new functionalities and major changes which is identified by an odd middle number.  examples: 2.1.x, 2.3.x, 2.5.x

After some time, a development version becomes the new base version for the stable branch.


Linux Kernel Source : The official version of the Linux kernel, as released by Linus Torvalds is available at http://www.kernel.org click here to see.

Linux 3.10 sources:
Raw size: 573 MB (43,000 les, approx 15,800,000 lines)
gzip compressed tar archive: 105 MB
bzip2 compressed tar archive: 83 MB (better)
xz compressed tar archive: 69 MB (best)


Getting Linux sources : You can get Linux kernel Source code from here.
http://www.kernel.org/pub/linux/kernel/v3.x/linux-3.10.9.tar.xz

After getting source code in tar folder we have to extract it using command: 
tar Jxvf linux-3.10.9.tar.xz

Don't worry about the commands and all now practically we will do it in next post... just understand the things how to get kernel and which version we should use... :)

Kernel con figuration :
The kernel con guration and build system is based on multiple Make files... 
All Makefiles inside the sub-directories in kernel source  interacts with the main Makefile which is present in the top directory of the kernel source tree. 
                      Interaction between all make files takes place using the make tool, which parses the Make file, through various targets, de fining which action should be done (con guration, compilation, installation, etc.).
Run make help to see all available targets.
Example:  $ make help // It will show all architecture defined in kernel source
                $ cd linux-3.6.x/
                $ make <target>  // Choose specific target 

The con guration for the specific target is stored in the .config file at the root of kernel source in simple text 
fi le, like key=value style.

As options have dependencies, typically never edited by hand, but through graphical or text interfaces:
 make xconfig, make gconfig (graphical)
 make menuconfig, make nconfig (text)
You can switch from one to another, they all load/save the same .config le, and show the same set of options

So this is how kernel is managed in kernel main line.... In next post we'll download latest kernel source code and we we'll compile the source code using cross compiler....

That's all for today !!
Good day

Abhishek Mourya 



Thursday, 13 February 2014

Loading u-boot into the board !!


Hi guys...

I hope you all are enjoying the journey of learning  embedded linux compilation and building on the target board.
In my last blog we have discussed how to build hex image of U-boot for our target board that is quite easy steps but any way as a beginner we have to learn and understand each and every steps... =D

So finally we got a hex image of u-boot bootloader so we can flash it on our board... today we will learn how to flash u-boot.hex into our target board and we'll try to explore u-boot environment.

Steps to load u-boot.hex into our board :

1) Start the FlashMagic tool (can be downloaded here). See Figure below for what FlashMagic looks like when it is started.
2) Click the “Browse” button and browse to the location of the u-boot.hex file.

3) Change the COM port to the COM port used by your target. Select baudrate as same as your com port have.

4) Click the “Start” button to download the u-boot.bin file to the target.








Explore the u-boot environment :Now we will see how to connect  the board with a terminal application and then explore the u-boot console and environment. You can use a terminal application of your choice. In this example we will use an application which we installed(see here... under the heading Serial line communication program ) already known as PICOCOM.

Connect a Terminal to the Board :
1. Start the PICOCOM application and configure the serial port. Setup Serial port
                            

2. Configure the port to use a baud rate of 115200, 8-bit data, no parity, 1 stop bit and no flow control.
$ picocom -b 115200 /dey/ttyUSB0

3. Press the Reset button on the base board to make sure the board restarts. You should now see output from the u-boot in the terminal, see Figure below. Make sure to hit any key to stop the auto boot procedure in 3 seconds.......

 
Commands to operate U-boot :

1) help:- List all available commands by using the help command.
# help
? - alias for 'help'
autoscr - run script from memory
base - print or set address offset
bdinfo - print Board Info structure
boot - boot default, i.e., run 'bootcmd'
bootd - boot default, i.e., run 'bootcmd'
...


2) Get specific instructions about a command, the example shows help text for the setenv command.
# help setenv
setenv name value ...
- set environment variable 'name' to 'value ...'
setenv name
- delete environment variable 'name'


3) printenv :- Print the current environment by using the printenv command.
# printenv
bootargs=root=/dev/ram initrd=0xa1800000,4000k console=ttyS0,115200N8
bootcmd=echo ;echo Booting from NAND FLASH (may take some seconds);echo
First loads 'uLinux.bin' and then 'jffs2.img';run nand_boot

bootdelay=3
baudrate=115200
tftp_boot=tftpboot a1500000 uLinux.bin;tftpboot a1800000 romfs.img;bootm
a1500000
nand_boot=nboot a1500000 0;bootm a1500000
nor_boot=bootm 80000000
...


etc.. etc...

This is how you can explore the environment for U-boot which provides you a command interface to give commands & these commands will help you to boot kernel image from different type of storage media that we will discuss later. So now your board is loaded with bootloader which is same as placenta in mother's uterus which loads life or new soul... in our case new soul is OS =D

In my next post we'll load our kernel image into board using usb method and we'll se the different method of loading kernel into board... if u have any queries please post below... hope u all will njoy !! :)


Thats it for today!!

Abhishek Mourya