Android

From WikiMwyann

Jump to: navigation, search

This page describes tips, tricks and fixes for Debian on an Openmoko Freerunner. I tested these tips on my OpenMoko and my HTC Magic.

Although this article is in the OpenMoko section, it can be mostly used for any Android implementation, if not told otherwise.

Contents

Starting with Android

Some dev links: sdk, emulator.

How to update Sapphire: [1] and Radio/SPL here: [2]

JF's ROMS: [3] (doesn't work very well with Sapphire, at least WiFi).

CyanogenMod ROM: [4] (the best rom I got so far, including iptables and busybox).

How to root the phone and get extra cool things: JesusFrekes firmware RC33/RC9.

Hidden "test" menu: "call" *#*#4636#*#*

Flashing the Sapphire

Warning: these steps are for sapphire only, they probably look like the same than other models, but I cannot guarantee this will work for you. At least it worked for me, as I wrote this tutorial while doing it. Of course, I'm not responsible for any data loss or phone brick. Also, these steps do not show how to unlock the phone, but only to root it. Go to an unlocking website to do so.

Needed tools:

Needed files:

Now the steps:

  1. Turn the phone OFF.
  2. Put the phone in fastboot mode: keep pressing VOL DOWN and press on/off
  3. Wait until green text displayed and dissapeared, and press Back
  4. Plug the phone into USB (red FASTBOOT USB should display)
  5. Type on your console:
    ./fastboot boot boot.img
  6. The phone will reboot and the computer should display:
    downloading 'boot.img'... OKAY
    booting... OKAY
  7. When booted, the phone is rooted, but not for long: next reboot and root is gone.
  8. Go into Settings, Applications, Debugging, and select USB debug.
  9. Now, on your computer type:
    ./adb push cm-recovery-1.4.img /sdcard/
  10. If there is an error, try:
    ./adb kill-server
  11. Computer shows something along these lines:
    * daemon not running. starting it now *
    * daemon started successfully *
    1280 KB/s (4098048 bytes in 3.124s)
  12. Now run:
    ./adb shell flash_image recovery /sdcard/cm-recovery-1.4.img
  13. That's it, you've just installed the CyanogenMod Recovery! Now uploading the update files...
  14. Type:
    ./adb push ota-radio-2_22_19_26I.zip /sdcard/
    ./adb push spl-signed.zip /sdcard/
    ./adb push update-cm-4.2.3.1-signed.zip /sdcard/
    ./adb push signed-dream_devphone_userdebug-ota-14721.zip /sdcard/
  15. Now let's begin the flashin'. First, shut your phone down. Then, keep pressing HOME and press on/off.
  16. Wait until recovery menu appears.
  17. Choose the apply any zip from sd, then choose ota-radio. Press HOME to confirm.
  18. After a while, it will ask you to reboot the phone. Do as it asked by choosing the first menu item. A logo of a package, an arrow and a phone will show up. Wait for total reboot.
  19. Recovery shows up again. Again, choose apply any zip from sd, and this time choose spl-signed.zip. Press HOME again to confirm.
  20. Again, it needs to reboot the phone. Do it, and wait for recovery to come up again.
  21. When that's done, we can install the distro itself. First, we need to wipe out all your data. Choose the wipe data/factory reset option. Confirm with HOME.
  22. For safety, we're gonna backup the original system. It's not needed but it's safer if you want to use the original system again. Choose nandroid v2.2 backup. This time, you don't need to confirm, as it's not an erasing option. The backup is quite fast.
  23. Now, go for it: choose apply any zip from sd and choose signed-dream_devphone_userdebug-ota-14721.zip. Press HOME, and wait. The file is quite big, so it can take some time. You will see the "unbox" image, then it will automatically reboot. HOLD HOME button while it reboots.
  24. When back in recovery, Apply sdcard:choose zip, pick update-cm-4.2.3.1-signed.zip from the list. Press HOME, and wait.
  25. When it's finished, it tells Install from sdcard complete. Reboot the phone by choosing the appropriate option.
  26. Hurray! Phone is rooted, and works much better than before with a lot of new software to install to.

GPRS

GPRS settings for Bouygues:

  • Name : ebouygtel.com / mmsbouygtel.com
  • APN Type : default
  • MCC : 208
  • MNC : 20
  • APN Type : default

Not needed but can be useful:

  • DNS 1 : 62.201.129.99
  • DNS 2 : 62.201.159.99 (reachable from the outer net too, so good for a resolv.conf)

Not needed at all (can more painful than helpful) but here for information:

  • Proxy : 62.201.129.225
  • Port : 8080

MMS parameters only:

To shutdown GPRS when you don't need it, just change for example the Name. It will not bother you anymore. Some application named APNdroid does that for you.

ADB

Android doesn't have ssh, it has it's own debugging tool: adb (Android Debug Bridge). It seems to work through USB only. It's available with the SDK.

Note: If you're in trouble with ADB driver not working with XP SP3, have a look at this:

  • Replace android_usb.inf
  • Remove: C:\WINDOWS\system32\drivers\Wdf01000.sys,
  • Remove: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Wdf
  • Remove: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Wdf01000
  • Restart your machine and install the driver again

How to do tethering via USB under Linux: [5] not needed anymore with CyanogenMod 4.2.3+, you just need to install (and remove after if you want) activesync to get RNDIS drivers to work (rndis_host under linux).

OpenMoko section only

Installation

Refer to this page for Android installation. You'll need a microSD card for it to run (this is where personal data will be stored). You'll also have to format it, so don't forget to take all data out of it.

To install the network device under Windows, you'll have to use the following file: Neo1973.inf.

Debian on Android

This is a very interesting thing : you can install Debian and use it apart from Android, with all the tools you want existing in Debian! Here is how to install it and another interesting link.

Important note: if you want to install it on an OpenMoko, it will fail: OpenMoko install miss the loopback support needed to mount the Debian install image. I got it working though by mounting it on a desktop computer and making a tar image that I extracted in an extra partition on the microSD card (formatted as ext3 of course).

Here is a short summary took from this link:

mkfs.ext3 /dev/mmcblk0p3
mount /dev/mmcblk0p3 /mnt/debian
debootstrap --foreign --arch armel lenny /mnt/debian
umount /mnt/debian
# On Android...
# ...don't forget disable sleep on AC power and plug it in.
busybox ash
# or maybe
mount -o loop /dev/block/mmcblk0p3 /data/debian
chroot /data/debian debootstrap/debootstrap --second-stage

Then, when you want to load it:

mount /dev/block/mmcblk0p3 /data/debian
export PATH=/usr/bin:/usr/sbin:/bin:$PATH 
export TERM=linux
export HOME=/root
export USER=root
chroot /data/debian /bin/bash
mount -t devpts devpts /dev/pts
mount -t proc proc /proc
mount -t sysfs sysfs /sys

Tip: If you want to access your sdcard in debian, you need to do (as adb shell or telnet) :

mkdir /data/debian/mnt/sdcard
mount -o bind /sdcard /data/debian/mnt/sdcard

For additional tips about Debian, go to the Debian page (isn't it obvious?)

SSH

On the phone, run this in the debian chroot:

/etc/init/ssh start

To use it on the computer with USB, here is an alias example:

alias droid='adb forward tcp:1622 tcp:22 && ssh -p 1622 root@localhost'

Note: you don't need to setup the forward each time, but it does not matter if you do.

Update: with new roms, there's IP over USB so you don't need to forward anymore, just ssh root@192.168.77.254 and here you are.

VNC

Download fbvncserver binary and run it on your phone.

X11 and Debian

You can achieve this by installing tightvncserver like said here.

Startup in CyanogenMod 4.2.3 and higher

You can automatically startup debian and other cool things in CyanogenMod.

Run telnetd on your phone, connect to it via wifi for example and type this in:

cat > /data/bootdeb << EOF
#!/system/bin/sh
mount -o noatime /dev/block/mmcblk0p3 /data/debian
export PATH=/usr/bin:/usr/sbin:/bin:$PATH 
export TERM=linux
export HOME=/root
export USER=root
chroot /data/debian /etc/init.d/first-boot
EOF

sh /data/bootdeb
cp /data/bootdeb /data/debian/boot/bootdeb

cat > /data/debian/boot/06debianinit << EOF
#!/system/bin/sh
/system/bin/usb-tether start
/system/bin/sh /data/telnetd.sh &
/system/bin/sh /data/bootdeb
# call a userinit.sh script if it's present on the sdcard
if [ -e /data/debian/boot/userinit.sh ];
then
    echo "--- Executing debian/boot/userinit.sh";
    /system/bin/sh /data/debian/boot/userinit.sh;
fi;

if [ -d /data/debian/boot/userinit.d ];
then
    busybox run-parts /data/debian/boot/userinit.d;
fi;
EOF

cat > /data/debian/boot/telnetd.sh << EOF
#!/system/bin/sh
/system/xbin/iptables -t filter -A INPUT -p tcp --dport 23 -s 127.0.0.1 -j ACCEPT
/system/xbin/iptables -t filter -A INPUT -p tcp --dport 23 -s \! 192.168.77.0/24 -j DROP
while true; do /system/bin/telnetd; done
EOF

cat > /data/debian/etc/init.d/first-boot << EOF
#!/bin/sh
hostname \`cat /etc/hostname\`
mount -t devpts devpts /dev/pts
mount -t proc proc /proc
mount -t sysfs sysfs /sys
/etc/init.d/ssh start
#/etc/init.d/samba start
EOF
chmod 110 /data/debian/etc/init.d/first-boot

cat > /data/debian/boot/userinit.sh << EOF
#!/system/bin/sh

# Enable USB Tether via WiFi and VPN
#/system/xbin/iptables -t nat -A POSTROUTING -o tiwlan0 -j MASQUERADE
/system/xbin/iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE

# Enable and filter out VNC access
# No need to use it locally, we're already on the phone...
#/system/xbin/iptables -t filter -A INPUT -p tcp --dport 5901 -s 127.0.0.1 -j ACCEPT
/system/xbin/iptables -t filter -A INPUT -p tcp --dport 5901 -s \! 192.168.77.0/24 -j DROP
/data/debian/boot/fbvncserver -rfbport 5901 -passwd toor -disablefiletransfer &

EOF

cat > /data/debian/boot/install_scripts.sh << EOF
#!/system/bin/sh

if [ ! -e /system/bin/sh ]; then
echo "This file must be run on the Android system, as root."
exit 1
fi

echo "Mounting /system rw"
mount -o remount,rw /system

echo "Copying files..."
cp /data/debian/boot/06debianinit /system/etc/init.d/06debianinit
chmod 110 /system/etc/init.d/06debianinit
cp /data/debian/boot/bootdeb /data/bootdeb
cp /data/debian/boot/telnetd.sh /data/telnetd.sh

if [ "`grep ads.mobclix.com /system/etc/hosts`" == "" ]; then
cat /data/debian/boot/hosts.ads >> /system/etc/hosts
fi

echo "Mounting /system ro"
mount -o remount,ro /system

echo "Done, now reboot your phone to activate changes"
EOF

echo android > /data/debian/etc/hostname
echo deb http://ftp.fr.debian.org/debian lenny main > /data/debian/etc/apt/sources.list
mknod /data/debian/dev/ptmx c 5 2
chroot /data/debian /etc/init.d/first-boot
chroot /data/debian /usr/bin/apt-get update
chroot /data/debian /usr/bin/apt-get install udev
chroot /data/debian /usr/bin/apt-get install openssh-server
chroot /data/debian /usr/bin/apt-get install samba
chroot /data/debian /usr/bin/passwd

sh /data/debian/boot/install_scripts.sh

Note : you'll have to run these lines in the terminal each time you update your ROM or reinstall it:

sh /data/bootdeb
sh /data/debian/boot/install_scripts.sh

Update : From CM 4.2.14, busybox does not have chroot anymore, but you can still get the binary from 4.2.13 here.

Tips & Tricks

Get rid of advertising

Place this at the end of your /etc/hosts file:

127.0.0.1 a.admob.com
127.0.0.1 adbatch.qwapi.com
127.0.0.1 ads.mobclix.com
127.0.0.1 beacon.pinchmedia.com
127.0.0.1 data.flurry.com
127.0.0.1 data.mobclix.com
127.0.0.1 event-img.qwapi.com
127.0.0.1 googleads.g.doubleclick.net
127.0.0.1 img1.iphone.mxweas.com
127.0.0.1 media.fastclick.net
127.0.0.1 met.adwhirl.com
127.0.0.1 mm.admob.com
127.0.0.1 mob.adwhirl.com
127.0.0.1 mxtube.iphone.mxweas.com
127.0.0.1 pagead2.googlesyndication.com
127.0.0.1 r.admob.com
127.0.0.1 s.mobclix.com
127.0.0.1 s3.amazonaws.com
127.0.0.1 www.clickspan.com
127.0.0.1 www.google-analytics.com
127.0.0.1 www.trippertlabs.com

About the big scripting above, just place this content in /data/debian/boot/hosts.ads and each time you'll install_scripts.shs these will be installed.

Links

Personal tools