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));

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

///////////////////////////////////////////////////////////
	block_start	= calc_unit(_10MB, sdInfo);
	block_offset	= calc_unit(SYSTEM_PART_SIZE, sdInfo);

	partInfo[0].bootable	= 0x00;
	partInfo[0].partitionId	= 0x83;

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

///////////////////////////////////////////////////////////	
	block_start += block_offset;
	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;
	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]);

///////////////////////////////////////////////////////////	
	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;
}
Exemple #2
0
int make_mmc_partition(int total_block_count, unsigned char *mbr, int flag, char *argv[])
{
	int		block_start = 0, block_offset;

	SDInfo		sdInfo;
	PartitionInfo	partInfo[4];

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

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

///////////////////////////////////////////////////////////
// 반드시 Unit단위로 먼저 계산한다.
	block_start = calc_unit(CFG_PARTITION_START, sdInfo);
	if (flag)
		block_offset = calc_unit((unsigned long long)simple_strtoul(argv[3], NULL, 0)*1024*1024, sdInfo);
	else
		block_offset = calc_unit(SYSTEM_PART_SIZE, sdInfo);

	partInfo[0].bootable	= 0x00;
	partInfo[0].partitionId	= 0x83;

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

///////////////////////////////////////////////////////////	
	block_start += block_offset;
	if (flag)
		block_offset = calc_unit((unsigned long long)simple_strtoul(argv[4], NULL, 0)*1024*1024, sdInfo);
	else
		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;
	if (flag)
		block_offset = calc_unit((unsigned long long)simple_strtoul(argv[5], NULL, 0)*1024*1024, sdInfo);
	else
		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]);

///////////////////////////////////////////////////////////	
	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;
}
Exemple #3
0
int main(int argc, char *argv[])
{
	FILE *fp;
	int	block_start = 0, block_offset = 0;
	int	total_block_count;
	int part_deb = 0;
	int part_android = 0;

	SDInfo sdInfo;
	PartitionInfo partInfo[4];
	unsigned char mbr[512];

	if (argc != 2) {
		printf("Usage: sd_fdisk <device_file>\n");
		return -1;
	}

	if (strcasestr(argv[0], "_deb")) {
		part_deb = 1;
	} else if (strcasestr(argv[0], "_android")) {
		part_android = 1;
	}

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

	total_block_count = get_sd_block_count(argv[1]);
	get_SDInfo(total_block_count, &sdInfo);

	memset(mbr, 0x00, sizeof(mbr));
	mbr[510] = 0x55; mbr[511] = 0xAA;

	/* Reserved area */
	block_offset = calc_unit(154624<<10, sdInfo);

	if (part_deb) {
		printf("Making partition table: Debian\n");

		block_start += block_offset;
		partInfo[0].bootable	= 0x00;
		partInfo[0].partitionId	= 0x0C;
		block_offset = calc_unit(_100MB * 2, sdInfo);
		make_partitionInfo(block_start, block_offset, sdInfo, &partInfo[0]);

		block_start += block_offset;
		partInfo[2].bootable	= 0x00;
		partInfo[2].partitionId	= 0x82;
		block_offset = calc_unit(_100MB * 4, sdInfo);
		make_partitionInfo(block_start, block_offset, sdInfo, &partInfo[2]);

		block_start += block_offset;
		partInfo[1].bootable	= 0x00;
		partInfo[1].partitionId	= 0x83;
		make_partitionInfo(block_start, BLOCK_END, sdInfo, &partInfo[1]);

		encode_partitionInfo(partInfo[0], &mbr[0x1BE]);
		encode_partitionInfo(partInfo[1], &mbr[0x1CE]);
		encode_partitionInfo(partInfo[2], &mbr[0x1DE]);

	} else if (part_android) {
		printf("Making partition table: Android\n");

		block_start += block_offset;
		partInfo[1].bootable	= 0x00;
		partInfo[1].partitionId	= 0x83;
		block_offset = calc_unit(_100MB * 2, sdInfo);
		make_partitionInfo(block_start, block_offset, sdInfo, &partInfo[1]);

		block_start += block_offset;
		partInfo[2].bootable	= 0x00;
		partInfo[2].partitionId	= 0x83;
		block_offset = calc_unit(_100MB * 4, sdInfo);
		make_partitionInfo(block_start, block_offset, sdInfo, &partInfo[2]);

		block_start += block_offset;
		partInfo[3].bootable	= 0x00;
		partInfo[3].partitionId	= 0x83;
		block_offset = calc_unit(_100MB * 4, sdInfo);
		make_partitionInfo(block_start, block_offset, sdInfo, &partInfo[3]);

		block_start += block_offset;
		partInfo[0].bootable	= 0x00;
		partInfo[0].partitionId	= 0x0C;
		make_partitionInfo(block_start, BLOCK_END, sdInfo, &partInfo[0]);

		encode_partitionInfo(partInfo[0], &mbr[0x1BE]);
		encode_partitionInfo(partInfo[1], &mbr[0x1CE]);
		encode_partitionInfo(partInfo[2], &mbr[0x1DE]);
		encode_partitionInfo(partInfo[3], &mbr[0x1EE]);

	} else {
		/* Default partition table */
		block_offset += BLOCK_END;
		partInfo[0].bootable	= 0x00;
		partInfo[0].partitionId	= 0x0C;
		make_partitionInfo(block_start, BLOCK_END, sdInfo, &partInfo[0]);

		encode_partitionInfo(partInfo[0], &mbr[0x1BE]);
	}

	fp = fopen("sd_mbr.dat", "wb");
	fwrite(mbr, 1, sizeof(mbr), fp);
	fclose(fp);

	return 0;
}