Thursday, February 22, 2007

How to test Null-modem serial cable

[machine A ]--------Null-Modem Serial Cable -------[ machine B ]


1. Set serial line in and out speed in both machine A and B
stty ispeed 115200 ospeed 115200 -F /dev/ttyS0

2. Send a sample file to machine B from machine A
cat testfile.txt > /dev/ttyS0

3. Receive the sample file in machine B from machine A
cat /dev/ttyS0

Wednesday, February 21, 2007

How to Setup KGDB

[Developemnt machine]--Null-Modem Serial Cable --[ target machine ]

1. connect target and development machine using Null-Modem Cable

2. kernel should be compiled for kgdb (kernel gdb) support. Either we can compile the kernel in the target machine itself or cross compile in the development system

3. If compiled in the target machine then copy the vmlinux and source code to development machine.

4. If compiled in the development machine then copy the bzImage to target system /boot directory and update the boot loader

5. Include the following kernel command line option "kgdbwait kgdb8250=0,115200" in the target kernel option

6. After booting, the target machine will wait for the host development machine to connect, by displaying the message :- Waiting for connection from remote gdb...

7. In the development machine,

root# gdb vmlinux

(gdb) shell echo -e "\003" > /dev/ttyS0
(gdb) set remotebaud 115200
(gdb) target remote /dev/ttyS0
Remote debugging using /dev/ttyS0
breakpoint () at kernel/kgdb.c:1212
1212 atomic_set(&kgdb_setting_breakpoint, 0);
warning: shared library handler failed to enable breakpoint
(gdb)

8. Give c "continue" (gdb) to boot the target machine.

9. If any crash in the target system then (gdb) in the development machine will break and using bt (back trace) you can get the exact kernel crash location

Redhat Kernel Compilation

1. Copy kernel source to your custom source
cp -R /usr/src/linux-2.4.x/ /usr/src/linux-2.4.xcustom/

2. Open /usr/src/linux-2.4.xcustom/Makefile and append "custom" to EXTRAVERSION

3. Remove already existing kernel compiled files
make mrproper

4. copy existing config file to /usr/src/linux-2.4.xcustom/
cp /boot/config-2.4.x /usr/src/linux-2.4.xcustom/.config

5. Do required changes in the existing configuration by menuconfig
make menuconfig

6. Do dependency compilation
make dep

7. Do kernel image compilation
make bzImage

8. Do kernel module compilation
make modules

9. Install kernel modules. This will install new modules in /lib/modules/2.3.xcustom
make modules_install

10. Install kernel images in to /boot directory and also update /etc/grup.conf
make install

new image is /boot/vmlinuz-2.4.xcustom
new initrd is /boot/initrd-2.4.xcustom.img

Friday, March 10, 2006

Terminal color code for vt100

This is very useful if you want to display your text messages in color from your c program(printf) on linux console


Format : esc[[{attribute};{foreground};{background}m
key stock for esc[ = CTRL+v ESC = hex char value of 0×1B(used in printf with %c format)
attribute 0 – reset, 1 – bright, 2 – dim, 3 – uderline
foreground (30 + color)
background (40 + color)
color 0 – black, 1 – red, 2 – green, 3 – yellow, 4 – blue

Example
^[[1;31;49m

Attr: Bold fg:red bg:white

Tuesday, March 07, 2006

Ext3 File System

Ext3 FS = (Ext2 FS) + Journal

Advantage over Ext2 File System = Fast crash recovery


Converting an Ext2 File System into an Ext3 File system in Linux OS

Use tune2fs command with -J option to add journal support to your partition edit the file /etc/fstab, change the file system type specified for the corresponding partition from ext2 to ext3

Swap partition

what is swap partition? – portion of hard disk space is used as RAM. useful for system which has less RAM and still want to run large programs.

How to create swap memory in linux?

  • create a empty file of required swap size
    dd if=/dev/zero of=/swap-file bs=1k count=65536
    swap memory = count*bs = 65536*1k = 64 MB
  • convert this file into a swap file format
    mkswap /swap-file 65536
  • enable swap file system
    swapon /swap-file

RAM disk

What is RAM disk?
RAM disk is a portion of RAM which is being used as a disk drive. Any data stored in RAM disk is lost when system is switched off. very useful for embedded system where there is not disk drive. Linux kernel 2.4 has built-in support for ramdisks

How to create a RAM disk in linux?
  • RAM disk size : default RAM disk size supported by linux is 4 MB so, if you need more ram space then include ramdisk_size=XXXX in kernel command line for kernel to reserve memory for ramdisk. here XXXX is ram size expressed in 1k block. for 16 MB, ramdisk_size=16000
  • Format your RAM disk : command :- mke2fs – m 0 /dev/ram0 16384. Linux supports 16 RAM disks by default (ram0 to ram15).
  • Mount your RAM disk : command :- mkdir /mnt/rd; mount /dev/ram0 /mnt/rd
  • Verify your RAM disk : command :- df -h

How to create RAM disk for embedded linux?

  • create a empty file of your file system size. here it is 16MB command :- dd if=/dev/zero of=ramdisk bs=1k count=16384
  • format the empty file as ext2 file system command :- mke2fs -F -m 0 -i 1024 ramdisk
  • create a mount point and mount the empty file system command :- mkdir ramdiskmountpoint;mount -t ext2 -o loop ramdisk ramdiskmountpoint
  • copy the tinytarget(uclibc and busybox) to mounted file system command :- cp -a tinytarget/* ramdiskmountpoint/
  • unmount the mount point and delete it command :- umount ramdiskmountpoint;rm -rf ramdiskmountpoint
  • compress the new file system present in raddiskfile command :- gzip -v9 ramdisk
  • Copy ramdisk.gz to arch/XXXX/ramdisk/ramdisk.gz where XXXX is target name. ex. ppc,mips,arm,etc.,
  • Enable the following options in kernel config : ramdisk and initial ramdisk