示例#1
0
/**
	Function for writing user partition.
*/
PUBLIC int _boot_partition_write(block_dev_desc_t *dev, wchar_t* partition_name, u32 size, u8* buf)
{
	disk_partition_t info;

	if(NULL == buf){
		debugf("%s:buf is NULL!\n", __FUNCTION__);
		return 0;
	}
	size = (size +(EMMC_SECTOR_SIZE - 1)) & (~(EMMC_SECTOR_SIZE - 1));
	size = size/EMMC_SECTOR_SIZE;
	if(0 == get_partition_info_by_name(dev, partition_name, &info))
	{
		if(TRUE != Emmc_Write(PARTITION_USER, info.start, size, buf))
		{
			debugf("%s: partition:%s read error!\n", __FUNCTION__,w2c(partition_name));
			return 0;
		}
	}
	else
	{
		debugf("%s: partition:%s >>>get partition info failed!\n", __FUNCTION__,w2c(partition_name));
		return 0;
	}
	debugf("%s: partition:%s write success!\n", __FUNCTION__,w2c(partition_name));
	return 1;
}
int set_recovery_message(const struct recovery_message *in)
{
	block_dev_desc_t *p_block_dev = NULL;
	disk_partition_t info;
	int size=8192;
	p_block_dev = get_dev("mmc", 1);
	if(NULL == p_block_dev){
		return -1;
	}
	if (!get_partition_info(p_block_dev, PARTITION_MISC, &info)) {
		memset(buf, 0, sizeof(buf));
		if(TRUE !=  Emmc_Read(PARTITION_USER, info.start, size/EMMC_SECTOR_SIZE, (void *)buf)){
			printf("function: %s emcc read error\n", __FUNCTION__);
			return -1;
		}
		memcpy((void *)buf, in, sizeof(*in));
		if(TRUE !=  Emmc_Write(PARTITION_USER, info.start, size/EMMC_SECTOR_SIZE, (void *)buf)){
			printf("function: %s emcc write error\n", __FUNCTION__);
			return -1;
		}
	}
	return 0;
}