wiki:Android Porting Guide

Introduction

This guide will talk about the specificities of android phones.

Common to most Android phones

kernel selection

If your device is supported by a cyanogenmod kenrel take it as a starting point.

Booting

When porting SHR, at some point you'll have to boot it. Since a lot of things can go wrong during boot we'll use some tricks to get some output in the case where things go wrong. Some(but not all) android phones have a recovery partition, we can use that to dual-boot: we could put SHR kernel on the recovery partition and keep the android kernel on the boot partition.

Ramconsole

Ramconsole is a way to recover the in-ram messages from the previsous boot. It requires you to reboot without removing the battery:

  • Add the following kernel argument to your kernel arguments
    panic=1
    
  • watchdogs can also make the kernel reboot.

Once the kernel has rebooted into android you can get the dmesg log here:

-r--r--r--    1 root     root         27703 Aug 13 21:10 /proc/last_kmsg

Framebuffer console

If the framebuffer is working you could try to use the framebuffer console to make the dmesg messages go on the display, note that it can break Xorg on some phones...

Serial console

If you have a serial cable for your phone serial console is the best.

wakelocks and suspend

Use the android fsousaged plugin for handling suspend resume, note that this plugin depend on a kernel part will tell the userspace the cause of the resume, on the htc dream it's implemented as theses 2 commits:  commit1 and  commit2

Screen resume

leds instead of backlight

Usually android phones uses /sys/class/led for the lcd backlight, instead of /sys/class/backlight. There are 2 ways to handle it:

SOC

A SOC or system on a chip is like a CPU, but with some peripherals on the same chip, for instance on the qualcomm devices you have in one chip:

  • The CPU
  • The modem
  • The audio(connected to the modem)
  • The GPS (connected to the modem)

sound

MSM and Snapdragoon

The msm7k devices like the htc dream have some alsa drivers(in sound/soc/msm) that can be found in various devices kernel, on  codeaurora. there are different versions, some use .mmap some don't(if you can make .mmap work fine use that since it gives sound multiplexing)

The snapdragoon devices like the nexus one now have a compatible alsa driver.

Previsously when the alsa driver was not written yet, a .asoundrc trick was created (that file went in /home/root/.asoundrc):

pcm.qsd8k {
        type plug
        slave {
                pcm "file:/dev/msm_pcm_out,raw"
                format S16_LE
                rate 44100
                channels 2
        }
} 

# Device for playing media audio
pcm.softvol {
    type softvol
    slave.pcm "qsd8k"
    control.name "PCM"
    control.card 0
} 
 

pcm.!default {
        type plug
        slave.pcm "softvol"
}

Wifi and bluetooth

bcm4329 (wifi)

The android devices usually use the bcm4329 wifi driver for the broadcom 4329 cards, this driver is a WEXT driver and lacks cfg80211/libnl interface and has issues with scanning. I found 2 broadcom drivers on AOSP:

Note that:

  • the htc HD2(also known as htc leo) device have working scan with bcm4329
  • There is an  htc hd2 wifi page
  • on the nexusone the following changes are needed:
    • replace -DCSCAN by -DWL_IW_USE_ISCAN in the bcm4329 Makefile
    • scan for wireless network like that:
      iwlist eth0 scan essid ""
      

The mainline driver which is compatible with the bcm4329 chip is:

/drivers/net/wireless/brcm80211/brcmfmac

bcm4329 (bluetooth)

See  the htc HD2 bluetooth page for more details

wl1251_sdio

GPS

  • The GPS works on the htc dream(it has been converted from an android library to a  GNU/Linux standalone activator called by ogpsd(we also have a  new standalone dbus-aware activator ) and it uses the autotools build system)
  • if you have a different modem than the htc dream, look at  the official android GPS libraries sources and do the same conversion than the htc dream
  •  gpstest in the android sources is capable of activating the GPS on android,for instance you could chroot that like this to do a quick test with the free android libraries(tested on Nexus One):
    mount -o bind /dev dev
    mount -o bind /proc proc    
    mount -o bind /sys sys
    mount -t yaffs2 /dev/mtdblock3 system
    mkdir -p dev/oncrpc
    cd dev/oncrpc
    ln -s ../30* ./
    cd ../../
    chroot ./ /system/xbin/gpstest
    
    

Modem(telephony)

Samsung

msm7k

snapdragoon

  • The newer snapdragoon seem to work fine with the  singleline plugin
  • The newer snapdragoon require  an activator to get audio during calls, that activator should be integrated in fsoaudiod.

data/3g

  • both the msm7k and the snapdragoon use the  pdp_qmi plugin
  • The other devices usually use one of the ppp plugins

usbnet

Usbnet is crucial for permitting you to ssh into your device when the rest doens't work(that's usually the case at the beginning of the port). To make usbnet work, select usbnet in the kenrel and add the following includes in drivers/usb/gadget/composite.c:

#include <linux/delay.h>
#include <linux/kdev_t.h>

Xorg

  • Add CONFIG_VT(virtual terminal) in your kenrel
  • try xf86-video-fbdev at first
  • your kenrel may need a refresh thread in the framebuffer driver or not...
  • remove VGA_CONSOLE(vga text console) else you'll have that:
    drivers/video/console/vgacon.c: In function ‘vgacon_startup’:
    drivers/video/console/vgacon.c:508:18: error: ‘PCIMEM_BASE’ undeclared (first use in this function)
    drivers/video/console/vgacon.c:508:18: note: each undeclared identifier is reported only once for each function it appears in
    drivers/video/console/vgacon.c: In function ‘vgacon_do_font_op’:
    drivers/video/console/vgacon.c:1073:22: error: ‘PCIMEM_BASE’ undeclared (first use in this function)