News Archive (1999-2012) | 2013-current at LinuxGizmos | Current Tech News Portal |    About   

Article: Developing Linux apps for the Trolltech Greenphone

Dec 6, 2006 — by LinuxDevices Staff — from the LinuxDevices Archive — 6 views

Foreword: Trolltech's Linux/Qtopia-powered Greenphone aims to provide a real (rather than emulated) hardware platform for mobile phone application developers to test their applications on. This hands-on review takes an in-depth look at the phone's software environment, and at the development tools supplied with the… phone. Enjoy . . . !


Developing Linux apps for the Trolltech Greenphone

by John Lombardo

Introduction


Lombardo's greenphone application development setup
(Click to enlarge)

I shuddered with anticipation as I opened the Fedex package. Ah, there it was — a little cellphone box like so many I've opened before. Only this one was lime green and white. Inside, instead of some chrome and gray phone of yesteryear where DIY means you get to pick your own ringtone, I found a little bundle of metallic-green coolness. The Trolltech greenphone.

The directions admonished me to let it charge for 24 hours before I turned it on, so, like everyone else on the planet, I pressed the power button right away to see it do its Linux-phone thing and… nothing. A little worried, I plugged it in and pressed the power button again and was greeted with the nice QT logo. Phew. Next was a screen with the (relatively) big title of “WARNING” followed by text that Tinker-Bell would have to squint to see.

This warning is first thing that anyone will see when using this phone. It basically says that the little Linux computer you hold in your hand is not intended to be your primary cellphone, but instead is intended to be a development platform.

I read in the forums somewhere that you can disable the warning, but I would advise against it. Leave it on so that every time you start to compare the greenphone with your Treo or Nokia or Whatever, you'll remember that it's not a fair comparison because the greenphone is for the development of cool tools that you can test out in a phone-like environment — not for using as your primary cellphone.

Don't get me wrong, it does work as a cellphone — it's just not a very good one. So if you forget that this is a development environment, you'll be disappointed. However, if you remember that it's a development environment, you'll be pleased.

The Phone

A detailed description of the greenphone is available in this LinuxDevices.com article, but here are the essentials:

  • XScale processor, clocked at 312MHz
  • 64MB RAM
  • 128MB flash
  • Mini-SD card slot
  • USB/Bluetooth/Camera/Touchscreen/Keypad
  • QVGA (quarter VGA) 320×240

The SDK

Trolltech delivers the greenphone SDK (software development kit) as a VMWare virtual machine. This is nice for several reasons:

  • You don't have to have a specific version of Linux.
  • Everyone has the same development environment.
  • You can host the environment both on Linux and Windows.
I won't say much about the installation process, except that you can use Trolltech's installation scripts on Windows without modification, via Cygwin.

Once installed, you fire up the development environment by starting the VMWare virtual machine.


Greenphone development environment
(Click to enlarge)

Once started, your desktop has nine icons to start different phases of the development process:
  • Assistant and Developer Guide — the Assistant brings you to the QT developer's bookshelf; the Developer's guide is the on-line version of the 10 page Greenphone Developer Quickstart Guide

  • Debugger and ARM-Linux debugger — The debugger executables for both the emulated greenphone and the real greenphone

  • Designer — The GUI tool for designing QT forms.

  • Konsole — Starts up a Linux console

  • Linguist — Automates the process of creating multiple language versions of your software

  • runqpe / runqvfb — Runs the emulated greenphone

Commandline on your phone

You know you've always wanted the commandline on your cellphone. Well, now you have it! Once you have set up network access between your greenphone and the Developer SDK as described in the Developer Quickstart Guide, you can get shell access to the phone with the “gph -console” command.

First, on the Developer SDK desktop, click the Konsole icon, to open up a terminal window:


Then, type:

    ifconfig eth1 2>/dev/null| sed -n 's/.*inet addr:([0-9.]*).*/1/p'
    10.10.10.21

If this returned nothing, you do not have connectivity to the greenphone. If you do, it should return the IP address of your side of the connection to the greenphone: 10.10.10.21.

Next, type the following command to connects to the greenphone using telnet over the USB cable:

    gph -console
    Success! Greenphone address is 10.10.10.20
    Trying 10.10.10.20...
    Connected to 10.10.10.20.
    Escape character is '^]'.
    BusyBox v1.2.1 (2006.10.12-23:46+0000) Built-in shell (ash)
    Enter 'help' for a list of built-in commands.
    [[email protected] /]$

Note that you're using the busybox commandline, not bash or tcsh. While the busybox shell has a lot of functionality, it may not be quite what you're expecting if you do a lot of shell scripting.

This can be a tricky procedure. I had a lot of problems connecting the greenphone while writing this article. I was never able to narrow down what the problem was, and more than once had to reboot the greenphone completely before I could connect again.

Developing Software Using the Emulated Greenphone

The SDK comes with a complete greenphone emulator, and you'll want to use it for most of your application development activities. In fact, many application developers may end up exclusively using the emulator to develop their application, and rely on someone else who actually owns the phone to test it out.

Open up a console window by clicking on the Konsole icon:


The following sourced script sets up your environment variables and PATH so that you can compile x86 binaries:

    source /opt/Qtopia/SDK/scripts/devel-x86.sh

The source code to the sample application is in the “projects” directory off the home directory of the default SDK user:

    cd ~/projects

Create a copy of your pristine sample application. I like to use “zug.” You can name it whatever you like.

    cp -a application zug

Make it writable…

    chmod -R a+rw zug

And cd into it…

    cd zug

Modify it so you know you're running the version you compile….

    sed -i 's/at all./&  Except say HELLO WORLD!/' examplebase.ui

Boilerplate Qtopia build steps…

    qtopiamake && make clean && make loud && make install

Now we start the emulated environment. Click the runqvfb icon, then the runqpe icon to start the Greenphone skin, then the Qtopia Phone environment…


A dialog box titled “Number: 555001” will appear. You can close it.

Now, tell Qtopia running in qvfb to scan for the new application:

    gph -rescan

You can run the example application directly from the command line and it will appear in the virtual greenphone, or you can navigate to it using the greenphone UI…

    ./example

Building and Deploying an Application to the Greenphone

The process for building and deploying an application to the greenphone is similar to building the emulated version. This procedure actually installs the package to the greenphone so you can execute it using the application menu on the greenphone — even when you're disconnected.

On the Developer SDK desktop, click the Konsole icon to open up a console window:


This sourced script sets up your environment variables and PATH so that you can compile greenphone binaries:

    source /opt/Qtopia/SDK/scripts/devel-greenphone.sh

The source code to the sample application is in the “projects” directory off the home directory of the default SDK user…

    cd ~/projects

Create a copy of your pristine sample application. I like to use “gzug.” You can name it whatever you like…

    cp -a application gzug

Make it writable…

    chmod -R a+rw gzug

And cd into it…

    cd gzug

Modify it so you know you're running the version you compile.

    sed -i 's/at all./&  Except say HELLO WORLD!/' examplebase.ui

Perform the boilerplate Qtopia build steps…

    qtopiamake && make clean && make

Create the Package, Install, it and Run it…

    gph -p -i -r

Under the greenphone's hood

To gain an understanding of how the greenphone works, you can connect to the shell running on the greenphone as described earlier in this article. Once there, you can use the standard Unix commands provided by busybox.

For example, the mount command gives us insight into what filesystems are available on the greenphone and how they're mounted:

    [[email protected] /]$mount
    /dev/root on / type ext2 (rw)
    none on /proc type proc (rw)
    tmpfs on /dev type tmpfs (rw)
    none on /dev/pts type devpts (rw)
    tmpfs on /var type tmpfs (rw)
    /dev/tffsb on /mnt/disk2 type ext2 (rw,noatime)
    /dev/tffsc on /mnt/user type ext2 (rw,noatime)
    /dev/tffsd on /mnt/user_local type vfat (rw,noatime)
    /dev/loop0 on /opt/Qtopia.rom type cramfs (ro)
    [[email protected] /]$ls -l /dev/root
    lrwxrwxrwx 1 root root 5 Dec 4 12:15 /dev/root -> tffsa

Here's what we learn:

Mount point Device Filesystem R/W status
/ tffsa ext2 rw
/mnt/disk2 tffsb ext2 rw
/mnt/user tffsc ext2 rw
/mnt/user_local tffsd vfa rw
opt/Qtopia.rom loop0 cramfs ro
/proc none proc rw
/dev tmpfs tmpfs rw
/dev/pts none tmpfs rw


Now, try running netstat:

    [[email protected] /]$netstat -na|grep LISTEN
    tcp 0 0 0.0.0.0:139 0.0.0.0:* LISTEN
    tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN
    tcp 0 0 0.0.0.0:23 0.0.0.0:* LISTEN
    unix 2 [ ACC ] STREAM LISTENING 767 /tmp/qtopia-0/valuespace_applayer
    unix 2 [ ACC ] STREAM LISTENING 1053 /tmp/.qt_soundserver-0
    unix 2 [ ACC ] STREAM LISTENING 728 /tmp/qtembedded-0/QtEmbedded-0

We see that there is an ftp server (21), telnet server (23) and smb server (25) listening on the phone. As well as three qtopia-specific named sockets.

The /etc/inittab configuration file shows us what the greenphone does at boot time. Let's take a look…

    [[email protected] /]$cat /etc/inittab |grep -v "^#" | grep -v "^$"
    ::sysinit:/etc/rc.d/rc.filesystems
    ::sysinit:/etc/rc.d/rc.newrootfs
    ::sysinit:/etc/rc.d/rc.modules
    ::sysinit:/etc/rc.d/rc.sysinit
    ::sysinit:/etc/rc.d/rc.services
    ttyS2::respawn:-/bin/sh
    ::respawn:/sbin/syslogd -n -C 512 -S -L -R hostpc >/dev/null 2>/dev/null
    ::respawn:/usr/sbin/atd /var/spool/at >/dev/null 2>/dev/null
    ::sysinit:/mnt/user/etc/trolltech_startup.sh
    ::shutdown:/etc/rc.d/rc.shutdown

The “sysinit” scripts run just at boot time, bringing up the file systems, loading modules, starting the network, etc. The rc.services script starts up the telnet, ftp and samba servers.

The /mnt/user/etc/trolltech_startup.sh script is especially interesting. It brings up Qtopia by first sourcing the Qtopia environment, then by running /opt/Qtopia.rom/qpe.sh. The qpe.sh script is responsible for keeping the qpe application up and running. The qpe app is the heart of the greenphone's graphical user interface.

Let's see what's running…

    [[email protected] bin]$ps
    PID Uid VmSize Stat Command
    1 root 320 S init # everyone's ancestor
    92 root 360 S /bin/ash /opt/Qtopia/qpe.sh # script to keep qpe up
    103 root 14812 S qpe # The main Qtopia server
    130 root 764 S ftpd # The ftp server
    134 root 1460 S /usr/local/samba/bin/smbd # Samba
    136 root 1292 S /usr/local/samba/bin/nmbd # Samba
    139 root 236 S /usr/sbin/telnetd # Telnet server
    155 root 3728 S < /opt/Qtopia/bin/qss # Sound server
    156 root 6112 S N /opt/Qtopia/bin/quicklauncher # A running application

The busybox version of the ps command has no options. However, it still gives us valuable information about what's running on the phone. I've annotated the output somewhat to highlight the more interesting executables.

Greenphone SDK source

For this review Trolltech allowed me to download the Greenphone SDK source. The source code is not currently available generally, but hopefully they'll get through the legal issues and allow everyone to download this source code. It's a treasure-trove of information on how to build Qtopia applications.

Conclusion

The Trolltech Greenphone SDK is well thought out:

  • They deliver the SDK as a VMWare virtual machine. This makes the development environment cross platform, easy to update, ensures all developers have the same toolset and eliminates a lot of frustration when installing the toolchain.

  • They include an emulated environment. Because you have an environment under which you can build most of your application, you don't actually have to have a greenphone at your disposal to write software for it. Obviously, you'll want to install any software you write on a real phone before releasing it — but this can be a last minute activity after the application development is mostly done.

  • All of the documentation is on the virtual machine.
However, there are some problems:
  • Most open source developers do not get paid for their work — therefore they develop open source software to scratch their own itch. Obviously Trolltech wants to tap into this phenomenon by making the greenphone available to developers. Unfortunately, the $700 price tag is beyond what most developers can afford for this purpose.

  • The source code to the applications is not available on the SDK. Currently, the source code is not available at all due to some legal issues. This source code is critical to the success of the greenphone. It would be difficult to develop anything without this valuable source of documentation. Trolltech should put whatever source code they can on their web site right away — and put the rest of the code up later when the legal issues are ironed out.
Bottom line:

Trolltech is doing an admirable job trying jumpstart the market for their software. To make it work, they have to get phones in the hands of developers who will write apps (and perhaps make Trolltech's apps better) for the phone. Those apps will then increase the value proposition for their toolkit which will attract the attention of the big hardware manufacturers. Once those manufacturers start cranking out huge numbers of phones, that will lower the price point for Qtopia-based phones and Trolltech will be out of the hardware business — which is exactly what they want. The question is can they get enough traction from Open Source developers and get enough phones in the wild.

My suggestion is this: Run a contest. That's exactly what VMWare did when they released the VMWare player, and now they have several hundred “virtual appliances” on their web site. Give a nice cash prize for the best application, and a phone each to the top runners up. Make sure all the entries are open sourced, and by the beginning of Q2 2007, they'll have at least one hundred new applications for the greenphone. That will be something that the hardware manufacturers will have a hard time ignoring.


About the author: John Lombardo is the author of Embedded Linux, the first book published on the subject. He's been working with Linux since the “0.9” days. However, he does remember downloading a very early version and thinking: “Yeah, right — how is this Linux thing going to compete with Coherent.”


 
This article was originally published on LinuxDevices.com and has been donated to the open source community by QuinStreet Inc. Please visit LinuxToday.com for up-to-date news and articles about Linux and open source.



Comments are closed.