Installation / Testing of TFTP in debian

1) installation

 $ sudo apt-get install xinetd tftpd tftp

where as xinetd – is Extended Internet Services Daemon(xinetd), it is the mechanism for activating and managing servers.

tftpd –  is TFTPDaemon, it is server

tftp –  is client

2) create a /etc/xinetd.d/tftp file, which has following content,

# default: off

# description: The tftp server serves files using the Trivial File Transfer

# Protocol. The tftp protocol is often used to boot diskless

# workstations, download configuration files to network-aware printers,

# and to start the installation process for some operating systems.

service tftp

{

socket_type = dgram

protocol = udp

port = 69

wait = yes

user = nobody

server = /usr/sbin/in.tftpd

server_args = -s /tftpboot

disable = no

}

3) create a directory as mentioned in server_args usually it is named as tftpboot

$ sudo mkdir /tftpboot

$ sudo chmod -r 777 /tftpboot

$ sudo chown -r nobody /tftpboot

4) restart xinetd mechanism, to up and start running our tftp server

 $ sudo /etc/init.d/xinetd restart

5) Checking,

Let us create a test file inside /tftpboot directory

 $ ls / > /tftpboot/test

$ tftp 192.168.1.2

tftp > get test

Received 222 bytes in 0.0 seconds

tftp > quit

You will get same test file at pwd, Hence our tftp server is working fine..You can get your ip address using

$ sudo ifconfig

Enjoy…!

Steps to create Cross Compiling Toolchain using Crosstool-ng

Crosstool-ng is an utility which can automate building of cross compiling toolchain for variety of architectures. Here I will show some steps to build for ARM architecture.

Needed packages, to be installed before using crosstool-ng

 $ sudo apt-get install autoconf automake libtool libexpat1-dev libncurses5-dev bison flex patch curl cvs texinfo build-essential subversion gawk python-dev gperf

Get latest Crosstool-ng

We can install this utility either globally or locally (inside the download directory). I choose latter option, after untarring and getting inside the newly generated directory follow commands as below.

 $ ./configure --enable-local 
 $ make 
 $ make install 

From now, building Cross compiling toolchain starts, be there at the same directory.

Type,

 $ ./ct-ng help 

for help.

Crosstool-ng comes with a set of ready-made configuration files for various typical setups:
Crosstool-ng calls them samples. They can be listed by using ./ct-ng list-samples.

We will use the arm-unknown-linux-uclibcgnueabi sample. It can be loaded by issuing:

 $ ./ct-ng arm-unknown-linux-uclibcgnueabi

Then, to refine the configuration, let’s run the menuconfig interface:

 $ ./ct-ng menuconfig

In Path and misc options:

  • Change Prefix directory to /usr/local/xtools/${CT_TARGET}. This is the place where the toolchain will be installed.
  • Change Maximum log level to see to DEBUG so that we can have more details on what happened during the build in case something went wrong.

In Toolchain options:

  • Set Tuple’s alias to arm-linux. This way, we will be able to use the compiler as arm-linux-gcc instead of arm-unknown-linux-uclibcgnueabi-gcc, which is much longer.

In Debug facilities:

  • Enable gdb, strace and ltrace. Remove the other options (dmalloc and duma). In gdb options, make sure that the Cross-gdb and Build a static gdbserver options are enabled; the other options are not needed.

Then, create the directory /usr/local/xtools/ and change its owner to your user, so that Crosstool-ng can write to it. Then, create the directory $HOME/src in which Crosstool-NG will save the tarballs it will download.

 $ ./ct-ng build

Wait, sometime to finish the process.

Enjoy….!

(FATAL: cannot open /dev/ttyUSB0: Device or resource busy ) How to connect ARM development board with Linux distro (development workstation)

When I tried to plug my development board, I saw serial port as ttyUSB0, but unfortunately it disappeared / disconnected. After googling I found the reason behind this is brltty (used for blinds) refer this. So, I decided to remove it

$ sudo apt-get remove brltty

After removing,

$ dmesg

[ 4876.621231] usb 7-1: FTDI USB Serial Device converter now attached to ttyUSB0

yes my development board is connected with development system at /dev/ttyUSB0.

$ ls -l /dev/ttyUSB0

crw-rw—- 1 root dialout 188, 0 Apr 25 11:51 /dev/ttyUSB0

I need to add my user to group “dialout” to access the serial port (ttyUSB0),

$ sudo adduser audhil dialout

Next problem is, when I  try to connect it with picocom(terminal emulation program) for serial communication.

$  picocom -b 115200 /dev/ttyUSB0 

where as baud rate is 115200, and my board is at /dev/ttyUSB0 port.

picocom v1.4

port is : /dev/ttyUSB0
flowcontrol : none
baudrate is : 115200
parity is : none
databits are : 8
escape is : C-a
noinit is : no
noreset is : no
nolock is : no
send_cmd is : ascii_xfr -s -v -l10
receive_cmd is : rz -vv

FATAL: cannot open /dev/ttyUSB0: Device or resource busy

To resolve this, I found the process which is using my serial port as,

$ sudo lsof /dev/ttyUSB0

COMMAND    PID    USER    FD    TYPE    DEVICE    SIZE/OFF    NODE    NAME

modem-man  1069    root      29u   CHR      188,0            0t0         484165    /dev/ttyUSB0

I need to edit /lib/udev/rules.d/77-mm-usb-device-blacklist.rules (for info) and add my new blocklist rule for my device.

$ sudo vim /lib/udev/rules.d/77-mm-usb-device-blacklist.rules

and add the line as below,

# Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC
ATTRS{idVendor}==”0403″, ATTRS{idProduct}==”6001″, ENV{ID_MM_DEVICE_IGNORE}=”1″

You can get info of chip for writing the rule as above, from

$  lsusb | grep FT232

Bus 007 Device 011: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC

Again trying to connect with picocom

$picocom -b 115200 /dev/ttyUSB0

picocom v1.4

port is : /dev/ttyUSB0
flowcontrol : none
baudrate is : 115200
parity is : none
databits are : 8
escape is : C-a
noinit is : no
noreset is : no
nolock is : no
send_cmd is : ascii_xfr -s -v -l10
receive_cmd is : rz -vv

Terminal ready

uboot>

press ctrl+a followed by ctrl+x to exit picocom

This time I succeded, my board is communicating with my development workstation.

Enjoy…!

How to Cross Compile Linux Kernel for ARM

Get the latest linux kernel

Follow commands,

$ tar -xf linux-x.xx.x.tar.gz
$ cd linux-x.xx.x/
$ make distclean

I use cross compiler which I created using crosstool ng, and my development board holds lpc3250

$ make ARCH=arm CROSS_COMPILE=arm-linux- lpc32XX_defconfig
$ make ARCH=arm CROSS_COMPILE=arm-linux-

You will get the kernel image at arch/arm/boot/zImage

But to create uImage, we can change our last command as below

$ make ARCH=arm CROSS_COMPILE=arm-linux- uImage

As a result you may get both zImage and uImage inside arch/arm/boot/ directory.

Enjoy…!

To remove anything, which is not completely installed using “sudo apt-get -f install “

Hi,

If any package which is not installed properly can be removed using

$ sudo apt-get -f install

main use of removing is we can get back our disk space, which is occupied by the package….

Enjoy…!

blkid – to find out file system of each partition in hard disk

Hi,

We can find out file system of each partition as follows

$ sudo blkid -o value -s TYPE /dev/sda1

ntfs

$ sudo blkid -o value -s TYPE /dev/sda2

ntfs

$ sudo blkid -o value -s TYPE /dev/sda3 (it is an extended partition)

$ sudo blkid -o value -s TYPE /dev/sda4

ext3

$ sudo blkid -o value -s TYPE /dev/sda5 (logical partition)

ntfs

$ sudo blkid -o value -s TYPE /dev/sda6 (logical partition)

ntfs

$ sudo blkid -o value -s TYPE /dev/sda7 (logical partition)

ext3

Make a note of it…

Enjoy…!

How to boot and run Ubuntu inside bochs emulator and make a virtual machine

I suggest simple steps for running ubuntu inside bochs emulator and my processor is Pentium(R) Dual-Core CPU T4500 @ 2.30GHz running debian distro.

Installation is simple,

$ sudo apt-get install bochs

This package contains an X11 GUI plugin for Bochs,

$ sudo apt-get install bochs-x

Another way of installation…

In order, to boot up a Operating system inside bochs we need

1) iso image of respective OS

2) disk image

3) bochsrc file

Hence,

For downloading iso image of ubuntu click here

For creating disk image

$ mkdir test

$ cd test/

$ bximage

It will drop to

========================================================================
                                                                    bximage
                                            Disk Image Creation Tool for Bochs
                         $Id: bximage.c,v 1.34 2009/04/14 09:45:22 sshwarts Exp $
========================================================================

Do you want to create a floppy disk image or a hard disk image?
Please type hd or fd. [hd]<press ENTER>

What kind of image should I create?
Please type flat, sparse or growing. [flat]<press ENTER>

Enter the hard disk size in megabytes, between 1 and 129023
[10] <How much MB of disk image>10240<press ENTER>

I will create a ‘flat’ hard disk image with

cyl=20805
heads=16
sectors per track=63
total sectors=20971440
total size=10239.96 megabytes

What should I name the image?
[c.img]<give any name>dummy.img<press ENTER>

Writing: [] Done.

I wrote 10737377280 bytes to dummy.img.

The following line should appear in your bochsrc:
ata0-master: type=disk, path=”dummy.img”, mode=flat, cylinders=20805, heads=16, spt=63

As a result you created a hard disk image dummy.img of size 10G inside present working directory. Be aware of including last line of previous output inside bochsrc file.

Next,

Creation of bochsrc file

$ vim bochsrc

My simple bochsrc file is

# bochsrc
#
megs: 1024
#
mouse: enabled=1
#
ata0-master: type=disk, path=”ubuntu.img”, mode=flat, cylinders=20805, heads=16, spt=63
ata1-master: type=cdrom, path=./ubuntu-12.10-desktop-i386.iso, status=inserted
#
log: ubuntuop.txt
#
boot: cdrom

Description,

megs: 1024 – I allocated 1024MB of RAM for my emulator

mouse: enabled=1 – I enabled mouse inside my emulator

ata0-master: type=disk, path=”ubuntu.img”, mode=flat, cylinders=20805, heads=16, spt=63 – Inclusion of hard disk image specification

ata1-master: type=cdrom, path=./ubuntu-12.10-desktop-i386.iso, status=inserted – Inclusion of OS iso image

log: ubuntuop.txt – It is normally a log file, which keeps tracking of emulator execution, can be referred at anytime for debugging purpose

boot: cdrom – boot my OS from cdrom(iso image of ubuntu) inside emulator

Be sure, that iso image file(ubuntu) + hard disk image file + bochsrc all at same directory.

To run ubuntu inside bochs,

$ bochs 

A new window will pop up and ubuntu will start booting inside of it.

Since it is Emulator, process of booting ubuntu may be slow, be patience to see how it is booting.

Enjoy…!

reference

“Init” is the first program that gets executed when linux kernel boots up. I created a compressed root file system in cpio format that hold only init file inside to it.

Prerequisites…

To get latest stable kernel click here

For qemu emulator installation click here

Short story

  • compile minimal kernel
  • create init from scratch
  • test using qemu emulator

Big story

Compiling minimal Kernel

$ tar -xvf linux-3.8.5.tar.xz

$ cd linux-3.8.5/

$ make distclean

$ make defconfig

$ make

As a result of above steps you will get kernel image

linux-3.8.5/arch/x86/boot/bzImage

Creating init from scratch

Create a fresh directory

$ mkdir test

$ cd test/

Create dummy.c file

$ vim dummy.c

FYI, content of dummy.c

#include <stdio.h>
int main(int argc,char *argv[])
{
char name[100];
printf(“Hello World…!\n”);
puts(“enter your name :”);
gets(name);
printf(“your name is : %s\n”,name);
while(1);
}

You can judge it as simple program!

Yes my init will prompt me to enter my name and it will print back to me, nothing more than this.

I am compiling statically linked version of above program, and naming the executable as init

$ gcc -static dummy.c -o init

To create cpio.gz format of executable

$ echo init | cpio -o -H newc | gzip > initramfs.cpio.gz

Copy kernel image, inside test directory

$ cp ../linux-3.8.5/arch/x86/boot/bzImage .

Testing using Qemu emulator

Be aware of kernel image and initramfs.cpio.gz are in same directory, then type the below command

$ qemu-system-i386 -kernel ./bzImage -initrd ./initramfs.cpio.gz

you will get,

qemu-system-i386: pci_add_option_rom: failed to find romfile "efi-e1000.rom"

VNC server running on `::1:5900'

Open a new terminal and type the below command

xvnc4viewer : 5900

Kernel will boot inside qemu emulator, and prompt for name, after insertion of name, it will again print back, as we expected.

Something like,

Hello World…!

enter your name : 

Mohammed Audhil

your name is : Mohammed Audhil

Congrats..! You made kernel to work for you…!

Enjoy…!

How to boot and run Ubuntu inside Qemu emulator and make a virtual machine

For installation of Qemu refer here

My host is a debian distro.

After successful installation, every body wants to test how it works, here I share a small demo installing Ubuntu 12.10 inside qemu emulator.

Click here to download Ubuntu 12.10 desktop image, you will get an image file of somewhat 750MB (named as ubuntu-12.10-desktop-i386.iso).

Creating a disk image of 10G to hold ubuntu.

 $ qemu-img create ubuntu.img 10G

Confirm both disk image and ubuntu’s iso image at same directory,

 $ qemu-system-i386 -hda ubuntu.img -boot d -cdrom ./ubuntu-12.10-desktop-i386.iso -m 512

qemu-system-i386 – normal qemu command represented for x86 machine

-hda – refers to hard disk, here I used the same 10G hard disk image

-boot [ a | c | d | n ] – boot from floppy disk(a), hard disk(c), cdrom(d), or etherboot(n), you may note that I used ‘d’ here

-cdrom – since I am booting using cdrom, I need an iso image, which I replaced by ubuntu-12.10-desktop-i386.iso

-m 512 – I allocated RAM of 512 MB for the virtual machine.

On hitting enter, it will prompt with VNC server, you need a VNC viewer to see Ubuntu booting…refer bottom of this for VNC info.

Since it is Emulator, process of booting ubuntu may be slow, be patience to see how it is booting.

Enjoy…!

Qemu – Emulator installation

Qemu is a powerful emulator and installation is very simple…

I suggest simple steps for running ubuntu inside Qemu emulator and my processor is Pentium(R) Dual-Core CPU T4500 @ 2.30GHz running debian distro.

a) qemu latest source code can be downloaded from here

b)

$ tar -xvzf qemu.x.xx.x.tar.gz

c)

$ cd qemu.x.xx.x

Am building qemu for x86 architecture

d)

$ ./configure --target-list=i386-softmmu

compiling,

e)

$ make

installing,

f)

$ sudo make install

once finished with installation you need to be client of VNC server please refer here for more info

For checking our installation

Please type

$ qemu-system-i386

you will get something like

qemu-system-i386: pci_add_option_rom: failed to find romfile “efi-e1000.rom”

VNC server running on `::1:5900′

nothing else.

It is prompting us to open the VNC viewer since qemu does not has any inbuild GUI.

To see output, open a new terminal and enter as below

$ xvnc4viewer :5900

you will get a black window of name (VNC: QEMU) and showing some thing like

SeaBIOS (version …..)

Booting from Hard Disk…

Boot failed: could not read the boot disk

Booting from Floppy…

Boot failed: could not read the boot disk

Booting from DVD/CD…

Boot failed: could not read from CDROM (code 0003)

No bootable device.

If you get as above congrats you successfully completed the task…!

Enjoy…!