wiki:Android/HTC/Vision/EmmcPartitioning

eMMC Partitioning

The partitioning of the Vision devices varies between the T-Mobile G2 and the Desire Z. One implication of this is that is unsafe to use a HBoot image from one on the other since the hboot code contains a look-up table listing partition order, offsets, and sizes. This is used when flash updates are performed to determine where to write the new images. The results of using an incorrect HBoot variation will be the corruption of one or more partitions, likely making the device inoperable.

Operation Modes

During early start-up after power-on two boot partitions are available as well as a Replay Protected Memory Block (RPMB). These are structural partitions of the storage medium, not the result of the more well-known and understood DOS partition table. There can also be up to four General Purpose partitions. Once the device is switched into user mode the only structural partition accessible is the User Data Area and its close associate the Enhanced User Data Area. See Understanding eMMC User Capacity to understand the difference.

Logical Addressing

The eMMC contains an embedded controller that presents a block device interface that can be treated as if it is a fixed disk. Sectors are addressed as logical offsets from the beginning of the block device. Sectors contain 512 bytes.

Sector 0 is expected to contain the primary partition table just like any other block device. It may contain up to four entries. Each may be a Primary partition or Extended partition definition. If there is an extended partition definition it defines a range of sectors offset from the beginning of the parent partition. The first sector of the extended partition itself is another partition table which can contain up to four Logical partition or further Extended partition definitions. The Logical partition definition starting offset is from the beginning of the Extended partition, not the beginning of the block device.

Further Extended partitions may be defined to form a long chain of extended partitions and logical partitions.
eMMC partitioning

Vision Partitioning

The T-Mobile G2 has twenty-eight partitions defined. The Desire Z has twenty-nine. The system and userdata partitions are slightly smaller on the Desire Z to allow for an additional partition - pdata - on the Desire Z.

Partitioning Bug

There is a bug in the way that HBoot creates partition definitions that shows itself when using partition-management tools such as fdisk to view the layout. The bug is represented as the red line on the diagram. fdisk believes there are an endless number of partitions and truncates its output when it realises something is wrong:

# fdisk -ul /dev/block/mmcblk0
Warning: deleting partitions after 60

Disk /dev/block/mmcblk0: 2332 MB, 2332033024 bytes
1 heads, 16 sectors/track, 284672 cylinders, total 4554752 sectors
Units = sectors of 1 * 512 = 512 bytes

              Device Boot      Start         End      Blocks  Id System
/dev/block/mmcblk0p1   *           1        1000         500  4d Unknown
Partition 1 does not end on cylinder boundary
/dev/block/mmcblk0p2            1001        1128          64  45 Unknown
Partition 2 does not end on cylinder boundary
/dev/block/mmcblk0p3            1129       10128        4500  46 Unknown
Partition 3 does not end on cylinder boundary
/dev/block/mmcblk0p4           10129     4554750     2272311   5 Extended
Partition 4 does not end on cylinder boundary
/dev/block/mmcblk0p5           10130       70129       30000  49 Unknown
/dev/block/mmcblk0p6           70131       95130       12500  50 Unknown
/dev/block/mmcblk0p7           95132       99227        2048  51 Unknown
/dev/block/mmcblk0p8           99229      105372        3072  52 Unknown
/dev/block/mmcblk0p9          105374      109469        2048  53 Unknown
/dev/block/mmcblk0p10         109471      111518        1024  54 Unknown
/dev/block/mmcblk0p11         111520      113567        1024  56 Unknown
/dev/block/mmcblk0p12         113569      131071        8751+ 55 Unknown
/dev/block/mmcblk0p13         131073      137216        3072  4a Unknown
/dev/block/mmcblk0p14         137218      143361        3072  4b Unknown
/dev/block/mmcblk0p15         143363      145410        1024  74 Unknown
/dev/block/mmcblk0p16         145412      163326        8957+ 75 Unknown
/dev/block/mmcblk0p17         163328      163839         256  76 Unknown
/dev/block/mmcblk0p18         163841      165888        1024  47 Unknown
/dev/block/mmcblk0p19         165890      167937        1024  34 Unknown
/dev/block/mmcblk0p20         167939      170498        1280  36 Unknown
/dev/block/mmcblk0p21         170500      187901        8701  71 Unknown
/dev/block/mmcblk0p22         187903      196094        4096  48 Unknown
/dev/block/mmcblk0p23         196096      196607         256  73 Unknown
/dev/block/mmcblk0p24         196609      200702        2047  26 Unknown
/dev/block/mmcblk0p25         200704     1343486      571391+ 83 Linux
/dev/block/mmcblk0p26        1343488     3577854     1117183+ 83 Linux
/dev/block/mmcblk0p27        3577856     4192254      307199+ 83 Linux
/dev/block/mmcblk0p28        4192256     4234750       21247+ 19 Unknown
/dev/block/mmcblk0p29        4234752     4235263         256  23 Unknown
/dev/block/mmcblk0p30          10130       70129       30000  49 Unknown
/dev/block/mmcblk0p31          70131       95130       12500  50 Unknown
/dev/block/mmcblk0p32          95132       99227        2048  51 Unknown
/dev/block/mmcblk0p33          99229      105372        3072  52 Unknown
/dev/block/mmcblk0p34         105374      109469        2048  53 Unknown
/dev/block/mmcblk0p35         109471      111518        1024  54 Unknown
/dev/block/mmcblk0p36         111520      113567        1024  56 Unknown
/dev/block/mmcblk0p37         113569      131071        8751+ 55 Unknown
/dev/block/mmcblk0p38         131073      137216        3072  4a Unknown
/dev/block/mmcblk0p39         137218      143361        3072  4b Unknown
/dev/block/mmcblk0p40         143363      145410        1024  74 Unknown
/dev/block/mmcblk0p41         145412      163326        8957+ 75 Unknown
/dev/block/mmcblk0p42         163328      163839         256  76 Unknown
/dev/block/mmcblk0p43         163841      165888        1024  47 Unknown
/dev/block/mmcblk0p44         165890      167937        1024  34 Unknown
/dev/block/mmcblk0p45         167939      170498        1280  36 Unknown
/dev/block/mmcblk0p46         170500      187901        8701  71 Unknown
/dev/block/mmcblk0p47         187903      196094        4096  48 Unknown
/dev/block/mmcblk0p48         196096      196607         256  73 Unknown
/dev/block/mmcblk0p49         196609      200702        2047  26 Unknown
/dev/block/mmcblk0p50         200704     1343486      571391+ 83 Linux
/dev/block/mmcblk0p51        1343488     3577854     1117183+ 83 Linux
/dev/block/mmcblk0p52        3577856     4192254      307199+ 83 Linux
/dev/block/mmcblk0p53        4192256     4234750       21247+ 19 Unknown
/dev/block/mmcblk0p54        4234752     4235263         256  23 Unknown
/dev/block/mmcblk0p55          10130       70129       30000  49 Unknown
/dev/block/mmcblk0p56          70131       95130       12500  50 Unknown
/dev/block/mmcblk0p57          95132       99227        2048  51 Unknown
/dev/block/mmcblk0p58          99229      105372        3072  52 Unknown
/dev/block/mmcblk0p59         105374      109469        2048  53 Unknown
/dev/block/mmcblk0p60         109471      111518        1024  54 Unknown


The cause is the way HBoot creates a new partition. To keep things 'simple' it creates a new Extended partition containing only one Logical partition for each partition required plus an Extended partition to contain the remaining unallocated sectors. The Extended partition tables therefore always contain two definitions. This is fine when there is still unallocated sectors remaining on the block device.

However, when all sectors have been allocated, the last partition table still contains two definitions, one of which is an Extended partition definition to what should be remaining unallocated sectors. There aren't any however so the starting offset and size are both left as 0.

This causes partition management tools to get caught in a loop because when they read the last Extended partition definition it says the next block of sectors start at offset 0 - that is from the start of the first Extended partition defined. So the partition management tools go back to the start and read the same entries again not realising the loop.

You can see the issue in the final partition table in the Desire Z Partition Table Chain below.

The fix is for HBoot to specifically remove the entry from the last Extended partition table - in practice that means setting the type field to 0 (no entry) rather than leaving it with the default of 5 (extended partition).

Desire Z Partition Table Chain

Using my part-list tool (which scans files for partition tables) and dd I captured the chain of partition tables:

Base:	decimal
File:		         512	z-part-table.1.sector0.bin
Searching...
Signature found. sector:        0 offset:         0
0 A  77    0  0  0    0  0  0          1       1000 (next       1001)
1    69    0  0  0    0  0  0       1001        128 (next       1129)
2    70    0  0  0    0  0  0       1129       9000 (next      10129)
3     5    0  0  0    0  0  0      10129    4544622 (next    4554751)
Done.
Base:	decimal
File:		        4096	z-part-table.2.sector10128.bin
Searching...
Signature found. sector:        1 offset:       512
0    73    0  0  0    0  0  0          1      60000 (next      60001)
1     5    0  0  0    0  0  0      60001      25001 (next      85002)
2     0    0  0  0    0  0  0          0          0 (next          0)
3     0    0  0  0    0  0  0          0          0 (next          0)
Done.
Base:	decimal
File:		        4096	z-part-table.3.sector70128.bin
Searching...
Signature found. sector:        2 offset:      1024
0    80    0  0  0    0  0  0          1      25000 (next      25001)
1     5    0  0  0    0  0  0      85002       4097 (next      89099)
2     0    0  0  0    0  0  0          0          0 (next          0)
3     0    0  0  0    0  0  0          0          0 (next          0)
Done.
Base:	decimal
File:		        4096	z-part-table.4.sector95128.bin
Searching...
Signature found. sector:        3 offset:      1536
0    81    0  0  0    0  0  0          1       4096 (next       4097)
1     5    0  0  0    0  0  0      89099       6145 (next      95244)
2     0    0  0  0    0  0  0          0          0 (next          0)
3     0    0  0  0    0  0  0          0          0 (next          0)
Done.
Base:	decimal
File:		        4096	z-part-table.5.sector99224.bin
Searching...
Signature found. sector:        4 offset:      2048
0    82    0  0  0    0  0  0          1       6144 (next       6145)
1     5    0  0  0    0  0  0      95244       4097 (next      99341)
2     0    0  0  0    0  0  0          0          0 (next          0)
3     0    0  0  0    0  0  0          0          0 (next          0)
Done.
Base:	decimal
File:		        4096	z-part-table.6.sector105368.bin
Searching...
Signature found. sector:        5 offset:      2560
0    83    0  0  0    0  0  0          1       4096 (next       4097)
1     5    0  0  0    0  0  0      99341       2049 (next     101390)
2     0    0  0  0    0  0  0          0          0 (next          0)
3     0    0  0  0    0  0  0          0          0 (next          0)
Done.
Base:	decimal
File:		        4096	z-part-table.7.sector109464.bin
Searching...
Signature found. sector:        6 offset:      3072
0    84    0  0  0    0  0  0          1       2048 (next       2049)
1     5    0  0  0    0  0  0     101390       2049 (next     103439)
2     0    0  0  0    0  0  0          0          0 (next          0)
3     0    0  0  0    0  0  0          0          0 (next          0)
Done.
Base:	decimal
File:		        4096	z-part-table.8.sector111512.bin
Searching...
Signature found. sector:        7 offset:      3584
0    86    0  0  0    0  0  0          1       2048 (next       2049)
1     5    0  0  0    0  0  0     103439      17504 (next     120943)
2     0    0  0  0    0  0  0          0          0 (next          0)
3     0    0  0  0    0  0  0          0          0 (next          0)
Done.
Base:	decimal
File:		        4096	z-part-table.9.sector113568.bin
Searching...
Signature found. sector:        0 offset:         0
0    85    0  0  0    0  0  0          1      17503 (next      17504)
1     5    0  0  0    0  0  0     120943       6145 (next     127088)
2     0    0  0  0    0  0  0          0          0 (next          0)
3     0    0  0  0    0  0  0          0          0 (next          0)
Done.
Base:	decimal
File:		         512	z-part-table.10.sector131072.bin
Searching...
Signature found. sector:        0 offset:         0
0    74    0  0  0    0  0  0          1       6144 (next       6145)
1     5    0  0  0    0  0  0     127088       6145 (next     133233)
2     0    0  0  0    0  0  0          0          0 (next          0)
3     0    0  0  0    0  0  0          0          0 (next          0)
Done.
Base:	decimal
File:		         512	z-part-table.11.sector137217.bin
Searching...
Signature found. sector:        0 offset:         0
0    75    0  0  0    0  0  0          1       6144 (next       6145)
1     5    0  0  0    0  0  0     133233       2049 (next     135282)
2     0    0  0  0    0  0  0          0          0 (next          0)
3     0    0  0  0    0  0  0          0          0 (next          0)
Done.
Base:	decimal
File:		         512	z-part-table.12.sector143362.bin
Searching...
Signature found. sector:        0 offset:         0
0   116    0  0  0    0  0  0          1       2048 (next       2049)
1     5    0  0  0    0  0  0     135282      17916 (next     153198)
2     0    0  0  0    0  0  0          0          0 (next          0)
3     0    0  0  0    0  0  0          0          0 (next          0)
Done.
Base:	decimal
File:		         512	z-part-table.13.sector145411.bin
Searching...
Signature found. sector:        0 offset:         0
0   117    0  0  0    0  0  0          1      17915 (next      17916)
1     5    0  0  0    0  0  0     153198        513 (next     153711)
2     0    0  0  0    0  0  0          0          0 (next          0)
3     0    0  0  0    0  0  0          0          0 (next          0)
Done.
Base:	decimal
File:		         512	z-part-table.14.sector163327.bin
Searching...
Signature found. sector:        0 offset:         0
0   118    0  0  0    0  0  0          1        512 (next        513)
1     5    0  0  0    0  0  0     153711       2049 (next     155760)
2     0    0  0  0    0  0  0          0          0 (next          0)
3     0    0  0  0    0  0  0          0          0 (next          0)
Done.
Base:	decimal
File:		         512	z-part-table.15.sector163840.bin
Searching...
Signature found. sector:        0 offset:         0
0    71    0  0  0    0  0  0          1       2048 (next       2049)
1     5    0  0  0    0  0  0     155760       2049 (next     157809)
2     0    0  0  0    0  0  0          0          0 (next          0)
3     0    0  0  0    0  0  0          0          0 (next          0)
Done.
Base:	decimal
File:		         512	z-part-table.16.sector165889.bin
Searching...
Signature found. sector:        0 offset:         0
0    52    0  0  0    0  0  0          1       2048 (next       2049)
1     5    0  0  0    0  0  0     157809       2561 (next     160370)
2     0    0  0  0    0  0  0          0          0 (next          0)
3     0    0  0  0    0  0  0          0          0 (next          0)
Done.
Base:	decimal
File:		         512	z-part-table.17.sector167938.bin
Searching...
Signature found. sector:        0 offset:         0
0    54    0  0  0    0  0  0          1       2560 (next       2561)
1     5    0  0  0    0  0  0     160370      17403 (next     177773)
2     0    0  0  0    0  0  0          0          0 (next          0)
3     0    0  0  0    0  0  0          0          0 (next          0)
Done.
Base:	decimal
File:		         512	z-part-table.18.sector170499.bin
Searching...
Signature found. sector:        0 offset:         0
0   113    0  0  0    0  0  0          1      17402 (next      17403)
1     5    0  0  0    0  0  0     177773       8193 (next     185966)
2     0    0  0  0    0  0  0          0          0 (next          0)
3     0    0  0  0    0  0  0          0          0 (next          0)
Done.
Base:	decimal
File:		         512	z-part-table.19.sector187902.bin
Searching...
Signature found. sector:        0 offset:         0
0    72    0  0  0    0  0  0          1       8192 (next       8193)
1     5    0  0  0    0  0  0     185966        513 (next     186479)
2     0    0  0  0    0  0  0          0          0 (next          0)
3     0    0  0  0    0  0  0          0          0 (next          0)
Done.
Base:	decimal
File:		         512	z-part-table.20.sector196095.bin
Searching...
Signature found. sector:        0 offset:         0
0   115    0  0  0    0  0  0          1        512 (next        513)
1     5    0  0  0    0  0  0     186479       4095 (next     190574)
2     0    0  0  0    0  0  0          0          0 (next          0)
3     0    0  0  0    0  0  0          0          0 (next          0)
Done.
Base:	decimal
File:		         512	z-part-table.21.sector196608.bin
Searching...
Signature found. sector:        0 offset:         0
0    38    0  0  0    0  0  0          1       4094 (next       4095)
1     5    0  0  0    0  0  0     190574    1142784 (next    1333358)
2     0    0  0  0    0  0  0          0          0 (next          0)
3     0    0  0  0    0  0  0          0          0 (next          0)
Done.
Base:	decimal
File:		         512	z-part-table.22.sector200703.bin
Searching...
Signature found. sector:        0 offset:         0
0   131    0  0  0    0  0  0          1    1142783 (next    1142784)
1     5    0  0  0    0  0  0    1333358    2234368 (next    3567726)
2     0    0  0  0    0  0  0          0          0 (next          0)
3     0    0  0  0    0  0  0          0          0 (next          0)
Done.
Base:	decimal
File:		         512	z-part-table.23.sector1343487.bin
Searching...
Signature found. sector:        0 offset:         0
0   131    0  0  0    0  0  0          1    2234367 (next    2234368)
1     5    0  0  0    0  0  0    3567726     614400 (next    4182126)
2     0    0  0  0    0  0  0          0          0 (next          0)
3     0    0  0  0    0  0  0          0          0 (next          0)
Done.
Base:	decimal
File:		         512	z-part-table.24.sector3577855.bin
Searching...
Signature found. sector:        0 offset:         0
0   131    0  0  0    0  0  0          1     614399 (next     614400)
1     5    0  0  0    0  0  0    4182126      42496 (next    4224622)
2     0    0  0  0    0  0  0          0          0 (next          0)
3     0    0  0  0    0  0  0          0          0 (next          0)
Done.
Base:	decimal
File:		         512	z-part-table.25.sector4192255.bin
Searching...
Signature found. sector:        0 offset:         0
0    25    0  0  0    0  0  0          1      42495 (next      42496)
1     5    0  0  0    0  0  0    4224622        513 (next    4225135)
2     0    0  0  0    0  0  0          0          0 (next          0)
3     0    0  0  0    0  0  0          0          0 (next          0)
Done.
Base:	decimal
File:		         512	z-part-table.26.sector4234751.bin
Searching...
Signature found. sector:        0 offset:         0
0    35    0  0  0    0  0  0          1        512 (next        513)
1     5    0  0  0    0  0  0          0          0 (next          0)
2     0    0  0  0    0  0  0          0          0 (next          0)
3     0    0  0  0    0  0  0          0          0 (next          0)
Done.
Base:	decimal
File:		         512	z-part-table.27.sector4364287.bin
Searching...
Signature found. sector:        0 offset:         0
0    25    0  0  0    0  0  0          1      42495 (next      42496)
1     5    0  0  0    0  0  0    4396654        513 (next    4397167)
2     0    0  0  0    0  0  0          0          0 (next          0)
3     0    0  0  0    0  0  0          0          0 (next          0)
Done.
Base:	decimal
File:		         512	z-part-table.28.sector4406783.bin
Searching...
Signature found. sector:        0 offset:         0
0    35    0  0  0    0  0  0          1        512 (next        513)
1     5    0  0  0    0  0  0          0          0 (next          0)
2     0    0  0  0    0  0  0          0          0 (next          0)
3     0    0  0  0    0  0  0          0          0 (next          0)
Done.

Attachments