Mobile/debug on maemo

From MozillaWiki
Jump to: navigation, search

DISCLAIMER

This guide is intended for developers who want to debug and/or profile applications running under maemo (either directly on the device, or from inside scratchbox). Though its main goal is to eventually be able to debug fennec on the device, it should still come in handy for debugging just about anything running under maemo.

The following step-by-step instructions are meant to be used on the Nokia's N810 internet tablet with the DIABLO maemo distro (newest stable release at the time of writing this document).

There's no guarantee herein. Deception and misfortune could still arise from following these steps, as they're based on a setup that could differ from yours.

SCRATCHBOX SDK

The various steps presented hereafter are based upon the assumption that you have installed the maemo 4.0.1 scratchbox SDK on your desktop with an additional target using the arm2007q3 toolchain, as described in Mobile/Build/cs2007q3. At this point, you should find at least those 2 targets in scratchbox:

  1. CHINOOK_ARMEL
  2. CHINOOK_ARMEL_2007 ==> the one that we're interesting in.

SETTING A DEBUGGING/PROFILING ENVIRONMENT

1. FLASH YOUR N810

if you've already installed DIABLO on your device, you can go to step 2.To check the installed OS version on the N810, go to [Settings] on the main toolbar and click "open" in the title 'Control Panel' tab. The 'version' field should read : "4.2008.36-5" or "5.2008.43-7". If lower than that, do the following steps from your desktop console:

./flasher-3.0 -F <your_path_to_the_image>/RX-44_DIABLO_5.2008.43-7_PR_COMBINED_MR0_ARM.bin -f -R
When "Suitable USB device not found, waiting" appears, turn on the N810 while holding the swap button. The flashing operation should start.
  • Turn on R&D mode on your N810 (to access super-user privileges) by using the flash utility as following:
./flasher-3.0 --enable-rd-mode -R
Again, when "Suitable USB device not found, waiting" appears, turn on the N810 while holding the swap button. The flashing operation should start and the R&D mode should be set in a flash.
  • flash the new oprofile-enabled kernel. oprofile is a profiling tool you'll want to be using when debugging and profiling on the N810. In order to use it, you must however update the device's kernel. Start by logging into scratchbox and select the CHINOOK-ARMEL-2007 target and do the following:
# add the diablo/tools repository
fakeroot echo "deb http://repository.maemo.org/ diablo/tools free non-free" >> /etc/apt/sources.list

# Sync the package database
apt-get update

# Download the oprofile-enabled kernel
fakeroot apt-get install kernel-diablo-oprofile

# The kernel should be laying in /boot, move it to /tmp
# notice that the image name could be different...
mv /boot/zImage-oprofile-diablo-200850 /tmp

Log out from scratchbox, and, in a desktop console...flash the new kernel image:

./flasher-3.0 -f --kernel /tmp/zImage-oprofile-diablo-200850 -R
Again, when "Suitable USB device not found, waiting" appears, turn on the N810 while holding the swap button.

2. SETUP YOUR N810

Now leave your desktop for a while and go to your N810. Turn it on and open an X Terminal :

  • Make the internal card executable

open the mmc-mount file:

sudo gainroot
vi /usr/sbin/mmc-mount

modify the 'mount' script line to match the following line :

mount -t vfat -o rw,noauto,nodev,nosuid,noatime,nodiratime,utf8,uid=29999,shortname=mixed "$1" "$2" > /dev/null

... save the file and reboot the device.

  • Add some swap space to your internal card
sudo gainroot
cd /media/mmc2
dd if=/dev/zero of=./swap.file bs=1M count=512; # this takes 3-4 min. on the N810
mkswap ./swap.file
echo "/media/mmc2/swap.file swap swap defaults 0 0" >> /etc/fstab
swapon -a
exit

To check if you've got 512 MB of swap as expected, type:

free

If you want this swap file to be mounted on device startup, you can add "swapon -a" in /etc/init.d/rcS, but it's not recommended to mount it systematically, as it will wear the flashcard out progressively.

  • Install OPROFILE

Now, let's install opcontrol and the related tools....

sudo gainroot
echo "deb http://repository.maemo.org/ diablo/tools free" >> /etc/apt/sources.list
apt-get update
yes | apt-get install oprofile
echo "user ALL = NOPASSWD: /usr/bin/opcontrol" >> /etc/sudoers
opcontrol --init

Before going further, let's see if your kernel is oprofile-enabled (it should be since you flashed the new kernel image in step 1).

opcontrol -status  # should NOT return something like "oprofile not supported by kernel"
  • Install debug packages

Still on the N810, from the X terminal, type :

sudo gainroot
echo "deb http://repository.maemo.org/ diablo/sdk free non-free" >> /etc/apt/sources.list
apt-get update
yes | apt-get install maemo-debug-scripts
debug-dep-install /usr/bin/osso-xterm.launch
The script should have installed most of debug packages excepts for "libaudiofile", "libesd", "libvte", "osso-xterm" and "zlib1g" for which no debug package are available.
  • Install other important tools
apt-get install file
  • Fix/update some binutils tools
TO COMPLETE

DEBUG AND PROFILE

Now that your N810 is all set, you're ready to debug and profile just about any program built for ARMEL target. We're going to use our fennec example hereafter.

  • Build fennec with debug symbols

Now go back to your desktop and log onto scratchbox CHINOOK-ARMEL-2007 target. Build fennec by following instructions at Mobile/Build/Fennec. You may choose to build fennec for DEBUG or PERF, but be sure to add the following line to your mozconfig in order to get debug symbols in the resultant libs :

ac_add_options --enable-debugger-info-modules
  • Package fennec

At this point, you may tar and copy fennec <objdir>/mobile/dist/bin folder to your device for testing, but this folder might still contain some symlinks, so it's better to package fennec before sending it over to the N810. So, from the 'objdir/mobile' folder, type :

make package PKG_SKIP_STRIP=1
The 'PKG_SKIP_STRIP=1' flag is important as it tells make NOT to strip debugging symbols off packaged libs!

You'll now find the packaged fennec under '<objdir>/mobile/dist/fennec'. copy the package outside of scratchbox prior to copying it over to the N810 :

cd <objdir>/mobile/dist; # replace <objdir> by the actual objdir directory
cp -R fennec /tmp