Tuesday, March 13, 2012

Constructing a new house

I bought an 8M plot in Bahria town Lahore last year and now planning to start construction on it. I spent last few months meeting with people who have recently constructed their houses, talking to various builders,architects and visiting newly constructed or under construction houses at Bahria. It was an awesome experience and I learned lots of ins and outs of construction process.


STEP 1 Drawing the map:
================
The first and most important step is to draw map of your dream house. To me, it totally depends on your requirements, your aesthetic sense, location and size of your plot. I visited many houses in Bahria town Lahore and other places, met their owners, got their feedback, discussed map of their house with them.  Below are some maps that I got from various sources during this survey. Almost all of them are less than 10M as my plot size is 8M so I was not interested in anything greater than 8M.

If you are like to draw your own maps, download sketchup and draw your own house maps. It is very powerful tool and has various interesting features.

Bahria Town Houses Maps:
===================

House Number 1:
============
 

House Number 3
==============
 

House Number 4:
================
 

Lake City Maps:
============
You can get maps of LakeCity villas from http://www.lakecitylahore.com/villas.html. They have villas in following sizes:
  • 10 Marla:  
  • 12 Marla: 
  • 14 Marla
  • 1 Kanal
Safari Villas Maps:
==============
Although I personally don't like design of safari villas but you can also look at maps of different safari villas to get an idea about house design. Bahria offers different styles in villas including:
 Izhar Villas:
=========
Izhar is a big group and their villas are very well designed and constructed. Izhar offers following Villas:
They have given complete maps with floor plans and pictures of interior. I personally like their villas.

Valencia Homes:
============
Valencia homes are available in following sizes:
  • 5 Marla
  • 10 Marla
  • 8 Marla
  • 16 Marla
You can find details of these houses from http://www.valanciahomes.com/

I will keep on updating this post as I get more maps. May Allah (SWT) bless all of you and your families with nice, beautiful and comfortable houses. Aaameen.

Monday, March 5, 2012

QEMU: Debugging your program

Lesson Number 2:
=============
This lesson assumes that reader is done with first lesson and has compiled and run HelloWorld application on QEMU's ARM emulation.

Debugging your program:
=================

To debug your program, you first need to build your program with debug information. For this gcc has -g switch. So your HelloWorld program needs rebuilding with -g compiler switch. Complete command will be:

arm-none-eabi-gcc -g3 -o HelloWorldARM HelloWorld.c -T {TOOLCHAIN_INSTALLATION}/arm-none-eabi/lib/generic-hosted.ld 


Running Program in QEMU with GDBStub:
===========================

Next step is to run this new HelloWorld ELF file on QEMU but we need to enable GDB stub in QEMU and we need to tell it to wait for GDB connection before execution of program. For this QEMU provides two switches
  • -s : QEMU will listen on port localhost:1234 for a connection by GDB
  • -S : QEMU will start as if you set a breakpoint at time zero, and you will need to use the GDB command "continue" to actually begin the simulation.
so command to launch QEMU will be:

 ./arm-softmmu/qemu-system-arm -kernel {PATH_OF_ YOUR_HELLOWORLD_ELF}-semihosting -nographic -s -S




Debug Session with Command-line GDB:
==========================

1) Go to your Sourcery toolchain for arm-none-eabi installation directory. It will be [Toolchain_installation_directory]/bin
2) Start GDB debug session using these commands:

  • ./arm-none-eabi-gdb [PATH_OF_YOUR_PROGRAM_WITH_DEBUG_INFO]
  • target remote localhost:1234
  • b main
  • c 
First command will start gdb and it will print details of GDB and a message of symbol loading.
Second command will ask GDB to connect to GDB server listening on port 1234 of localhost.
Third command will place a breakpoint at main function.
Fourth command will resume (continue) the debug session and it will then hit the breakpoint at main function.
You can then step through the code using "n" i.e. step over or "s" i.e. step into commands at GDB terminal.

Example Command line Debugsession:
========================

taimoor@pkl-tmirza-ubuntu:~/$ ./arm-none-eabi-gdb /home/taimoor/Lab_Preparation/Qemu_Stuff/Example_Programs/helloDashT

GNU gdb (Sourcery CodeBench 2011.09-60) 7.2.50.20100908-cvs
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-none-eabi".
For bug reporting instructions, please see:
<https://support.codesourcery.com/GNUToolchain/>...
Reading symbols from /home/taimoor/Personal/@UCP/Lab_Preparation/Qemu_Stuff/Example_Programs/helloDashT...done.
GDB can't read core files on this machine.

(gdb) target remote localhost:1234
Remote debugging using localhost:1234
__cs3_reset_generic () at /opt/codesourcery/arm-none-eabi/lib/src/generic-reset.S:34
34        b    __cs3_start_asm_sim

(gdb) b main
Breakpoint 1 at 0x274: file HelloWorld.c, line 5.

(gdb) c
Continuing.

Breakpoint 1, main () at HelloWorld.c:5
5        int i=0;
(gdb)


Debug Session with CDT/Cross GDB:
=========================

1) Start CDT
2) Go to Run->Debug Configurations...
3) Create a new debug configuration of type "C/C++ Remote Application"
4) Click Browse Button adjacent to C/C++ Application box and select your HelloWorld Application.
5) No need to specify any project.
6) Click New button next to Connection combo box and create a Local connection. Give any name to connection e.g. I used "Test" and Finish that dialog.

Your configuration should look like this:



7) Go to Debugger tab of your configuration.
8) Click Browse button next to GDB Debugger box and select "arm-none-eabi-gdb" from your toolchain's bin directory.
9) Click Apply to save your configuration and then click Debug button.
10) Your debug session will start and breakpoint in main will get hit.
11) You can step through the code using F6.

Example CDT Debug session:
===================


I modified my HelloWorld program and added a loop in it.

Enjoy Cross Debugging.

QEMU Step by Step

Lesson Number 1:
============


How to install Qemu:
=============

1) Go to http://wiki.qemu.org/Download and install qemu source code. You can use wget http://wiki.qemu.org/download/qemu-1.0.1.tar.gz

2) Unzip downloaded QEMU source via UI or using following command:
tar -xvzf qemu-1.0.1.tar.gz

3) Goto directory where you unzipped QEMU sources and configure your QEMU using following commands:

  • ./configure 
    • If you do not give any target list to ./configure, it will configure qemu for all supported targets. But you can configure QEMU for a particular target using --target-list=[LIST_OF_Targets].
    • You can obtain list of supported targets by running ./configure without any parameter and then scrolling up and see "target list"
    • For x86 run this command as ./configure i386-softmmu
  • make
    • This will build QEMU for configured list of targets.
  • make install
    • I don't prefer installation and normally does not use this command. 

Getting the Toolchain:
==============

The best toolchain available is CodeSourcery's. You need to go to https://sourcery.mentor.com/GNUToolchain/ and install whatever toolchain you need.

I installed arm-none-eabi to use it for baremetal application development.

Writing a Hello World Program:
====================

1) Open any editor and type simple helloworld program. On Ubuntu you can use cat aswell:

$ cat > HelloWorld.c
#include <stdio.h>

int main()
{

     printf("Hello from ARM processor"\n");
     return 0;
}

2) Goto your toolchain installation directory and build your application using following command:

arm-none-eabi-gcc -o HelloWorldARM HelloWorld.c -T {TOOLCHAIN_INSTALLATION}/arm-none-eabi/lib/generic-hosted.ld

3) This will build your HelloWorld program and generate an ELF.

4) You can check the type of generated built file using following command:
  • file ./HelloWorldARM
This will give following:
./HelloWorldARM: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, not stripped

Running program QEMU's ARM CPU Emulator:
=================================

 1) Goto your QEMU directory and run following command:

  • ./arm-linux-user/qemu-arm {PATH_OF _YOUR_HELLOWORLD_ELF}

Running program in QEMU's Machine Emulator:
===============================

1) You can also run your HelloWorld program using QEMU's ARM machine emulation.
  • ./arm-softmmu/qemu-system-arm -kernel {PATH_OF _YOUR_HELLOWORLD_ELF}-semihosting -nographic

Ubuntu Login screen not appearing

Had a hard time today when rebooted my Ubuntu machine after more than 3 months and its login screen stopped appearing. Only pinkish background screen was coming.

After some investigations, found out that problem was because of zlib which I installed for Qemu building.
I had installed zlib from source so I had to do following steps:

1) Switched to console using Alt+Ctrl+F2 and logged in text mode
2) Went to directory where zlib was installed (cd zlib/installed/directory)
3) make uninstall
4) Rebooted my PC.

WOW....