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 :)



Thursday, September 15, 2016

How to rebuild package in Buildrot

Hi Folks! Welcome to my Blog. 

Most of the developers have this question, "How to rebuild a given package without rebuilding everything from scratch" as it is time consuming.
 
Buildroot doesn’t keep track of which package installs what files in the output/staging and output/target directories. However, implementing clean package removal is on the TODO-list of Buildroot developers.

Here are the steps do the rebuild of a package.

let us change directory to buildroot source root directory

$cd buildroot

Here we take an example of modifying raw.c file available in the util-linux package, and compile the package alone to get our new changes into the binary raw.
 
Step1: Modify the Source

In the buildroot/output/build directory you find the source of the package util-linux-<version no> lets say util-linux-2.26.2 is the package we are interested to re-compile

$gedit ./output/build/util-linux-2.26.2/disk-utils/raw.c

Save and exit after the modifications
 
Step2: Build the package
 
make <package>-rebuild, followed by make or make <package>

$ make util-linux-rebuild
$ make

This completes the build if no compilation errors. The freshly built executable is 
 
Step3: Use the new binary
 
Binary compiled with the new changes is available at path buildroot/output/build/util-linux-2.26.2/raw which you can copy to sbin folder of your root file-system. 
 
For more details refer to Buildroot Documentation

please leave your comments, it will be encouraging :)