Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,806,623 Members 50,720 Now Online
XDA Developers Android and Mobile Development Forum

[DEV] Custom MTD Partitions for the N1

Tip us?
 
intersectRaven
Old
(Last edited by intersectRaven; 30th September 2011 at 10:17 AM.)
#1  
Recognized Developer - OP
Thanks Meter 1,013
Posts: 1,965
Join Date: Mar 2010

 
DONATE TO ME
Default [DEV] Custom MTD Partitions for the N1

With the advent of Blackrose custom HBOOT which gives us S-OFF, we can now resize the MTD partitions of our N1. This method is the one used by lbcoder in the Desire thread where you patch the recovery and boot in order to pass modified MTD partition information which supersedes the one provided by the SPL. Using this, I've managed to increase my userdata partition by ~50 MB by taking ~50 MB from the cache partition.

These instructions are for advanced users only. This will involve hex calculations and command line instructions that are not for the faint of heart. I don't believe it's dangerous though so anyone could still try since I will try to make these instructions as detailed as I possibly can.

What you need:
N1 with Blackrose HBOOT (I'm not sure this is needed though after I read more in-depth about the patch)
hex calculator (or a pencil & paper if you want to do it manually)
adb
fastboot
unpack-bootimg.pl
mkbootimg
recovery.img <- in my case I used ClockWorkMod 5.0.2 from here
boot.img <- taken from CM zip (in my case my KANG)

Partition Layout:
0x000003ee0000-0x000003fc0000 : "misc"
0x000004240000-0x000004640000 : "recovery"
0x000004640000-0x0000049c0000 : "boot"
0x0000049c0000-0x00000dac0000 : "system"
0x00000dac0000-0x0000139c0000 : "cache"
0x0000139c0000-0x00001fe00000 : "userdata"

Partition Sizes in Hex:
0x0000000e0000 : "misc"
0x000000400000 : "recovery"
0x000000380000 : "boot"
0x000009100000 : "system"
0x000005f00000 : "cache"
0x00000c440000 : "userdata"

Step-by-step Instructions:
A>Backup your current system: (OPTIONAL)
*I'm assuming you're using CWM 5.0.2 for the backup step since I tried using 3.X and the restore didn't work
1.) Boot your N1 into recovery using either adb reboot recovery or through the bootloader
2.) Backup your current system (I'm going to assume you know how to use your recovery for this)

B>Calculate new MTD parameter values:
*For this example I'm going to transfer ~50MB of cache space to my userdata partition:
1.) Since I know the cache partition is ~100MB in size, I'll just divide the hex size in 2:
0x5f00000 / 2 = 0x2f80000 <= this will be our new cache size
**Note that there is a minimum of 0x20000 (128k) for a partition and the size must be divisible by it which is why I'm playing safe and just dividing the original number in order to get an easier value for this example.
2.) Add the new cache partition size to the original cache partition starting address to get the new starting address of the userdata partition:
0xdac0000 + 0x2f80000 = 0x10a40000 <= this will be the new starting address for userdata
3.) Get the new userdata size by subtracting the new starting address of userdata with the ending address:
0x1fe00000 - 0x10a40000 = 0xf3c0000 <= this will be the new userdata size

C>Create a new recovery.img file which uses the new values:
1.) Breakdown the recovery.img file into it's kernel and ramdisk components using unpack-bootimg.pl:
.\unpack-bootimg.pl recovery.img
*This will yield 2 files and 1 directory. You can delete the directory since we only need the files.
2.) Rename the kernel from the recovery.img-kernel.gz made from unpack-bootimg.pl to recovery.img-kernel.
3.) Create the recovery-new.img file using mkbootimg with the new MTD command embedded:
mkbootimg --cmdline 'no_console_suspend=1 console=null mtdparts=msm_nand:0x0e0000@0x03EE0000(misc),0x0400 000@0x04240000(recovery),0x0380000@0x04640000(boot ),0x09100000@0x49C0000(system),0x02f80000@0xDAC000 0(cache),0x0f3c0000@0x010a40000(userdata)' --kernel recovery.img-kernel --ramdisk recovery.img-ramdisk.cpio.gz -o recovery-new.img --base 0x20000000
*Note that the values for cache starting address, userdata starting address and userdata size have been changed to the newly calculated values in the previous step.
**This will yield recovery-new.img which will be used in the next steps.

D>Create a new boot.img file which uses the new values:
1.) Breakdown the boot.img file into it's kernel and ramdisk components using unpack-bootimg.pl:
.\unpack-bootimg.pl boot.img
*This will yield 2 files and 1 directory. You can delete the directory since we only need the files.
2.) Rename the kernel from the boot.img-kernel.gz made from unpack-bootimg.pl to boot.img-kernel.
3.) Create the boot-new.img file using mkbootimg with the new MTD command embedded:
mkbootimg --cmdline 'no_console_suspend=1 wire.search_count=5 mtdparts=msm_nand:0x0e0000@0x03EE0000(misc),0x0400 000@0x04240000(recovery),0x0380000@0x04640000(boot ),0x09100000@0x49C0000(system),0x02f80000@0xDAC000 0(cache),0x0f3c0000@0x010a40000(userdata)' --kernel boot.img-kernel --ramdisk boot.img-ramdisk.cpio.gz -o boot-new.img --base 0x20000000
*Note that the values for cache starting address, userdata starting address and userdata size have been changed to the newly calculated values in the previous step.
**This will yield boot-new.img which will be used in the next steps.

E>Flash the recovery-new.img:
1.) Boot into bootloader and use fastboot command to flash the new recovery:
fastboot flash recovery recovery-new.img

F>Make system operational:
1.) Boot into recovery mode.
2.) Erase everything (factory reset)
3.) Either:
- Flash the ROM you took the original boot.img from OR
- Restore the backup you made previously (this only works (or has been tested) on CWM 5.0.2)
4.) DO NOT REBOOT YET!!!

G>Flash modified boot.img:
1.) Use adb to reboot to bootloader directly from recovery: (this is for safety since if you boot from an unmodified boot.img you'll have to start from F again.
adb reboot bootloader
2.) Use fastboot to flash the new boot image:
fastboot flash boot boot-new.img
3.) You may restart normally.

For those who've read this far, everything above has been rendered obsolete! Here's an editor for the SPL itself for the partition sizes:
http://intersectraven.euroskank.com/...LHexEditor.exe
*Instructions are in dla5244's thread 2nd post.

Try it at your own risk though!

Credits:
dla5244 - for bringing S-OFF to our N1 even after a looong time since its release
Firerat - for the original patch idea
Lbcoder - for coming up with the idea in the Desire thread
Xperia Z1 Compact - Stock ROM w/ own kernel
Nexus 7 (2013) - Stock ROM w/ own kernel

Buy me a beer (or something...)
BitCoin donations accepted:
15MZpCG4J21myvk8mxfHgjCrJ97SgaZmwC
The Following 13 Users Say Thank You to intersectRaven For This Useful Post: [ Click to Expand ]
 
intersectRaven
Old
#2  
Recognized Developer - OP
Thanks Meter 1,013
Posts: 1,965
Join Date: Mar 2010

 
DONATE TO ME
Reserved!

(I'm learning to reserve now... )
Xperia Z1 Compact - Stock ROM w/ own kernel
Nexus 7 (2013) - Stock ROM w/ own kernel

Buy me a beer (or something...)
BitCoin donations accepted:
15MZpCG4J21myvk8mxfHgjCrJ97SgaZmwC
The Following User Says Thank You to intersectRaven For This Useful Post: [ Click to Expand ]
 
drzplaya1121
Old
#3  
Senior Member
Thanks Meter 20
Posts: 286
Join Date: Aug 2009
Location: Bronx, NY
2 Questions:

Is the userdata space where downloaded apps go?

why didn't you choose any other partition to transfer empty space from?
The Following User Says Thank You to drzplaya1121 For This Useful Post: [ Click to Expand ]
 
intersectRaven
Old
#4  
Recognized Developer - OP
Thanks Meter 1,013
Posts: 1,965
Join Date: Mar 2010

 
DONATE TO ME
Quote:
Originally Posted by drzplaya1121 View Post
2 Questions:

Is the userdata space where downloaded apps go?

why didn't you choose any other partition to transfer empty space from?
1.) Yes.
2.) This is a sample. If you want to transfer from system or to system from cache, this example will show you how to do so.
Xperia Z1 Compact - Stock ROM w/ own kernel
Nexus 7 (2013) - Stock ROM w/ own kernel

Buy me a beer (or something...)
BitCoin donations accepted:
15MZpCG4J21myvk8mxfHgjCrJ97SgaZmwC
The Following User Says Thank You to intersectRaven For This Useful Post: [ Click to Expand ]
 
drzplaya1121
Old
#5  
Senior Member
Thanks Meter 20
Posts: 286
Join Date: Aug 2009
Location: Bronx, NY
thank U. Now I have no need to buy a new phone because of constantly running out of memory
 
rjmohit
Old
(Last edited by rjmohit; 26th September 2011 at 09:27 AM.)
#6  
rjmohit's Avatar
Senior Member
Thanks Meter 49
Posts: 249
Join Date: Sep 2010

 
DONATE TO ME
Does it mean that every time I flash a new kernel, the whole effort will go waste?

Also, can I use the same procedure for Amon RA recovery??
 
intersectRaven
Old
#7  
Recognized Developer - OP
Thanks Meter 1,013
Posts: 1,965
Join Date: Mar 2010

 
DONATE TO ME
Quote:
Originally Posted by rjmohit View Post
Does it mean that every time I flash a new rom (which obviously has a different boot.img), the whole effort will go waste?

Also, can I use the same procedure for Amon RA recovery??
For that you need to do only steps D, F and G. If you flash only a kernel which uses koush's anykernel updater, you don't need to do anything.
Xperia Z1 Compact - Stock ROM w/ own kernel
Nexus 7 (2013) - Stock ROM w/ own kernel

Buy me a beer (or something...)
BitCoin donations accepted:
15MZpCG4J21myvk8mxfHgjCrJ97SgaZmwC
 
rjmohit
Old
#8  
rjmohit's Avatar
Senior Member
Thanks Meter 49
Posts: 249
Join Date: Sep 2010

 
DONATE TO ME
Quote:
Originally Posted by intersectRaven View Post
For that you need to do only steps D, F and G. If you flash only a kernel which uses koush's anykernel updater, you don't need to do anything.
Thanks.
One more silly question
Will the following procedure work.
1. Flash any ROM.
2. Then flash the modified boot.img (which may not belong to that ROM).
3. Then optionally flash the desired kernel.
 
intersectRaven
Old
#9  
Recognized Developer - OP
Thanks Meter 1,013
Posts: 1,965
Join Date: Mar 2010

 
DONATE TO ME
Quote:
Originally Posted by rjmohit View Post
Thanks.
One more silly question
Will the following procedure work.
1. Flash any ROM.
2. Then flash the modified boot.img (which may not belong to that ROM).
3. Then optionally flash the desired kernel.
Yeah. That would work since you're replacing the kernel anyways. What's important is that the kernel is compatible with the ROM.
Xperia Z1 Compact - Stock ROM w/ own kernel
Nexus 7 (2013) - Stock ROM w/ own kernel

Buy me a beer (or something...)
BitCoin donations accepted:
15MZpCG4J21myvk8mxfHgjCrJ97SgaZmwC
The Following User Says Thank You to intersectRaven For This Useful Post: [ Click to Expand ]
 
houzuoguo
Old
#10  
houzuoguo's Avatar
Senior Member
Thanks Meter 88
Posts: 578
Join Date: Jun 2010
Location: Hamburg
Well done IR :P cannot wait to resize my data partition..
Google Nexus One
Cyanogen Mod 7 Nightly + IntersectRaven's Customizable AVS kernel
Sandisk 32GB Class 4 MicroSDHC

Follow me on Twitter http://twitter.com/hzguo

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes