platform/msm_shared/partition_parser.c
unsigned int
mmc_boot_read_mbr(struct mmc_boot_host *mmc_host,
		  struct mmc_boot_card *mmc_card)
{
	unsigned char buffer[BLOCK_SIZE];
	unsigned int dtype;
	unsigned int dfirstsec;
	unsigned int EBR_first_sec;
	unsigned int EBR_current_sec;
	int ret = MMC_BOOT_E_SUCCESS;
	int idx, i;

	/* Print out the MBR first */
	ret = mmc_boot_read_from_card(mmc_host, mmc_card, 0,
				      BLOCK_SIZE, (unsigned int *)buffer);
	if (ret) {
		dprintf(CRITICAL, "Could not read partition from mmc\n");
		return ret;
	}

	/* Check to see if signature exists */
	ret = partition_verify_mbr_signature(BLOCK_SIZE, buffer);
	if (ret) {
		return ret;
	}

	/*
	 * Process each of the four partitions in the MBR by reading the table
	 * information into our mbr table.
	 */
	partition_count = 0;
	idx = TABLE_ENTRY_0;
	for (i = 0; i < 4; i++) {
		/* Type 0xEE indicates end of MBR and GPT partitions exist */
		dtype = buffer[idx + i * TABLE_ENTRY_SIZE + OFFSET_TYPE];
		if (dtype == MBR_PROTECTED_TYPE) {
			gpt_partitions_exist = 1;
			return ret;
		}
		partition_entries[partition_count].dtype = dtype;
		partition_entries[partition_count].attribute_flag =
		    buffer[idx + i * TABLE_ENTRY_SIZE + OFFSET_STATUS];
		partition_entries[partition_count].first_lba =
		    GET_LWORD_FROM_BYTE(&buffer[idx +
						i * TABLE_ENTRY_SIZE +
						OFFSET_FIRST_SEC]);
		partition_entries[partition_count].size =
		    GET_LWORD_FROM_BYTE(&buffer[idx +
						i * TABLE_ENTRY_SIZE +
						OFFSET_SIZE]);
		dfirstsec = partition_entries[partition_count].first_lba;
		mbr_fill_name(&partition_entries[partition_count],
			      partition_entries[partition_count].dtype);
		partition_count++;
		if (partition_count == NUM_PARTITIONS)
			return ret;
	}

	/* See if the last partition is EBR, if not, parsing is done */
	if (dtype != MBR_EBR_TYPE) {
		return ret;
	}

	EBR_first_sec = dfirstsec;
	EBR_current_sec = dfirstsec;

	ret = mmc_boot_read_from_card(mmc_host, mmc_card,
				      (EBR_first_sec * 512),
				      BLOCK_SIZE, (unsigned int *)buffer);
	if (ret) {
		return ret;
	}
	/* Loop to parse the EBR */
	for (i = 0;; i++) {
		ret = partition_verify_mbr_signature(BLOCK_SIZE, buffer);
		if (ret) {
			ret = MMC_BOOT_E_SUCCESS;
			break;
		}
		partition_entries[partition_count].attribute_flag =
		    buffer[TABLE_ENTRY_0 + OFFSET_STATUS];
		partition_entries[partition_count].dtype =
		    buffer[TABLE_ENTRY_0 + OFFSET_TYPE];
		partition_entries[partition_count].first_lba =
		    GET_LWORD_FROM_BYTE(&buffer[TABLE_ENTRY_0 +
						OFFSET_FIRST_SEC]) +
		    EBR_current_sec;
		partition_entries[partition_count].size =
		    GET_LWORD_FROM_BYTE(&buffer[TABLE_ENTRY_0 + OFFSET_SIZE]);
		mbr_fill_name(&(partition_entries[partition_count]),
			      partition_entries[partition_count].dtype);
		partition_count++;
		if (partition_count == NUM_PARTITIONS)
			return ret;

		dfirstsec =
		    GET_LWORD_FROM_BYTE(&buffer
					[TABLE_ENTRY_1 + OFFSET_FIRST_SEC]);
		if (dfirstsec == 0) {
			/* Getting to the end of the EBR tables */
			break;
		}
		/* More EBR to follow - read in the next EBR sector */
		dprintf(SPEW, "Reading EBR block from 0x%X\n", EBR_first_sec
			+ dfirstsec);
		ret = mmc_boot_read_from_card(mmc_host, mmc_card,
					      ((EBR_first_sec +
						dfirstsec) * 512), BLOCK_SIZE,
					      (unsigned int *)buffer);
		if (ret) {
			return ret;
		}
		EBR_current_sec = EBR_first_sec + dfirstsec;
	}
	return ret;
}
/*
 * Read MBR from MMC card and fill partition table.
 */
Read MBR from MMC card and fill partition table.
Read MBR from MMC card and fill partition table .
unsigned int
mmc_boot_read_mbr(struct mmc_boot_host *mmc_host,
		  struct mmc_boot_card *mmc_card)
{
	unsigned char buffer[BLOCK_SIZE];
	unsigned int dtype;
	unsigned int dfirstsec;
	unsigned int EBR_first_sec;
	unsigned int EBR_current_sec;
	int ret = MMC_BOOT_E_SUCCESS;
	int idx, i;
	ret = mmc_boot_read_from_card(mmc_host, mmc_card, 0,
				      BLOCK_SIZE, (unsigned int *)buffer);
	if (ret) {
		dprintf(CRITICAL, "Could not read partition from mmc\n");
		return ret;
	}
	ret = partition_verify_mbr_signature(BLOCK_SIZE, buffer);
	if (ret) {
		return ret;
	}
	partition_count = 0;
	idx = TABLE_ENTRY_0;
	for (i = 0; i < 4; i++) {
		dtype = buffer[idx + i * TABLE_ENTRY_SIZE + OFFSET_TYPE];
		if (dtype == MBR_PROTECTED_TYPE) {
			gpt_partitions_exist = 1;
			return ret;
		}
		partition_entries[partition_count].dtype = dtype;
		partition_entries[partition_count].attribute_flag =
		    buffer[idx + i * TABLE_ENTRY_SIZE + OFFSET_STATUS];
		partition_entries[partition_count].first_lba =
		    GET_LWORD_FROM_BYTE(&buffer[idx +
						i * TABLE_ENTRY_SIZE +
						OFFSET_FIRST_SEC]);
		partition_entries[partition_count].size =
		    GET_LWORD_FROM_BYTE(&buffer[idx +
						i * TABLE_ENTRY_SIZE +
						OFFSET_SIZE]);
		dfirstsec = partition_entries[partition_count].first_lba;
		mbr_fill_name(&partition_entries[partition_count],
			      partition_entries[partition_count].dtype);
		partition_count++;
		if (partition_count == NUM_PARTITIONS)
			return ret;
	}
	if (dtype != MBR_EBR_TYPE) {
		return ret;
	}
	EBR_first_sec = dfirstsec;
	EBR_current_sec = dfirstsec;
	ret = mmc_boot_read_from_card(mmc_host, mmc_card,
				      (EBR_first_sec * 512),
				      BLOCK_SIZE, (unsigned int *)buffer);
	if (ret) {
		return ret;
	}
	for (i = 0;; i++) {
		ret = partition_verify_mbr_signature(BLOCK_SIZE, buffer);
		if (ret) {
			ret = MMC_BOOT_E_SUCCESS;
			break;
		}
		partition_entries[partition_count].attribute_flag =
		    buffer[TABLE_ENTRY_0 + OFFSET_STATUS];
		partition_entries[partition_count].dtype =
		    buffer[TABLE_ENTRY_0 + OFFSET_TYPE];
		partition_entries[partition_count].first_lba =
		    GET_LWORD_FROM_BYTE(&buffer[TABLE_ENTRY_0 +
						OFFSET_FIRST_SEC]) +
		    EBR_current_sec;
		partition_entries[partition_count].size =
		    GET_LWORD_FROM_BYTE(&buffer[TABLE_ENTRY_0 + OFFSET_SIZE]);
		mbr_fill_name(&(partition_entries[partition_count]),
			      partition_entries[partition_count].dtype);
		partition_count++;
		if (partition_count == NUM_PARTITIONS)
			return ret;
		dfirstsec =
		    GET_LWORD_FROM_BYTE(&buffer
					[TABLE_ENTRY_1 + OFFSET_FIRST_SEC]);
		if (dfirstsec == 0) {
			break;
		}
		dprintf(SPEW, "Reading EBR block from 0x%X\n", EBR_first_sec
			+ dfirstsec);
		ret = mmc_boot_read_from_card(mmc_host, mmc_card,
					      ((EBR_first_sec +
						dfirstsec) * 512), BLOCK_SIZE,
					      (unsigned int *)buffer);
		if (ret) {
			return ret;
		}
		EBR_current_sec = EBR_first_sec + dfirstsec;
	}
	return ret;
}
unsigned int mmc_boot_read_mbr ( struct mmc_boot_host * mmc_host , struct mmc_boot_card * mmc_card ) { unsigned char buffer [ BLOCK_SIZE ] ; unsigned int dtype ; unsigned int dfirstsec ; unsigned int EBR_first_sec ; unsigned int EBR_current_sec ; int ret = MMC_BOOT_E_SUCCESS ; int idx , i ; ret = mmc_boot_read_from_card ( mmc_host , mmc_card , 0 , BLOCK_SIZE , ( unsigned int * ) buffer ) ; if ( ret ) { dprintf ( CRITICAL , " \n " ) ; return ret ; } ret = partition_verify_mbr_signature ( BLOCK_SIZE , buffer ) ; if ( ret ) { return ret ; } partition_count = 0 ; idx = TABLE_ENTRY_0 ; for ( i = 0 ; i < 4 ; i ++ ) { dtype = buffer [ idx + i * TABLE_ENTRY_SIZE + OFFSET_TYPE ] ; if ( dtype == MBR_PROTECTED_TYPE ) { gpt_partitions_exist = 1 ; return ret ; } partition_entries [ partition_count ] . dtype = dtype ; partition_entries [ partition_count ] . attribute_flag = buffer [ idx + i * TABLE_ENTRY_SIZE + OFFSET_STATUS ] ; partition_entries [ partition_count ] . first_lba = GET_LWORD_FROM_BYTE ( & buffer [ idx + i * TABLE_ENTRY_SIZE + OFFSET_FIRST_SEC ] ) ; partition_entries [ partition_count ] . size = GET_LWORD_FROM_BYTE ( & buffer [ idx + i * TABLE_ENTRY_SIZE + OFFSET_SIZE ] ) ; dfirstsec = partition_entries [ partition_count ] . first_lba ; mbr_fill_name ( & partition_entries [ partition_count ] , partition_entries [ partition_count ] . dtype ) ; partition_count ++ ; if ( partition_count == NUM_PARTITIONS ) return ret ; } if ( dtype != MBR_EBR_TYPE ) { return ret ; } EBR_first_sec = dfirstsec ; EBR_current_sec = dfirstsec ; ret = mmc_boot_read_from_card ( mmc_host , mmc_card , ( EBR_first_sec * 512 ) , BLOCK_SIZE , ( unsigned int * ) buffer ) ; if ( ret ) { return ret ; } for ( i = 0 ; ; i ++ ) { ret = partition_verify_mbr_signature ( BLOCK_SIZE , buffer ) ; if ( ret ) { ret = MMC_BOOT_E_SUCCESS ; break ; } partition_entries [ partition_count ] . attribute_flag = buffer [ TABLE_ENTRY_0 + OFFSET_STATUS ] ; partition_entries [ partition_count ] . dtype = buffer [ TABLE_ENTRY_0 + OFFSET_TYPE ] ; partition_entries [ partition_count ] . first_lba = GET_LWORD_FROM_BYTE ( & buffer [ TABLE_ENTRY_0 + OFFSET_FIRST_SEC ] ) + EBR_current_sec ; partition_entries [ partition_count ] . size = GET_LWORD_FROM_BYTE ( & buffer [ TABLE_ENTRY_0 + OFFSET_SIZE ] ) ; mbr_fill_name ( & ( partition_entries [ partition_count ] ) , partition_entries [ partition_count ] . dtype ) ; partition_count ++ ; if ( partition_count == NUM_PARTITIONS ) return ret ; dfirstsec = GET_LWORD_FROM_BYTE ( & buffer [ TABLE_ENTRY_1 + OFFSET_FIRST_SEC ] ) ; if ( dfirstsec == 0 ) { break ; } dprintf ( SPEW , " \n " , EBR_first_sec + dfirstsec ) ; ret = mmc_boot_read_from_card ( mmc_host , mmc_card , ( ( EBR_first_sec + dfirstsec ) * 512 ) , BLOCK_SIZE , ( unsigned int * ) buffer ) ; if ( ret ) { return ret ; } EBR_current_sec = EBR_first_sec + dfirstsec ; } return ret ; }
Read MBR from MMC card and fill partition table.
Read MBR from MMC card and fill partition table .
/* Print out the MBR first */ /* Check to see if signature exists */ /*
	 * Process each of the four partitions in the MBR by reading the table
	 * information into our mbr table.
	 */ /* Type 0xEE indicates end of MBR and GPT partitions exist */ /* See if the last partition is EBR, if not, parsing is done */ /* Loop to parse the EBR */ /* Getting to the end of the EBR tables */ /* More EBR to follow - read in the next EBR sector */