Keywords:Android 4.0 NAND partition userdata size fdisk
Platform information:
Kernel:Linux3.0
System:Android4.0.3
Inand:SDIN5C2-8G-L (SanDisk)
Platform:S5pv310 (Samsung exynos 4210)
I. NAND partition size:
Our machine uses 8 GB inand. The Samsung platform generally divides it into four areas:
(1) FAT partition, used as SD card;
(2) system partition, equivalent to a computer C drive, used to install the Android system;
(3) userdata partition;
(4) cache partition.
Ii. Partition change operation process
1. Change the code/common/cmd_mmc_fdisk.c in uboot.
In this file, we can see the definition of the size of the four partitions:
#defineSYSTEM_PART_SIZE(300*1024*1024)#defineUSER_DATA_PART_SIZE(600*1024*1024)#defineCACHE_PART_SIZE(300*1024*1024)
2. Compile uboot and burn
# Sudo fastboot flash bootloader u-boot.bin (Samsung platform commands, different platforms may be different)
Restart to enter the uboot command line mode. Make sure to restart.
3. repartition fdisk-C 0
# Fdisk-C 0 // re-partition inand
# Fdisk-P 0 // view inand partition information
As shown in the following figure, Mb is our new shard space.
Smdkv310 # fdisk-C 0 count: 10000 fdisk is completedpartion # size (MB) block start # block count partition_id 1 6233 2610960 12766380 0x0c // FAT partition, 2 303 136620 622380 0x83 // system partition as SD card, equivalent to computer C drive 3 600 759000 1229580 0x83 // userdata partition 4 303 1988580 622380 0x83 // cache Partition
4. reformat the entire system zone.
After the system is heavily partitioned, the original location of the program is changed, and the system partition (equivalent to the computer's c disk) is also changed, so you need to reformat it. (The following command is run on the Samsung platform, which varies with the platform)
fatformat mmc 0:1ext4fromat mmc 0:2ext4fromat mmc 0:3ext4fromat mmc 0:4
5. Record the entire system
sudo fastboot flash fwbl1 v310N.nbl1.bin sudo fastboot flash bootloader u-boot.bin sudo fastboot flash zImagesudo fastboot flash ramdisk-uboot.imgsudo fastboot flash system.img
6. Open the machine, as shown in. view the change result.
Iii. fdisk command Analysis
1. Command Definition
U_BOOT_CMD(fdisk, 6, 0, do_fdisk,"fdisk\t- fdisk for sd/mmc.\n","-c <device_num>\t- create partition.\n""fdisk -p <device_num> [<sys. part size(MB)> <user data part size> <cache part size>]\t- print partition information\n");
2. Implementation Functions of do_fdisk
We usually use fdisk-C 0 to format inand, fdisk-P 0 to view partition information. Here we can see the parsing of these two commands:
Int do_fdisk (pai_tbl_t * cmdtp, int flag, int argc, char * argv []) {If (argc = 3 | argc = 6) {If (strcmp (argv [1], "-c") = 0) return create_mmc_fdisk (argc, argv ); // format the partition else if (strcmp (argv [1], "-P") = 0) return print_mmc_part_info (argc, argv ); // print the partition information} else // If the argc condition is not met, print the help information {printf ("Usage: \ nfdisk <-P> <device_num> \ n "); printf (" fdisk <-C> <device_num> [<sys. part Size (MB)> <user data part size> <cache part size>] \ n ");} return 0 ;}
3. If fdisk-C 0 is used, go to create_mmc_fdisk and analyze this function.
Int create_mmc_fdisk (INT argc, char * argv []) {intrv; inttotal_block_count; unsigned charmbr [512]; memset (MBr, 0x00,512 ); total_block_count = get_mmc_block_count (argv [2]); // obtain the block information, in the unit of 512 if (total_block_count <0) Return-1; // format partition (total_block_count, MBR, (argc = 6? 1:0), argv); Rv = put_mmc_mbr (MBr, argv [2]); If (RV! = 0) Return-1; printf ("fdisk is completed \ n"); // The partition is successful. Print the information argv [1] [1] = 'P '; print_mmc_part_info (argc, argv); // print the partition information return 0 like fdisk-P 0 ;}
4. Let's see how the Formatting Function make_mmc_partition is implemented.
There are two important references: block_start and block_offset; the start and size (offset) of each block. Let's draw a picture to better express this.
Here we can see
#defineSYSTEM_PART_SIZE(300*1024*1024)#defineUSER_DATA_PART_SIZE(600*1024*1024)#defineCACHE_PART_SIZE(300*1024*1024)
The application of these macros, block_start = calc_unit (partition _partition_start, sdinfo), calculates the partition size
Int make_mmc_partition (INT total_block_count, unsigned char * MBR, int flag, char * argv []) {intblock_start = 0, block_offset; sdinfosdinfo; partitioninfopartinfo [4]; memset (unsigned char *) & sdinfo, 0x00, sizeof (sdinfo); get_sdinfo (total_block_count, & sdinfo ); //////////////////////////////////////// //// // block_start = calc_unit (pai_partition_start, sdinfo); // obtain the starting address of the first partition. If (FLAG) block_offset = calc_unit (unsigned long) simple_strtoul (argv [3], null, 0) * 1024*1024, sdinfo); elseblock_offset = calc_unit (system_part_size, sdinfo); // calculate the partition size. The values here are not very familiar, that is, we start to change the values, this is the partinfo [0] of the system partition. bootable = 0x00; partinfo [0]. partitionid = 0x83; make_partitioninfo (block_start, block_offset, sdinfo, & partinfo [0]); // start partitioning //////////////////////////////////// /// // block_start + = block_offset; // change the start address of the next analysis to ensure that the partition is continuous if (FLAG) block_offset = calc_unit (unsigned long) simple_strtoul (argv [4], null, 0) * 1024*1024, sdinfo); elseblock_offset = calc_unit (user_data_part_size, sdinfo); partinfo [1]. bootable = 0x00; partinfo [1]. partitionid = 0x83; make_partitioninfo (block_start, block_offset, sdinfo, & partinfo [1]); //////////////////////////////////////// /// // block_start + = block_offset; if (FLAG) block_offset = calc_unit (unsigned long) simple_strtoul (argv [5], null, 0) * 1024*1024, sdinfo); elseblock_offset = calc_unit (cache_part_size, sdinfo); partinfo [2]. bootable = 0x00; partinfo [2]. partitionid = 0x83; make_partitioninfo (block_start, block_offset, sdinfo, & partinfo [2]); //////////////////////////////////////// /// // block_start + = block_offset; block_offset = block_end; partinfo [3]. bootable = 0x00; partinfo [3]. partitionid = 0x0c; make_partitioninfo (block_start, block_offset, sdinfo, & partinfo [3]); //////////////////////////////////////// /// // memset (MBr, 0x00, sizeof (MBR); MBR [510] = 0x55; MBR [511] = 0xaa; encode_partitioninfo (partinfo [0], & MBR [0x1ce]); encode_partitioninfo (partinfo [1], & MBR [0x1de]); encode_partitioninfo (partinfo [2], & MBR [0x1ee]); encode_partitioninfo (partinfo [3], & MBR [0x1be]); Return 0 ;}
5. the implementation function of fidsk-P 0 is also very simple.
int print_mmc_part_info(int argc, char *argv[]){intrv;PartitionInfopartInfo[4];rv = get_mmc_part_info(argv[2], 1, &(partInfo[0].block_start), &(partInfo[0].block_count),&(partInfo[0].partitionId) );rv = get_mmc_part_info(argv[2], 2, &(partInfo[1].block_start), &(partInfo[1].block_count),&(partInfo[1].partitionId) );rv = get_mmc_part_info(argv[2], 3, &(partInfo[2].block_start), &(partInfo[2].block_count),&(partInfo[2].partitionId) );rv = get_mmc_part_info(argv[2], 4, &(partInfo[3].block_start), &(partInfo[3].block_count),&(partInfo[3].partitionId) );printf("\n");printf("partion # size(MB) block start # block count partition_Id \n");if ( (partInfo[0].block_start !=0) && (partInfo[0].block_count != 0) ) printf(" 1 %6d %8d %8d 0x%.2X \n",(partInfo[0].block_count / 2048), partInfo[0].block_start,partInfo[0].block_count, partInfo[0].partitionId);if ( (partInfo[1].block_start !=0) && (partInfo[1].block_count != 0) ) printf(" 2 %6d %8d %8d 0x%.2X \n",(partInfo[1].block_count / 2048), partInfo[1].block_start,partInfo[1].block_count, partInfo[1].partitionId);if ( (partInfo[2].block_start !=0) && (partInfo[2].block_count != 0) ) printf(" 3 %6d %8d %8d 0x%.2X \n",(partInfo[2].block_count / 2048), partInfo[2].block_start,partInfo[2].block_count, partInfo[2].partitionId);if ( (partInfo[3].block_start !=0) && (partInfo[3].block_count != 0) ) printf(" 4 %6d %8d %8d 0x%.2X \n",(partInfo[3].block_count / 2048), partInfo[3].block_start,partInfo[3].block_count, partInfo[3].partitionId);return 1;}