Monday, August 30, 2010

Using Newly-Compiled AOSP OS WITH My Hacked Kernel

(The rooting part—steps 3 & 4— should not be necessary.)

1. Compile Android 2.2 v 1.1
2. Flash complete Android 2.2 v 1.1
3. Download UniversalAndroot-1.6.2-beta.apk from computer to phone
$ adb install /path/to/Universal-Androot-1.6.2-beta.apk
4. (On the phone.) Run Universal Androot for Android 2.2 from listed apps
5. Get phone into bootloader mode: (Back on computer)
$ adb reboot-bootloader
6. Split the Android 2.2 v1.1 "boot.img" file into "boot.img-kernel" and "boot.img-ramdisk.gz".
$ ./ boot.img
Page size: 2048 (0x00000800)
Kernel size: 2206592 (0x0021ab80)
Ramdisk size: 167182 (0x00028d0e)
Second size: 0 (0x00000000)
Board name:
Command line: no_console_suspend=1 msmsdcc_sdioirq=1 wire.search_count=5
Writing boot.img-kernel ... complete.
Writing boot.img-ramdisk.gz ... complete.
6. Rename "zImage" (newly-compiled kernel) as "boot.img-kernel"
$ mv path/to/zImage other/path/to/boot.img-kernel
7. Zip up "boot.img-kernel" (formerly zImage) with "boot.img-ramdisk.gz"
./mkbootimg --kernel boot.img-kernel --ramdisk boot.img-ramdisk.gz -o my-boot.img --cmdline 'no_console_suspend=1 msmsdcc_sdioirq=1 wire.search_count=5' --base 0x20000000
8. Flash phone with new "my-boot.img" file
$ sudo ./fastboot flash boot my-boot.img

Friday, August 27, 2010

Compiling the Android OS: Take 3 -- It Works!

Last night, I followed the directions here:

I got to   ~/mydroid/$ make   and then let it compile last night. This morning, there was an error which is posted on this site:

Basically, it was ", not found"

The following blog post has great instructions and a fix for this error, so I followed his directions from that point on. Thank you, Al Sutton!

I flashed and rebooted the phone and it worked!

1. From the top of the source tree go to out/target/product/passion/
2. Run “sudo fastboot flash system system.img
3. Then run “sudo fastboot flash boot boot.img
4. Then run “sudo fastboot flash recovery recovery.img
5. Then run “sudo fastboot flash userdata userdata.img
6. Then run “sudo fastboot reboot

The phone's display looks right again and it responds to the buttons again! :D I have a working compiled OS to work with now!

Compiling the Android OS: Take 2

Turns out, it's a bit more complicated than I previously thought. I ran "make clean" and then followed the instructions I've posted below. I've just run "make" again (without the -j3). I'm letting it compile for the night and tomorrow morning I will hopefully be able to finish the next steps and flash the phone successfully this time!

Thanks to lpasq at xda developers for posting the code I needed!

#clean out prior compiled files
make installclean
make clean

#update AOSP froyo source files
repo init -u git:// -b froyo
cd ~
repo sync

#setup compiling environment and build
cd ~
. build/

#USB connect N1 and initiate ADB
cd ~
adb devices

#ADB pull needed device files
cd ~
cd device
cd htc
cd passion

#build the Passion *.img's
cd ~
make -j3

#view compiled folder's new boot.img/system.img/userdata.img
cd ~
cd out
cd target
cd product
cd passion
echo 'see flashable files:'
ls *.img

cd ~
make -j3 otapackage

Thursday, August 26, 2010

A Note on the Enabled Serial Port for Nexus One

It worked! Then, I flashed it to the phone and it persisted on reboot!

However, our apps could not access the newly-enabled serial port without superuser permissions. We fixed that this way.
$ ./adb shell
$ su
# chmod 777 /dev/ttyMSM0
Then, after rebooting the phone, the permissions for /dev/ttyMSM0 went back to normal (or were re-written on boot up).

For a phone running Cyanogen 6, I ran:
$ adb shell
$ su
# mount -o remount,rw /dev/block/mtdblock3 /system
I then pushed a file named 99foo to the phone's /etc/init.d/ directory (/etc/ is a symlink to /system/etc). The complete contents of 99foo:
#makes USB-serial available to all users
chmod 777 /dev/ttyMSM0

I changed the permissions for 99foo so that they matched the permissions of the rest of the numbered files in this folder. I saw the existing permissions for 99foo as well as the rest of the numbered files by running this command:
# cd /etc/init.d
# ls -l
Then, I used chmod to add and take permissions as necessary. Then, I rebooted the phone. Now, the serial port is accessible to all users all the time!

For the phone running Android 2.2 with our hacked kernel, I will either edit the init.rc to allow access to /dev/ttyMSM0 for all users or, more likely, I will edit the init.rc file to run another file that I will write. Since I cannot edit init.rc while it's on the phone, I used this command (from my comPuter) to copy the init.rc to a location on my computer:
$ adb pull /init.rc /home/myname/init.rc
I will edit it. Then, I'll put it back with this command.
$ adb push /home/myname/init.rc /init.rc

I'm using this page for help.

I won't get to this very soon, as I have a more pressing matter to resolve. I'll blog more about it after I make some more progress.

Compiling the Android OS

I followed the directions on this site:

When I ran "make" from the "mydroid" folder, I kept getting this error:
error: gnu/stubs-64.h: No such file or directory

I'm using a 32-bit system, so I don't have a stubs-64.h. The installation guide says 64 bit systems are untested and they recommend a 32-bit system, so that seems like a strange error. Until, we did some looking around online and found out that the command they give on the installation guide points to something other than the stable froyo release (top of trunk, which I guess may be gingerbread or some updated version of froyo?).

Then, I ran this (almost the same, but I specify which version of Android OS to reference):
$ repo init -u git:// -b android-2.2_r1.1
$ make

It compiled completely this time and now it's time to flash it to a phone!

Tuesday, August 17, 2010

Enabling the Serial Port on a Nexus One

The Nexus One USB port works as a serial port when there's no power coming into the connector. But the stock kernel sets it up as a console. To use it as a general-purpose serial port, you have to use a kernel with CONFIG_USB_ANDROID_ACM enabled and CONFIG_MSM_SERIAL_DEBUGGER disabled.

If you want to skip installing the NDK, downloading and compiling the kernel, you can try this precompiled zImage.

We did this on a rooted Nexus One with an unlocked bootloader running Cyanogen CM6. It's probably not necessary to be running Cyanogen for this to work.

Download NDK from here:

Install NDK using instructions from the website.

Make sure arm-eabi-gcc is in your path. It's in android-ndk-r4b/build/prebuilt/linux-x86/arm-eabi-4.4.0/bin.
(export PATH=$PATH:/path/to/android-ndk-r4b/build/prebuilt/linux-x86/arm-eabi-4.4.0/bin to add it)

Make sure your machine has git: $ sudo apt-get install git-core
$ git clone git://
$ git branch -a
$ git checkout -b android-msm-2.6.32 origin/android-msm-2.6.32
$ cd msm
$ ARCH=arm CROSS_COMPILE=arm-eabi- make mahimahi_defconfig
$ ARCH=arm CROSS_COMPILE=arm-eabi- make menuconfig
Exit the menu and say "yes" when it asks if you want to save.

$ gedit .config
Turn on CONFIG_USB_ANDROID_ACM (uncomment it and change "is not set" for "=y").
Turn off CONFIG_MSM_SERIAL_DEBUGGER (comment it out)
$ ARCH=arm CROSS_COMPILE=arm-eabi- make

The kernel image should compile and is found in arch/arm/boot/zImage

Try kernel without permanently storing it on the phone. Download fastboot from here:

Reboot into fastboot mode. Power up the Nexus One while holding the trackball. Plug in the USB cable and the fastboot screen should say "fastboot usb".
$ sudo ./fastboot boot /path/to/msm/arch/arm/boot/zImage

If you get this message, then you probably forgot to run as root.
creating boot image...
creating boot image - 2232320 bytes
< waiting for device >

Once the phone boots up, use adb shell to ls /dev/tty* and if you see dev/ttyMSM0, it worked. (We haven't tried actually using the port yet).

When you reboot you'll be back into your old kernel. Haven't flashed this for real yet.

Check out the thread linked below for more info on actually using the serial port.

The following sites were helpful:

Hello World!

I have a technical blog.

The end.