Developing Linux apps for the Trolltech Greenphone
时间:2006-12-13 来源:paradiseHIT
by John Lombardo (Dec. 5, 2006) 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
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:
Trolltech delivers the greenphone SDK (software development kit) as a VMWare virtual machine. This is nice for several reasons:
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:
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' 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 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: [root@greenphone /]$mount Here's what we learn:
Now, try running netstat: [root@greenphone /]$netstat -na|grep LISTEN 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... [root@greenphone /]$cat /etc/inittab |grep -v "^#" | grep -v "^$" 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... [root@greenphone bin]$ps 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:
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." Related stories:
|
相关阅读 更多 +