platform/msm_shared/mmc.c
unsigned int
mmc_erase_card(unsigned long long data_addr, unsigned long long size)
{
	unsigned int mmc_ret = MMC_BOOT_E_SUCCESS;
	unsigned long long erase_grp_size;
	unsigned long long data_end = 0x00000000;
	unsigned long long loop_count;
	unsigned int out[512] = { 0 };

	/* Converting size to sectors */
	size = size / 512;

	if (ext_csd_buf[MMC_BOOT_EXT_ERASE_GROUP_DEF]) {
		erase_grp_size =
		    (512 * ext_csd_buf[MMC_BOOT_EXT_HC_ERASE_GRP_SIZE] * 1024);
		erase_grp_size = erase_grp_size / 512;
	} else {
		erase_grp_size = (mmc_card.csd.erase_grp_size + 1) *
		    (mmc_card.csd.erase_grp_mult + 1);
	}

	if (erase_grp_size == 0) {
		return MMC_BOOT_E_FAILURE;
	}

	if (size % erase_grp_size) {
		dprintf(CRITICAL, "Overflow beyond ERASE_GROUP_SIZE:%llu\n",
			(size % erase_grp_size));

	}
	loop_count = (size / erase_grp_size);
	/*
	 *In case the partition size is less than the erase_grp_size
	 0 is written to the first block of the partition.
	 */
	if (loop_count < 1) {
		mmc_ret = mmc_write(data_addr, 512, (unsigned int *)out);
		if (mmc_ret != MMC_BOOT_E_SUCCESS)
			return mmc_ret;
		else
			return MMC_BOOT_E_SUCCESS;
	} else {
		data_addr = ((mmc_card.type != MMC_BOOT_TYPE_MMCHC) &&
			     (mmc_card.type != MMC_BOOT_TYPE_SDHC))
		    ? (unsigned int)data_addr : (unsigned int)(data_addr / 512);
		data_end = data_addr + erase_grp_size * (loop_count - 1);
	}

	/* Sending CMD35 */
	mmc_ret = mmc_boot_send_erase_group_start(&mmc_card, data_addr);
	if (mmc_ret != MMC_BOOT_E_SUCCESS) {
		dprintf(CRITICAL, "Error %d: Failure sending erase group start "
			"command to the card (RCA:%x)\n", mmc_ret,
			mmc_card.rca);
		return mmc_ret;
	}

	/* Sending CMD36 */
	mmc_ret = mmc_boot_send_erase_group_end(&mmc_card, data_end);
	if (mmc_ret != MMC_BOOT_E_SUCCESS) {
		dprintf(CRITICAL, "Error %d: Failure sending erase group end "
			"command to the card (RCA:%x)\n", mmc_ret,
			mmc_card.rca);
		return mmc_ret;
	}

	/* Sending CMD38 */
	mmc_ret = mmc_boot_send_erase(&mmc_card);
	if (mmc_ret != MMC_BOOT_E_SUCCESS) {
		dprintf(CRITICAL,
			"Error %d: Failure sending erase command "
			"to the card (RCA:%x)\n", mmc_ret, mmc_card.rca);
		return mmc_ret;

	}

	dprintf(CRITICAL, "ERASE SUCCESSFULLY COMPLETED\n");
	return MMC_BOOT_E_SUCCESS;
}
/*
 * Function to erase data on the eMMC card
 */
Function to erase data on the eMMC card
Function to erase data on the eMMC card
unsigned int
mmc_erase_card(unsigned long long data_addr, unsigned long long size)
{
	unsigned int mmc_ret = MMC_BOOT_E_SUCCESS;
	unsigned long long erase_grp_size;
	unsigned long long data_end = 0x00000000;
	unsigned long long loop_count;
	unsigned int out[512] = { 0 };
	size = size / 512;
	if (ext_csd_buf[MMC_BOOT_EXT_ERASE_GROUP_DEF]) {
		erase_grp_size =
		    (512 * ext_csd_buf[MMC_BOOT_EXT_HC_ERASE_GRP_SIZE] * 1024);
		erase_grp_size = erase_grp_size / 512;
	} else {
		erase_grp_size = (mmc_card.csd.erase_grp_size + 1) *
		    (mmc_card.csd.erase_grp_mult + 1);
	}
	if (erase_grp_size == 0) {
		return MMC_BOOT_E_FAILURE;
	}
	if (size % erase_grp_size) {
		dprintf(CRITICAL, "Overflow beyond ERASE_GROUP_SIZE:%llu\n",
			(size % erase_grp_size));
	}
	loop_count = (size / erase_grp_size);
	if (loop_count < 1) {
		mmc_ret = mmc_write(data_addr, 512, (unsigned int *)out);
		if (mmc_ret != MMC_BOOT_E_SUCCESS)
			return mmc_ret;
		else
			return MMC_BOOT_E_SUCCESS;
	} else {
		data_addr = ((mmc_card.type != MMC_BOOT_TYPE_MMCHC) &&
			     (mmc_card.type != MMC_BOOT_TYPE_SDHC))
		    ? (unsigned int)data_addr : (unsigned int)(data_addr / 512);
		data_end = data_addr + erase_grp_size * (loop_count - 1);
	}
	mmc_ret = mmc_boot_send_erase_group_start(&mmc_card, data_addr);
	if (mmc_ret != MMC_BOOT_E_SUCCESS) {
		dprintf(CRITICAL, "Error %d: Failure sending erase group start "
			"command to the card (RCA:%x)\n", mmc_ret,
			mmc_card.rca);
		return mmc_ret;
	}
	mmc_ret = mmc_boot_send_erase_group_end(&mmc_card, data_end);
	if (mmc_ret != MMC_BOOT_E_SUCCESS) {
		dprintf(CRITICAL, "Error %d: Failure sending erase group end "
			"command to the card (RCA:%x)\n", mmc_ret,
			mmc_card.rca);
		return mmc_ret;
	}
	mmc_ret = mmc_boot_send_erase(&mmc_card);
	if (mmc_ret != MMC_BOOT_E_SUCCESS) {
		dprintf(CRITICAL,
			"Error %d: Failure sending erase command "
			"to the card (RCA:%x)\n", mmc_ret, mmc_card.rca);
		return mmc_ret;
	}
	dprintf(CRITICAL, "ERASE SUCCESSFULLY COMPLETED\n");
	return MMC_BOOT_E_SUCCESS;
}
unsigned int mmc_erase_card ( unsigned long long data_addr , unsigned long long size ) { unsigned int mmc_ret = MMC_BOOT_E_SUCCESS ; unsigned long long erase_grp_size ; unsigned long long data_end = 0x00000000 ; unsigned long long loop_count ; unsigned int out [ 512 ] = { 0 } ; size = size / 512 ; if ( ext_csd_buf [ MMC_BOOT_EXT_ERASE_GROUP_DEF ] ) { erase_grp_size = ( 512 * ext_csd_buf [ MMC_BOOT_EXT_HC_ERASE_GRP_SIZE ] * 1024 ) ; erase_grp_size = erase_grp_size / 512 ; } else { erase_grp_size = ( mmc_card . csd . erase_grp_size + 1 ) * ( mmc_card . csd . erase_grp_mult + 1 ) ; } if ( erase_grp_size == 0 ) { return MMC_BOOT_E_FAILURE ; } if ( size % erase_grp_size ) { dprintf ( CRITICAL , " \n " , ( size % erase_grp_size ) ) ; } loop_count = ( size / erase_grp_size ) ; if ( loop_count < 1 ) { mmc_ret = mmc_write ( data_addr , 512 , ( unsigned int * ) out ) ; if ( mmc_ret != MMC_BOOT_E_SUCCESS ) return mmc_ret ; else return MMC_BOOT_E_SUCCESS ; } else { data_addr = ( ( mmc_card . type != MMC_BOOT_TYPE_MMCHC ) && ( mmc_card . type != MMC_BOOT_TYPE_SDHC ) ) ? ( unsigned int ) data_addr : ( unsigned int ) ( data_addr / 512 ) ; data_end = data_addr + erase_grp_size * ( loop_count - 1 ) ; } mmc_ret = mmc_boot_send_erase_group_start ( & mmc_card , data_addr ) ; if ( mmc_ret != MMC_BOOT_E_SUCCESS ) { dprintf ( CRITICAL , " " " \n " , mmc_ret , mmc_card . rca ) ; return mmc_ret ; } mmc_ret = mmc_boot_send_erase_group_end ( & mmc_card , data_end ) ; if ( mmc_ret != MMC_BOOT_E_SUCCESS ) { dprintf ( CRITICAL , " " " \n " , mmc_ret , mmc_card . rca ) ; return mmc_ret ; } mmc_ret = mmc_boot_send_erase ( & mmc_card ) ; if ( mmc_ret != MMC_BOOT_E_SUCCESS ) { dprintf ( CRITICAL , " " " \n " , mmc_ret , mmc_card . rca ) ; return mmc_ret ; } dprintf ( CRITICAL , " \n " ) ; return MMC_BOOT_E_SUCCESS ; }
Function to erase data on the eMMC card
Function to erase data on the eMMC card
/* Converting size to sectors */ /*
	 *In case the partition size is less than the erase_grp_size
	 0 is written to the first block of the partition.
	 */ /* Sending CMD35 */ /* Sending CMD36 */ /* Sending CMD38 */