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 https://www.rtems.org/

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://git.rtems.org/rtems-source-builder.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://git.rtems.org/rtems 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

(gdb)

My hello word is look like :

hello word

Advertisements

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.

1

Second step is to create new directory called mymodules.

mkdir mymodules

Now change your current directory.

cd mymodules

2

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

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

clean:
    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 .

4

In module programming there is no <stdio.h>

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

function.

_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 www.kernel.org 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

su

roor

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

xx

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/

ls

x

cd linux-3.10.71

choose as per your version instead using linux-3.10.71

step 6 :

ls

make menuconfig

w

y

after some time new GUI will appear inside terminal

gui

select general setup

then local version- append to kernel release

z

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

punit-custome

then ok

save

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

make

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 computer.you 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 different.here 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:

sync
sudo eject /dev/sdc

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