



﻿﻿One of the really attractive things about the N900 is the possibility of customising it. You see, I’m a bit of a geek at times. A nerd, if you will. And the idea of being able to tweak the way my phone works appeals to me, whether it be in fixing a bug I find in an app or out-and-out writing a new one for something the manufacturer hadn’t though of (and I think a lot of the iPhone’s appeal to geeks is represented by that too, app store policy issues aside). But that’s not an option on symbian. First off, well, programming for symbian is fairly horrible; and secondly, you’d need the source code to the app which most companies aren’t going to provide without a rather large chunk of change.

But the N900 runs linux and therefore it should be really easy to code for (if you’ve written code on linux before). And since Python is one of the easier ways to write an application, I wondered how long it would take me to get up and running with Python on the N900, from nothing installed through to getting “Hello, World” running. So here’s how it went.

Start the clock at 1300h. After a brief google search, I open this blog post and the PyMaemo quick start guide. Right, there are two options:

1. Don’t install any complex cross-compiling environment, just develop the python code on your desktop machine and then just scp the .py file(s) to the N900 and run the application from there (this requires that you’ve installed the OpenSSH package on the N900, which I had already).

2. Go the whole hog with scratchbox and set up the full Maemo5 SDK and be able to run apps on the desktop in an emulated N900 environment for test/debug purposes.

Okay, it’s 1308h so let’s do the first route just to see how long it takes. I download and install the the Personal IP desktop widget to see what the N900’s IP is, and then ssh to it (I have a minor hassle with trying to ssh to the N900 when it’s on its 3G IP address, which you can’t do for networking reasons; so I put it on the local wireless lan and the problem goes away).

Copy hello.py (stolen from the maemo.org wiki) to the N900 with scp.

[cc escaped=”true” lang=”python”]

import gtk from gtk import Window, Button, Widget if __name__ == "__main__": window = Window(gtk.WINDOW_TOPLEVEL) window.connect("destroy", gtk.main_quit) button = Button("Hello World") button.connect_object("clicked", Widget.destroy, window) window.add(button) window.show_all() gtk.main()

[/cc]

Then from the ssh session into the N900 I run [cci]python hello.py[/cci] and then hit Ctrl-Shift-P to take a screenshot and haul this out of /home/user/MyDocs/.images/Screenshots using scp:

That’s 27 minutes from absolutely nothing to “Hello, World” on an embedded system. While eating lunch and blogging my steps. Can I just say that the N900 rocks for this alone?

Okay, but it’s not a real cross-platform dev environment. So next up, route 2 – the full Maemo5 SDK and scratchbox.

Scratchbox, for those who’ve never heard of it, is the emulated N900 environment, which uses Xephyr (an X-within-X server) for the display. It proved a little tricky to install on my laptop, because I’m running on a 64-bit platform. Here’s what I did:﻿

sudo apt-get install xserver-xephyr

That’s all it took for Xephyr, but the Maemo SDK was a wee bit more annoying.

wget http://repository.maemo.org/stable/5.0/maemo-sdk-install-wizard_5.0.py chmod a+x maemo-sdk-install-wizard_5.0.py sudo ./maemo-sdk-install-wizard_5.0.py

From here it’s just a straightforward wizard installation:











Quite a few EULAs, but eventually the real work gets going…﻿﻿﻿

And at this point, you go off and make a cup of tea while it all downloads. This runs for a half-hour or so on my network connection until (the clock’s at 1414h for those keeping score)…

So the install failed. A bit of digging reveals that the wierd assertion error that caused the bug (you can see it in the screenshot there) is a 32bit -v- 64bit problem. This is overcome with a boot kernel option so I re-ran the install wizard to uninstall what it had installed, then rebooted and used the GRUB editor to set vdso32=0 in the boot options for the kernel and let it boot up. You can, of course, find other more permanent ways to do that, and it can be done via sysctl.conf as well if your kernel is version ﻿2.6.24 or earlier (mine’s 2.6.30 so no hope there, has to be done by boot parameter).

Once that was done and we’d rebooted, I re-ran the install wizard. It does takes a lot of time (it’s woefully optimistic about installing inside of 20 minutes), but it needs no input, so you’re free to get some coffee or read away…

Until it finally succeeds.

The clock’s now at 1714h for those keeping score. The next job is to fire up the development environment. This starts off easy enough:

Xephyr :2 -host-cursor -screen 800x480x16 -dpi 96 -ac & ln -s /scratchbox/users/mdennehy/home/mdennehy scratchbox cp /tmp/hello.py scratchbox/MyDocs/ /scratchbox/login export DISPLAY=:2 af-sb-init.sh start

And there we are, the emulated N900 device starts up:

Now to run the app is a bit more complicated, you have to add the python SDK to the emulated device too. First, ensure the following lines are in its sources.list file:

deb http://repository.maemo.org/extras-devel fremantle free non-free deb-src http://repository.maemo.org/extras-devel fremantle free

Then update and install:



apt-get update apt-get install python-gtk2 python-sdk

And finally, run the python script (which you can just copy from your $HOME to the directory in the emulated N900).

run-standalone.sh python2.5 hello.py

And don’t forget to shut the door and turn out the lights once you’re done:

af-sb-init.sh stop exit

That took until 1815h, but most of the delay was in setup; actual code hassles were nonexistant. That’s remarkable for an embedded platform like this. 27 minutes to get a basic app running; an afternoon (most of it spent doing other stuff while stuff downloaded) to get the full development environment (with emulator) up and running. Simply excellent. The N900 really is a very good platform for development work, especially with Python.

Share this: Twitter

Facebook

Pinterest

More

Tumblr

LinkedIn





Like this: Like Loading...

Tags: Linux, maemo, n900, nokia, pymaemo, Python, scratchbox