Android-partition Analysis

Source: Internet
Author: User

Reprint please indicate source: Cuixiaolei's Technical Blog

This is where the Android partition is spoken. The specific use is introduced in another piece of article, here just take it out to introduce.

Android storage is divided into two types

A DDR3/4 called RAM, such as the EMMC standard, with a smaller capacity

One is called Rom,rom size is relatively large, such as 8g/16g/32g/64g/128g.

We have to brush the phone, is to put system.img/recovery.img/ Userdata.img in accordance with the partition table burned in the corresponding address of the ROM, this part called the system part, such as 16G mobile phone, only 11G after boot, where 5G is occupied by these partitions, the user can use the storage size of 11G.

We read Kernel/ramdisk to ram from the Boot/recovery partition during the bootloader phase, then boot kernel, load the virtual file system RAMDisk, start init, and read the contents of the filesystem in the ROM.

The contents of the boot.img/recovery.img are as follows, Bootloader will get kernel/ramdisk/second/device size from the boot header and the address to be loaded into RAM, read aboot/ Recovery the contents of the partition to RAM.

The composition of the recovery.img/boot.img is the same, but the size and information of the file is different, the file name is the same.

 Analyze BOOT_IMG_HDR structure lift 
Kernel_size kernel represents the actual size of the Zimage
Kernel_addr kernel The physical address of the loaded memory,  Also bootloader to jump address

tags_addr    TAGS_ADDR is the physical memory address used to transmit parameters, which is to pass the parameters in bootloader to kernel, The parameter is placed on this address
page_size    page_size is the page size of the memory chip (RAM/EMMC), depending on the memory chip
cmdline      command line it can be used by bootloader to kernel the contents of the parameter, stored in the TAG_ADDR address
Second optional
** +-----------------+ ** | Boot Header     | 1 page** +-----------------+** | kernel          | n pages  * * +-----------------+** | RAMDisk         | m pag Es  * * +-----------------+** | Second Stage    | o pages** +-----------------+** | device tree     | p pages** +------ -----------+
bootable/bootloader/lk/app/aboot/bootimg.h#ifndef _boot_image_h_#define_boot_image_h_typedefstructBOOT_IMG_HDR Boot_img_hdr;#defineBoot_magic "android!"#defineBoot_magic_size 8#defineBoot_name_size 16#defineBoot_args_size 512#defineBoot_img_max_page_size 4096structboot_img_hdr{unsignedCharMagic[boot_magic_size];  unsigned kernel_size; /*size in bytes*/unsigned kernel_addr; /*Physical Load Addr*/unsigned ramdisk_size;/*size in bytes*/unsigned ramdisk_addr;/*Physical Load Addr*/unsigned second_size; /*size in bytes*/unsigned second_addr; /*Physical Load Addr*/unsigned tags_addr; /*Physical addr for kernel tags*/unsigned page_size; /*Flash Page Size we assume*/unsigned dt_size; /*device_tree in bytes*/unsigned unused; /*Future expansion:should is 0*/unsignedCharName[boot_name_size];/*Asciiz Product Name*/unsignedCharCmdline[boot_args_size]; unsigned id[8];/*timestamp/checksum/sha1/etc*/};/*** +-----------------+ ** | Boot Header | 1 page** +-----------------+** | Kernel | N pages * * +-----------------+** | RAMDisk | M pages * * +-----------------+** | Second Stage | o pages** +-----------------+** | Device Tree | P pages** +-----------------+**** n = (kernel_size + page_size-1)/page_size** m = (ramdisk_size + page_size-1)/Pag e_size** o = (second_size + page_size-1)/page_size** p = (dt_size + page_size-1)/page_size** 0. All entities is page_size aligned in flash** 1. Kernel and RAMDisk are required (size! = 0) * * 2. Second is optional (Second_size = = 0-no second) * * 3. Load each element (kernel, RAMDisk, second) at** the specified physical address (KERNEL_ADDR, etc) * * 4.  Prepare tags at tag_addr. Kernel_args[] is** appended to the kernel commandline in the tags.** 5. R0 = 0, r1 = machine_type, r2 = tags_addr** 6. If second_size! = 0:jump to second_addr** else:jump to Kernel_addr*/BOOT_IMG_HDR*mkbootimg (void*kernel, unsigned kernel_size,void*RAMDisk, unsigned ramdisk_size,void*Second, unsigned second_size, unsigned page_size, unsigned*bootimg_size);voidBootimg_set_cmdline (Boot_img_hdr *hdr,Const Char*cmdline); #defineKernel64_hdr_magic 0x644d5241/* ARM64 */structkernel64_hdr{uint32_t insn;    uint32_t res1;    uint64_t Text_offset;    uint64_t Res2;    uint64_t Res3;    uint64_t res4;    uint64_t res5;    uint64_t Res6;    uint32_t magic_64; uint32_t Res7;};#endif








MTK Partition Table storage location: Device/mediatek/build/build/tools/ptgen/xxx/xxx.xls
ptgen.pl files will parse the XLS file into Xxxandroid_scatter.txt in out/target/product/xxx/
MTK's Flashtool tool reads this file and writes the associated image to the ROM.

High-pass partitioned table storage location: Different items, different locations, search Partition.xml $find with find. -name "*partition*.xml", the final generation of rawprogram0.xml files, the high-pass brush machine tool will be based on this file to burn the relevant image to the ROM.


Android-partition Analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.