My most recent holiday project was flashing cyanogenmod onto a rather elderly HTC Desire Bravo. Released in 2010 this device is positively ancient by Internet standards, but it was very well received at the time and I still liked it even as I retired it. Not enough space for apps was the problem. A tiny 512MB drive had to hold everything and with updates required to unremovable apps I had no space for anything else.
Perhaps a custom ROM that didn’t need Facebook and Twitter apps would free up some space and get it back in service.
You will need
- HTC Desire Bravo
- USB lead
- SD Card
- Some time
Unlocking the bootloader
HTC provide all of the tools required to unlock the bootloader. Go to htcdev.com and register. The registration page only works in Internet Explorer. The first of many little twists this process was going to contain. Look for “Unlock Bootloader” on the developer centre page.
I needed to update HBOOT. HTC give clear instructions as to if this is needed or not, and a ROM update utility (RUU). Unfortunately this is packaged as an exe so this step at least is windows only.
Connecting the phone to Windows 10 needs HTC Sync Manager. The drivers seem a bit suspect though. At first it would insist my fully charged phone had less than 30% battery, then when it did approve the upgrade, it would fail to find the phone once it had started in bootloader mode.
Fortunately the RUU extracts the ROM.ZIP it is going to install to the phone. Search for it and copy the ROM.ZIP to the root of the SD card and rename it to PB99IMG.zip. Then reboot the device into bootloader mode and it should magically find the new file and install it.
The next step is to get the OEM identifier for your device
fastboot oem get_identifier_token
This will produce a long string to paste back into the HTCDEV website to prompt them to send you an unlock file for your device. We can assume this process will firmly void your warranty forever.
fastboot flash unlocktoken Unlock_code.bin
And your phone will, with dire warnings, ask if you want to unlock the bootloader. Hell yes.
- Register at HTCDEV.com using Internet Explorer
- Find “Unlock Bootloader”
- Download and run the RUU program
- If the RUU doesn’t work, you can find the ROM.ZIP in your temporary files and copy it to PB99IMG.zip on the phone’s SD card manually, then reboot into bootloader to apply it.
- Download the fastboot program for your platform
- Get the OEM device ID ‘fastboot oem get_identifier_token‘ and paste it into HTCDEV.com
- Flash the phone with the unlock code you get for step 5 ‘fastboot flash unlocktoken Unlock_code.bin‘
- Accept the warning displayed on your phone to unlock the bootloader
Installing a recovery partition
With the bootloader unlocked, turn off the phone and then hold down the volume down and power buttons to boot into the bootloader. Use the volume control buttons to navigate the menus and the power button to confirm. At the moment the recovery option will give an error and you have to reboot the phone. We are going to fix that by installing a new tool to the recovery partition.
Find and select the fastboot option if the phone has not already chosen it. This will let us use the fastboot tool from HTCDEV to update the recovery partition. There are several recovery tools available. I downloaded clockworkmod recovery and flashed it onto my phone via the fastboot command.
./fastboot flash recovery recovery-clockwork-touch-126.96.36.199-bravo.img
This makes the recovery option in the bootloader work correctly.
- Download clockworkmod recovery
- Boot phone to fastboot in the bootloader menu
- Install the recovery image: ./fastboot flash recovery recovery-clockwork-touch-188.8.131.52-bravo.img
Installing the ROM
The final step is to download a ROM and discover a day later that the company based on it is going out of business and is taking down all of the install instructions. I got cm-184.108.40.206-bravo.zip at what may have been the last possible moment.
Copy that onto your SD card on the phone. Either via the regular ROM or by pushing it while in recovery mode.
./adb push ~/src/htc/cm-220.127.116.11-bravo.zip /sdcard/
Next restart the phone and hold the same volume-down and power button combination to start the bootloader. You should see the recovery option when bootloader is selected. Navigate to this option and press the power button to boot into ClockworkMod recovery.
Use the options in recovery to backup everything you want. A two year out-of-service phone had nothing I needed anymore so I used the factory reset option to delete the cache and data partitions and the format system option under the mount menu to clear that partition too.
Then select the install zip option in the menu. Search for the ROM zip on the SD card and install it. When it’s complete, reboot the phone and you should be done. The first time I did this, the new ROM entered a reboot cycle and did not start. I fixed that with the factory reset/format system option detailed above.
- Download your rom of choice. Save it to the phone’s SD card
- Use recovery to wipe everything from your phone’s internal storage
- Use recovery to install the ROM
Job’s done! aka ‘The bad news’
Yes, the unremovable facebook and twitter apps took up precious space, but they did it on the system partition. The relatively spartan cyanogenmod install just means there’s a lot of free space going to waste on the system partition. You are still stuck with the same tiny fraction of userdata storage you had before and if you install the google apps so you can shop in the play store you are going to run out of space while they are updating. This led my phone to force-close the google play services every few seconds.
One option I had would be to update the cyanogenmod install to bake more apps into the system partition. I don’t know how to do this and the documentation is gone forever. Maybe when LineageOS is up and running I’ll review this decision.
The alternative is to update the partition information on my phone to steal the free space from system and give it to userdata. While I also don’t know how to do that, I am a Linux nerd. I think I can figure this out.
While my phone was crashing with no space the partitions looked like this:
Filesystem Size Used Avail Use% Mounted on
/dev/block/mtdblock3 250.0M 133.0M 117.0M 53% /system
/dev/block/mtdblock5 147.6M 147.6M 147.6M 100% /data
/dev/block/mtdblock4 40.0M 1.1M 38.9M 3% /cache
/dev/block/mtdblock5 147.6M 147.6M 147.6M 100% /cache/download
System is read-only. Once the installation is complete nothing is taking that. I could steal 100M from it to donate to the userdata partition. I could take 30M from cache too. Between them both I’d nearly double the space I had to play with.
Repartitioning the internal storage
The official specs say the device has 512MB of internal storage. The three mtdblock devices above add up to 437MB. The dmesg log gives us a lot more detail.
[ 17.830780] Creating 6 MTD partitions on "msm_nand":
[ 17.835845] 0x00001ff60000-0x000020000000 : "misc"
[ 17.842010] 0x000004240000-0x0000046c0000 : "recovery"
[ 17.851196] 0x0000046c0000-0x0000049c0000 : "boot"
[ 17.855285] 0x0000049c0000-0x0000143c0000 : "system"
[ 18.113861] 0x0000143c0000-0x000016bc0000 : "cache"
[ 18.155639] 0x000016bc0000-0x00001ff60000 : "userdata"
msm_nand is the internal storage. The partitions in order are:
*here be dragons* (66.25MB)
That first segment is not described anywhere but the second segment is deliberately offset. Since I know the HTCDEV unlock method leaves some security features in place to preserve the radio firmware and some other items, I think it’s best to leave that alone.
This partition table is baked into the kernel, but the kernel was compiled with CONFIG_MTD_CMDLINE_PARTS=y set. This means we can provide the kernel with a replacement partition map on the boot command line.
I edited the recovery image in vi (seriously) and the kernel command was “no_console_suspend=1 msmsdcc_sdioirq=1 wire.search_count=5”. In overwrite mode I added the required parameters at the end of the existing command line which chews up some of the plentiful null padding.
no_console_suspend=1 msmsdcc_sdioirq=1 wire.search_count=5 mtdparts=msm_nand:4608K@0x4240000(recovery),3M(boot),150M(system),10M(cache),284288K(userdata),-(misc)
Note the offset for the recovery partition to leave the dragons alone, and all of the sizes are integers. 4608K is the same as 4.5M, but the kernel will choke on the decimal point and discard the whole parameter, defaulting to the baked in definitions.
I then unzipped the cyanogenmod zip and performed the same edit to the boot.img it contains.
Copy the updated cyanogenmod zip to the phone’s SD card and use the commands above to reflash the recovery partition with your updated information.
Reboot to recovery and perform a factory reset to format cache and data. If you backed up your data partition previously then I don’t know if you will be able to restore it after this, but I am pretty sure the new partition table will require a complete format of the edited partitions.
Reboot your phone and check the new partition table.
/dev/block/mtdblock2 150.0M 132.6M 17.4M 88% /system
/dev/block/mtdblock4 277.6M 196.5M 81.1M 71% /data
/dev/block/mtdblock3 10.0M 1.2M 8.8M 12% /cache
/dev/block/mtdblock4 277.6M 196.5M 81.1M 71% /cache/download
Nearly doubling the available userspace has breathed new life into an old phone. I’ve not encountered any immediate side-effects from the repartitioning though I will update if there is.
My HTC Desire is back in service. It remains a little dated, but I think this could have kept it in contention versus buying a new phone which would have saved me a reasonable stack of cash.
Every system update I do from now on will need me to edit the boot image. Failing to do that could lead me to trouble.
New system updates may expect there to be more system space than now exists. This may also lead to trouble.
So … Yeah!
The HTC Desire remains a nice piece of kit and Cyanogenmod looks pretty robust. I look forward to seeing what LineageOS manages once it finds its feet.