Luke Dupin, Ruby, C++, Java, G1, Android, Monitoring, Software Engineer, Wii Mote, Linux, Ubuntu, Ruby on Rails, QT, OpenGL

Connecting a Wiimote to G1 Android. Wii mote, Android, G1, HTC Dream

Project Overview
  • Root your phone - Gain root access to your G1. This provides unrestricted access to the hardware and software on your G1.
  • Upgrade to CyanegonMod - Provides an Android build with the ability to mount linux filesystems
  • Install Debian - Debian provides a linux driver model which the current cWiid library uses to communicate with a Wiimote
  • Connect the Wiimote - We use proven linux software to communicate with the Wiimote directly over bluetooth
  • Develop for the G1/Wiimote - Download and install a simple development enviornment that compiles code for your phone. This allows the user to get data from the Wiimote into the Android API using simple TCP/IP sockets
Project Media
Connect a Wiimote directly to an Android G1 phone.


Removing your battery and SD card.
Requirements
Before you start
Follow the instructions exactly. Although most steps are safe, there are a few steps that could potentialy brick your phone. In this tutorial, I presume the user has a MicroSD card adapter and SD card reader on their computer. If you don't, you can still complete the tutorial. Simply connect your phone over USB, and copy the files directly to the phones SD card. Once the files are copied, unmount the G1 on both your computer and your phone, physically remove the USB cable from the phone, and complete the step in question. Here are a few helpful tips:
  • Ensure your G1 is fully charged
  • Read the entire tutorial before starting step 1
  • Backup all your contacts and any other data you want to keep, or you will lose it
  • Make sure you have a valid google account
  • While flashing, never remove any cables, power off your phone, or push buttons
  • Set aside at least an hour to complete the tutorial
  • Start downloading all the required files now
  • At the bottom of each step, there are images that act as a visual confirmation. I recommend viewing all the images before starting the step at hand
  • Text inside this box means you should run the commands on your G1
  • Text inside this box means you should run the commands on your computer
For users without SD card readers/adapters
It is possible to complete this tutorial without ever removing the SD card from your phone. I highly advise against doing it this way because a mistake will leave you with a phone that doesn't boot up, and the only way to remedy that is to change what files are on the SD card. With that said, if you are going to do the tutorial without messing with SD card adapters, here are some tips:
  • You need a USB cable to connect your computer to your phone
  • When the cable gets connected, in your phone's notices, you will see USB connected. Click on that and select mount
  • Copy whatever files you need onto your SD card from your computer
  • Unmount the drive from your computer
  • IMPORTANT Physically remove the USB cable from your phone
Disclaimer
Any user of this tutorial takes full responsibility for any harm to their G1 or any effected system. I take no responsibility for any unintended consequences.
Step 1. Down grade to firmware RC29
The first step to get root access is down grading our G1's firmware to RC29. The RC29 and older firmware versions have a very seriouse security hole; anything typed on the key board is ran as root. We will use this exploit to start a telnet daemon on the phone and access the filesystem.
  • Remove the SD card from your G1 phone and insert it into your computer.
  • Unzip DREAMIN-RC29.zip. Copy DREAMIMG.nbh onto the root directory of your SD card: cp DREAMING.nbh /media/G1Hack
  • Power off your phone
  • Remove the SD card from the computer and insert it into your phone
  • Ensure your SD card is unmounted and the USB cable IS NOT connected
  • Hold Camera button and power button together until the boot loader screen appears
  • The flash will pop up, follow those instructions to flash. I have seen this phase fail. Please reformat your card again and ensure it is a valid fat32 format.
  • Once the flash operation is completed your system will check its primary componets, you should see OK next to all of them. The system check and radio_V2 take some time so be patient
  • Once the flashing is completed you will be returned to the rainbow screen. Wait for at least 60 seconds to be safe, then remove the battery.
Step 2. Unlock the filesystem
Now that we have an older firmware release we can get root access to the filesystem. During this step we remount the filesystem with write access and update the recovery image. This enables us to upload a new Hardware SPL which in turn allows us to flash non-T-Mobile firmware.
  • Remove the SD card from your G1 phone and insert it into your computer.
  • Copy recovery.img to the SD card: cp recovery.img /media/G1Hack/recovery.img
  • Remove the SD card from the computer and insert it into your phone
  • Power on your phone
  • Connect your G1 to your local wifi network
  • From the home screen on your phone, press enter two(2) times (Visual feedback: You wont see any)
  • Type: telnetd (Visual feedback: contacts will be searched)
  • Press enter (Visual feedback: You wont see any)
  • Find your phone's IP address: From home -> Push the menu button -> Settings -> Wireless settings -> click on your connection
  • Ensure your SD card is unmounted and the USB cable IS NOT connected
  • From your computer, telnet into your phone, type: telnet PHONE_IP_ADDRESS
    telnet 192.168.1.101
  • Type: mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system
  • Type: cd sdcard
  • Type: flash_image recovery recovery.img
  • Type: cat recovery.img > /system/recovery.img
  • You now have root access and can upgrade your hard SPL
Step 3. Update your Hard SPL
The Hard SPL(Second Program Loader) is the bootloader that starts Android on your G1. The factory SPL only allows us to flash T-Mobile firmware. The problem there is, that firmware doesn't come with root access turned on. Since we need root access, will need none factory firmware. Thus we must update the SPL in flash memory.
  • Power off the phone
  • Remove the SD card from your G1 phone and insert it into the computer.
  • Copy hard_spl.zip to the SD card as update.zip: cp hard_spl.zip /media/G1Hack/update.zip
  • Remove the SD card from the computer and insert it into your phone
  • Ensure your SD card is unmounted and the USB cable IS NOT connected
  • Press and hold the home key and the power key until you see an exclamation point on the screen
  • Press Alt+L to get a flash screen
  • Press Alt+S to update the SPL
  • Once flashing is complete, Press Home and Back firmly then release together to reboot
  • Your phone will reboot and you now have an unlocked G1
Step 4. Install a root enabled firmware
At this point the phone is unlocked and life is grand. The problem is the firmware version we are currently running is old as the hills. Lets get something newer on there.
  • Power off the phone
  • Remove the SD card from your G1 phone and insert it into the computer.
  • Copy Jesus Freak 1.5.1 to SD card as update.zip: cp JFv1.51_CRB43-US(2).zip /media/G1Hack/update.zip
  • Remove the SD card from the computer and insert it into your phone
  • Ensure your SD card is unmounted and the USB cable IS NOT connected
  • Press and hold the home key and the power key until you see an exclamation point on the screen
  • Press Alt+L to get a flash screen
  • Press Alt+S to update the firmware version
  • Once flashing is complete, Press Home and Back firmly then release together to reboot
  • When you boot, your phone will take you through the "Welcome to Android" steps. Google account is required
Step 5. Update the radio firmware
The radio controller on your phone has been down graded during this process. For your phone to work with newer firmware versions, like cupcake, we need to update it.
  • Power off the phone
  • Remove the SD card from your G1 phone and insert it into the computer.
  • Copy ota-radio-2_22_19_26I.zip to SD card as update.zip: cp ota-radio-2_22_19_26I.zip /media/G1Hack/update.zip
  • Remove the SD card from the computer and insert it into your phone
  • Ensure your SD card is unmounted and the USB cable IS NOT connected
  • Press and hold the home key and the power key until you see an exclamation point on the screen
  • Press Alt+L to get a flash screen
  • Press Alt+S to update the firmware version
  • Once flashing is complete, Press Home and Back firmly then release together to reboot
Step 6. CyanogenMod (Optional, extremely recommend)
By now we are problably running JesusFreak 1.51. This is fine and dandy but JF has stated that there will be no more support for that firmware. Further more, JF 1.51 isn't a CRC1 release, which means its not the latest and greatest. CyanogenMod is a wonderful group that releases extremely good builds. In other words, you want to upgrade to CyanogenMod.
  • Goto CyanogenMod's Website
  • Download the latest stable release (update-cm-4.0.4-signed.zip when I wrote this)
  • Power off the phone
  • Remove the SD card from your G1 phone and insert it into the computer.
  • Copy update-cm-4.0.4-signed.zip to SD card as update.zip: cp update-cm-4.0.4-signed.zip /media/G1Hack/update.zip
  • Remove the SD card from the computer and insert it into your phone
  • Ensure your SD card is unmounted and the USB cable IS NOT connected
  • Press and hold the home key and the power key until you see an exclamation point on the screen
  • Press Alt+L to get a flash screen
  • REQUIRED Press Alt+W to wipe settings (Your phone wont boot this step is skipped)
  • Press Alt+S to update the firmware version
  • Once flashing is complete, Press Home and Back firmly then release together to reboot
  • When you boot, your phone will take you through the "Welcome to Android" steps. Google account is required
  • *If your phone takes an extremely long time to boot, you likely forgot to wipe your settings. Don't fret, poweroff your phone, and follow ALL the steps above starting with pressing home and power to boot.
  • You may notice your sex appeal just went up slightly, that's because your phone is now, bad ass
Step 7. Install Debian
At this point our G1 phone is pretty steller. Our only problem is that Android doesn't provide any means to talk directly to your bluetooth hardware, yet. The good news is, Debian does provide bluetooth access, and Debian maintains an up to date build that will install directly onto our G1. Now, we all love Android, and we don't want to hurt or change how it runs, so we wont. Linux provides a feature called loopback's that allows a single file to act like a drive. We are going to use this feature to install a completely contained ISO of Debian on our SD card. Once we do that, we will jail Debian, providing a safe separation between Android and Debian. To access this in-prisoned Debian, we'll ssh into it and have a fully working, linux environment.
  • Remove the SD card from your G1 phone and insert it into the computer.
  • bunzip2 debian.img.bz2
  • Create a directory called kit inside your SD card: mkdir /media/G1Hard/kit
  • Copy debian.img to the kit directory: cp debian.img /media/G1Hard/kit/debian.img
  • Copy busybox to the kit directory: cp busybox /media/G1Hard/kit/busybox
  • Copy the debian script to the kit directory: cp debian /media/G1Hard/kit/debian
  • Remove the SD card from the computer and insert it into your phone
  • On your phone, open a terminal and type the following commands
  • Ensure your SD card is unmounted and the USB cable IS NOT connected
  • su
  • telnetd
  • Telnet into your phone from your computer
  • From your computer, type: telnet PHONE_IP_ADDRESS
    telnet 192.168.1.101
  • Now we are logged into our phone as root. We want to setup an environment that is easy to use and linux compatiable. Type the follow commands into your telnet window
  • bash
  • export kit=/sdcard/kit
  • export bin=/data/local/bin
  • export mnt=/data/local/mnt
  • export PATH=$bin:/usr/bin:/usr/sbin:/bin:$PATH
  • export TERM=linux
  • export HOME=/root
  • Now we need to install our tools. Android doesn't have a copy command that comes with it. The good news is that cat offers the basic functionality we need. Type the follow commands into your telnet window
  • mkdir $bin
  • cat $kit/debian > $bin/debian
  • chmod 755 $bin/debian
  • cat $kit/busybox > $bin/busybox
  • chmod 755 $bin/busybox
  • Now that we have our tools installed, we want to boot the debian filesystem. Once the filesystem is booted, we need to remount a few drives to point at the real system hardware. Type the follow commands into your telnet window
  • busybox mknod /dev/loop0 b 7 0
  • busybox mkdir -p $mnt
  • busybox mount -o loop,noatime $kit/debian.img $mnt
  • busybox chroot $mnt /bin/bash
  • mount -t devpts devpts /dev/pts
  • mount -t proc proc /proc
  • mount -t sysfs sysfs /sys
  • rm -f /etc/mtab
  • ln -s /proc/mounts /etc/mtab
  • Now we have a running debian system jailed with chroot, and ready to use. The last step is we need a simple and fast way to get into it whenever we want. First we will set a root password; then install ssh. Type the follow commands into your telnet window
  • passwd root
  • apt-get update
  • apt-get upgrade
  • apt-get install openssh-server
Step 8. Connect a Wiimote to your G1
At this point the last thing to do is install a simple Wiimote test application on your phone. Please note that the program is slow as you will find out shortly. The good news is, when the graphical interface isn't running, the library is extremely fast!
  • Reboot your phone (Required)
  • On your phone, open a terminal and type the following commands
  • su
  • debian
  • From your computer, type: ssh root@PHONE_IP_ADDRESS
    ssh root@192.168.1.101
  • This step requires a unix machine with X11 forwarding enabled. From the ssh connection you just made, run the follow commands
  • apt-get install wmgui
  • export DISPLAY=127.0.0.1:10.0
  • Ensure your phone's bluetooth is turned on!
  • wmgui
  • On the window that should have just opened on your computer: File → Connect (Follow instructions from there)
  • Go hit the bars and pick up chicks with your Wiimote connected to a G1. You might actually have to fight them off with the Wiimote. Please use with caution.
Step 9. Debian-Arm development environment
Most of you wont care about this. If you are planning to write applications that use the Wiimote you will need this, or need to create something simular. Below are instructions to run an arm emulated device through Qemu using debian-arm. If you aren't a C developer or you don't have linux, don't bother.
  • My system is Ubuntu 9.04 64bit. qemu is version 0.10.0. I'm not sure how this will work on any other system, however, google probably knows.
  • Download Versatile Kernel
  • Download Versatile Initrd
  • Download debian_lenny_armel.qcow.bz2 (900Megs)
  • bunzip2 debian_lenny_armel.qcow.bz2
  • sudo apt-get install qemu
  • qemu-system-arm -M versatilepb -kernel vmlinuz-2.6.26-1-versatile -initrd initrd.img-2.6.26-1-versatile -drive file=debian_lenny_armel.qcow,cache=writeback -m 256 -append "root=/dev/sda1 console=ttyAMA0" -nographic
  • If you want graphical, which is really slow: qemu-system-arm -M versatilepb -kernel vmlinuz-2.6.26-1-versatile -initrd initrd.img-2.6.26-1-versatile -drive file=debian_lenny_armel.qcow,cache=writeback -m 256 -append "root=/dev/sda1"
  • There are two accounts on this system: root, and user. The passwords are the same as the account names I.E. Username: root, Password root
Sources and shout outs
I wanted to site some of the sources that allowed me to put this together. Some of them I took from verbatim. Thank you to everyone who posted information about this.