android 시스템 이식 emmc 기록(4) - fdisk 구역 명령 분석

fdisk -c 0
명령 분석:
----------------------------------
 
int do_fdisk(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])

{

       if ( argc != 3 )

       {

              printf("Usage: fdisk <-c or -p> <device_num>
"); return 0; } // if ( strcmp(argv[1], "-c") == 0 ) return create_mmc_fdisk(argc, argv); // else if ( strcmp(argv[1], "-p") == 0 ) return print_mmc_part_info(argc, argv); printf("Usage: fdisk <-c or -p> <device_num>
"); return 0; } ---------------------------------------------------------- int create_mmc_fdisk(int argc, char *argv[]) { int rv; int total_block_count; unsigned char mbr[512]; memset(mbr, 0x00, 512); // 0, , fdisk -c 0 , 。 0 , total_block_count = get_mmc_block_count(argv[2]); --------------------------- int get_mmc_block_count(char *device_name) { int rv; struct mmc *mmc; int block_count = 0; int dev_num; // 0 0 dev_num = simple_strtoul(device_name, NULL, 0); mmc = find_mmc_device(dev_num); // rv = mmc_init(mmc); if (rv) { printf("mmc/sd device's initialization is failed.
"); return -1; } //emmc/sd , . // , 512 。 //BLOCK_SIZE = 512 // emmc 1024 。 , // , 。 block_count = mmc->capacity *(mmc -> read_bl_len / BLOCK_SIZE) return block_count; -----------------------------------------

//파티션 목록 생성 MBR
      make_mmc_partition(total_block_count, mbr);
//파티션 목록 MBR 노드 디바이스에 쓰기
      rv = put_mmc_mbr(mbr, argv[2]);
------------------
//파티션 목록 생성 MBR:
1: MBR 분석 - sd 카드
 =======================================
int make_mmc_partition(int total_block_count, unsigned char *mbr)
{
	int		block_start = 0, block_offset;

	SDInfo		sdInfo;
	PartitionInfo	partInfo[4];

///////////////////////////////////////////////////////////	
	memset((unsigned char *)&sdInfo, 0x00, sizeof(SDInfo));

///////////////////////////////////////////////////////////
	//  sd  ,  ,            	
	get_SDInfo(total_block_count, &sdInfo);

///////////////////////////////////////////////////////////
//         10M,          
//         ,10MB/512
	block_start	= calc_unit(_10MB, sdInfo);
	//     256MB,system  
	block_offset	= calc_unit(SYSTEM_PART_SIZE, sdInfo);

	partInfo[0].bootable	= 0x00;
	partInfo[0].partitionId	= 0x83;
	//      ,  partInfo【0】,     10M   ,  u-boot,kernel ramdisk
	
	make_partitionInfo(block_start, block_offset, sdInfo, &partInfo[0]);

///////////////////////////////////////////////////////////	
	block_start += block_offset;
	//350M  datauser   
	block_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;
	//cache    100M
	block_offset = calc_unit(CACHE_PART_SIZE, sdInfo);
	
	partInfo[2].bootable	= 0x00;
	partInfo[2].partitionId	= 0x83;

	make_partitionInfo(block_start, block_offset, sdInfo, &partInfo[2]);

///////////////////////////////////////////////////////////
	//     vfat  , 0c id。	
	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   ,   55AA
	//[1FE] [1FF]
	mbr[510] = 0x55; mbr[511] = 0xAA;
	//MBR :1BE-1CD:     1  ,1CE-1DD :     2 
	//  1DE-1ED :   3   1EE-1FD :    4        5     ,1FE   55AA
	//   + F 
	//system  :   2,  partInfo[0]     2,
	//  DPT   
//                  MBR 。
	encode_partitionInfo(partInfo[0], &mbr[0x1CE]);
	//datause  ,partInfo[1]:     3
	encode_partitionInfo(partInfo[1], &mbr[0x1DE]);
	//cache  ,partInfo[2]:     4
	encode_partitionInfo(partInfo[2], &mbr[0x1EE]);
	//    :partInfo[3]      1
	encode_partitionInfo(partInfo[3], &mbr[0x1BE]);
	
	return 0;
}
--------------------
make_partitionInfo
---------------------
//                
void make_partitionInfo(int LBA_start, int count, SDInfo sdInfo, PartitionInfo *partInfo)
{
        int             temp = 0;
        int             _10MB_unit;

	//      10M
        partInfo->block_start   = LBA_start;

//-----------------------------------------------------
        if (sdInfo.addr_mode == CHS_MODE)
        {	//    = c * H * s    SD    =     * 512byte
        	//  ,      
                partInfo->C_start       = partInfo->block_start / (sdInfo.H_end * sdInfo.S_end);
                temp                    = partInfo->block_start % (sdInfo.H_end * sdInfo.S_end);
                partInfo->H_start       = temp / sdInfo.S_end;
                partInfo->S_start       = temp % sdInfo.S_end + 1;

                if (count == BLOCK_END)
                {  //      
                        _10MB_unit = calc_unit(_10MB, sdInfo);
                        partInfo->block_end     = sdInfo.C_end * sdInfo.H_end * sdInfo.S_end - _10MB_unit - 1;
                        partInfo->block_count   = partInfo->block_end - partInfo->block_start + 1;

                        partInfo->C_end = partInfo->block_end / sdInfo.unit;
                        partInfo->H_end = sdInfo.H_end - 1;
                        partInfo->S_end = sdInfo.S_end;
                }
                else
                {
                        partInfo->block_count   = count;

                        partInfo->block_end     = partInfo->block_start + count - 1;
                        partInfo->C_end         = partInfo->block_end / sdInfo.unit;

                        temp                    = partInfo->block_end % sdInfo.unit;
                        partInfo->H_end         = temp / sdInfo.S_end;
                        partInfo->S_end         = temp % sdInfo.S_end + 1;
                }
        }
//-----------------------------------------------------
        else
        {
                partInfo->C_start       = 0;
                partInfo->H_start       = 1;
                partInfo->S_start       = 1;

                partInfo->C_end         = 1023;
                partInfo->H_end         = 254;
                partInfo->S_end         = 63;

                if (count == BLOCK_END)
                {
                        _10MB_unit = calc_unit(_10MB, sdInfo);
                        partInfo->block_end     = sdInfo.total_block_count - _10MB_unit - 1;
                        partInfo->block_count   = partInfo->block_end - partInfo->block_start + 1;

                }
                else
                {
                        partInfo->block_count   = count;
                        partInfo->block_end     = partInfo->block_start + count - 1;
                }
        }
}
======================================================================

 
 

좋은 웹페이지 즐겨찾기