[Miscellaneous Android Development] cheeyee:
Tutorial on how to modify mtd_partition info in Novo8 Stock Kernel

There has been a growing interest in how the mods are made. Here I show you with how to modify the mtd_partition sizes in the Novo8 kernel. This information may help others to make similar mods to other devices based on the amlogic kernel.

The first thing you need to know, is how do I find the offset in the kernel to modify. First of all, you need to know how the mtd_partition is structed. To find that out, you need to look in the the kernel source in the file /include/linux/mtd/partition.h. There you will find the mtd_partition struct definition.

struct mtd_partition {

char *name; /* identifier string */

uint64_t size; /* partition size */

uint64_t offset; /* offset within the master MTD space */

uint32_t mask_flags; /* master MTD flags to mask out for this partition */

struct nand_ecclayout *ecclayout; /* out of band layout for this partition (NAND only)*/

};

We see the size and offset are 64bits long. Remember this point.

Following this, you can run dmesg and to dump out the kernel log. In there you can see the mtd_partition info for your device. It show the start offset and the end offset of each partition.

Based on this info you can calculate the size by (end_offset - start_offset).

Here is the example from Novo8 Stock ROM.

<6>[ 3.003000] NAND device: Manufacturer ID: 0x2c, Chip ID: 0x2c (Micron C revision NAND 8GiB MT29F64G-C)

<6>[ 3.013000] 1 NAND chips detected

<6>[ 3.016000] aml_m1_nand aml_m1_nand.0: time_mode=5, bus_cycle=4, adjust=1, start_cycle=5, end_cycle=6,system=5.3ns

<5>[ 3.026000] Creating 8 MTD partitions on "C revision NAND 8GiB MT29F64G-C":

<5>[ 3.033000] 0x000002000000-0x000003000000 : "logo"

<5>[ 3.040000] 0x000003000000-0x000004000000 : "aml_logo"

<5>[ 3.045000] 0x000004000000-0x000006000000 : "recovery"

<5>[ 3.050000] 0x000006000000-0x000008000000 : "boot"

<5>[ 3.055000] 0x000008000000-0x00001c000000 : "system"

<5>[ 3.082000] 0x00001c000000-0x000024000000 : "cache"

<5>[ 3.086000] 0x000024000000-0x000084000000 : "userdata"

<5>[ 3.153000] 0x000084000000-0x000200000000 : "NFTL_Part"

You can verify the size against the /proc/mtd info.

C:\>adb shell cat /proc/mtd

dev: size erasesize name

mtd0: 00800000 00200000 "nandboot"

mtd1: 01000000 00400000 "logo"

mtd2: 01000000 00400000 "aml_logo"

mtd3: 02000000 00400000 "recovery"

mtd4: 02000000 00400000 "boot"

mtd5: 14000000 00400000 "system"

mtd6: 08000000 00400000 "cache"

mtd7: 60000000 00400000 "userdata"

mtd8: 17c000000 00400000 "NFTL_Part"

How that we have the info. We can construct the hex string to search for in a hex editor.

Lets take for example, the "userdata" partition. The size is 60000000 and offset is 24000000. Since they have to be 64bits, then in hex code would be

size = 0000000060000000

offset = 0000000024000000

You would then guess that we should search for 00000000600000000000000024000000, but it is not in this case. The bytes are in reverse order (I forgot what you call it, big-endian or small-endian whatever it is).

You would actual be searching for 00000060000000000000002400000000. Luckily on the Novo8 kernel, there is only one occurrence found for this hex value.

So, here are the search hex values for the partitions. Because of mask_flags and ecclayout, you will find these values are close to each other separated by some bytes in between.

logo -- 00000001000000000000000200000000

aml_logo -- 00000001000000000000000300000000

recovery -- 00000002000000000000000400000000

boot -- 00000002000000000000000600000000

system -- 00000014000000000000000800000000

cache -- 00000008000000000000001c00000000

userdata -- 00000060000000000000002400000000

NFTL_Part-- 00000000000000000000000000000000 -- This is kind of interesting. What it means is the start_offset starts at the end_offset of the previous partition and the size spans untill the end of the nand.

Part2. How to modify the partition size

=======================================

Please note that when you change the size of one partition, you are not affecting only that single partition. Other partitions are affected because they will have to shift in order to make room for a size increase or claim the free area if you shrink.

Let's increase the size of system partition to 0x16000000 (352MB) as an example. In thise case, logo, aml_logo, boot partitions are unaffected because they are before system, but cache and userdata are affected because they have to move to make space for the increase in system. You will have to re-caculate the start offset of cache and userdata. So you will be modifing info of 3 partitions instead. We don't need to change NFTL_Part.

Here are the new partition info.

Partition || Start Offset || Size || End Offset || Replace Hex Value

system 08000000 16000000 1E000000 00000016000000000000000800000000 (the start offset does not change, but size changed)

cache 1E000000 08000000 26000000 00000008000000000000001E00000000 (the start offset changed, and size is the same)

userdata 26000000 60000000 86000000 00000060000000000000002600000000 (the start offset changed, and size is the same)

****************************** Caution *********************************

Please don't try not to change the logo, aml_logo, recovery, boot partition because it may cause a brick.

Also if you make userdata > 2GB, Market will not work. That was the case when I made the 3GB mod in Froyo, Market will display not eought space error message. Don't know if it will be the same in CM7.

****************************** Caution *********************************