Post Reply

[DEV] Custom MTD Partitions for the N1

OP intersectRaven

26th September 2011, 03:24 AM   |  #1  
OP Recognized Developer
Thanks Meter: 1,013
 
1,965 posts
Join Date:Joined: Mar 2010
Donate to Me
More
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
Last edited by intersectRaven; 30th September 2011 at 10:17 AM.
The Following 13 Users Say Thank You to intersectRaven For This Useful Post: [ View ]
26th September 2011, 03:25 AM   |  #2  
OP Recognized Developer
Thanks Meter: 1,013
 
1,965 posts
Join Date:Joined: Mar 2010
Donate to Me
More
Reserved!

(I'm learning to reserve now... )
The Following User Says Thank You to intersectRaven For This Useful Post: [ View ]
26th September 2011, 04:40 AM   |  #3  
Senior Member
Flag Bronx, NY
Thanks Meter: 20
 
286 posts
Join Date:Joined: Aug 2009
More
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: [ View ]
26th September 2011, 04:44 AM   |  #4  
OP Recognized Developer
Thanks Meter: 1,013
 
1,965 posts
Join Date:Joined: Mar 2010
Donate to Me
More
Quote:
Originally Posted by drzplaya1121

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.
The Following User Says Thank You to intersectRaven For This Useful Post: [ View ]
26th September 2011, 04:51 AM   |  #5  
Senior Member
Flag Bronx, NY
Thanks Meter: 20
 
286 posts
Join Date:Joined: Aug 2009
More
thank U. Now I have no need to buy a new phone because of constantly running out of memory
26th September 2011, 09:01 AM   |  #6  
rjmohit's Avatar
Senior Member
Thanks Meter: 50
 
250 posts
Join Date:Joined: Sep 2010
Donate to Me
Question
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??
Last edited by rjmohit; 26th September 2011 at 09:27 AM.
26th September 2011, 09:07 AM   |  #7  
OP Recognized Developer
Thanks Meter: 1,013
 
1,965 posts
Join Date:Joined: Mar 2010
Donate to Me
More
Quote:
Originally Posted by rjmohit

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.
26th September 2011, 09:31 AM   |  #8  
rjmohit's Avatar
Senior Member
Thanks Meter: 50
 
250 posts
Join Date:Joined: Sep 2010
Donate to Me
Quote:
Originally Posted by intersectRaven

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.
26th September 2011, 10:22 AM   |  #9  
OP Recognized Developer
Thanks Meter: 1,013
 
1,965 posts
Join Date:Joined: Mar 2010
Donate to Me
More
Quote:
Originally Posted by rjmohit

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.
The Following User Says Thank You to intersectRaven For This Useful Post: [ View ]
26th September 2011, 11:20 PM   |  #10  
houzuoguo's Avatar
Senior Member
Flag Hamburg
Thanks Meter: 88
 
578 posts
Join Date:Joined: Jun 2010
Well done IR :P cannot wait to resize my data partition..

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes