Documentation/Maemo 5 Final SDK Installation

'''WARNING: Never rm -r /scratchbox or subfolders, you got bindmounts of proc/ dev/ etc to your REAL SYSTEM. You will kill your system when indiscriminately deleting stuff in /scratchbox!'''

Introduction
The following document describes the installation of the Maemo 5 Final SDK. Maemo SDK uses Scratchbox as the cross compilation environment into which Maemo specific development files are installed.

Before we begin with the installation, have a look at the minimum system requirements. We officially support x86-32 Debian based distributions, mainly Debian and Ubuntu though it is possible to install the SDK on other flavours of Linux too.

Once you are sure that your development machine fulfils these requirements, you can proceed with the following guidelines:

Maemo 5 SDK comes with two command-line installation scripts and GUI installer (beta) to ease the SDK installation.
 * Scratchbox installer script which downloads and installs the required version of Scratchbox onto your host machine.
 * Maemo SDK installer which sets up two targets (armel and x86) inside Scratchbox, downloads the minimal rootstraps for both targets, and installs the open source development files based on the user selection during the installation process.
 * GUI installer which combines both Scratchbox and SDK installation.

Maemo 5 SDK also provides the essential Nokia proprietary binary packages needed for Maemo development and additional Nokia applications in an authenticated repository. In order to have access to this repository, you will need to accept the End User License Agreement (EULA).

For the complete functionality and usability of the Maemo SDK, it is required to install Nokia proprietary binary packages in addition to the open source packages.

What is not included in the Maemo SDK?
Xephyr X11 server software is needed on your host machine before you can run any applications in the Maemo SDK. It is an X11 server that provides a device screen for the developer so that you can see all the Maemo application windows and visuals on your host machine. This software is not included in the SDK mainly because it is available on most linux distributions.

If you choose to install Maemo SDK using the GUI installer on Debian based systems, it will provide an option to install Xephyr for you.

If not, you can manually install Xephyr as follows:

On Debian based linux systems, Xephyr can be installed outside Scratchbox environment using apt with root permission:

$ sudo apt-get install xserver-xephyr

On a Gentoo system you need to install xorg-server with the kdrive useflag. This builds the Xephyr binary.

Installing Maemo 5 SDK using GUI Installer
Maemo 5 SDK installation is now made easy with GUI installer. This installer will install Scratchbox and Maemo 5 SDK on Debian based systems. This installer will allow installation of nokia closed packages and applications provided that EULA at this webpage is accepted.

Features of the GUI installer

 * Install/Upgrade Scratchbox
 * Installation of Maemo 5 SDK
 * Installation of nokia-binaries
 * Installation of nokia-apps
 * Installation of Xephyr, if missing
 * Can create a launcher for Xephyr on Desktop
 * Can create a shortcut to Scratchbox home folder on Desktop
 * Can create Maemo 5 info page on Desktop that contains useful links for developers
 * Uninstallation of Scratchbox and targets (Debian-based distros only)

GUI installer offers standard and custom installation modes in a wizard. Standard installation will use default settings, while custom offers more choices. Please note that standard mode will overwrite any of the standard targets if present, but contents of Scratchbox home will be preserved. Please use the custom mode if you don't want to overwrite your targets.

The GUI installer Qt application requires Python bindings for Qt. GUI installer can install the required packages if not already installed.

The installer will use the  environment variable if available. If your connection does not seem to work, you will be asked to manually enter proxy settings.

GUI installer has been tested on Ubuntu Karmic and Debian Lenny, both 32bit and 64bit versions. The GUI installer needs to download Maemo SDK so it requires a working Internet connection. On 64bit kernel, you need to disable VDSO for 32bit applications manually.

On systems with Grub2, this can be done in the file /etc/default/grub.

Starting installation with GUI installer
There is some missing options in this Python script if you run from non-Debian Linux systems you got errors, because it will not automatically define the installation path of Scratchbox, to correct this errors you must patch this script.

Also you must uncheck the Xephyr checkbox and install it manually.

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

$ Installer requires root privileges Ubuntu sudo ./maemo-sdk-install-wizard_5.0.py  Debian su -c ./maemo-sdk-install-wizard_5.0.py

Limitations of the GUI installer

 * As the installer will do package installation, you should quit all package managers before running it.
 * Please note that detecting Scratchbox is not perfect and it will detect only if it is installed in the  path.
 * Please note that python-qt features used in this installer might not be available in older Ubuntu and Debian distros.
 * Due to differences in versions of Python Qt bindings, certain parts of installation can work differently on different systems.
 * Installer only shows required settings on 64-bit machines but does not add them automatically.
 * Installer will always use DISPLAY :2, if you want to use a different value, you need to change it manually.
 * GUI installer does not work on SUSE Linux. You can use command line installers instead.

Installing Maemo 5 SDK on 32-/64-bit Debian/Ubuntu-based distributions
Since the Scratchbox site has packages for both architectures, and the Debian packages work fine on Ubuntu, it is easiest to just install from the Hathor release.

1. Set up a new APT source using the instructions at http://www.scratchbox.org/download/scratchbox-hathor/

2. Follow the installation instructions at http://www.scratchbox.org/documentation/user/scratchbox-1.0/html/installdoc.html or follow on for simplified instructions.

3. Update your APT cache: then install Scratchbox: The installation will ask you some questions about users and groups to set up.

4. Download the SDK setup script:

5. Since Scratchbox Hathor is based on Debian Squeeze, and the SDK script assumes etch is to be used, we need to make a small change to it:

6. Set the permissions to execute the script:

7. Users of Ubuntu 10.04 LTS will need to do the following to fix the installation, note that this may reduce system security! 

8. If you have not already added a user to scratchbox, do so now:

At this step, you should have a working Scratchbox environment ready.

9. Proceed further to run the Maemo SDK installer script. This script is run as  outside the Scratchbox environment.

10. If you are installing running this script in Ubuntu 10.10 Maverick Meerkat, you might find the following error: In that case follow the instructions at http://www.terabyteunlimited.com/kb/article.php?id=454

11. If you have installed Scratchbox in a path alternative to, you will need to specify the path with ‘-s PATH’ option. More information on available command line options can be found with --help option. Follow the instructions on the go.

11. Once the script has successfully completed its execution, you can login into Scratchbox. If you are not able to login, take a look at the limitations of Scratchbox.

12. Proceed further to accept the EULA in order to obtain the Nokia proprietary binary packages. These Nokia binaries are essential for the complete functionality of the Maemo SDK:

12.1. Accept the EULA on this webpage 12.2. Copy the  entry given to you after the license acceptance to your Scratchbox x86 and armel target’s   file. Execute the commands below on the  and   targets.

[sbox-FREMANTLE_X86: ~] > sb-conf select FREMANTLE_ARMEL [sbox-FREMANTLE_ARMEL: ~] > nano /etc/apt/sources.list # add deb line [sbox-FREMANTLE_ARMEL: ~] > apt-get update [sbox-FREMANTLE_ARMEL: ~] > fakeroot apt-get install nokia-binaries nokia-apps

[sbox-FREMANTLE_ARMEL: ~] > sb-conf select FREMANTLE_X86 [sbox-FREMANTLE_X86: ~] > nano /etc/apt/sources.list # add deb line [sbox-FREMANTLE_X86: ~] > apt-get update [sbox-FREMANTLE_X86: ~] > fakeroot apt-get install nokia-binaries nokia-apps

The above step installs all needed Nokia proprietary binary packages along with the open source binaries that have dependencies to Nokia proprietary binary packages. With this, your Maemo 5 SDK environment is set up completely and ready for development.

13. If you got any DNS errors with  resolving 'repository.maemo.org', you have need to update the resolver config inside scratchbox with

Installing Maemo 5 SDK on openSUSE
There are instructions at opensuse.org.

At the moment, the instructions are only available at the old version of the openSUSE-wiki: http://old-en.opensuse.org/Maemo5

Installing Maemo 5 SDK on non-Linux operating systems
If you do not have a Linux environment (Windows or Mac OS X), you can install a Maemo SDK virtual machine image from tablets-dev.nokia.com. VMPlayer is required.

Starting/Shutting down the SDK UI
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 &

Ubuntu 10.04 users using the package in the repositories will have to run the same command without the  and , however the terminal window will have to stay open. For recent Ubuntu releases the recommended Xephyr command line (using Finnish keyboard layout) is:

$ Xephyr :2 -host-cursor -screen 800x480x16 -dpi 96 -ac -keybd ephyr,,,xkbmodel=evdev,xkblayout=fi

Ubuntu 10.10:

$ Xephyr :2 -host-cursor -screen 800x480x16 -dpi 96 -ac

Ubuntu 10.10 & poulsbo (GMA 500, Nokia Booklet 3G):

$ Xephyr :2 -host-cursor -screen 800x480x16 -dpi 96 -ac -nodri

To run  from desktop edit

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

Starting Scratchbox on non-Debian based systems
If Scratchbox was installed from Debian packages, the  init script is installed and Scratchbox should start automatically when the system is rebooted. However, if you have installed Scratchbox from tarballs, then rebooting your machine will clear away all the mounts and binfmt_misc registrations that Scratchbox requires to work. To get your Scratchbox working again after reboot, you have to run the following command as root:

$ sudo /scratchbox/sbin/sbox_ctl start

Alternatively you can add  as an init script to the   directory and create the appropriate links at your system's runlevel directories. This procedure works on some systems:

$ ln -s /scratchbox/sbin/sbox_ctl /etc/init.d/scratchbox-core $ /usr/sbin/update-rc.d scratchbox-core defaults

Refer to your system's documentation for the correct instructions.

Upgrading from Maemo 5 Beta2 SDK
A smooth upgrade from beta2 to Final SDK is unfortunately not possible. Hence it is advised to freshly install the Final SDK. Before you do so, read through the instructions below.

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. The -u option in the Scratchbox installer has been updated to create the necessary symlinks. Running the installer with -u option when the Scratchbox has been already installed will just add the user and create symlinks. Running it for already existing user will check for the symlink and create it if needed.

Run the command below to create the symlink for existing Scratchbox user:

$ sudo ./maemo-scratchbox-install_5.0.sh -u 

Alternatively, you can create the symlinks manually as follows, if Scratchbox is installed in the default location:

$ sudo ln -s /scratchbox/users/ /home/ /scratchbox/users/ /home/user

The Final SDK installer additionally creates a directory  under.

Reason: In order to facilitate installing applications under  on the device, a symlink   has been created pointing to. The SDK inherits this feature. Under Scratchbox,  points to   which in turn points to. Installing the rootstraps makes this point to, which is not what we want, since we need   to be target specific. In order to resolve this situation, we have to manually check whether  is a symlink and if it is, remove it and create a directory with the same name.

Upgrading from Maemo 4.x/Diablo SDK
Due to the fact that there are API breaks in Fremantle, we cannot upgrade Diablo SDK to Fremantle. We can however have Fremantle Scratchbox targets co-exist with Diablo targets.

For this, we need to first upgrade the Scratchbox installation on our host machine.


 * Download the Maemo5 scratchbox installer.


 * Set executable permissions and run it as follows:

$ chmod a+x ./maemo-scratchbox-install_5.0.sh $ sudo ./maemo-scratchbox-install_5.0.sh -U -u  -s /scratchbox

Once the Scratchbox installation is done, run the Maemo 5 Final SDK installer.

On x86 and x86_64 Debian-based systems

 * You can add the following line into your host machine's  file.

deb http://scratchbox.org/debian/ hathor 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

The Scratchbox packages will be unpacked to  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  and mount several directories  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/ /home/ /scratchbox/users/ /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/fremantle/armel/maemo-sdk-rootstrap_5.0_20.2010.36-2_armel.tgz http://repository.maemo.org/stable/fremantle/i386/maemo-sdk-rootstrap_5.0_20.2010.36-2_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_20.2010.36-2_i386.tgz

[sbox-FREMANTLE_X86: ~] > echo 'Acquire::http::Pipeline-Depth "0";' >> /etc/apt/apt.conf.d/00maemo
 * 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: ~] > sb-conf in -edFL [sbox-FREMANTLE_X86: ~] > apt-get update [sbox-FREMANTLE_X86: ~] > fakeroot apt-get install maemo-sdk-debug
 * either way, continue here:

The meta-package  installs all needed open source runtime, development and debug pakcages into the target. Use  if you want only runtime packages to be installed or use   if you want only the runtime and 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  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  has been created pointing to  . The SDK inherits this feature. Under Scratchbox,   points to   which in turn points to  . Installing the rootstraps makes this point to , which is not what we want, since we need   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  directory.

[sbox-FREMANTLE_ARMEL: ~] >rm -rf /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 UI framework.

Un-installation
Make sure that you have no process running inside Scratchbox. Uninstalling Scratchbox will remove everything that is installed and saved inside Scratchbox. Please take a backup of your files from Scratchbox user home directory if needed.

On Debian based systems, do the following with root permissions:

$ sudo apt-get remove scratchbox-* --purge $ sudo rm -rf /scratchbox

On non-Debian based systems, you need to stop scratchbox as follows before removing it.

$ sudo /scratchbox/sbin/sbox_ctl stop $ sudo rm -rf /scratchbox

Limitations of Scratchbox
The following limitations have been noted in the usage of Scratchbox:

VDSO support
Scratchbox versions prior to 1.0.18 (Hathor) do not work when VDSO32 support is enabled in the host's kernel, although there are some workarounds for older versions, 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

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  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  may, in these cases, make your system unbootable.

Known Issues in the SDK
$ sudo su $ echo "vm.mmap_min_addr = 0" >> /etc/sysctl.conf $ sysctl -p $ exit #to go back to user
 * A list of issues and their solutions can be found in the Developer FAQ article
 * Unnecessary warnings and debugging messages are printed out when the hildon application framework is started.
 * Armel target does not bring up the UI framework
 * It has been noted that Xephyr dies with the application framework at times. The crash in question might even be Xephyr related since the application framework behaves differently with different versions/builds of Xephyr. The case seems to be worst on Xephyr that comes with Ubuntu Jaunty, there Xephyr will die when running any application that contains an input field and clicking on that field with a mouse to invoke the input method. On Fedora Core 10 the Xephyr does not mind the mouse clicks but dies when shutting down the application framework. On the other hand Xephyr on Ubuntu Intrepid or even the Intrepid version recompiled for Jaunty does not experience crashing in these situations. A patch is already available for the Xephyr on Ubuntu Jaunty and can be found at http://bugs.freedesktop.org/show_bug.cgi?id=21591. Binaries packages for xserver-xephyr package and its dependencies (libgpg-error0 and libcrypt11) can be download from Ubuntu Jaunty repositories.
 * The performance of clutter can be improved by enabling hardware acceleration if not enabled already. In some cases, it would require installing restricted/proprietary drivers (Eg: on host machines with ATI or NVidia graphics card). Refer to Maemo 5 Clutter performance for more details.
 * Running Xephyr with  option disables entry of “@” symbol. However, removing   option disables cursor keys.
 * Running Xephyr with  is causing Xephyr to crash in Ubuntu Lucid and Debian Squeeze when the Hildon Application Framework is closed.
 * Xephyr in Ubuntu Lucid does not support the  option anymore. https://bugs.launchpad.net/ubuntu/+source/xorg-server/+bug/531872
 * In order to run ARMEL binaries in scratchbox the  needs to be set to 4096 or lower. Normally the SDK installer warns about that, but in Ubuntu Lucid the /proc entry is visible only to root, so the SDK installer can not see it. https://bugs.launchpad.net/ubuntu/+source/linux/+bug/568844 This also prevents qemu from checking the value, in which case it is assumed to be 0. Because of this, until the bug is fixed (kernel 2.6.34 is unaffected, and at least that version will be in Maverick), the value should be set to 0 on Lucid.
 * To install on Ubuntu 10.04 (restart installation afterwards):

Next steps
Once you have Scratchbox installed and the Maemo 5 UI running in Xephyr, you have everything you need to start building, packaging and developing software for the N900.

To get started with a sample application, try following this tutorial on packaging.