Saturday, March 20, 2010

Setup Maemo/N900 Development on Ubuntu

To setup Maemo 5 (Nokia N900) Development Environment on your computer, here's what you need:
  • Linux operating system, preferably Debian or Ubuntu (I use Ubuntu 10.04 Lucid Lynx)
  • Plenty of hard drive space. The total environment is about 3.5 GB, and more if you install the Qt SDK. If you use the Debian packages you have to free that much space in the root partition.
  • Plenty of time and bandwidth.
Before installing Maemo 5 (Fremantle) SDK, you must prepare the environment by installing Xephy, and disabling VDSO.

Install Xephyr
sudo aptitude install -y -r xserver-xephyr
  
Disable VDSO

Scratchbox does not work when VDSO32 support is enabled in the host's kernel. We're working on making it possible, but at the moment there are some workarounds, which are presented here.
If your host has VDSO32 turned on you will get an error like this when trying to login to Scratchbox.
No directory, logging in with HOME=/
Inconsistency detected by ld.so: rtld.c: 1192: dl_main: Assertion `(void *) 
ph->p_vaddr == _rtld_local._dl_sysinfo_dso' failed!

x86-64 kernel

x86-64 Linux kernels starting from version 2.6.25 enable VDSO32 by default. To temporarily disable VDSO32 execute
sysctl abi.vsyscall32=0
On Linux kernel 2.6.24 <= you can disable VDSO32 by executing
sysctl vm.vdso_enabled=0
or
sysctl kernel.vdso=0
The current setting of VDSO32 can be verified by using sysctl. Only values 0 and 2 are compatible with Scratchbox. In our examples we use 0 (disable). 2 enables compat mode.
You can set all of these permanently by adding the following lines to /etc/sysctl.conf
vm.vdso_enabled = 0
abi.vsyscall32 = 0
kernel.vdso = 0
Save the file and run the command:
$ sudo sysctl -p
Please note the correct line depends on your Linux kernel version. When you execute sysctl -p you may get a warning about unknown keys. You can safely ignore those warnings as long as one of the 3 settings works.
WARNING : You should try setting these values by echoing them to the given locations before adding them to sysctl.conf to see if they cause any problems. For example, in some Ubuntu Gutsy installations, it has been observed that changing the VDSO settings will hang the system and thus making permanent changes in sysctl.conf may, in these cases, make your system unbootable.

Install Maemo 5 SDK

There are two ways to install Maemo 5 SDK:
  1. Automatic Installation (using downloader)
  2. Manual Installation (using apt-get)
Both Maemo 5 SDK Installation methods are described here

With Automatic installation, you just download a tiny Maemo 5 SDK installer provided by Nokia (there's also a pretty GUI one). Note that if your connection is flaky, chances are you can't resume and will have to start over.

My connection is very flaky so I used Manual Installation. Despite how it's called, it's not actually so manual.

Manual Maemo 5 SDK is included below for convenience. (Note: these instructions work as of March 2010)
On x86-32 Debian based systems:
  • You can add the following line into your host machine's /etc/apt/sources.list file.
deb http://scratchbox.org/debian/ maemo5-sdk main
  • Install the needed Scratchbox packages with root permission
$ sudo apt-get update
$ 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

On x86-64 Debian based systems:
  • Download the Scratchbox packages from here.
  • Force the installation of the x86-32 packages with root permission as follows:
$ sudo dpkg -i --force-architecture 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  

The Scratchbox packages will be unpacked to /scratchbox directory and the installation procedure will ask you some questions about the group and user accounts. Default group to Scratchbox is 'sbox'.
  • Users who will be using Scratchbox should be added using the following command with root permission:
$ sudo /scratchbox/sbin/sbox_adduser USER yes

It will automatically include the user to the Scratchbox group, create user directories under /scratchbox/users and mount several directories (/dev, /proc, /tmp) under the user directory.
  • Some of the Nokia applications shipped with the final SDK use a hard coded path for user home directory which presents a problem since the default username on the device differs from the username on the developer's machine. To make these applications work, it is required to create a home directory that matches the hard coded value. This needs to be done outside scratchbox using root privileges.
$ sudo ln -s /scratchbox/users/<username>/home/<username> /scratchbox/users/<username>/home/user


  • For the group membership to be effective in the current terminal session, run the following command:
$ newgrp sbox
Note: This command will change the existing group ID during the current login session to 'sbox'. If you do not want to change, simply logout and log back in for the group membership to be effective.


  • Log-in to Scratchbox.
$ /scratchbox/login


  • Configure the scratchbox x86 and armel targets as follows:
[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
  


  • Download the minimal rootstraps.
[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
  


  • Switch to x86 target, install the devkits, etc and fakeroot into the target, install the minimal rootstrap and finally the Maemo development files.
[sbox->:~]> sb-conf se FREMANTLE_X86
[sbox-FREMANTLE_X86: ~] > sb-conf rs maemo-sdk-rootstrap_5.0_i386.tgz
  • Some users seem to have problems downloading all files with apt http pipelining enabled. If you want to make sure or you get download errors like "104 connection reset by peer" at the fakeroot steps below, then disable http pipelining with the next command:
[sbox-FREMANTLE_X86: ~] > echo 'Acquire::http::Pipeline-Depth "0";' >> /etc/apt/apt.conf.d/00maemo
  • either way, continue here:
[sbox-FREMANTLE_X86: ~] > sb-conf in -edFL
[sbox-FREMANTLE_X86: ~] > apt-get update
[sbox-FREMANTLE_X86: ~] > fakeroot apt-get install maemo-sdk-debug

The meta-package 'maemo-sdk-debug' installs all needed open source runtime, development and debug pakcages into the target. Use maemo-sdk-runtime if you want only runtime packages to be installed or user maemo-sdk-dev if you want only the runtime + development packages to be installed.
  • Accept the EULA from here to obtain the URL to access the Nokia binaries repository.
  • Add the URL thus obtained to the Scratchbox target's /etc/apt/sources.list and do the following:
[sbox-FREMANTLE_X86: ~] >apt-get update
[sbox-FREMANTLE_X86: ~] >fakeroot apt-get install nokia-binaries nokia-apps


  • In order to facilitate installing applications under /opt on the device, a symlink /opt has been created pointing to /home/opt. The SDK inherits this feature. Under Scratchbox, /opt points to /target/links/opt which in turn points to /targets/<target_name>/opt. Installing the rootstraps makes this point to /home/opt, which is not what we want, since we need /opt to be target specific. In order to resolve this situation,
[sbox-FREMANTLE_X86: ~] >rm /targets/FREMANTLE_X86/opt
[sbox-FREMANTLE_X86: ~] >mkdir /targets/FREMANTLE_X86/opt


  • Execute similar steps on the armel target too to set it up:
[sbox-FREMANTLE_X86: ~]> sb-conf se FREMANTLE_ARMEL
[sbox-FREMANTLE_ARMEL: ~] > sb-conf rs maemo-sdk-rootstrap_5.0_armel.tgz
  • again,the next command disables http pipelining, if you like:
[sbox-FREMANTLE_X86: ~] > echo 'Acquire::http::Pipeline-Depth "0";' >> /etc/apt/apt.conf.d/00maemo
  • pipelining disabled or not, here we go again...
[sbox-FREMANTLE_ARMEL: ~] > sb-conf in -edFL
[sbox-FREMANTLE_ARMEL: ~] > apt-get update
[sbox-FREMANTLE_ARMEL: ~] > fakeroot apt-get install maemo-sdk-debug


  • Add the same URL obtained above to access the Nokia binaries repository under /etc/apt/sources.list file of the Scratchbox armel target.
[sbox-FREMANTLE_ARMEL: ~] >apt-get update
[sbox-FREMANTLE_ARMEL: ~] >fakeroot apt-get install nokia-binaries nokia-apps


  • Create the /opt directory.
[sbox-FREMANTLE_ARMEL: ~] >rm /targets/FREMANTLE_ARMEL/opt
[sbox-FREMANTLE_ARMEL: ~] >mkdir /targets/FREMANTLE_ARMEL/opt

With this, you must now have both the targets setup and ready to use.

Start the Maemo SDK UI Framework
Before starting the UI framework, ensure that you have installed the following:
  • Xephyr X11 server on the host machine outside the Scratchbox environment
  • The SDK as described above
  • The Nokia proprietary binary packages
1. Now, run Xephyr outside the scratchbox environment:
$ Xephyr :2 -host-cursor -screen 800x480x16 -dpi 96 -ac -kb &

2. Login to Scratchbox X86 target
$ /scratchbox/login

Welcome to Scratchbox, the cross-compilation toolkit!

Use 'sb-menu' to change your compilation target.

See /scratchbox/doc/ for documentation.

[sbox-FREMANTLE_X86: ~]>
  

3. Set the DISPLAY variable to match the display setting given for the Xephyr server.
[sbox-FREMANTLE_X86: ~] >export DISPLAY=:2

4. Start the UI framework .
[sbox-FREMANTLE_X86: ~] >af-sb-init.sh start

5. You will now see the UI framework up and running on the Xephyr window.
6. You can shut down the UI framework as follows:
 [sbox-FREMANTLE_X86: ~] >af-sb-init.sh stop

1 comment:

  1. The -kb option for launching Xephyr causes an error, I used Xephyr without that switch and it worked still.

    Thank you for the well written tutorial, I have really appreciated this.

    ReplyDelete

Be the first to comment!