Hacking my Android HTC (Vision) T-Mobile G2
Home - Sun hat
Conditions of Use

Hacking my Android HTC (Vision) T-Mobile G2

Gotta root it first

My biggest problem was the jargon. I've been working with Linux from nearly the beginning so I was not brought up referring to the operating system as a "ROM" and/or "Firmware" the way these phone people do. Not only that, ROM seems to refer to everything: The phone radio code, the boot loader, the recovery system, and other stuff that normal computers don't have, but not the ACTUAL ROM which loads the Radio operating system! Really, they're right calling it a ROM if you don't have root access, and the whole point of gaining root acces is to stop it being a ROM.

I found this site to be very valuable for help understanding the phone, and for me this was most important: The phone has TWO processors, one to run the "radio", i.e make it a phone, and another to provide the user interface to the phone and to make it a "smart" phone, i.e a pocket computer, and game machine. It's the second processor that runs the Android OS. There is a ROM to tell the radio processor how to load its OS (not Android) and that OS knows how to load an OS, Android, on the other processor. If you get a bad radio system (or just "radio") on your phone you've made it into a "brick" because there is no way short of buying specialized hardware and software to get a working radio OS on it in that case. So as long as you haven't messed up your radio, your phone can still be salvaged.

I rooted my phone following this procedure and referring to this. A little scary and some actual work but no problem otherwise.

Now that it's no longer a ROM

If I'm going to have a computer, the four fundamental things I need are a terminal emulator, bash, vim, and better keyboard.

Adding bash

Googling around I found that CyanogenMod (CM7) includes bash and vim, but I also found that dsixda's Android Kitchen would add bash for me and, besides, the idea of managing my own system was more intriguing to me than just adopting a "mod" including CyanogenMod so I set it up and used it to add bash to my phone. But...

I found that just having bash on my phone wasn't what I was used to. I'm used to having a home directory with a bash initialization script, and I'm used to the current directory being my home directory when my shell starts up, I'm not used to being dumped into / when my shell starts.

I created myself a directory /sdcard/rmk for my home directory and I created an /etc/profile bash system start-up script to make it my start-up current directory complete with the HOME environment variable. To configure "Android Terminal Emulator" to start bash initialized with /etc/profile you start Terminal Emulator, press the menu button select "More > Preferences > Command line" and enter
(or where ever it is that bash is installed) and then select "Initial command" and enter
source /etc/profile.
(This last should not be necessary, bash should do it on start-up, but the bash in dsixda's Android Kitchen doesn't do it, and I have no clue why. If that bash gets fixed or you use another one that behaves correctly, and /etc/profile gets run twice, you'll know by looking at PATH because the original will get inserted twice.)

Now, since there will probably be updates for my phone I decided to simplify the process of restoring this bash start-up configuration to my phone after updates so I created a plugin for dsixda's Android Kitchen. If you want to use the plugin put the plugin script and the /etc/profile script (without the /etc/) in the
directory. <kitchen> denotes the path to the directory that contains dsixda's Android Kitchen.

Adding VIM

I combed vim out of the CM7 /system/xbin directory and made a tarball of it here, and if you put that tarball and this script in the
directory as described in the section about adding bash above you can use the kitchen to add it to your system. Since vim uses libncurses, it is very desirable to set the TERM variable in your environment as I do in my .bashrc file in my $HOME directory. You'll notice that I also set up bash to use vi style command line editing.

Verbatim 97537 Bluetooth Mobile Folding Keyboard

The pantout keyboard of the G2 really won't do for working in bash or vim, nor will the softkeyboard, so it's necessary to get a very portable but more functional keyboard working with the G2.

I chose and purchased the Verbatim Bluetooth Mobile Folding Keyboard only to find that it will not hook up to the G2 except with the BlueInput app and even then the Ctrl key is ignored. Not good. For some reason I developed a vague dislike for the developers of BlueInput and their app and decided not to use it. Maybe it's because they didn't go the extra mile for us bash and vim users.

Here's my solution

The android description of how keyboard keys are mapped to characters and functions is not good and it changes from Gingerbread to Ice Cream Sandwich so the current documents don't apply to the G2 and it's difficult if not impossible to ascertain which of the documents you might run across apply to Gingerbread. So my solution is a kludge.

I went here to find out about tools and techniques useful to explore how the Verbatim interacts with my G2. I got hciconfig and hcitool out of the CM7 /system directory. I could not find hidd there so I got it from here. I put these files in /system/xbin.

I didn't use the kitchen to do it because by this time I'd gotten my ASUS Transformer Prime and rooted it, and in the proces of doing that I discovered sysrw, sysrw2, sysro and sysro2 by VIPERBOY so I modified them to work on the G2, put them in /system/bin and did the work right on the G2 instead of using the kitchen. Don't forget to do sysro when you're done mucking around in /system. (I'll probably make a kitchen plugin for this Verbatim keyboard next time I update my phone.)

You can follow the pairing instructions that come with the keyboard to pair it with your G2, but it will not connect. I found by experimenting with
hidd --connect
hidd --unplug
that it is necessary to press the paring button on the keyboard after issuing the
hidd --connect
command to get the keyboard to connect with hidd on the G2.

The scanty android keyboard input documentation alerted me to the existence of
on my G2. The *.kcm.bin file is binary, as the extension implies, but the source can be found in the android Gingerbread source tree, and here it is. Looking at querty.kl and qwerty.kcm it became clear why the Ctrl on the Verbatim keyboard was ignored. It doesn't appear in qwerty.kcm but there is a fn key mentioned which turns alpha keys into numbers and symbols. Hmmmmmmm. More exploration of the function of the Verbatim keyboard connected to the G2 revealed that the Alt and AltGr keys map the the fn column in qwerty.kcm. I don't need no extra numbers and symbols! This was the information I needed to create VerbatimKeyboard.kcm and VerbatimKeyboard.kl. These files convert Alt and AltGr to work like Ctrl and even embed a numeric keypad on the far right side of the keyboard using Shift-Alt.

The afore-mentioned not-so-good documentation mentions a program makekcharmap to create the *.kcm.bin file from the *.kcm file but I didn't find it after building the complete Gingerbread source tree. I finally stumbled upon this to learn that it's really called kcm (this version built on MAC OS X 10.5.8) and so now I have VerbatimKeyboard.kcm.bin

I read about ways to get android to associate a particular *.kl and *.kcm.bin set of files with a particular device, but after trying some that didn't work and trying to learn more about others I just gave up and wrote scripts to replace qwerty.* with VerbatimKeyboard.* each time I connect (btkb and btkb_) the Verbtim keyboard and replace VerbatimKeyboard.* with qwerty.* each time I disconnect (stkb and stkb_) the Verbatim keyboard. (The *kb* files go in /system/xbin.) If you look at the scripts you'll discover that I've replaced the address of my keyboard with ##:##:##:##:##:##. You replace that with the address of your keyboard which you will discover using
hcitool scan
But you'll probably have to press the pairing button on the keyboard while the scan is in process. You'll also discover that I keep the *.kl and *.kcm.bin files in a directory in my $HOME directory set up in

Next project: Put chroot Ubuntu on it.

Home - Sun hat
Conditions of Use