Sunday, October 17, 2010

Compiling QT-Embedded on Technologic Systems TS-TPC-7395

I've been trying to get QT embedded working on the 7395 for a few days now and I kept a log of the steps I took to get there. Unfortunately, I left the 7395 at work on Friday so I can't test the compiled binaries until tomorrow but I'm pretty confident that everything here is right...

I based this guide on Donal O'Connor's guide for the TS-TPC-7390 which you can find here:

 http://automon.donaloconnor.net/cross-compiled-qt-embedded-step-by-step/74/

First order of business is to set up a VirtualBox VM with Ubuntu 10.10 (I used VirtualBox 3.2.10 on an OS/X host). Make sure you give the VM at least a 20GB hard drive as the stuff you will need to compile is going to take up more than the default 8GB and you want to have plenty of space left over to do your actual application development on the VM. Once you get the OS installed, you may want to have VirtualBox install the guest OS drivers. This allows the VM to use bigger resolutions than 800x600. You don't have to do this but it only takes a minute and it makes everything else a lot more pleasant.

Once you have the OS set up we're ready to begin:

Step 1: Set up the cross compiler for the TS-7395 on the development machine:

Open Firefox and go to ftp://ftp.embeddedarm.com
Find the TS-TPC-7395 and download the cross compiler (crosstool-linux-gcc-3.3.4-glibc-2.3.2-0.28rc39.tar.bz2)

In the file explorer navigate to to the firefox downloads folder (~/Downloads)
Right click on the tar file and extract the contents to this folder (this will create a folder called usr)

Now we need to place the cross compiler in the right place in your filesystem

Open a terminal (Applications -> Accessories -> Terminal)
In the terminal:
    $ cd ~/Downloads/usr/local
   
$ sudo cp -r opt /usr/local
   
$ gedit ~/.bashrc

This opens up an instance of gedit text editor. On the top line of the file you opened paste the following so that you can call the cross compiler by just typing in arm-linux-gcc instead of having to type the whole path:

$ export PATH=$PATH:/usr/local/opt/crosstool/arm-linux/gcc-3.3.4-glibc-2.3.2/bin

Save and close the file. Now we need to add this same item to Root's bashrc file so back in your terminal:

    $ sudo gedit /root/.bashrc
Add the following line to the top of the file:

$ export PATH=$PATH:/usr/local/opt/crosstool/arm-linux/gcc-3.3.4-glibc-2.3.2/bin

Once you've done this you need to either exit and restart the terminal or at the prompt type 'bash' (without the quotes). If you don't do this the shell doesn't seem to update itself to include the aliases you added.

Ok so now we're ready to test the cross compiler. To do this we need to write a simple hello world program in C and also C++. We will attempt to compile these with our cross compiler then run each of them on the TS-TPC-7395.

Open the file explorer and go to your home folder. Create a folder called compiler-test. Inside that folder create two other folders, helloworld-c and helloworld-cpp.

Lets create the C version first. In the termial issue this command:
    $ gedit ~/compiler-test/helloworld-c/helloworld.c
    for a basic hello world program your text file should look like this:

    #include <stdio.h>

    void main(void){
   
        printf("Hello World!");
    }


    save and close the text file.

Now we see if we can compile our new program. In the terminal issue these commands:
    $ cd ~/compiler-test/helloworld-c
   
$ arm-gcc-linux helloworld.c -o helloworld.out

You may see some warnings about the main function having a return type of void instead of int. This is really no big deal for our purposes. In your terminal issue:

    $ file helloworld.out

You should get a response like this: 
    helloworld.out: ELF 32-bit LSB executable, ARM, version 1, dynamically linked (uses shared libs), for GNU/Linux 2.4.3, not stripped

So now we know that we can compile a C program into an ARM compatible binary. Now lets move onto C++

In your terminal issue the following command:

    $ gedit ~/compiler-test/helloworld-cpp/helloworld.cpp
In the text editor write a simple C++ hello world program like this:

    #include <iostream>
    using namespace std;

    int main(){
        cout << "Hello World!" << endl;
        return 0;
    }

save and exit the text editor.

In your terminal we will now compile the program. Issue this command:
    $ cd ~/compiler-test/helloworld-cpp
   
$ arm-linux-g++ helloworld.cpp -o helloworldcpp.out
After the compile is finished, you shouldn't see any errors. In your terminal check the finished binary with the file command like this:

    $ file helloworldcpp.out

You should get a response like this:
helloworldcpp.out: ELF 32-bit LSB executable, ARM, version 1, dynamically linked (uses shared libs), for GNU/Linux 2.4.3, not stripped

So now we know that we can compile C and C++ binaries for our TS-7395 board so lets get started on compiling QT-X11 and QT-Embedded for our development machine


Step 2: Compile and Install QT-X11 and QT-Embedded for the development machine

Open a new terminal (Close any other terminal instances you may have open) and issue the following commands:

    $ cd ~
   
$ mkdir -p /project/downloads/qt_embedded
   
$ mkdir -p /project/sysapps/host
   
$ mkdir -p /project/sysapps/device
   
$ cd ~/project/downloads/qt_embedded
   
$ wget ftp://ftp.trolltech.com/qt/source/qt-embedded-linux-opensource-src-4.5.3.tar.gz
   
$ wget ftp://ftp.trolltech.com/qt/source/qt-x11-opensource-src-4.5.3.tar.gz
   
$ cd ~/project/sysapps/host
   
$ tar -xzvf ~/project/downloads/qt_embedded/qt-embedded-linux-opensource-src-4.5.3.tar.gz
   
$ tar -xzvf ~/project/downloads/qt_embedded/qt-x11-opensource-src-4.5.3.tar.gz

     $ export QT4DIR=~/project/sysapps/host/qt_embedded/qt-x11-opensource-src-4.5.3
   
$ export QTEDIR=~/project/sysapps/host/qt_embedded/qt-embedded/host/qt-embedded-linux-opensource-src-4.5.3

   
$ sudo apt-get install libx11-dev libxmu-dev libpng12.dev
   
$ sudo apt-get install libxtst-dev
   
$ sudo apt-get install build-essential
    $ mkdir -p qt_embedded/host
   
$ cp -r qt-x11-opensource-src-4.5.3/ qt_embedded/
   
$ cp -r qt-embedded-linux-opensource-src-4.5.3/ qt_embedded/
   
$ cd $QT4DIR
   
$ export QTDIR=$QT4DIR
    $ export PATH=$QTDIR/bin:$PATH
   
$ export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
    $ ./configure -prefix /usr/local/qt4


   
Here it will ask what version of QT you want. If you have a commercial licence type 'C' otherwise type 'O'. The rest of this guide assumes the opensource 'O' option. After you choose the type, it will ask you to accept the license terms. Type 'yes' when prompted and hit enter.

    $ make
   
$ sudo make install

   
$ mkdir -p $QTEDIR/bin
   
$ cp bin/uic $QTEDIR/bin/
   
$ export TMAKEPATH=$TMAKEDIR/lib/linux-g++
   
$ export QMAKESPEC=$QTDIR/mkspecs/linux-g++
   
$ export PATH=$PATH:/usr/local/qt4/bin
   
$ cd ~/project/sysapps/host/qt_embedded/qt-x11-opensource-src-4.5.3/tools/qvfb/
   
$ qmake
   
$ make
   
$ sudo cp ../../bin/qvfb /usr/local/qt4/bin
Close the terminal to clear the envs created earlier and open a new one.

    $ export QTEDIR= ~/project/sysapps/qt_embedded/host/qt-embedded-linux-opensource-src-4.4.3
   
$ cd $QTEDIR
   
$ export QTDIR=$QTEDIR
   
$ export PATH=$PATH:$QTDIR/bin
   
$ export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
   
$ ./configure -prefix /usr/local/qte4 -qvfb
   
$ make
   
$ sudo make install
           Now you need to launch an instance of qvfb for the qte app to run in
    $ /usr/local/qt4/bin/qvfb

Create a new terminal window and issue:
    $ /usr/local/qte4/examples/draganddrop/draggableicons/draggableicons -qws

You should now see an instance of the draggable icons demo appear in the virtual framebuffer you launched.

Close the demo, virtual framebuffer and both terminals. Now launch a new terminal.
Step 3: Compile TSLIB and QT-Embedded for the 7395

    $ cd ~/project/downloads
   
$ wget ftp://ftp.mars.org/debian/pool/main/t/tslib/tslib_1.0.orig.tar.gz
   
$ sudo apt-get install autoconf
   
$ sudo apt-get install automake
   
$ sudo apt-get install libtool
   
$ cd ~/project/sysapps/tslib/tslib-1.0
   
$ sudo ./autogen.sh
   
$ ./configure CC=arm-linux-gcc CXX=arm-linux-g++ PLUGIN_DIR=/usr/local/linux-arm/plugins -prefix=/usr/local/linux-arm -host=arm-linux    
$ gedit config.h

In gedit scroll towards the end of the file. you will see a line that says: #define malloc rpl_malloc
Comment it out (to do so change the line to this: /* #define malloc rpl_malloc */
Save the file and close.

Back in your terminal
    $ make
   
$ sudo make install
   
$ mkdir ~/project/sysapps/device/qt_embedded
   
$ cd ~/project/sysapps/device/qt_embedded
   
$ tar -xzvf ~/project/downloads/qt_embedded/qt-embedded-linux-opensource-src-4.4.3.tar.gz
   
$ cd qt-embedded-linux-opensource-src-4.4.3
   
$ export QTDIR=$PWD
   
$ export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
Before you build, you should modify some of the QT-Embedded source files to fix the 15/16 bit color issue that Donal mentions in his guide. To see how to make the patch, check out this page on Donal's site:
http://automon.donaloconnor.net/qt-embedded-443-and-ts-7390-color-depth-issues/90/
Now we need to let QMAKE know where to find QMAKE_INCDIR and QMAKE_LIBDIR

In terminal:
    $ cd mkspecs/qws/linux-arm-g++/
   
$ gedit qmake.conf

In text editor you will see a file like this:
    #
    # qmake configuration for building with arm-linux-g++
    #

    include(../../common/g++.conf)
    include(../../common/linux.conf)
    include(../../common/qws.conf)

    # modifications to g++.conf
    QMAKE_CC                = arm-linux-gcc
    QMAKE_CXX               = arm-linux-g++
    QMAKE_LINK              = arm-linux-g++
    QMAKE_LINK_SHLIB        = arm-linux-g++

    # modifications to linux.conf
    QMAKE_AR                = arm-linux-ar cqs
    QMAKE_OBJCOPY           = arm-linux-objcopy
    QMAKE_STRIP             = arm-linux-strip

    load(qt_config)

Add the following lines after the include() statements:
    QMAKE_INCDIR += /usr/local/linux-arm/include
    QMAKE_LIBDIR += /usr/local/linux-arm/lib

The final file should look like this:
    #
    # qmake configuration for building with arm-linux-g++
    #

    include(../../common/g++.conf)
    include(../../common/linux.conf)
    include(../../common/qws.conf)

    QMAKE_INCDIR += /usr/local/linux-arm/include
    QMAKE_LIBDIR += /usr/local/linux-arm/lib

    # modifications to g++.conf
    QMAKE_CC                = arm-linux-gcc
    QMAKE_CXX               = arm-linux-g++
    QMAKE_LINK              = arm-linux-g++
    QMAKE_LINK_SHLIB        = arm-linux-g++

    # modifications to linux.conf
    QMAKE_AR                = arm-linux-ar cqs
    QMAKE_OBJCOPY           = arm-linux-objcopy
    QMAKE_STRIP             = arm-linux-strip

    load(qt_config)

Save the file and close it.

Back in the terminal:
    $ cd $QTDIR
   
$ ./configure -embedded arm -xplatform qws/linux-arm-g++ -no-qvfb -depths all -qt-mouse-tslib -qt-kbd-usb -I/usr/local/arm/tslib/include -L/usr/local/arm/tslib/lib
   
$ make
   
$ sudo make install

Make install will install to /usr/local/Trolltech/QtEmbedded-4.5.3-arm/
You can inspect one of the example executables using the file command and you should see that they are also ARM linux binaries.

No comments:

Post a Comment