[Samsung Galaxy Mini] Doc_cheilvenerdi.org:
[DEV] Increase Internal Memory to Whatever You Want!

HOW I DID IT... The Source...

In this post, and few others, I'm going to explain "step by step", "tool by tool" and "code by code" exactly what I do to tweak a boot image for my Galaxy Mini!

Let's follow together an example: I'm going to tweak the boot image of the 2.3.3 XXKPF Stock ROM.

While downloading it from samfirmware, I set up a minimal working environment.

From here on I'll use a PC with a Linux Gentoo Amd64 No Multilib Chroot32 unstable OS, but everything works with any other distribution (ubuntu, debian, opensuse, etc...). Actually Linux is mandatory for me (on Windows you could try to set up a cygwin environment).

I'll do all the job in a system folder called boot_mod, typing all the commands from the console (...or terminal):

doc@gandalf ~/boot_mod $

Once downloaded the XXKPF firmware (which is multipackage) I unrar the CODE archive to this folder and extract from it the boot image:

doc@gandalf ~/boot_mod $ tar xf CODE_S5570XXKPF_CL189639_REV02_user_mid_true.tar.md5 boot.img
doc@gandalf ~/boot_mod $ ls -l
total 212864
-rw-r--r-- 1 doc doc 211589203 Jan 31 09:39 CODE_S5570XXKPF_CL189639_REV02_user_mid_true.tar.md5
-rw-r--r-- 1 doc doc 6377472 May 7 2011 [b]boot.img[/b]
doc@gandalf ~/boot_mod $

BACKUP

First af all I prepare the Odin Archive of the original boot image, just to share it later: CODE_S5570XXKPF_boot.tar.md5.

doc@gandalf ~/boot_mod $ tar -H ustar -c boot.img > CODE_S5570XXKPF_boot.tar
doc@gandalf ~/boot_mod $ md5sum CODE_S5570XXKPF_boot.tar >> CODE_S5570XXKPF_boot.tar
doc@gandalf ~/boot_mod $ mv CODE_S5570XXKPF_boot.tar CODE_S5570XXKPF_boot.tar.md5
doc@gandalf ~/boot_mod $ ls -l
...
-rw-r--r-- 1 doc doc 6379579 Jan 31 09:51 CODE_S5570XXKPF_boot.tar.md5
...
doc@gandalf ~/boot_mod $

I prepare it just to restore back from the modded image, without flashing the full firmware from scratch.

SPLIT

Now, using this perl script split_bootimg.pl (downloaded into this folder too... Thanks to William Enck for it) I split the boot image into its components, the kernel and the initial ramdisk.

doc@gandalf ~/boot_mod $ ./split_bootimg.pl boot.img
Page size: [b]4096[/b] (0x00001000)
Kernel size: 3221952 (0x003129c0)
Ramdisk size: 3146572 (0x0030034c)
Second size: 0 (0x00000000)
Board name:
Command line:
Writing boot.img-kernel ... complete.
Writing boot.img-ramdisk.gz ... complete.
doc@gandalf ~/boot_mod $ ls -l
...
-rw-r--r-- 1 doc doc 6377472 May 7 2011 boot.img
-rw-r--r-- 1 doc doc 3221952 Jan 31 09:56 boot.img-kernel
-rw-r--r-- 1 doc doc 3146572 Jan 31 09:56 boot.img-ramdisk.gz
-rw[b]x[/b]r-[b]x[/b]r-[b]x[/b] 1 doc doc 6121 Jan 31 09:44 split_bootimg.pl
...
doc@gandalf ~/boot_mod $

Notice: The perl script must be set executable with the chmod command...

I look at the output for Page size (bold 4096) because I'll need it later to complete the task.

I actually miss a number that I must read from the boot.img binary.

I'll read it with an hexadecimal editor:

doc@gandalf ~/boot_mod $ hexedit boot.img
...
00000000 41 4E 44 52 4F 49 44 21 C0 29 31 00 00 80 60 13 ANDROID!.)1...`.
00000010 4C 03 30 00 00 00 60 14 00 00 00 00 00 00 50 14 L.0...`.......P.
00000020 00 01 [color=blue][b]60[/b][/color] [color=red][b]13[/b][/color] 00 10 00 00 00 00 00 00 00 00 00 00 ..`.............
00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
...
doc@gandalf ~/boot_mod $

I show the first 64 bytes of the file while I need only the bolded and coloured ones...

I read them this way:

base address = 0x[color=red][b]13[/b][/color][color=blue][b]60[/b][/color]0000

Anyway I need to check for this only once for any Phone model (I feel that this number will be the same for all these samsung phone models too...).

Before Starting the Real Task I must be sure that I'm able to put back toghether the splitted parts of the boot image...

To do it I need to compile a relevant tool from the AOSP Source Code: mkbootimg. Here is my one for 32bit Linux distributions: mkbootimg.

I download it into the working folder too and set it executable with chmod command...

doc@gandalf ~/boot_mod $ ./mkbootimg --kernel boot.img-kernel --ramdisk boot.img-ramdisk.gz --base 0x13600000 --pagesize 4096 -o boot_COPY.img
doc@gandalf ~/boot_mod $

I used the numbers just discovered... eh eh...

Now I'll check the original image and the selfmade one looking for differences... If they differ DON'T GO AHEAD!!! The modded boot image will never work!

doc@gandalf ~/boot_mod $ diff boot.img boot_COPY.img
doc@gandalf ~/boot_mod $

If I don't read something like Binary files ... differ everything works... I CAN CREATE boot images on my own!

RAMDISK - FIRST ROUND

Now I create a subfolder where I'll store the initial ramdisk contents:

doc@gandalf ~/boot_mod $ mkdir ramdisk
doc@gandalf ~/boot_mod $ [b]cd[/b] ramdisk
doc@gandalf ~/boot_mod/ramdisk $ gunzip -c ../boot.img-ramdisk.gz | cpio -i
14299 blocks
doc@gandalf ~/boot_mod/ramdisk $

Notice: Mostly I'll work within tha ramdisk subfolder... the following commands must run from there to work!

And here it is! The ramdisk Folder opened:

doc@gandalf ~/boot_mod/ramdisk $ ls -l
total 744
-rw-r--r-- 1 doc doc 13444 Jan 31 10:17 TASS.rle
drwxrwx--x 2 doc doc 4096 Jan 31 10:17 data
-rw-r--r-- 1 doc doc 118 Jan 31 10:17 default.prop
drwxr-xr-x 2 doc doc 4096 Jan 31 10:17 dev
-rw-r--r-- 1 doc doc 222472 Jan 31 10:17 fsua
-rwxr-x--- 1 doc doc 94380 Jan 31 10:17 init
-rwxr-x--- 1 doc doc 1677 Jan 31 10:17 init.goldfish.rc
-rwxr-x--- 1 doc doc 3048 Jan 31 10:17 init.qcom.post_boot.sh
-rwxr-x--- 1 doc doc 7976 Jan 31 10:17 init.qcom.rc
-rwxr-x--- 1 doc doc 6563 Jan 31 10:17 init.qcom.sh
-rwxr-x--- 1 doc doc 24201 Jan 31 10:17 init.rc
drwxr-xr-x 3 doc doc 4096 Jan 31 10:17 lib
drwxr-xr-x 2 doc doc 4096 Jan 31 10:17 proc
-rw-r--r-- 1 doc doc 331588 Jan 31 10:17 recovery
drwxr-x--- 2 doc doc 4096 Jan 31 10:17 sbin
drwxr-xr-x 2 doc doc 4096 Jan 31 10:17 sys
drwxr-xr-x 2 doc doc 4096 Jan 31 10:17 system
-rw-r--r-- 1 doc doc 0 Jan 31 10:17 ueventd.goldfish.rc
-rw-r--r-- 1 doc doc 5759 Jan 31 10:17 ueventd.rc
doc@gandalf ~/boot_mod/ramdisk $

KERNEL MODULES

Stop working on ramdisk for a while...

Now I must deal with the hardest task of the tweak...

I need to compile two kernel modules for my new modded image...

It seems a simple period, but I need to compile inside Linux for an outside Arm architecture...

I'll explain on a next post how I did it!

...continued in post n. 53...

Surely it could be possible... I actually did it for Galaxy ACE too, but I don't have the possibility to test the modded images... finally, the kernel for Galaxy Fit, Ace and Mini is pretty the same, so I bet on it!