Monday, December 20, 2010

Building Qt 4.7.1 for Arm (QQ2440/Mini2440)

This post will tell you how to compile Qt for any ARM based processor, S3C2440 in my case.
You need to download the latest source code from Nokia website. Click here to download version 4.7.1. Ignore the below task if you already have download the source.
# wget http://get.qt.nokia.com/qt/source/qt-everywhere-opensource-src-4.7.1.tar.gz
Untar the source to a local directory (example: /home/user/USER/)
# tar -xzvf qt-everywhere-opensource-src-4.7.1.tar.gz
Specify which cross-compiler to use by setting the PATH environment variable.
# export PATH=path/to/cross/compiler:$PATH
You have to modify the mkspecs/qws/linux-arm-g++/qmake.conf file for toolchain related paths that Qt will use for compilation. Modify the below entries according to your toolchain.
QMAKE_CC = arm-none-linux-gnueabi-gcc
QMAKE_CXX = arm-none-linux-gnueabi-g++
QMAKE_LINK = arm-none-linux-gnueabi-g++
QMAKE_LINK_SHLIB = arm-none-linux-gnueabi-g++
QMAKE_AR = arm-none-linux-gnueabi-ar cqs
QMAKE_OBJCOPY = arm-none-linux-gnueabi-objcopy
QMAKE_RANLIB = arm-none-linux-gnueabi-ranlib

Now your code base is ready for compilation. Start the compilation by following command.
# cd qt-everywhere-opensource-src-4.7.1
# ./configure -embedded arm -xplatform qws/linux-arm-g++ -prefix /usr/local/Qt \
-qt-mouse-tslib -little-endian -no-webkit -no-qt3support -no-cups -no-largefile \
-optimized-qmake -no-openssl -nomake tools
# make && make install

To run your ARM compiled applications we have to set following environment variables on the NFS root of the board.
# export TSLIB_TSEVENTTYPE=INPUT
# export TSLIB_CONSOLEDEVICE=none
# export TSLIB_FBDEVICE=/dev/fb0
# export TSLIB_TSDEVICE=/usr/input/ts
# export TSLIB_CALIBFILE=/usr/etc/pointercal
# export TSLIB_CONFFILE=/usr/etc/ts.conf
# export TSLIB_PLUGINDIR=/usr/lib/ts
# export LD_LIBRARY_PATH=/usr/local/Qt/lib
# export QTDIR=/usr/local/Qt
# export QWS_MOUSE_PROTO=tslib:/usr/input/ts
# export QWS_DISPLAY=LinuxFB:mmWidth=240:mmHeight=320

The Qt library binary (and fonts subdir) should be placed on a user defined directory of the board and then set LD_LIBRARY_PATH to this directory.
Qt binary application must be run with -qws command line argument to inform Qt that we are working on a Linux embedded system.

Friday, December 10, 2010

Creating Arm Toolchain

I like to work on my ARM board [QQ2440] which is based on Samsung S3C2440 ARM CPU. At first when I started to work, I worked with readily avaliable toolchains like those available from CodeSourcery, but I always wanted to try and build the toolchain from scratch. At first I searched web to find the steps like this and that but I wanted a much cool solution, something that is elegant and at the same time powerful. So, I came across this wonderful tool, CrossTool-NG. This the advanced version of its father CrossTool. So I went on and decided to give it a try.

Below are the steps to follow:

  • Download the latest CrossTool-NG tarball.
  • Extract to a location using the command
tar -xjvf crosstool-ng-1.9.0.tar.bz2
  • Now compile and install, please note you need root privilege to install, I normally do by making use of "sudo"
cd crosstool-ng-1.9.0 ./configure make sudo make install

Now we are finished with the simple installation steps of CrossTool, and here comes the steps to build a brand new toolchain of our own. We start by creating a directory, say "toolchain" where all the build is going to happen. Below are the steps

  • Change to the new created directory and configure your toolchain by following command
cd toolchain ct-ng menuconfig

  • Now setup some path variables and paths
  • During the build, the tarballs are download and saved to the path, here "/home/sachin/shared"

  • Need to set the architecture parameters

  • Some other toolchain options, set the tuples alias, good when you like to use standard alias like "arm-linux" for your toolchain.

  • Choose the kernel version against which you will be going to build the kernel. You need to careful here, as choosing the latest version might lead to a situation that, when you build older kernels, the busybox will show nasty old kernel errors. So I choose long-term stable 2.6.32.x

  • So in this way you can continue with your adventure, or download the ready made config file from here.
Now is start the build, while build is going on the system will download all the required tarballs, so make sure you have live internet connection. The binaries are located at the location /home/USER/x-tools/arm-xpress-linux-gnueabi where USER is the linux user name, sachin in my case.
[sachin@xpress toolchain]$ ct-ng build
[INFO ]  Performing some trivial sanity checks
[INFO ]  Build started 20101210.124223
[INFO ]  Building environment variables
[INFO ]  =================================================================
[INFO ]  Retrieving needed toolchain components' tarballs
[INFO ]  Retrieving needed toolchain components' tarballs: done in 1.08s (at 00:20)
[INFO ]  =================================================================
[INFO ]  Extracting and patching toolchain components
[INFO ]  Extracting and patching toolchain components: done in 5.23s (at 00:25)
[INFO ]  =================================================================
[INFO ]  Installing kernel headers
[INFO ]  Installing kernel headers: done in 34.50s (at 01:00)
[INFO ]  =================================================================
[INFO ]  Installing GMP
[INFO ]  Installing GMP: done in 818.31s (at 14:39)
[INFO ]  =================================================================
[INFO ]  Installing MPFR
[INFO ]  Installing MPFR: done in 114.82s (at 16:34)
[INFO ]  =================================================================
[INFO ]  Installing PPL
[INFO ]  Installing PPL: done in 430.07s (at 23:44)
[INFO ]  =================================================================
[INFO ]  Installing CLooG/ppl
[INFO ]  Installing CLooG/ppl: done in 40.21s (at 24:24)
[INFO ]  =================================================================
[INFO ]  Installing MPC
[INFO ]  Installing MPC: done in 48.70s (at 25:13)
[INFO ]  =================================================================
[INFO ]  Installing libelf
[INFO ]  Installing libelf: done in 21.35s (at 25:35)
[INFO ]  =================================================================
[INFO ]  Installing binutils
[INFO ]  Installing binutils: done in 406.44s (at 32:21)
[INFO ]  =================================================================
[INFO ]  Installing static core C compiler
[INFO ]  Installing static core C compiler: done in 565.23s (at 41:47)
[INFO ]  =================================================================
[INFO ]  Installing C library headers
[INFO ]  Installing C library headers: done in 153.94s (at 44:21)
[INFO ]  =================================================================
[INFO ]  Installing C library start files
[WARN ]    Removing "-pipe" for use with glibc>=2.6
[INFO ]  Installing C library start files: done in 130.95s (at 46:32)
[INFO ]  =================================================================
[INFO ]  Installing shared core C compiler
[INFO ]  Installing shared core C compiler: done in 638.93s (at 57:11)
[INFO ]  =================================================================
[INFO ]  Installing C library
[WARN ]    Removing "-pipe" for use with glibc>=2.6
[INFO ]  Installing C library: done in 2468.27s (at 98:19)
[INFO ]  =================================================================
[INFO ]  Installing final compiler
[INFO ]  Installing final compiler: done in 1453.91s (at 122:33)
[INFO ]  =================================================================
[INFO ]  Installing libelf for the target
[INFO ]  Installing libelf for the target: done in 42.04s (at 123:16)
[INFO ]  =================================================================
[INFO ]  Installing dmalloc
[INFO ]  Installing dmalloc: done in 76.23s (at 124:32)
[INFO ]  =================================================================
[INFO ]  Installing D.U.M.A.
[INFO ]  Installing D.U.M.A.: done in 6.90s (at 124:39)
[INFO ]  =================================================================
[INFO ]  Installing cross-gdb
[INFO ]  Installing cross-gdb: done in 686.93s (at 136:06)
[INFO ]  =================================================================
[INFO ]  Installing gdbserver
[INFO ]  Installing gdbserver: done in 55.26s (at 137:02)
[INFO ]  =================================================================
[INFO ]  Installing ltrace
[INFO ]  Installing ltrace: done in 11.29s (at 137:13)
[INFO ]  =================================================================
[INFO ]  Installing strace
[INFO ]  Installing strace: done in 61.61s (at 138:15)
[INFO ]  =================================================================
[INFO ]  Cleaning-up the toolchain's directory
[INFO ]    Stripping all toolchain executables
[INFO ]  Cleaning-up the toolchain's directory: done in 14.60s (at 138:30)
[INFO ]  Build completed at 20101210.150051
[INFO ]  (elapsed: 138:27.51)
[INFO ]  Finishing installation (may take a few seconds)...

Friday, November 26, 2010