Monday, June 14, 2010

Setting Up Maemo 5/N900 Dev Environment on Windows  

I've been learning to write applications for a number of mobile platforms, one of them being Nokia's N900 smartphone. To that end I was trying to setup the Maemo 5 SDK, but it's taken me more than a week to do so. Let's see why, and what I did to finally get a Maemo 5 emulator up so that I could test code I wrote for the device, without having to install it on the device itself.

I've called the N900 a "smartphone" because that's what Nokia is calling it but it's really a UMPC with a phone built-in. The N900 runs the ARM port of Maemo 5 (a.k.a. Fremantle). Maemo 5 is a Debian based operating system, so you'll be using apt-get to install software onto the device. The N900 even ships with an "X Terminal" app pre-installed. That is probably one of the things that tells you that the phone was built by geeks.

Anyway.

The Maemo 5 SDK is really an emulated environment that allows you to write and compile code for testing. It uses scratchbox as the cross-compilation toolkit. You login to scratchbox, which has emulated environments (targets) for both x86 and ARM setup using a rootstrap (think of it as an operating system installer) for each platform. You write code and test it on the emulated x86 target. You can then compile in the ARM target, and deploy it on the phone for final testing.

The reason for this is that compilation and execution is faster in the x86 target as it uses native compilation tools. Compilation for ARM would be slower.

The documentation points to multiple ways of installing the Maemo SDK.
  1. If you are not using Linux, you are pointed to a VMWare image that has been created for you with all the tools already setup.
  2. If you are using Debian-based installation of Linux, you can setup the SDK in three different ways:
    1. The GUI installer
    2. The automated command-line installer
    3. Manual Installation

Which sounds great until you find out that only one of the above actually works - The manual installation.

I wanted to set this up at work, where I only have Windows PCs. So I jumped for the VMWare image. The link takes you to a page on the nokia.com domain, where you need to accept the EULA before you can see the list of available downloads. Sadly though, for the past few weeks, the vmware image has been missing from this list.

I did find the image on this page at one point, and went ahead and downloaded it. However, there was a problem with the image and it was deleted the next day. For the curious, the problem I saw was that when you ran the emulator, all the apps on the emulated device started up fine, but you could only see their title-bars. The body of the window was blank.

So I had to create my own virtual machine. Below are the instructions on how to do that using VMWare Server on a Windows PC. I prefer to use the old VMWare Server 1.0 release, but the instructions should work the same on new versions and other virtualization software too.
  1. Download the ISO file for the 32-bit x86 version of Ubuntu Server 9.10 Karmic Koala. I would recommend using this specific version since that's what Maemo's developers seem to use as their development environment. I'm choosing the server edition to keep the VM light. The desktop edition will also work but will be slower.
  2. Create a VM in VMWare Server, with at least 5GB of hard disk space (I used 10GB). If you don't allocate all diskspace at the time of creation, the VM will slow down everytime it needs to grow the disk file. This might be acceptable if you are low on disk. I suggest 512MB of RAM though less will probably work for most development needs. I use bridged networking so that the VM has its own identity on the network. The VM will need access to the internet, so make sure you set this up.
  3. Setup the ISO file as the CDROM drive for the newly created VM.
  4. Start the VM, and it will boot from the ISO file
  5. Install Ubuntu onto the VM as a full server install. I don't recommend using the JeOS/Virtual Server option, as I had some problems with dependencies that probably came from using a kernel optimized for virtual environments.
  6. Towards the end of the installation, choose to use the installation as an "SSH Server". This will make sure that you can login to the virtual machine using SSH instead of using the VMWare Server Console.
  7. Install an X-Server of your choice. I prefer Cygwin/X. I've been using it for years, and I've never had a problem with it.
    1. The instructions to install Cygwin/X can be found at this page.
    2. I've found it necessary to ensure selection of the following additional packages to get Cygwin/X working optimally: font-adobe-dpi75, font-encodings, fontconfig, xwinwm.
    3. You'll also need the xhost package.
    4. I like using Cygwin to connect to the virtual machine instead of using additional tools like putty. If you want to do the same, also install the openssh package.
  8. Once all the installation is done, boot into your newly setup VM, and log in using the user you created at installation.

I tried to install Maemo SDK using the automated command-line scripts (which is pretty much the same as the GUI tool). However, this didn't work for me. So at my third attempt, I created a fresh new VM, and used the manual installation instructions. I'll be repeating those instructions here with my comments on what worked and what did not.

The first thing we need to do is to install scratchbox. Ubuntu's universe repositories have version 2 of scratchbox available that can be easily installed, but this doesn't work well with Maemo 5. There is a Maemo Garage project called Maemo SDK+ that is currently trying to make the SDK compatible with Scratchbox 2. As of now, I don't recommend using it.

We will install directly from the scratchbox project repository. For this we have to add the scratchbox repository to our apt sources file.

Use the following command to edit the file, or use any editor you're comfortable with. (Remember, that sudo will ask you for the password of the user currently logged in. Ubuntu doesn't have the root user by default, and this is a good thing. All root access is by preceding commands with sudo.)
$ sudo vi /etc/apt/sources.list

Add this line to the bottom of the file.
deb http://scratchbox.org/debian/ maemo5-sdk main


If you are behind a firewall, you need to first tell the tools what your proxy is. Use this command:
export http_proxy=http://[username]:[password]@[proxy-host]:[proxy-port]

If your proxy doesn't authenticate, just use
export http_proxy=http://[proxy-host]:[proxy-port]

Now you'll need to refresh the apt cache with the newly added repository.
$ sudo apt-get update


Scratchbox doesn't work when VDSO is enabled. It is enabled in Ubuntu 9.10, so we need to turn it off.

To disable VDSO support in Ubuntu, use this command to edit the sysctl file.
$ sudo vi /etc/sysctl.conf

Add this line to the bottom of the file.
vm.vdso_enabled = 0

To load these changes, run the following command:
sudo sysctl -p


You can now install scratchbox. Run the following command (all on one line). The apt-get tool will download all files and dependencies (there will be around 400MB of them), and install the software.

$ sudo apt-get install scratchbox-core scratchbox-libs scratchbox-devkit-qemu scratchbox-devkit-debian scratchbox-devkit-doctools scratchbox-devkit-perl scratchbox-toolchain-host-gcc scratchbox-toolchain-cs2007q3-glibc2.5-arm7 scratchbox-toolchain-cs2007q3-glibc2.5-i486 scratchbox-devkit-svn scratchbox-devkit-git scratchbox-devkit-apt-https


I sometimes got 503 errors while downloading some of the dependencies, but re-running the command allowed it to proceed smoothly.

Now we need to setup the currently logged in user as a scratchbox user. Run the following command.
$ sudo /scratchbox/sbin/sbox_adduser $USER yes

$USER should expand to the name of the user currently logged in. If you have created another user on the VM, and want to set up that user instead, replace $USER with the username of the user you want setup.

Some Nokia applications (which will be running inside the emulator) look for the home directory of the logged in user to be named "user", like it is on the device. To get around this problem, run the following command
$ sudo ln -s /scratchbox/users/<username>/home/<username> /scratchbox/users/<username>/home/user

where <username> is the username of the currently logged in user. This creates a symbolic link called "/home/user" in scratchbox, which points to the home directory of the user you setup. This means that if you want multiple users setup in scratchbox, they'll have to replace the symbolic link every time they log in.

At this point, the documentation suggests running the newgrp command to ensure your current session is in the sbox group. Call me superstitious, but I recommend simply logging out of your session and logging back in.

Once you are logged back into the VM, you must login to scratchbox to setup the Maemo SDK. Use the following command
$ /scratchbox/login

This takes you into the scratchbox environment. However this is a brand new environment, and we will need to setup Maemo here. First, we will need to create the two targets (for X86 and ARM). Use these commands.

[sbox->:~]> sb-conf st FREMANTLE_X86 -c cs2007q3-glibc2.5-i486 -d perl:debian-etch:doctools:svn:git -t none
[sbox->:~]> sb-conf st FREMANTLE_ARMEL -c cs2007q3-glibc2.5-arm7 -d qemu:perl:debian-etch:doctools:svn:git -t qemu-arm-sb

At each command you will get a message saying that no target is currently selected. This is expected, so ignore it.

Again, if you are behind a firewall, you'll need to setup your proxy. Use the same command used above.

Now, download the rootstrap files.

[sbox->:~]> wget http://repository.maemo.org/stable/5.0/armel/maemo-sdk-rootstrap_5.0_armel.tgz http://repository.maemo.org/stable/5.0/i386/maemo-sdk-rootstrap_5.0_i386.tgz


Remember, these are the installers of the two targets (emulated operating systems) you just created. Now you need to switch to the X86 target and install the rootstrap.

[sbox->:~]> sb-conf se FREMANTLE_X86
[sbox-FREMANTLE_X86:~]> sb-conf rs maemo-sdk-rootstrap_5.0_i386.tgz
[sbox-FREMANTLE_X86:~]> sb-conf in -edFL
[sbox-FREMANTLE_X86:~]> apt-get update
[sbox-FREMANTLE_X86:~]> fakeroot apt-get install maemo-sdk-debug


This will again download and install a large number of packages. If you get 503 errors downloading some files, just rerun the last command. The "fakeroot" prefix is required because apt-get checks whether you have root permissions before it will run.

You now want to install the Nokia restricted binaries. To setup the repository for this, go to this page. Accept the EULA. You will then see the line in the repository that looks something like this
deb http://repository.maemo.org/ fremantle/xxxxxxxxxxxxxxxx nokia-binaries

Add this line to the bottom of the apt sources file. You can use this command:
$ vi /etc/apt/sources.list

Now you need to refresh the repository catalog and install the required binaries.
[sbox-FREMANTLE_X86:~]> apt-get update
[sbox-FREMANTLE_X86:~]> fakeroot apt-get install nokia-binaries nokia-apps

This will again download a little more than 100MB of files and install them.

You need to repeat these steps for the ARM environment setup.

[sbox-FREMANTLE_X86:~]> sb-conf se FREMANTLE_ARMEL
[sbox-FREMANTLE_ARMEL:~]> sb-conf rs maemo-sdk-rootstrap_5.0_armel.tgz
[sbox-FREMANTLE_ARMEL:~]> sb-conf in -edFL
[sbox-FREMANTLE_ARMEL:~]> apt-get update
[sbox-FREMANTLE_ARMEL:~]> fakeroot apt-get install maemo-sdk-debug


Edit the apt sources file using this command
$ vi /etc/apt/sources.list

and add the line provided by Nokia, to the end of the file.

Then install the Nokia binaries.
[sbox-FREMANTLE_ARMEL:~]> apt-get update
[sbox-FREMANTLE_ARMEL:~]> fakeroot apt-get install nokia-binaries nokia-apps


Scratchbox should now be properly setup with the Maemo 5 SDK.

You need to now understand how to run the emulator so you can see how your application would look on the device. The Maemo UI is a desktop environment just like any in other Linux installation. This means you need an X Server running for the desktop to load in.

The Maemo documentation talks about installing Xephyr. However, it assumes you are running Linux. Xephyr isn't available on Windows, but you can use Cygwin/X instead.

One important point is that N900's screen has 16-bit color depth. So your X Server also needs to be running at 16-bit color depth. However, since Cygwin/X only supports controlling color depth for full-screen X Servers, you will need to reduce the color depth of your Windows desktop. If you don't, the emulator screen will not look accurate, and some widgets will not display properly. To set the color depth on Windows XP, right-click on your desktop, and click on Properties. Select the Settings tab. Change the Color Quality dropdown to 16-bit, and click Ok.

First, start two instances of Cygwin Bash Shell. You'll find the shortcut to this in your Start Menu under "Cygwin". Alternatively, you can use the shortcut "XWin Server" under "Cygwin-X". This will open an xterm, which is a lot more convenient to use than the Cygwin Bash Shell. You can start another xterm by clicking on the shortcut for the same in the sample where you found the shortcut for "XWin Server". Remember we need two terminals running.

We now need to start a separate X Server, that has the dimensions of the Nokia N900 device. Use this command in the first Cygwin Bash Shell/xterm to start this server.

$ XWin :2 -screen 0 800x480 -clipboard


The ":2" above specifies the "screen number" that the X server uses. If you've started "XWin Server", you'll see an icon in your system tray that says "Cygwin/X Server:0.0" when you hover over it. Since screen number "0" is already used, I've arbitrarily used "2" instead. You can use any number you like.

This will open an 800x480 sized blank window on your screen. The background may be gray, checked, or black. The command will not exit, so keep your shell open.

In the other Cygwin Bash Shell, run the following commands.

$ export DISPLAY=:2
$ xterm

Remember to use the same sceen number as the value of the DISPLAY variable as you used to start the X Server.

This will start an xterm in the newly opened X Server window. In this xterm, run the following command
$ xhost + 192.168.0.100
$ exit

where 192.168.0.100 is the IP address of the VM. This step authorizes processes from the VM to write to this X Server. The exit command closes the xterm since we don't need it anymore.

Now login to the VM, and to scratchbox. If not already set, set the target to the X86 version, using the command:
[sbox->:~]> sb-conf se FREMANTLE_X86


Now we want to start the Maemo UI. Set the DISPLAY variable and start the UI.

[sbox-FREMANTLE_X86:~] export DISPLAY=192.168.0.50:2
[sbox-FREMANTLE_X86:~] af-sb-init.sh start

where 192.168.0.50 is the IP address of your Windows machine, and :2 is the screen number where your X Server is running.

You may get a number of warnings about HAL, a VolumeMonitor and a cellular operator. You can safely ignore these.

You should now be able to see the N900's home screen.

That's it! Now read the documentation and start programming!

Labels: , , ,

Thursday, November 5, 2009

Google Wave tips - 3 : Manage Your Inbox  

Google Wave's interface is similar to your average modern email client, in that it has an Inbox, allows you to create Folders, and allows you to Search for waves with various keywords.

The important thing then, becomes that just like email, when a wave you are interested in gets updated, you should know as soon as possible. And if you are not interested in something anymore, you should be able to make it go away.

Mark waves as Read/Unread
Just like Email, you can mark a Wave as Read or Unread. To do so, click the "Read" or "Unread" button in the toolbar on the wave pane. Unread waves show up in bold text in your inbox. Once you marking a wave as Read, you will see further updates marked differently when you open it. Newly inserted text will show up in yellow, deleted text will show up in red with a strike-through, and new blips will show up with a green vertical bar to the left.
Use folders to keep your Inbox clean
Reading Public waves is a good way to learn about how to use Google Wave, and discover gadgets, and robots, or find solutions to problems. However, as soon as you read a public wave, it will show up in your inbox. Read a few public waves, and your inbox gets cluttered, since every update to these waves sends them to the top of your inbox.
You can create folders, by clicking the (+) button next to the word "Folders" in the Navigation pane. To move a wave to a folder, select the wave, then click "Move to" and select the folder. A wave that's moved to a folder, will show up in your inbox again when updated. Moving waves to folders makes it easier to find them later, if they've been archived. (more on that below)
Don't want to follow a wave anymore?
If you are no longer interested in knowing about updates to a wave, open that wave, and click the "Mute" button in the toolbar of the wave's pane. (Remember to use the Mute button in the toolbar rather than the one in the Search pane. The buttons in the Search pane don't always work as expected.) Doing this will remove the wave from your inbox, and you will never be notified of updates to it. This is also true of waves you may have edited, or even started. Also, at this time other followers of that wave will have no way of knowing that you have muted it, so they may continue with the conversation assuming you are reading their updates. However, muted waves still appear in your search results.
If you want to see all the waves you've muted, search for "is:mute".
If you want to search waves you've muted, append "is:mute" to the search query.
If you want to excluded muted waves from search results, add "-is:mute" to the search query.
Make a wave disappear till someone updates it
The lesser the number of waves that appear in your inbox, the easier it is to manage. So once you have read all the latest updates in a wave, you might not want it to show up in your inbox till someone updates it again. To do this, select the wave, and click the Archive button in the toolbar of the wave's pane. (Again, remember to use the button on the wave pane, not the one on the Search pane.)
Ignore a wave and stop it from showing up in searches
Muting a wave allows you to ignore any updates to a wave, but such a wave will still show up in your searches - with a small box with the word "Mute" near the title of the wave. If you are sure you have no interest in a wave anymore, you can send it to Trash. Just click the Trash button in the toolbar of the wave's pane. If your wave pane is too narrow, the Trash button might be hidden. Click the "..." button to show the remaining buttons on the toolbar. Just like Mute, other participants on a wave will not know you've sent that wave to your trash.

Labels: , ,

Tuesday, November 3, 2009

Tips for new Google Wave users - 2  

So you are one of the lucky few who got a Google Wave invite, but you've been letting it go to waste because you just can't figure out how to use it.

This is the second in my series of tips for Google Wave users, which should make it a little easier for you to start taking advantage of this new technology.

Easily read new updates to a wave
If you're following a busy wave - one with a large number of users for example - the frequency of updates may make it difficult to follow the conversation, because Google Wave allows you to add replies anywhere, not just at the bottom of the wave. To go through all unread updates, us the SPACE key on your keyboard. Pressing will take you through all unread updates since they last time you read the wave, one by one.
Increase your screen real estate
If you have a monitor with a resolution of only 1024x768, you probably think the Google Wave user interface is very cramped. This is true. At such a low resolution, the existence of so many panes - Navigation, Contacts, Search, etc - leaves very little space for the wave you might be interested in. There are different ways of increasing how much you see on your screen.
  • Maximize the wave - This is the simplest way to see more of your wave. To do this, click the "Maximize" button (the square one) on the top right of your wave pane. The disadvantage of this, is that you can no longer see the other panes like Navigation and Search.
  • Resize the other panes - You can resize the other panes to make more space for your wave view pane. To do this, hover over the space between two panes, and you should see your mouse pointer turn into a resize icon.
  • Decrease your browser's font size or Zoom Out - Most browsers allow you to reduce the font size of the content in a web page, or even zoom out the page completely. The default fonts used in Google Wave can seem a little large if your monitor is at a low resolution. Both Firefox 3.5 and Chrome, support 'Zoom Out', and using it (click Ctrl and '-' together) allows you to see more of your wave on a small screen. Using Zoom Out in Chrome, prevents you from resizing any panes for some reason. This is probably a bug in Google Wave that should get fixed at some point. It works well in Firefox though. Do note that many websites aren't tested to work well with browsers' Zoom Out feature, so it's possible that your experience might not be perfect.
More easily make a wave public
There seems to be a new robot that makes waves public, which works a little better than public@a.gwave.com, which I mentioned in my previous post on Google Wave tips. The new robot has the address easypublic@appspot.com and doesn't continuously disappear from your contacts. However, easypublic is a user contributed robot, so there's no guarantee that it will always be around. Also, it seems a lot slower. I also expect public@a.gwave.com's issues to get fixed soon.
Keep your wave small
A lot of processing in the Wave UI is handled by Javascript, which runs in your browser. So a wave with a lot of data, or a large number of updates/blips, will be slower, since it is your browser on your desktop/laptop/netbook that processes it all. A large number of active participants can also slow your wave down.
Be careful about making a wave public
Once a wave is made public, it's not possible to make it private again (at least right now). And a public wave's history can be seen by anyone who has access to Google Wave. In the future, it'll probably be viewable by anyone whether they have Google Wave access or not. So if you added some private information to a wave, and then deleted it before making it public, anyone can playback your wave to see your data before it was deleted. This is true about adding any new participants to a wave. Everyone who has access to a wave, will be able to view all its history, no matter how late they were added.

That's all for now. I will be back with new tips soon. Watch this space!

Labels: , ,

Friday, October 2, 2009

What's with Google Wave invites?  

There seems to be a lot of confusion with the 8 Google Wave invites that Google Wave Preview (not sandbox) users seem to have. I just thought I'd give my impressions of how they work.

Quoting from the Google Blog
Starting Wednesday, September 30 we'll be sending out more than 100,000 invitations to preview Google Wave to:
  • Developers who have been active in the developer preview we started back in June
  • The first users who signed up and offered to give feedback on wave.google.com
  • Select business and university customers of Google Apps
We'll ask some of these early users to nominate people they know also to receive early invitations — Google Wave is a lot more useful if your friends, family and colleagues have it too. This, of course, will just be the beginning. If all goes well we will soon be inviting many more to try out Google Wave.

My impressions -
  1. They intend to quickly ramp up to 100,000 users, but quickly doesn't necessarily mean on Day 1.
  2. They are aware of negative impressions that have already been aired, like Anil Dash's post on why he thinks Google Wave will not catch on. Google Wave is complicated. The average user won't get it yet.
  3. It's really a Preview, not Beta like GMail when it first came out. GMail was fully functional. With Wave, even the requirements are still being worked out.
  4. Google Wave is not an application or a service. Well not yet, anyway. Lars and his team are first trying to put a whole new type of infrastructure in place. They expect the user community to build the actual applications on top of it, given a few samples to show what's possible.
  5. The reason for the preview is to figure out what the world wants to do with Wave. Look at the types of people they're inviting. Only Early Adopters. Not your average joe.
  6. Security features aren't really that great on Google Wave yet. If it becomes easy for spammers to get on Google Wave, it could bring the whole thing down.
  7. Invites aren't a "gift for someone you love". Invites are a necessity in Google Wave. They are the only way you can collaborate with people you already know. Collaboration with strangers is simply too chaotic. The public wave ecosystem in Google Waves is mostly a mess.
  8. Given all this, they wouldn't want to use Invites the same way they did with GMail. They want to be very careful about who they actually hand out invites to. They want people who can take their vision, and shape Wave into something useful. And yet, they can't let these constraints get in the way of allowing people to create communities of people of their own choice, to collaborate with.


Now look at the Wave that allows you to invite others.


Notice the following in this Wave -
  1. Invitations will not be sent immediately - They don't say how much of a delay there will be, though.
  2. Lot of stamps to lick - This makes it sound like invites will either go through a special process (approval?) before being sent out, or that they might send invitations out in phases ramping up at a pace they are more comfortable with.
  3. People you've nominated - The word "nominated" here must mean that you don't make the choice of who gets on Wave next, but that you only make a suggestion. I see two possibilities. Either they use nominations to create a priority list for sending out invites, or they have some kind of approval workflow before accepting a nomination.

Labels: , ,