Monday, March 5, 2012

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

No comments:

Post a Comment