Friday, 21 June 2013

Jellybean (Android 4.2.2) on HTC Desire

Yes, the latest Android OS can be run on HTC Desire. This says something about the upward compatibility of the HTC Desire.

The whole process consists of four parts.

  • Root the phone to gain root access
  • Preparing the SD card
  • Choose a custom ROM image and burn it into flash
  • Run the A2SD script


Rooting the phone

It is of moderate difficulty. There are a few software tools that we can choose to perform the task, and it is possible to combine different tools together to do it. You should get a microSD card reader too (for copying files from PC to SD card).

Before rooting the phone, we need to set S-OFF. S-OFF is security off. It is a HTC technique to check the validity of their firmware. Since we are modifying the firmware, we need to set the phone to S-OFF.

The preparation steps:

  • Enable USB debug on the phone
  • Download HTC Sync and install it, after that, uninstall HTC Sync. This leaves the drivers in the Windows that is essential for working with the phone in Windows
  • Download and install HBoot driver
  • Choose the recovery image, you can choose Revolutionary Recovery or 4Ext Recovery. For HTC Desire GSM model, the 4Ext Recovery image can be downloaded from (Desire GSM)
  • Download the adb tools from [FAQ] ADB and FASTBOOT for Windows
  • Download the recovery tool from Revolutionary page
  • Download the root file, and copy it to SD card. (You may need to remove the SD card from phone, and put it into card reader). The root file i use is Superuser-3.0.7-efgh-signed.zip


The S-Off steps:
1) unzip and run the recovery tool, you can choose not to install revolutionary recovery. After that, your phone is S-OFF.

You check that by booting into HBoot (Turn off the phone,  then hold volume down and power button together, until you see the HBoot screen), you should see a pink revolutionary label above your HBoot image.

The adding custom recovery image steps:
1) Boot into Fastboot
2) Connect PC to phone via USB, you see "Fastboot USB" on your phone.
3) Open command prompt box and issue
 "fastboot flash recovery c:\your recovery image filename"
After that, you have a S-OFF phone with custom recovery image.

The Rooting steps:
1) Boot into HBoot, choose recovery from the menu.
2) In recovery menu, choose flash zip from SD card.
3) Choose the root file that you copy to phone's SD card
4) Wait till it is finished, then choose reboot

Now the phone is rooted!

Preparing the SD card

In order to overcome HTC Desire's internal memory limitation (512MB internal flash memory), you will setup new Android to use SD card as its primary app and cache storage. This way you can install more apps than it is possible with the internal memory. The setup is done by A2SD script which you will use when installing new Android.

Firstly, you boot your rooted phone to 4Ext Recovery. Then you go to select "Partition the SD card". I have a 2GB SD card, so i setup a 1GB sd-ext partition and format it with ext4 file system. I skip the swap partition. After that you reboot your phone, go to 4Ext Recovery again, and choose wipe data and cache.

Secondly, take out the SD card, put it to card reader, and copy the custom ROM file to the SD card.

Finally, put the SD card back into the phone, and reboot your phone, go to 4Ext Recovery again.

Installing the Custom ROM 

This custom ROM zip file shall contain the JellyBean Android OS. In 4Ext Recovery, choose Install Zip from SD card and select the custom ROM file. Once the installation is finished, restart the phone. Let it boot up normally. If you choose CyanogenMod custom ROM, you will see the CyanogenMod spinning for around 10 minutes.

After that, when the boot up process is done, you are in the new JellyBean Android!

A2SD script

Open the Terminal Emulator app, and you will have to activate A2SD by running the following commands.

# su

grant root access to terminal emulator

# a2sd install

For CyanogenMod, a2sd will ask you three questions, answer with Y, N, Y.

After you run the A2SD script, the phone will be restarting. The A2SD will now copy existing apps and cache to your SD card, and freeing space from phone's internal memory. After phone reboot, you have a new JellyBean with the power of A2SD script.


Tuesday, 18 June 2013

Disable ehci_hcd in Linux

Background:

If your USB device cannot work with USB2.0, you need to disable ehci_hcd on Linux to make it work. If the ehci_hcd module is compiled into kernel, there is a way to disable it.

# cd /sys/bus/pci/drivers/ehci_hcd
# ls

You will see some files with 0000:00:xx.x format. Execute the command below to disable the files.
# sudo sh -c 'echo -n "0000:00:xx.x" > unbind'

The command should disable ehci_hcd. You have to do this every time Linux boots up. If you want to disable ehci_hcd automatically, put the below in your startup_script.

# cd /sys/bus/pci/drivers/ehci_hcd/
# sudo sh -c 'find ./ -name "0000:00:*" -print| sed "s/\.\///">unbind'

Saturday, 1 June 2013

Creating Dummy file system on Linux

USB mass storage gadget can read a block device or a normal file. This normal file or block device is called the backing storage for the gadget.

The steps to create a backing storage file for testing with USB mass storage gadget driver, are as below. USB gadget driver can read the MBR from the backing storage file.

root@victorBox:/home/victor# dd bs=1M count=1 if=/dev/zero of=/home/victor/backing_file
1+0 records in
1+0 records out
1048576 bytes (1.0 MB) copied, 0.00331003 s, 317 MB/s


root@victorBox:/home/victor# fdisk /home/victor/backing_file
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x8544f2df.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
You must set cylinders.
You can do this from the extra functions menu.
Command (m for help): x
Expert command (m for help): s
Number of sectors (1-63, default 63): 8
Expert command (m for help): h
Number of heads (1-256, default 255): 16
Expert command (m for help): c
Number of cylinders (1-1048576): 16
Expert command (m for help): r
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4, default 1):
Using default value 1
First sector (1-2047, default 1): 1
Last sector, +sectors or +size{K,M,G} (1-2047, default 2047):
Using default value 2047
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): b
Changed system type of partition 1 to b (W95 FAT32)
Command (m for help): p
Disk /home/victor/backing_file: 1 MB, 1048576 bytes
16 heads, 8 sectors/track, 16 cylinders, total 2048 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x8544f2df
                    Device Boot      Start     End        Blocks   Id  System
/home/victor/backing_file1            1        2047        1023+   b  W95 FAT32

Command (m for help): w
The partition table has been altered!

WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.

root@victorBox:/home/victor# fdisk -lu /home/victor/backing_file
Disk /home/victor/backing_file: 1 MB, 1048576 bytes
16 heads, 8 sectors/track, 16 cylinders, total 2048 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x8544f2df
                    Device Boot    Start     End        Blocks  Id  System
/home/victor/backing_file1          1        2047       1023+   b   W95 FAT32

root@victorBox:/home/victor# losetup -o 512 /dev/loop0 /home/victor/backing_file 
root@victorBox:/home/victor# mkdosfs /dev/loop0
mkdosfs 3.0.9 (31 Jan 2010)
Loop device does not match a floppy size, using default hd params
root@victorBox:/home/victor# mount -t vfat /dev/loop0 /mnt/
root@victorBox:/home/victor# cp examples.desktop /mnt/
root@victorBox:/home/victor# ls /mnt/
examples.desktop
root@victorBox:/home/victor# umount /dev/loop0
root@victorBox:/home/victor# losetup -d /dev/loop0