Friday, November 25, 2016

Unpack, modify and repack ramdisk.img

Hi folks, once again welcome to my blog.

While working on android we need to modify the permission for a process or create certain folders during early initialization of file-system or post file-system, we may even need to set some android system properties and all these go into init.rc file which is packed into ramdisk image, kernel mounts ramdisk during the boot process. 

Even if me modify them from android shell as sudo user, these files will be overridden in the next reboot, to over come this we need to modify the init.rc file, pack it into ramdisk.img and replace this file into boot partition, this saves time from clean compilation of the android source and helps to verify modifications very easily.

ramdisk.img is converted into uRamdisk, an image for  U-Boot.

we need following tools:
  • mkbootfs (preset at the following path Android_src/out/host/linux-86/bin/)
  • mkimage (available from u-boot-tools)

Unpaking ramdisk.img:

$ cp ramdisk.img ramdisk.cpio.img
$ mkdir ramdisk
$ cd ramdisk
$ gzip -dc ../ramdisk.cpio.gz | cpio -i

** Now you modify the content of files in the ramdisk folder


Repacking ramdisk to ramdisk.img:

$ cd ..
$ mkbootfs ./ramdisk | gzip > ramdisk_new.gz
$ mv ramdisk_new.gz ramdisk_new.img


Creating uRamdisk U-Boot image:

$ mkimage -A arm -O linux -T ramdisk -d ./ramdisk_new.img uRamdisknew
$ mv uRamdisknew uRamdisk
$ file uRamdisk
uRamdisk: u-boot legacy uImage, , Linux/ARM, RAMDisk Image (gzip), 754577 bytes, 
Fri Nov 25 11:44:11 2016, Load Address: 0x00000000, Entry Point: 0x00000000, Header 
CRC: 0xB265DBB9, Data CRC: 0xC13DD420
$ 

now you are ready to copy this new uRamdisk image to boot partition of the SD card are any boot media. I have used this many time when I worked on android with BBB or Panda board.

Please leave your comments :)



1 comment: