GSOC 2016 : Improvement of Board Support Package for Beagle Bone Black

Well this post summerizes my awesome Google Summer of Code experience under the RTEMS project. Aim of my project was to improve peripheral support for Pulse Width Modulation(PWM)  and I2C devices under RTEMS RTOS for popular Beagle Bone Black TI board. During first first half of GSOC I have worked on PWM device driver. You can find my work from following links :

Commits :

Commit History :

Testing demo of driver can be found on youtube :

All above PWM code is merged upstream RTEMS repo.

After first half I tried to develop I2C driver. To develop that I understood generic i2c RTEMS framework which took lots of time. It was great learning experience to develop i2c driver with non-interrupt driver programming (polling ) as well as  interrupt driver programming. To write the non-interrupt driver code I have reffered Minix i2c driver source code which added experience of learning architecture of minix os.

Inspite of working hard on developing I2C driver unfortunetly, I am not able to run it successfully and so not able to merge it with RTEMS repo. But post GSOC I will definetely try to merge it with mainline master repo.

Well still you can find my unmerged work at

Developed PWM APIs will be useful to RTEMS users. Many embedded applications such as automotive,space,robotics can use these APIs. Certainly it is my first great contribution after Linux kernel.

Acknowledgement :

Whatever work I have done will never possible without help of great mentors. I am sincerely grateful to my mentors Ben Gras, Martin Galvan, Marcos Díaz, Ketul Shah.

Thank you guys !! I have learned a lot from your experience.

It is first time I have worked with experienced developers globally. I know time is precious and even though these guys are quite busy they help me a lot with every issues I have come across. I appreciate all the efforts to teach me from small to big technical things.

How to open file through c program using POSIX API ?

Today we will learn basic open() command of the linux .Look at the following program

First explore basics of read() and open() through following link.



Create one hello.txt file using vi editor.

sudo vi /hello.txt

write “hello” inside the file .

I believe beginner didn’t get what file descriptor is (Did U !! You probably intelligent then 🙂 )

Those who don’t.  File descriptor is non negative number.Every file whenever we open the file one entry will be created inside the kernel for that file. If the file Descriptor value is negative than OS will throw an error.Maximum value of file descriptor can be OPEN_MAX.

REMEMBER: whenever we open or create any file , the kernel returns a file descriptor to process.

REMEMBER: UNIX System shells associates the file descriptor 0 with Standard Input of a process, file descriptor 1 with Standard Output, and file descriptor 2 with Standard Error.

Compile and  execute following open.c program.

#define BLOCK_SIZE 4096
int main()
int fd=-1;
char buff[50];
int i=0;
ssize_t bytes_read=-1;
perror(“Open failed”);
return 1;

return 0;

Sample Output









I hope you understand the simple open.c program .Best exercise to do with this program is try to dynamically allocate memory to the buffer .If you have any doubt I am here just a comment far away from you

Getting Started with RTEMS (hello word )

I have proposed Idea in Google summer of code (gsoc) 2015 to develop Board support package(BSP) for x86_64 architecture .As a beginner I am going to create SPARC architecture hello word.

First of all, What RTEMS is ?

The Real-Time Executive for Multiprocessor Systems or RTEMS is an open source Real Time Operating System (RTOS).

For more information, you can always go to

Quickly I would like to show you how to start with the hello world.

I am using Ubuntu 13.10 version. We need to build some RTEMS tools for creating environment.

Install following packages in your Ubuntu :

$ sudo apt-get install build-essential

$ sudo apt-get build-dep binutils gcc g++ gdb unzip git python2.7-dev

$ sudo apt-get install git

After that we first need to suggest the path from where we will use commands for RTEMS.

$ export PATH=$HOME/development/rtems/4.11/bin:$PATH

This is very important step .So You must need to set this path carefully. After building hello word Every time this command have to be issued to use rtems in-built tools.

For setup of RETMS ,

Any where directory can be created in User space .But I would like to create in home directory .So open the terminal .change your directory to home directory

$ cd

$mkdir -p development/rtems/src

From Git repo ,It would better if we have latest RTEMS source builder .

$git clone git://

$ cd rtems-source-builder

If everything went good then check it whether it works or not .

$ source-builder/sb-check

RTEMS Source Builder environment is ok

This message should be issued in terminal.

Now we need tools like Gcc,Gdb etc for any kind of development in particular architecture

We can always check .Right now which architecture is supported by RTEMS

$ ./source-builder/sb-set-builder –list-bsets

Here I am going to setup environment to create hello word for sparc architecture.

$ ../source-builder/sb-set-builder –log=l-sparc.txt \ –prefix=$HOME/development/rtems/4.11 4.11/rtems-sparc

Check if environment is setup using

$ ls $HOME/development/rtems/4.11

Now environment for sparc is set up .We need to download rtems4.11 version .

$ cd

$ cd development

$ git clone git:// rtems4.11

check whether directory named rtems4.11  is listed under development directory or not.

$ ls

$ cd rtems4.11 

$ export PATH=$HOME/development/rtems/4.11/bin:$PATH

$ ./bootstrap

$ cd ..

$ mkdir b-sparc

$ cd b-sparc

$ ../rtems4.11/configure –target=sparc-rtems4.11 –enable-rtemsbsp=sis \ –enable-tests=samples –disable-posix

$ make

$ sudo PATH=$HOME/development/rtems/4.11/bin:${PATH} make install

Now you can go to b-sparc

$ cd b-sparc

$ sparc-rtems4.11-gdb `find . -name hello.exe`

Gdb debugger will open and It is a need to start the simulator to debug compiled program.

(gdb) tar sim

(gdb) load

(gdb) r

You will find your default hello word from RTEMS itself.

Now migrate to hello directory using following

$ cd /development/b-sparc/sparc-rtems4.11/c/sis/testsuites/samples/hello

list out the file under Hello directory.

$ ls

Edit that one with your name .Save your modification and again change the location .

$ cd b-sparc

$ make

$ sudo PATH=$HOME/development/rtems/4.11/bin:${PATH} make install

That it. How easy it is to make a hello word.

Any executable file can be debugged in only simulator after compiling.

For checking new hello word

$ cd

$ cd development/b-sparc

$ sparc-rtems4.11-gdb `find . -name hello.exe`

(gdb) tar sim

(gdb) load


My hello word is look like :

hello word

First device driver module on your custom kernel

After compiling custom kernel in UBUNTU 13.10 we can move forward to our first device driver.

Turn on your laptop after compiling kernel and at the time of boot select advance (2nd option…!).

Choose your custom kernel as per your given name.

Now first check on which kernel you logged in with uname -r command in terminal.


Second step is to create new directory called mymodules.

mkdir mymodules

Now change your current directory.

cd mymodules


create firstmodule.c

vi firstmodule.c

write following c program

 *  firstmodule.c – The simplest kernel module.
#include <linux/module.h>    /* Needed by all modules */
#include <linux/kernel.h>    /* Needed for KERN_INFO */

int init_module(void)
    printk(KERN_INFO “Hello world 1.\n”);

     * A non 0 return means init_module failed; module can’t be loaded.
    return 0;

void cleanup_module(void)
    printk(KERN_INFO “Goodbye world 1.\n”);

Close After writing using (CTRL+C).

In the same directory write Makefile

vi Makefile

obj-m += mymodule.o

    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

save and close the file .Keep holding same directory location in terminal and type make

It will compile module .


In module programming there is no <stdio.h>

It uses other header files.One more important thing Module programming does not have Main


_init shows that it is initiation of module.

_Exit shows that it is exit of the module.

Inside module all will be executing concurrently. After Compiling mymodule.ko file will be created. Now its ready to kernel

open your terminal (current directory should be mymodules)and type

insmod mymodule.ko

Thats it.

Your first device driver is ready to work along with current kernel .

Some useful commands for Module loading and unloading

lsmod – To list out how many modules are loaded in the your kernel .

rmmod filename.ko– to unload the loaded module.

insmod filename.ko – to load the module.

modprobe finename.ko – to load the module along with dependencies.

For more information I am always here to help you.Comment your doubts.

Dyamic loading and Unloading of device drivers in Linux

Why people uses Linux server more than windows? Only reason is secure ?

Another reason for using Linux over Windows is for windows we need to reboot after installing device driver .In the case of server we can not reboot the whole server as server is doing important jobs.

On the Linux device drivers can be added on the fly .No need of reboot .This feature is known as Dynamic loading and unloading. Even if driver unloaded from kernel It will immediately be disabled.

Dealing with archive file in Linux

Tar is command which can be used to extract, create , modify or maintain the file that are archived in tar format.

I recommended following basic argument must be remembered as beginner programmer to deal with compressed file.

c, –create

is  used to create new archive file

x, –extract, –get

is used to extract from archive file

-f, –file=ARCHIVE  

Use archive file (or device) ARCHIVE.

-j, –bzip2

to read or write archives using the bzip2 compressor.

-J, –xz

to read or write archives using the xz compressor.

-z, –gzip, –gunzip

to read or write archives through gzip

-Z, –compress, –uncompress

use the compress program when operating on files.

So these are the some of the basic command argument which is frequently used with tar function.

In linux single dash() is used with single letter and with full function name double dash() is used.Value can be assigned(=) to full funcation name only like

tar --create --file=archive.tar file1 file2

from above all arguments , lets take example of first argument

c, –create

here both are same , any one can be used to create archive

i.e tar -c file

i.e  tar –create  file

for other arguments rules will be same.

So i think you guys now able to play with compressed files. 🙂

How to compile custom kernel in Ubutntu ?

Today we will initiate first step to create our own kernel. So carefully following steps to build kernel inside ubuntu.I am using 64-bit ubuntu 13.10.

First of go to and download any kernel version (recommended latest stable version)

After downloading Right-click and extract here.

then open terminal (CTRL+ALT+T)

STEP 1: Enter into root user



enter your root password.

If it gives any error even if you are typing your password then reset it by  typing sudo root passwd.

then enter new unix password that’s it.

Now enter into root user.When you enter into root user $ will become # in terminal.

step 2:

type cd Downloads/ to change your directory

and create directory named kernel by typing mkdir kernel

Screenshot from 2015-03-09 21:20:10

step 3:

For a while open your Download folder into ubuntu .

copy linux-x.x.x to kernel directory.

step 4:

Now we need to install some necessary packages inside system so

open new terminal (CTRL+ALT+T) and type

sudo apt-get install gcc libncurses5-dev dpkg-dev

Screenshot from 2015-03-09 21:14:27


step 5 :

After completion of installation Open new terminal (CTRL +ALT +T )

again enter into root user and type your password

change directory type

cd Downlods/kernel/



cd linux-3.10.71

choose as per your version instead using linux-3.10.71

step 6 :


make menuconfig



after some time new GUI will appear inside terminal


select general setup

then local version- append to kernel release


now give any name there .I have given punit-custom


then ok


save the customization. and click on exit until you come to default terminal window.

step 7:

make -j 3 KDEB PKGVERSION=1.punit-custom deb-pkg


you have to type your custom name instead of punit-custom

It will take around 30 minutes …

Final step : sudo dpkg -i ../linux*.deb

now reboot your will final custom kernel in your advance option

How to make Bootable pendrive with command prompt Linux(Without any software ….:-) …)

Sometimes we need to boot the windows 7 into pen drive from Linux operating system.Terminal is good friend of us then why to go for any software .we can make pen drive bootable without any software .Lets see how…!! 😉

  1. Plug in the pen drive and determine the device it’s mounted on with the command:

sudo fdisk -l

2. Umount the device

umount /dev/sdc1

In my case suppose its sdc1 , in your case it may be dev means device

3. Format the pendrive

sudo mkdosfs -n ‘USB-Drive-Name’ -I /dev/sdc -F 32

4.Make the ISO file recognizable to BIOS by using following command

isohybrid filename.iso

5.This step is to copy the ISO file from original location to pendrive

sudo dd if=filename.iso of=/dev/sdc bs=4k

Here write root of your device name for example if your device shown as sbd1 then here write /dev/sbd.

6. Finally before ejecting do following commands:

sudo eject /dev/sdc

That’s it. Very welcome to any queries. any one can issue a topic I can elaborate on that. 🙂