[DEV] Custom MTD Partitions for the N1

Search This thread

intersectRaven

Senior Member
Mar 13, 2010
2,260
1,558
www.intersectraven.net
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),0x0400000@0x04240000(recovery),0x0380000@0x04640000(boot),0x09100000@0x49C0000(system),0x02f80000@0xDAC0000(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),0x0400000@0x04240000(recovery),0x0380000@0x04640000(boot),0x09100000@0x49C0000(system),0x02f80000@0xDAC0000(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/tools/SPLHexEditor.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:

rjmohit

Senior Member
Sep 20, 2010
328
63
Google Pixel 3 XL
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:

rjmohit

Senior Member
Sep 20, 2010
328
63
Google Pixel 3 XL
Okay, I extracted the recovery.img file, now when I try to extract recovery.img-kernel.gz, it gives the following error: not in gzip format. Exactly same happens for boot.img. I tried extracting it with different extractors on windows and ubuntu, nothing worked. Pls help.
 

blahbl4hblah

Inactive Recognized Developer
Oct 3, 2010
6,061
1,514
Los Angeles, CA
I don't like using MTD because over time you will notice lag. If your already using sd-ext then your data is basically not being used. And I believe that cache never gets past 50% usage. Just putting in my two cents
 

intersectRaven

Senior Member
Mar 13, 2010
2,260
1,558
www.intersectraven.net
Okay, I extracted the recovery.img file, now when I try to extract recovery.img-kernel.gz, it gives the following error: not in gzip format. Exactly same happens for boot.img. I tried extracting it with different extractors on windows and ubuntu, nothing worked. Pls help.

That's odd. In my installation, it worked flawlessly. :confused: Were there no errors during the run of unpack?

I don't like using MTD because over time you will notice lag. If your already using sd-ext then your data is basically not being used. And I believe that cache never gets past 50% usage. Just putting in my two cents

:confused:
 

rjmohit

Senior Member
Sep 20, 2010
328
63
Google Pixel 3 XL
I may sound a bit noobish, but I'm facing one more hindrance:
How exactly do I run the mkbootimg file in the ubuntu terminal? I mean, can you give me the exact syntax?
I was facing a similar problem with the perl script, but then I found a solution on google, but didnt find anything for the mkbootimg. Can I run it under windows cmd?
 

intersectRaven

Senior Member
Mar 13, 2010
2,260
1,558
www.intersectraven.net
I may sound a bit noobish, but I'm facing one more hindrance:
How exactly do I run the mkbootimg file in the ubuntu terminal? I mean, can you give me the exact syntax?
I was facing a similar problem with the perl script, but then I found a solution on google, but didnt find anything for the mkbootimg. Can I run it under windows cmd?

I already posted the syntax in the instructions. You just need to make sure the mkbootimg file has execute permissions in order for it to run. :)
 
  • Like
Reactions: rjmohit

intersectRaven

Senior Member
Mar 13, 2010
2,260
1,558
www.intersectraven.net
I tried your program. Everything worked fine. Just that my /cache now shows 290 MB free, while I had resized it to 20 MB!! Is that a bug? /system & /data show proper sizes though. thanks. :)

Is it the display on the program or display on the Android device when booted? :confused:

Wait, I found it. It's a bug. Thanks! I'll edit it when I get home. For now, please double check the values by reopening the made file before flashing. If the values are incorrect, please DON'T FLASH!!! :)
 
Last edited:

Top Liked Posts

  • There are no posts matching your filters.
  • 12
    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),0x0400000@0x04240000(recovery),0x0380000@0x04640000(boot),0x09100000@0x49C0000(system),0x02f80000@0xDAC0000(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),0x0400000@0x04240000(recovery),0x0380000@0x04640000(boot),0x09100000@0x49C0000(system),0x02f80000@0xDAC0000(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/tools/SPLHexEditor.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
    1
    Reserved!

    (I'm learning to reserve now... :p)
    1
    2 Questions:

    Is the userdata space where downloaded apps go?

    why didn't you choose any other partition to transfer empty space from?
    1
    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. :)
    1
    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. :)