Monday, 29 April 2013

Makefile in linux Kernel


The Makefile controls the creation of the actual image file. This includes control of the program and
device files install destinations, install destinations of data and configuration files required by the program, and checksum generation. Makefile with single source file.

hello.c
------------------------------------------------------------------------------------------------------------------------
#include <stdio.h>
int main()
{
printf(“World”);
return 0;
}
------------------------------------------------------------------------------------------------------------------------

Makefile
------------------------------------------------------------------------------------------------------------------------
EXEC = hello
OBJS = hello.o

all: $(EXEC)
$(EXEC): $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS)
clean:
-rm -f $(EXEC) *.elf *.gdb *.o
%.o: %.c
$(CC) -c $(CFLAGS) -o $@ $< //if $(CC) =$(CROSS_COMPILE_APPS)gcc

------------------------------------------------------------------------------------------------------------------------

Executables with multiple source code files can be supported by making changes in the Makefile. The following example generates a single executable.

For Example: hello from hello.c and print.c.

hello.c
------------------------------------------------------------------------------------------------------------------------
#include <stdio.h>
extern void print_hello(char * string);
int main(int argc, char * argv[])
{
print_hello(“World”);
return 0;
}

------------------------------------------------------------------------------------------------------------------------

print.c
------------------------------------------------------------------------------------------------------------------------
void print_hello(char * string)
{
printf(“Hello %s\n”, string);
}
------------------------------------------------------------------------------------------------------------------------
Makefile
------------------------------------------------------------------------------------------------------------------------
EXEC = hello
OBJS = hello.o print.o ----------------------------------- Add “print.o”

all: $(EXEC)
$(EXEC): $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS)
clean:
-rm -f $(EXEC) *.elf *.gdb *.o
%.o: %.c
$(CC) -c $(CFLAGS) -o $@ $< //if $(CC) =$(CROSS_COMPILE_APPS)gcc

------------------------------------------------------------------------------------------------------------------------
This Makefile will create two files
  1. FLAT: formate binary file, This is the file which is an executable on target.
  2. .gdb: extension file, This will be containing additional debug & symbol table information to allow user to debug user application program with GBD.

Sunday, 28 April 2013

How to compile a Kernel and upgrade the kernel version for PC


                                                        How to compile a Kernel
                                                                   

 Downloading and configuring

Step1: Downloading :

      Download a kernel, unpack it into any path and create the “linux” link so that the commands are a little more generic. File name would be linux-x.y.z.tar.bz2, where x.y.z is actual version number.


For example I am taking a file inux-2.6.37.6.tar.bz2 which represents 2.6.37.6 kernel version. Use wget command to download kernel source code. It is common to let the ”linux” link point to the kernel you are currently working with.



 Step2:
   
 Now, get a kernel config file by following these steps.

Step3: configuring
It's a good idea to use the configuration of our current working kernel as a basis for the kernel. Therefore we copy the existing configuration to /usr/src/linux:  

 Step4:
            :/usr/src/linux#

Which brings up the kernel configuration menu. Go to Load an Alternate Configuration File and choose .config (which contains the configuration of your current working kernel) as the configuration file:





Then we need to browse through the kernel configuration menu and make our choices. When we finished and select Exit, answer the following question (Do you wish to save your new kernel configuration?) with Yes:






Step 5: Build The Kernel
   
To build the kernel, execute these two commands:

After --append-to-version= you can write any string that helps you identify the kernel, but it must begin with a minus (-) and must not contain whitespace.
Now be patient, the kernel compilation can take some hours, depending on our kernel configuration and our processor speed.

Step 6: Install The New Kernel
After the successful kernel build, we can find two .deb packages in the /usr/src directory.
They were called linux-image-2.6.37.6-custom_2.6.37.6-custom-10.00.Custom_i386.deb (which contains the actual kernel) and linux-headers-2.6.37.6-custom_2.6.37.6-custom-10.00.Custom_i386.deb (which contains files needed if you want to compile additional kernel modules later on). I install them like this:


 


 
(We can now even transfer the two .deb files to other Ubuntu systems and install them there exactly the same way, which means you don't have to compile the kernel there again.)
That's it. We can check /boot/grub/menu.lst now, we should find two stanzas for our new kernel there:

Text Box: vi /boot/grub/menu.lst



Now we can see these two stanzas;

title           Ubuntu, kernel 2.6.37.6-custom
root            (hd0,0)
kernel          /boot/vmlinuz-2.6.37.6-custom root=/dev/sda1 ro quiet splash
initrd          /boot/initrd.img-2.6.37.6-custom
savedefault
boot

title           Ubuntu, kernel 2.6.37.6-custom (recovery mode)
root            (hd0,0)
kernel          /boot/vmlinuz-2.6.37.6-custom root=/dev/sda1 ro single
initrd          /boot/initrd.img-2.6.37.6-custom
boot

Step 7: update-grub
Step 8: Reboot
Text Box: $  reboot



Step 9:
If everything goes well, it should come up with the kernel. We can check this by running
Text Box: uname -r



This will display something like 2.6.37.6-custom



TO UNISTSLL THE OLDER KERNEL:
This will show you how to find out your current running kernel and how to remove older ones that are not being used by your system. This will help you free up some space and may also improve your system’s performance.
Objectives:
·      Find out your current running kernel
·      Remove older kernels 

Step 1: To get started, press Ctrl – Alt – T to open Terminal. When it opens, run the commands below to view your current running kernel.
uname -r

Next, take notes of your current kernel. DO NOT REMOVE THIS!

Step 2: Next, type the command below to view / list all installed kernels on your system.
dpkg --list | grep linux-image

Next, find all the kernels that which number are lower than your current kernel.  When you know which kernel to remove, continue below to remove it.
Step 3: Finally, run the commands below to remove the kernel you selected.
sudo apt-get purge linux-image-x.x.x.x-generic


When you’re done, run the commands below to update grub2
Step 4:
sudo update-grub2


Tuesday, 23 April 2013

How to Install/setup social media chatting like Gtalk,Ipmsg,and Skype on Linux(Ubuntu 12.04)


In ubuntu(12.04) social meada and chattig software installation

1.Gtalk:

go to ubutu software center
--> search for emphathy
click to install or uninstall the software.


2. Pidgin:
      This is same as empathy this also you can install it in the same way as empathy


3. IP messanger:

go to ubutu software center
--> search for xipmsg


click to install or uninstall the software.

4. Skype:
go to ubutu software center
--> search for skype

click to install or uninstall the software.

5. Start on system startup:
to left most top corner you will get click on it you will get a option saying startup application

click on it to add your executable to start on system startup

Executabls are present in path /usr/bin

How to access and change the u-Boot env variables in linux


Have you ever thought to change the U-boot settings once, after you got the Linux console? Well, you might be thinking to entering into the U-boot setting prompt to do this. But there is a beautiful method already exist to achieve this operation!

Well, here I'm not giving anything from the sky or vanishing anything like a magician, but trying to show a Utility tool (you can't say exactly it's a tool, better it can be consider as one option ;) ) which already available :0 .

All you have to do is, to try some geeky way (though very simple) only at once and do the magic always.
The key tool which you have to enable is "fw_printenv" from the U-boot.

Follow the below steps to make the wonders in U-boot from your own lovely Linux console ;)
  1. Step 1: Generate the "fw_printenv" utility tool in U-boot

    1. give 'env' (optional parameter) in u-boot and compile it. Be patient for the compilation ;) 
    2. The above step generate the 'fw_printenv' in the U-Boot directory tools/env 
    3. Copy the 'fw_env.config' file too.
  2. Step 2: Well, we copied, but where to paste it ! Follow the steps ;)

    1. Copy fw_printenv to /sbin on the root file system of your own board. 
    2. The interesting thing here is that the fw_printenv binary also contains the code for fw_setenv.  The functions of fw_setenv are run when the program is invoked with the name "fw_setenv".   this is most easily accomplished by creating a symbolic link from fw_printenv to fw_setenv, as in "ln -sf /sbin/fw_printenv /sbin/fw_setenv"                                                                                       
  3. Step 3: Create config file for the utility, in order to take place the action(I have not used config file in my example given here).

    1. Remember, you copied 'fw_env.config' from 'u-boot/tools/env/' path? But you didn't play with  it yet right? ;) Well, this is the right time for that! All you have to do is, copy the fw_env.config  into /etc path. Finished? Relaxed? No...remember, this is a geeky professional way dude ;) 
    2. Open the 'fw_env.config' and make required changes related to env size, flash sector size and number of sectors according to flash which you are using. You have to change the fw_env.config with respect to your system modification rather than simply putting it into /etc. you can easily check this from /proc/mtd.
Once you configure the appropriate values in fw_env.config, then rest of the stuffs are pretty easy.

From the Linux console, you can print the u-boot setting by giving the fw_printenv where as with fw_setenv , you can edit the u-boot settings!!! Easy right? 

If you get something like:

Warning: Bad CRC, using default environment
bootcmd=bootp; setenv bootargs root=/dev/nfs nfsroot=${serverip}:${rootpath} ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}::off; bootm
bootdelay=5
baudrate=115200
it means the values in /etc/fw_env.config are not correct, so don't even try fw_setenv

Example wrt  processor architecture.
changes did with respect to my LPC1788 board(changes highleted with yellow collour).
  1. u-boot/tools/env/Makefile changed:
#
# (C) Copyright 2002-2006
# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
#
# See file CREDITS for list of people who contributed to this
# project.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
#
include $(TOPDIR)/config.mk
SRCS := $(obj)crc32.c fw_env.c fw_env_main.c
HEADERS := fw_env.h
CPPFLAGS := -Wall -DUSE_HOSTCC -I$(SRCTREE)/include
CFLAGS := -Os -mcpu=cortex-m3 -mthumb -I$(INSTALL_ROOT)/linux/inlude/linux
LDFLAGS := -mcpu=cortex-m3 -mthumb -L$(INSTALL_ROOT)/linux/lib
ifeq ($(MTD_VERSION),old)
CPPFLAGS += -DMTD_OLD
endif
all: $(obj)fw_printenv
$(obj)fw_printenv: $(SRCS) $(HEADERS)
$(CROSS_COMPILE)gcc $(CPPFLAGS) $(LDFLAGS) $(SRCS) -o $(obj)fw_printenv
clean:
rm -f $(obj)fw_printenv $(obj)crc32.c
$(obj)crc32.c:
ln -s $(src)../../lib_generic/crc32.c $(obj)crc32.c
#########################################################################

include $(TOPDIR)/rules.mk

sinclude $(obj).depend

#########################################################################


Note: copied from application folder /app/Makefile(This two lines says that we need to compile wrt  processor architecture.)

CFLAGS := -Os -mcpu=cortex-m3 -mthumb -I$(INSTALL_ROOT)/linux/inlude/linux
LDFLAGS := -mcpu=cortex-m3 -mthumb -L$(INSTALL_ROOT)/linux/lib

2. fw_env.h
----------------------------------------------------------------------------------------------------------------------------------
/*
* (C) Copyright 2002-2008
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
*
* See file CREDITS for list of people who contributed to this
* project.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
/*
* To build the utility with the run-time configuration
* uncomment the next line.
* See included "fw_env.config" sample file (TRAB board)
* for notes on configuration.
*/
/*#define CONFIG_FILE "/etc/fw_env.config"*/
/*#define HAVE_REDUND For systems with 2 env sectors */
#define DEVICE1_NAME "/dev/mtd0"
/*#define DEVICE2_NAME "/dev/mtd2"*/
#define DEVICE1_OFFSET 0x00000
#define ENV1_SIZE (4 * 1024) /* taken it with comparig to the file u-boot/include/configs/lpc-lnx-evb.h*/
#define DEVICE1_ESIZE 0x20000 /*taken from proc/mtd erasesector*/
#define DEVICE1_ENVSECTORS 1
/*#define DEVICE2_OFFSET 0x0000
#define ENV2_SIZE 0x4000
#define DEVICE2_ESIZE 0x4000*/
#define CONFIG_BAUDRATE 115200
#define CONFIG_BOOTDELAY 5 /* autoboot after 5 seconds */
#define CONFIG_BOOTCOMMAND \
"bootp; " \
"setenv bootargs root=/dev/nfs nfsroot=${serverip}:${rootpath} " \
"ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}::off; " \
"bootm"
extern int fw_printenv(int argc, char *argv[]);
extern char *fw_getenv (char *name);
extern int fw_setenv (int argc, char *argv[]);
extern unsigned long crc32 (unsigned long, const unsigned char *, unsigned);
----------------------------------------------------------------------------------------------------------------------------------

Well, I would like to share three good web links also for your better understanding..