Thursday, February 19, 2015

"eMMC Partition tools usage for msm7x30/msm8x60"
(A repost from Anyclub...)

In the eMMC boot, there are some changes in eMMC partitioning.


Code:
partition.xml           - Everything begins with this file, which describes the number of 
                          partitions desired, and how many sectors each one should be.
PartitioningTool.py     - translates partition.xml into binary partitions
msp.exe                 - writes binary partitions to SD/eMMC cards using card reader
mjsdload.cmm            - writes binary partitions to SD/eMMC cards using Trace32
msp.py                  - writes binary partitions to a single image file
QPST                    - writes binary partitions to SD/eMMC cards on Target
Helper /Debug Tools:
Code:
parseBinaryPartitionFile.pl     - Decodes MBR partition tables. Run: 
                                  "Perl parseBinaryPartitionFile.pl partition.bin" 
                                  to generate the partition information
parseGPT.pl                     - Decodes GPT partition tables
partition.xml

These are the property entries that can be added in new partiton.xml to specify the configuration.
Code:
<parser_instructions>
  WRITE_PROTECT_BOUNDARY_IN_KB                = 0
  GROW_LAST_PARTITION_TO_FILL_DISK            = false
  ALIGN_ALL_LOGICAL_PARTITIONS_TO_WP_BOUNDARY = false
</parser_instructions>
WRITE_PROTECT_BOUNDARY_IN_KB: Typical boundaries are 64MB, i.e. 65536 KB. This
means that a 256MB eMMC card has 4 write protect boundaries. Any or all of
them can be marked as read-only. Different vendors allow for different sized
boundaries.

GROW_LAST_PARTITION_TO_FILL_DISK: In partition.xml the size of each partition
is specified. If this field is TRUE, then the last partition size is ignored
and set to 0. Then during patching this size is updated such that the last
partition extends to use all remaining space.

ALIGN_ALL_LOGICAL_PARTITIONS_TO_WP_BOUNDARY: To allow total flexibility, it
could be that a partition that is currently writeable might need to be marked
as read-only. This can only happen *if* that partition begins on a write
protect boundary (i.e. 64MB). Thus if this field is TRUE, then all logical
partitions are positioned such that they begin on a write protect boundary.


PartitioningTool.py

Is a new tool used to generate the the partition.xml
When run, it will output following 5 files:

1. emmc_lock_regions.xml

This hold the sector ranges that need to be marked as read-only by the
operating system (this is from readonly="true" in partition.xml) i.e. modem
code and boot images are typically on read-only partitions Typical
Write-Protect boundary is 64MB = 131072 sectors = 0x20000 sectors. The file
below is protecting the very first 64MB region of the card,

Boundary #0
Starting at sector 0
Ending at sector 131071 (for a total of 131072 sectors
)

code:
<?xml version="1.0" ?>
<protect>
  <!-- NOTE: This is an ** Autogenerated file ** -->
  <!-- NOTE: Sector size is 512bytes, WRITE_PROTECT_BOUNDARY_IN_KB=0,   WRITE_PROTECT_BOUNDARY_IN_SECTORS=0 -->
  <!-- NOTE: "num_sectors" in HEX "start_sector" in HEX, i.e. 10 really equals 16 !! -->
  <program boundary_num="0" num_boundaries_covered="1" 
       num_sectors="20000" num_sectors_dec="131072" physical_partition_number="0"  
       start_sector="0"    start_sector_dec="0"/>
  <information WRITE_PROTECT_BOUNDARY_IN_KB="0"/>
</protect>
 2. partition0.bin

This holds the partition tables, i.e. MBR followed by all EBRs. This is the
partition table in binary format. It is copied over to the storage device in a
1 to 1 manner. I.e. how it looks in partition0.bin is exactly how the
partition table will look on the storage device. partition0.bin is a "generic"
file meant to fit on *any* size SD/eMMC card, as a result, there are 0's that
need to be patched,such as EXT partition and last partition size.

3. patch0.xml

Contain the patching instructions to tailor each partition table
"partition0.bin" to a specific SD/eMMC card. I.e. the partition0.bin
partition tables can be applied to any size storage device As a result,
there are empty values (zeros) in the partition tables that must be filled
in with a specific cards sector size

There are two ways to apply this patch:
a) (patch before) When you patch the "zeros" in the partition tables held in the file partition0.bin, and then write it to the card
b) (patch after) When you write partition0.bin to the card (which still has "zeros" in it), and then patch the cards partition tables directly


4. rawprogram0.xml

precise sector details of all partitions and what files (if any) need to
be placed there. In addition to writing partition tables onto a device,
often times it is desired to write one or more files into the partition
area as well, The File has partition name (i.e. label), where it begins
(start_sector) and how big it is (num_partition_sectors). It also
describes what file(s) to write to this partition, as well as any
offsets.

Example:


Code:
<program file_sector_offset="0" filename="partition0.bin" label="MBR" 
       num_partition_sectors="1" physical_partition_number="0" 
       size_in_KB="0.5" start_sector="0"/>

<program file_sector_offset="1" filename="partition0.bin " label="EXT" 
       num_partition_sectors="2"  physical_partition_number="0" 
       size_in_KB="1.0" start_sector="779"/>
The 1st line describes taking the 1st sector from partition0.bin, and writing it to sector 0 of the card.
The 2nd line describes taking the 2nd and 3rd sector from partition0.bin and writing it to sector 779 of the card.
I.e. file_sector_offset = 2 and num_partition_sectors=2

5. loadpt.cmm

This is used by the mjsdload.cmm to flash the image.


msp.exe

This is used to apply the patches

This program will program a memory card (SD/eMMC) attached to the PC as USB mass storage device
Use -d to detect the path of the memory card if you are unsure what to do first

Commands list:

Code:
-h      (Print this help message)                                               Ex. msp -h
-d      (Detect which storage device ID is active)                              Ex. msp -d
-p      (Print partition information)                                           Ex. msp -p /dev/sdb
-pp     (Print partition information - DETAILED)                                Ex. msp -pp /dev/sdb
-x      (Write files as outlined in rawprogram.xml)                             Ex. msp -x rawprogram.xml /dev/sdb
-xx     (Write files as outlined in rawprogram.xml - DETAILED)                  Ex. msp -xx rawprogram.xml /dev/sdb
-s      (Write SINGLE IMAGE "singleimage.bin" as outlined in rawprogram.xml)    Ex. msp -s rawprogram.xml 8192
-v      (Verify file written correctly as outlined in rawprogram.xml)           Ex. msp -v rawprogram.xml boot.img /dev/sdb
-f      (Program single file as outlined in rawprogram.xml)                     Ex. msp -f rawprogram.xml boot.img /dev/sdb
To program the SD/eMMC with msp.exe in mass storage mode:

Code:
STEPS                           Complete example (patch after)
-------------------------------------------------------------
parse partition.xml             python PartitioningTool.py partition.xml 
Detect your device              msp -d
Program your device             msp -x rawprogram0.xml /dev/sdb
Patch your device               msp -xx patch0.xml /dev/sdb


STEPS                           Complete example (patch before)
-------------------------------------------------------------
parse partition.xml             python PartitioningTool.py partition.xml 
Detect your device              msp -d
Patch your files                msp xx  patch0.xml 15758336 (patch the 8GB card offline,this will change the partition0.bin)
Program your device             msp x   rawprogram0.xml /dev/sdb
The msp.py program can also used to patch the files.

For example:
python msp.py patch0.xml 15758336

This will patch the 8GB card offline, and change the partition0.bin.

No comments:

Post a Comment