Installing CM7 7.1.2 (2.3.7) on a Motorola Milestone

Since, I got a new phone, I decided to upgrade my old Motorola Milestone with the latest cyanogenmod. CyanogenMod 7 for Milestone A853 is not officially supported by CyanogenMod, however, since I don’t need the phone to be working, I installed it.

As my phone is already rooted, I did not need to follow these instructions.

Preparation

  • Download OpenRecovery
  • Copy the extracted files (directory OpenRecovery, file update.zip, file vulnerable_recovery.sbf) to the sdcard of your phone.
  • Reboot into recovery (Press Camera button, then press Power. Hold them both untill you see the recovery screen. Then, press Volume Up and Camera button at the same time untill you see the recovery menu)
  • Apply the update.zip -> You are now in Open Recovery
  • Download latest google apps and place them on the sdcard of your phone in the folder OpenRecovery/updates
  • Before building CM7, you should download repo from here. Once you have the file, make it executable chmod a+x repo.
  • Make sure you have installed the following dependencies (Ubuntu) bison flex g++-multilib gcc-multilib gperf lib32ncurses5-dev lib32z1-dev libc6-dev-i386 libx11-dev mesa-common-dev openjdk-6-jdk

Compiling CM7

Depending on your CPU and bandwidth, this may take some hours.

mkdir cm4mm
cd cm4mm
repo init -u git://github.com/nadlabak/android.git -b gingerbread
repo sync
vendor/cyanogen/get-rommanager
. build/envsetup.sh && brunch umts_sholes

Flashing

  • Copy the update-cm-7...-Milestone-signed.zip from out/target/product/umts_sholes to OpenRecovery/updates
  • Factory Reset / Wipe Cache Partition AND Dalvik Cache
  • Flash the Cyanogen update-cm-7...-Milestone-signed.zip file
  • Flash the Google Apps zip file
  • Reboot

Installing dropbear an a PCH-A200/A210 (NMT – Networked Media Tank)

First, install opkg by using the NMT Community Software Installer. If you are using Ubuntu, install sudo apt-get install mono-complete (which is probably more than you need) to make NMT-CSI run. Download the opkg package, then run sh "Linux Start.sh" and go to File -> Install from File -> opkg_c200_v0.1.8-nmt1.zip. Of course you need to start FTP in order to connect to your device. For more details, go here.

Once opkg is installed get the package list opkg update and install opkg install dropbear. This failed with my setup, so I had to configure it manually:

  • create keys: dropbearkey -t dss -f dropbear_dss_host_key, dropbearkey -t rsa -s 1024 -f dropbear_rsa_host_key
  • copy them to /share/.ssh and make them chmod 600
  • also copy your authorized_keys to this directory

After that, I modified /share/Apps/local/etc/init.d/51dropbear.sh in order to start dropbear (inspired by this thread).

#!/bin/sh
[ -e /share/Apps/local/etc/default/dropbear ] && . /share/Apps/local/etc/default/dropbear
if [ "$DROPBEAR_ENABLE" = "no" ]; then
    exit
fi
if [ -n "`pidof /share/Apps/local/sbin/dropbear`" ]; then
    killall /share/Apps/local/sbin/dropbear 2>/dev/null
fi
# root does not have a shell, so ssh wont work. Give the root a shell
sed -i 's#root:x:0:0:root:/root:/bin/true#root:x:0:0:root:/root:/bin/sh#g' /etc/passwd
mkdir -p /etc/dropbear
cp /share/.ssh/dropbear_dss_host_key /etc/dropbear
mkdir -p /root/.ssh
chmod 700 /root/.ssh
cp /share/.ssh/authorized_keys /root/.ssh/
chown root.root /root
# -s Disable password logins
/share/Apps/local/sbin/dropbear -s

Lets hope that the installation of an ssh server on the new Popcorn Hour A-300 is a bit easier.

Update 15.12.2011: I installed unison for doing backups on my NMT. Unfortunately, I did not find the package here. However, it turned out to be easier than I thougt. Instead of cross-compiling my own package, I tried the package from debian, and it worked by just copying the binary into the /share/Apps/local/bin/. The only problem is the CPU that slows the encrypted traffic down to around 10MBit/s.

Upload Artifacts on the Command Line

I had to patch an external library and since my project uses Maven, I wanted to upload this patched library to my Maven repository. It turned out that I had to use maven2 as maven3 handles extensions differently.

Stackoverflow provided the rest of the information I needed to upload a library to my maven repository.

/home/draft/java/apache-maven-2.2.1/bin/mvn deploy:deploy-file -Durl=scp://tomp2p.net/home/draft/maven -DrepositoryId=ssh-tomp2p -DgroupId=org.jboss.netty -DartifactId=netty -Dversion=3.2.6.Patched -Dpackaging=jar -Dfile=target/netty-3.2.6.Patched.jar

Battery Life of a HP 5103

After reading the following articles, I decided to tweak battery life on my HP 5103. Before I started, I installed the latest Linux 3.1 kernel.

The battery usage without any tweaks was 11.4W as reported by powertop. I tested the option pcie_aspm=force and the power usage went down to 10.3W. Another tweak I did was to mount the / with the option noatime to reduce disk IO. If this option is set, reading accesses won’t be written (atime) to disk. However, I did not do any measurements.

Furthermore, I disabled bluetooth and added the following lines to rc.local (found here and here)

for i in /sys/class/scsi_host/host?/link_power_management_policy; do
    echo min_power > $i
done
for i in /sys/bus/usb/devices/*/power/autosuspend; do
    echo 1 > $i
done
for i in $(find /sys/devices/pci* -wholename "/sys/devices/pci*/power/control"); 
    do if [[ "$(cat $i)" == "on" ]]; then 
         echo "auto" > $i; 
    fi; 
done;

And now I’m down to 9.5W. Further reduction can be achieved by dimming the backligth.

If you want to have this done automatically, you may want to install laptop-mode-tools. However, you need first to change the line

Look for :
	"2.6" ) ;;

And add right after on line following, which ought to allow kernel 3.0, 3.12 .. 3.9876.

3.[0-9]*) ;;

If your mouse is only working after replugging, add it to the blacklist (in /etc/laptop-mode/conf.d/usb-autosuspend.conf set AUTOSUSPEND_USBID_BLACKLIST="046d:c018"), or buy a mouse that supports autosuspend. I also had to disable the WLAN autosuspend (/etc/laptop-mode/conf.d/wireless-power.conf), as this is with brcmsmac not possible.

(X)Ubuntu 11.10

Yesterday, I installed 11.10 oneirc on my HP 5103. The HP5103 is a netbook, which is not very fast, so I was wondering how good the new Ubuntu would work. First I tried Unity. The good part ist that they included now many of the nice features that I was missing before, e.g., multiload, which is an applet to show the cpu and network load. The reason I decided not to use Unity is because the windows key is too unreliable. Since staring application with the windows key is a central part of the Unity concept, its needs to work 100% reliabel. Pressing [win]-[e][enter], must always open Firefox regardless of the CPU load or windows focus.

Then, I installed gnome-shell. The first thing I tried was if the windows key is working as expected regardless of the CPU load or windows focus. It did work as expected, good news. However, the system monitor seems to be work in progres and I could not place it on top, it stayed on the bottom. The interesting part is that those extensions are written is javascript and are using css. This makes the extensions easy to write (no gcc, no libriaries), but it needs a good development environment, something like Firebug. Another point I am concerned is speed: while the javascript extension is flexible, I am not sure if the UI remains fast and snappy. I recently read that the Firefox developers decided to replace their XUL layout engine with a native one for greater responsiveness and less memory consumption. It seems that gnome-shell is heading in the other direction.

The feature that made me finally switch back to Xubuntu is dual monitor, which was not working with Ubuntu (gnome-shell and Unity). The screen would go black, then show colored stripes. I am having a GMA 3150, which does not have the best Linux support, but at least in Xubuntu, I can attach a second monitor. Another thing I noticed is that it just feels much faster than gnome-shell and Unity.

Manually Decrypt your Encrypted Home Directory with your Login Password

The home folder encryption uses two passwords: one password, which is the login password that encrypts/decrypts the mount password. The encrypted mount password is stored in the file wrapped-passphrase. This way, if the user changes the password, only the mount password needs to be re-encrypted.

I am using Ubuntu 11.10, so depending on your distribution, the commands may be different.

  1. ecryptfs-unwrap-passphrase /home/username/.ecryptfs/wrapped-passphrase
  2. sudo ecryptfs-add-passphrase --fnek (use key from above, copy second key, that is displayed)
  3. create /tmp/username
  4. sudo mount -t ecryptfs /home/.ecryptfs/username/.Private /tmp/username
  5. select: aes, 16, n, y, and paste the second key from above

Manually Uncrypt your Ecrypted Home Directory with your Login Password

The home folder encryption uses two passwords: one password, which is the login password that encrypts/decrypts the mount password. The encrypted mount password is stored in the file wrapped-passphrase. This way, if the user changes the password, only the wrappend passphrase needs to be re-encrypted.

I am using Ubuntu 11.10, so depending on your distribution, the commands may be different.

  1. ecryptfs-unwrap-passphrase /home/username/.ecryptfs/wrapped-passphrase
  2. sudo ecryptfs-add-passphrase --fnek (use key from above, copy second key, that is displayed)
  3. create /tmp/username
  4. sudo mount -t ecryptfs /home/.ecryptfs/username/.Private /tmp/username
  5. select: aes, 16, n, y, and paste the second key from above

Naming Issues with broadcom-sta module

The broadcom-sta module wl will use the eth* naming pattern by default. If you are having two network interfaces, e.g. lan and wlan (I’m having a BCM43224), ifconfig will output:

eth0      Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx  
          inet addr:192.168.1.249  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: xx/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3255 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2849 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:2032027 (2.0 MB)  TX bytes:359760 (359.7 KB)
          Interrupt:19 
eth1      Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx  
          inet addr:192.168.1.215  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: xx/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:112 errors:1 dropped:0 overruns:0 frame:11971
          TX packets:91 errors:34 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:13829 (13.8 KB)  TX bytes:15989 (15.9 KB)
          Interrupt:16 

This behavior can be changed by setting the name in the option in /etc/modprobe.d/modprobe.conf (you may need to create this file if it does not exist) by adding the option options wl name=wlan0. As an alternative, you can use the b43 kernel module (requires kernel 3.1+) or brcmsmac instead of broadcom-sta. To switch, type in console "echo "blacklist wl" >> /etc/modprobe.d/blacklist" as root and reboot (or remove the the wl kernel module).

How to Install mod_pagespeed

According to the project page, mod_pagespeed is:

mod_pagespeed is an open-source Apache module that automatically optimizes web pages and resources on them. It does this by rewriting the resources using filters that implement web performance best practices. Webmasters and web developers can use mod_pagespeed to improve the performance of their web pages when serving content with the Apache HTTP Server.

mod_pagespeed includes several filter that optimize JavaScript, HTML and CSS stylesheets. It also includes filters for optimizing JPEG and PNG images. The filters are based on a set of best practices known to enhance web page performance. Webmasters who set up mod_pagespeed in addition to configuring proper caching and compression on their Apache distribution should expect to see an improvement in the loading time of the pages on their websites.

Installation

Go to the Page Speed project page and download it (wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-beta_current_amd64.deb). Then install it (sudo dpkg -i mod-pagespeed-beta_current_amd64.deb). Its a good idea to clean up your stuff unless your working in the tmp directory. The mod_pagespeed module is enabled by default, to disable use a2dismod pagespeed.

Tests and Performance

Google is claiming an reduction of page load time by up to 50%, but the following reviews/blogs measured different numbers:

  • “I get a 13% profit with mostly default values, a good configured server should propably even do better.” found here
  • “Mod_pagespeed may slow down your site, speed up your website significantly or anywhere in between, while running in Safe Mode... If you use the non-Safe Mode filters the speed gain will very likely go up, but maybe not that much.” found here
  • “mod-pagespeed brought an average of 19.9% improvement in page load times” found here

WLAN Tethering

WLAN tethering is a mechanism to share a mobile connection. This is very handy if someone has multiple devices, but only one 3G device with a reasonable data plan. Since a mobile (smart) phones typically have WLAN and 3G, it is possible to connect to the Internet with 3G and set WLAN to act as an access point. Since I went to vacations with 3 devices with WLAN capabilities (2 Android phones, 1 laptop), I wanted to use the 3G network for all my devices without changing SIM cards all the time.

I investigated how to get my Android phone to act as an access point. I soon found out that without a rooted phone, it is a hassle. For a rooted phone, you have to have a custom kernel with iptables support to use this. Furthermore, the phone gets hot. Other solutions do not require a rooted phone, such as installing a proxy on the Android phone, and using the USB cable to forward packets. All you need to do, is to install the Android SDK, enable USB debugging on your phone, and you have your proxy. The downside is that it is only a proxy, and for each application you have to configure the proxy settings manually.

Thus, I did not use my Android phone for WLAN tethering, but opted for a mobile access point with a 3G USB stick with my laptop.

Mobile Access Point

To use your laptop as a mobile access point, you need to install hostapd, which is a user space daemon for access points. It supports standards, such as 802.1X/WPA/EAP. It is important to know that you most likely need a recent wifi driver, which is mac80211 based, for an easy installation. If you have such a new driver, you can set your hostapd.conf to

interface=wlan0
driver=nl80211
ssid=test
channel=1

I recommend also to use some kind of encryption, because if other people are using your 3G connection and you are paying on a bandwidth basis, it can get expensive. With /etc/init.d/hostapd start you can start the daemon and test if it works. The next thing I did was to create a script in /etc/NetworkManager/dispatcher.d/, which starts the access point automatically when you insert the USB stick and the laptop was on AC power. Make sure you disable “Wireless Networking” in the Network Manager!

#!/bin/bash
# Script to dispatch NetworkManager events
#
# Starts a mobile access point if on AC power

if [ -z "$1" ]; then
    echo "$0: called with no interface" 1>&2
    exit 1;
fi

IFACE="$1"
MODE=`cat /proc/acpi/ac_adapter/ACAD/state | cut -d':' -f2 | tr -d ' '`

# Run the right scripts
case "$2" in
    up)
        if [ "$IFACE" == "ppp0" ] && [ "$MODE" == "on-line" ]; then
                ifconfig wlan0 192.168.0.1 netmask 255.255.255.0 up
                iwconfig wlan0 channel 6
                iwconfig wlan0 txpower 20
                /etc/init.d/dnsmasq start
                echo "1" > /proc/sys/net/ipv4/ip_forward
                iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
                /etc/init.d/hostapd start
        fi
        ;;
    down)
        if [ "$IFACE" == "ppp0" ] ; then
                /etc/init.d/hostapd stop
                /etc/init.d/dnsmasq stop
                echo "0" > /proc/sys/net/ipv4/ip_forward
                iptables -t nat -F
                iwconfig wlan0 mode managed
        fi
        ;;
    *)
        echo "$0: called with unknown action \`$2'" 1>&2
        exit 1
        ;;
esac

Make the 3G connection start automatically in “Network Manager”, plug in the 3G USB stick and your laptop is an WLAN access point that connects with 3G to the Internet.

Git in Eclipse

Git is a distributed version control system. Many large projects use Git for managing their codebase, such as the Linux Kernel or Gnome . The key difference to a non-distributed version control such as Subversion is that a commit in Git is done locally, which means you have all the versions locally. To “commit” it to a remote repository, you need to “push” it. Although Git has all the version information locally, it often uses less space than Subversion. You can use Git offline, while with Subversion, for all the operations you have to be online.

Git is efficient for handling large projects. Although my projects are not large at all, I decided to try Git. Since I use Eclipse, an Eclipse plugin for Git is essential because switching to the console is cumbersome. While for Subversion, there are 2 plugins: Subclipse and Subversive with all the nice features you can think of: revision graphs, graphical merge tools, ... For Git, there is EGit, which seems to be a plugin at an early stage and misses some important features (I tried version 0.8.0.201005021513). While with subversion, commit and update works with a couple of clicks, with EGit a commit/push needs more clicks. Especially for the push, there is room for improvement, e.g., filling the form with the last entered URI. However, the pull, which is basically a fetch/merge is not there yet. You can fetch the latest data from a repository, but there is no support for merging in EGit, so I had to use the command line.

Nevertheless, I’ll stick with Git/EGit and see how it goes.

Huawei E1762 failed to connect

Yesterday, I bought a Huawei E1762 HSPA USB stick for mobile Internet, but it was not able to connect. I quickly checked with Windows, and after a bunch of installed driver from the USB stick, it worked. So the problem is with my installed Ubuntu version 9.10.

The USB stick under Windows works as follows that it first appears as a CD-ROM device, containing all the necessary drivers for Windows. Having autostart enabled, the drivers are automatically installed and then the device switches its mode to a USB modem. Fortunately both types of devices (storage and modems) are well supported in the Linux kernel, the only thing that needs to be done is to switch the mode from storage to modem.

Mode switching in Linux requires usb-modeswitch, which can be installed on Ubuntu 9.10. However, the Huawei E1762 is not recognized. Quickly checking the device id with lsusb shows that there is no configuration file for the device 12d1:1446 in /etc/usb_modeswitch.conf. Since the latest usb-modeswitch data files contain the configuration files for this device, its only necessary add the missing configuration file to make this device work.

Ubuntu 9.10 uses an ancient version of usb-modeswitch (1.0.2), so using the latest usb-modeswitch data files does not work and the changes have to be applied manually. The following site contains all the necessary steps to change the configuration file, in short its:

sudo apt-get install usb-modeswitch

then in the file /etc/usb_modeswitch.conf change to

########################################################
# Huawei E220 (aka "Vodafone EasyBox II", aka "T-Mobile wnw Box Micro")
# Huawei E230
# Huawei E270
# Huawei E870
# and probably most other Huawei devices (just adapt product ID)
#
# Two options: 1. removal of "usb-storage"  2. the special control
# message found by Miroslav Bobovsky
#
# Contributor: Hans Kurent, Denis Sutter, Vincent Teoh

DefaultVendor=  0x12d1
;DefaultProduct= 0x1003
DefaultProduct= 0x1446

TargetVendor= 0x12d1
;TargetProduct= 0x1003
TargetProduct= 0x1446

# choose one of these:
;DetachStorageOnly=1
;HuaweiMode=1

MessageEndpoint=0x01
MessageContent= "55534243000000000000000000000011060000000000000000000000000000"

then create the file /etc/udev/rules.d/15-huawei-e1762.rules or update usb_modeswitch.rules with

SUBSYSTEM=="usb", SYSFS{idProduct}=="1446", SYSFS{idVendor}=="12d1", RUN+="/usr/sbin/usb_modeswitch"

Finally my Huawei E1762 is working with usb-modeswitch (version 1.0.2).