Enable adb access in Cyanogenmod image without screen <2015-08-14 Fri>

In stock Cyanogenmod firmware adb access needs to be enabled by user interaction. To enable adb in a Cyanogenmod ROM before flashing it to the devices a couple of settings need to be altered.

Using the following steps adb access was successfully enabled on Cyanogenmod 11 on a Xperia Mini Pro using a LegacyXperia ROM.

The tool Abootimg is required and available on Ubuntu:

sudo apt-get install abootimg

It is assumed that the Cyanogenmod image is located in an otherwise empty directory and has the filename cm.zip.

First, extract the image, boot.img and the ramdisk:

pushd .
rm -r zip_content 
rm -r boot.img.d 
rm -r initrd.d 
rm -r ramdisk.d
mkdir zip_content &&
unzip cm.zip -d zip_content/ &&
mkdir boot.img.d &&
mkdir initrd.d &&
mkdir ramdisk.d &&
cp zip_content/boot.img boot.img_backup &&
cd boot.img.d &&
abootimg -x ../zip_content/boot.img &&
cd ../initrd.d &&
cat ../boot.img.d/initrd.img | gunzip | cpio -vid &&
cd ../ramdisk.d/ &&
cat ../initrd.d/sbin/ramdisk.cpio | cpio -vid &&

Next, edit ramdisk.d/default.prop to set the following:


Copy the public adb key of the user that is going to access the phone (~/.android/adb_keys.pub) to the ramdisk (ramdisk.d/adb_keys):

cp ~/.android/adb_keys.pub ramdisk.d/adb_keys

Finally, rewrap everything into a .zip image again:

pushd .
cd ramdisk.d
find . | cpio --create --format='newc' > ../initrd.d/sbin/ramdisk.cpio &&
cd ../initrd.d/ &&
find . | cpio --create --format='newc' | gzip > ../boot.img.d/myinitrd.img &&
cd ../boot.img.d/ &&
rm ../zip_content/boot.img &&
abootimg --create ../zip_content/boot.img -f bootimg.cfg -k zImage -r myinitrd.img &&
cd ../zip_content &&
zip -r ../cm_adb_enabled.zip *

The new image cm_adb_enabled.zip can be flashed using the standard procedure described in the Cyanogenmod wiki for your particular device.

On older Xperia phones zip_content/boot.img has to be flashed using fastboot (fastboot flash boot boot.img) before flashing cm.zip using Clockworkmod recovery.

To view the screen on the pc I recommend androidscreencast. If the touchscreen is still working it is advisable to enable adbd using the standard way by tapping multiple times on the "Build" entry in "Preferences", "About phone".

Viewing the screen in Clockworkmod recovery works by reading out the frame buffer and converting the raw data to an image. Something along the lines of this will work depending on the Clockworkmod recovery version used:

adb pull /dev/graphics/fb0 fb0.raw
ffmpeg -vframes 1 -f rawvideo -pix_fmt rgb565le -s 640x1000 -i fb0.raw fb0.png

Keep in mind that there are two complete screens in the frame buffer and only one is visible at a time. The resolution and format may vary between different versions of Clockworkmod recovery. Candidates for the pix_fmt option that work are rgb565le, rgb565be, bgr565le, bgr565be.

See also: