New: XDA launches forum for app developers. Discuss coding, tools, marketing, and more.
XDA Developers Android and Mobile Development Forum
Forgot your password?
 
Post Reply+
Tip us?
 
srl3gx
Old
#1  
Senior Member - OP
Thanks Meter 206
Posts: 140
Join Date: Aug 2012
Location: Trivandrum
Default [ARM][x86_64]ElfTool - Pack and unpack boot image for sony mobile devices

ElfTool

This tool will help you to pack and unpack boot image for sony mobile devices.

Usage :
For unpacking
Code:
elftool unpack -i input-path -o output-path
For packing
If you have header file containing address of kernel, ramdisk etc..
Code:
elftool pack -o output-path header=path/to/header kernel-path ramdisk-path,ramdisk ipl-path,ipl rpm-path,rpm cmdline-path@cmdline
Else
Code:
elftool pack -o output-path kernel-path@address ramdisk-path@address,ramdisk ipl-path@address,ipl rpm-path@address,rpm cmdline-path@cmdline
The tool was created for injecting twrp recovery ramdisk to fxp cm10 boot images to prevent overwriting of cwm ramdisk over twrp ramdisk. I hope this tool will be useful for other developers also.

Here is how I used it for injecting twrp to fxp cm10 boot images.

During start of twrp run backup.sh. This will extract twrp ramdisk from the boot partition and store it in /cache/backup
Code:
mount /cache
cd /cache
mkdir backup
cd backup
dump_image /dev/block/mmcblk0p3 /cache/backup/oldboot.img
mkdir oldboot
elftool unpack -i /cache/backup/oldboot.img -o /cache/backup/oldboot
cd oldboot
mkdir uramdisk
cd uramdisk
gzip -dc ../ramdisk | cpio -i
mv sbin/ramdisk-recovery.cpio /cache/backup/ramdisk-recovery.cpio
cd /cache/backup
rm -irf oldboot
rm oldboot.img
When a new zip file is installed inject.sh is run. This will extract the newly installed boot image and inject the twrp ramdisk into it and then flash the newly created bootimage.
Code:
#!/sbin/sh
mount /cache
dump_image /dev/block/mmcblk0p3 /cache/newboot.img
mkdir /cache/newboot
elftool unpack -i /cache/newboot.img -o /cache/newboot
rm cache/newboot.img
cd /cache/newboot
mkdir uramdisk
cd uramdisk
gzip -dc ../ramdisk | cpio -i
rm ../ramdisk
if [ -e "/cache/backup/ramdisk-recovery.cpio" ];then
	cp /cache/backup/ramdisk-recovery.cpio sbin/ramdisk-recovery.cpio
	cd ..
	mkbootfs uramdisk > ramdisk.cpio
	cat ramdisk.cpio | gzip > ramdisk
	rm -irf uramdisk
	rm ramdisk.cpio
	elftool pack -o /cache/injectboot.img kernel@0x00208000 ramdisk@0x01400000,ramdisk cmdline@cmdline
	cd /cache
	rm -irf newboot
	if [ -e "/cache/injectboot.img" ];then
		erase_image /dev/block/mmcblk0p3
		flash_image /dev/block/mmcblk0p3 /cache/injectboot.img
		rm /cache/injectboot.img
	fi
fi
Both arm and x86_64 versions are available.

Thanks to sony for providing boot image format in packelf.py

Source code can be found here
Attached Files
File Type: zip elftool_arm.zip - [Click for QR Code] (493.0 KB, 88 views)
File Type: zip elftool_x86_64.zip - [Click for QR Code] (552.4 KB, 142 views)
The Following 10 Users Say Thank You to srl3gx For This Useful Post: [ Click to Expand ]
 
zoldyck
Old
#2  
zoldyck's Avatar
Senior Member
Thanks Meter 1194
Posts: 736
Join Date: Nov 2012
Location: Lombok
yeah
thanks bro
My Works

Quote:
I do work for free & for my enjoyment, and I don't expect any money for this. So if you like my work, feel free to hit thanks
Tags
kernel, pack, sin, sony, unpack