Ejemplo n.º 1
0
static int write_to_ptn_emmc(struct fastboot_ptentry *ptn, unsigned long offset, char* response)
{
	int status     = -1;

#if  defined(CONFIG_4430PANDA)
	/* panda board does not have eMMC on mmc1 */
	int slot_no = 0;
#else
	/* blaze has emmc on mmc1 */
	int slot_no = 1;
#endif

	// First chunk
	if (offset == 0) {
		printf("fastboot: writing to partition '%s'\n", ptn->name);

		if (mmc_init(slot_no)) {
			sprintf(response, "FAIL:Init of MMC card");
			return status;
		}

		// Sparse image detection
		if (((sparse_header_t *)interface.transfer_buffer)->magic == SPARSE_HEADER_MAGIC) {
			/* Compressed image: sparse header is detected */
			printf("fastboot: image is in sparse format\n");
			do_unsparse_start(ptn->start, slot_no);
			mmcwrite_is_sparsed = 1;
		} else {
			mmcwrite_is_sparsed = 0;
		}
	}

	// Write the image
	if(mmcwrite_is_sparsed) {
		// Sparsed image: unspase it
		printf("fastboot: Writing sparse image into '%s'\n", ptn->name);
		if (!do_unsparse_process(interface.transfer_buffer, download_bytes)) {
			printf(" DONE!\n");
			status = 0;
		} else {
			printf(" FAILED!\n");
			sprintf(response, "FAIL: Sparsed Write");
		}
	}
	else {
		/* Normal image: no sparse */
		printf("fastboot: Writing normal image into '%s'\n", ptn->name);
		if (mmc_write(slot_no, interface.transfer_buffer,
		    ptn->start + (offset/512), download_bytes) <= 0) {
			printf(" FAILED!\n");
			sprintf(response, "FAIL: Write partition");
		} else {
			printf(" DONE!\n");
			status = 0;
		}
	}

	if(status == 0) sprintf(response, "OKAY");
	return status;
}
Ejemplo n.º 2
0
int lge_dynamic_nvdata_emmc_write(enum lge_dynamic_nvdata_offset offset,char* buf,int size)
{
	int pos = (int)offset;
	int start_sector_no;
	int pos_in_sector;
	char sector_buf[LGE_NVDATA_SECTOR_SIZE];

	if(size <= 0)
		return LGE_NVDATA_EMMC_ERR_SIZE_TOO_SMALL;

	if(size > LGE_NVDATA_SECTOR_SIZE)
		return LGE_NVDATA_EMMC_ERR_SIZE_TOO_LARGE;

	start_sector_no = LGE_DYNAMIC_NVDATA_PARTITION_START_SECTOR + (int)(pos/LGE_NVDATA_SECTOR_SIZE);
	pos_in_sector = pos % LGE_NVDATA_SECTOR_SIZE;

	if(start_sector_no > LGE_DYNAMIC_NVDATA_PARTITION_LAST_SECTOR)
		return LGE_NVDATA_EMMC_ERR_SECTOR_MISMATCH;

	if(size+pos_in_sector > LGE_NVDATA_SECTOR_SIZE)
		return LGE_NVDATA_EMMC_ERR_ALIGN_MISMATCH;
	
	//mmc_init(1);
	// read nvdata partition
	mmc_read(1,start_sector_no,sector_buf,LGE_NVDATA_SECTOR_SIZE);

	memcpy(&(sector_buf[pos_in_sector]),buf,size);

	mmc_write(1,sector_buf,start_sector_no,LGE_NVDATA_SECTOR_SIZE);

	return size;
}
Ejemplo n.º 3
0
void cmd_flash_mmc(const char *arg, void *data, unsigned sz)
{
	unsigned long long ptn = 0;
	unsigned long long size = 0;

	ptn = mmc_ptn_offset(arg);
	if(ptn == 0) {
		fastboot_fail("partition table doesn't exist");
		return;
	}

	if (!strcmp(arg, "boot") || !strcmp(arg, "recovery")) {
		if (memcmp((void *)data, BOOT_MAGIC, BOOT_MAGIC_SIZE)) {
			fastboot_fail("image is not a boot image");
			return;
		}
	}

	size = mmc_ptn_size(arg);
	if (ROUND_TO_PAGE(sz,511) > size) {
		fastboot_fail("size too large");
		return;
	}

	if (mmc_write(ptn , sz, (unsigned int *)data)) {
		fastboot_fail("flash write failure");
		return;
	}
	fastboot_okay("");
	return;
}
static int mdss_dsi_dfps_store_pll_codes(struct msm_panel_info *pinfo)
{
	int ret = NO_ERROR;
	int index;
	unsigned long long ptn;

	index = partition_get_index("splash");
	if (index == INVALID_PTN) {
		dprintf(INFO, "%s: splash partition table not found\n", __func__);
		ret = NO_ERROR;
		goto store_err;
	}

	ptn = partition_get_offset(index);
	if (ptn == 0) {
		dprintf(CRITICAL, "ERROR: splash Partition invalid offset\n");
		ret = ERROR;
		goto store_err;
	}

	mmc_set_lun(partition_get_lun(index));

	ret = mmc_write(ptn, sizeof(uint32_t), &pinfo->dfps);
	if (ret)
		dprintf(CRITICAL, "mmc write failed!\n");

store_err:
	return ret;
}
Ejemplo n.º 5
0
DRESULT disk_write(BYTE drv, const BYTE *buff, DWORD sector, BYTE count) {
    #if CFG_HAVE_SDCARD == 1
    switch (drv) {
        case 0:
    #endif
            return dataflash_write(buff, sector, count);
    #if CFG_HAVE_SDCARD == 1
        case 1:
            return mmc_write(buff, sector, count);
        default:
            return RES_PARERR;
    }
    #endif
}
Ejemplo n.º 6
0
uint32_t fs_sd_write_sectors (uint32_t start_sector,
                              uint32_t n_sectors,
                              void *buffer)
{
    int status;

    status = mmc_write (sd, start_sector, n_sectors, (uint32_t*)buffer);
    if (MMC_OK == status) {
        return 0;
    }

    dprintf (CRITICAL, "fs_sd_write_sectors failed: s 0x%08x, n 0x%08x, status = %d\n",
             start_sector, n_sectors, status);

    return 1;
}
Ejemplo n.º 7
0
static int do_format(void)
{
	struct ptable *ptbl = &the_ptable;
	unsigned sector_sz, blocks;
	unsigned next;
	int n;

	printf("Formatting %s(%d) slot.\n", mmc_slot?"EMMC":"SD", mmc_slot);
	if (mmc_init(mmc_slot)) {
		printf("mmc init failed?\n");
		return -1;
	}

	mmc_info(mmc_slot, &sector_sz, &blocks);
	printf("blocks %d\n", blocks);

	start_ptbl(ptbl, blocks);
	n = 0;
	next = 0;
	for (n = 0, next = 0; partitions[n].name; n++) {
		unsigned sz = partitions[n].size_kb * 2;
		if (!strcmp(partitions[n].name,"-")) {
			next += sz;
			continue;
		}
		if (sz == 0)
			sz = blocks - next;
		if (add_ptn(ptbl, next, next + sz - 1, partitions[n].name))
			return -1;
		next += sz;
	}
	end_ptbl(ptbl);

	fastboot_flash_reset_ptn();
	if (mmc_write(mmc_slot, (void*) ptbl, 0, sizeof(struct ptable)) != 1)
		return -1;

	printf("\nnew partition table:\n");
	load_ptbl();

	return 0;
}
Ejemplo n.º 8
0
void cmd_erase_mmc(const char *arg, void *data, unsigned sz)
{
	unsigned long long ptn = 0;
	unsigned int out[512] = {0};

	ptn = mmc_ptn_offset(arg);
	if(ptn == 0) {
		fastboot_fail("partition table doesn't exist");
		return;
	}


	/* Simple inefficient version of erase. Just writing
	   0 in first block */
	if (mmc_write(ptn , 512, (unsigned int *)out)) {
		fastboot_fail("failed to erase partition");
		return;
	}
	fastboot_okay("");
}
static int emmc_set_recovery_msg(struct recovery_message *out)
{
	char *ptn_name = "misc";
	unsigned long long ptn = 0;
	unsigned int size = ROUND_TO_PAGE(sizeof(*out),511);
	unsigned char data[size];
	int index = INVALID_PTN;

	index = partition_get_index((unsigned char *) ptn_name);
	ptn = partition_get_offset(index);
	if(ptn == 0) {
		dprintf(CRITICAL,"partition %s doesn't exist\n",ptn_name);
		return -1;
	}
	memcpy(data, out, sizeof(*out));
	if (mmc_write(ptn , size, (unsigned int*)data)) {
		dprintf(CRITICAL,"mmc write failure %s %d\n",ptn_name, sizeof(*out));
		return -1;
	}
	return 0;
}
Ejemplo n.º 10
0
void memory_writeb(word address, byte data)
{
    // DMA transfer
    if (address == 0x4014) {
        for (int i = 0; i < 256; i++) {
            ppu_sprram_write(cpu_ram_read((0x100 * data) + i));
        }
        return;
    }
    switch (address >> 13) {
    case 0:
        return cpu_ram_write(address & 0x07FF, data);
    case 1:
        return ppu_io_write(address, data);
    case 2:
        return psg_io_write(address, data);
    case 3:
        return cpu_ram_write(address & 0x1FFF, data);
    default:
        return mmc_write(address, data);
    }
}
Ejemplo n.º 11
0
/* This function read the 1st bootmsg block and return the command which stores at
 * the begining of this block
 */
void bootmsg_write_command(const char* command)
{
    unsigned int   mmc_cont = 1;
    struct fastboot_ptentry *pte;

    pte = fastboot_flash_find_ptn(bootmsg_partition);
    if (!pte) 
    {
        printf("bootmsg_get_command: cannot find '%s' partition\n", bootmsg_partition);
    }

    /* read the 1st bootmsg block */ 
    mmc_read(mmc_cont, pte->start, bootmsg_1st_block, BOOTMSG_BLOCK_SIZE);

    /* Copy the new string */
    strncpy(bootmsg_1st_block, command, COMMAND_SIZE);

    /* Write it back */
    mmc_write(mmc_cont, bootmsg_1st_block, pte->start, BOOTMSG_BLOCK_SIZE);

    /* Ensure that command is null terminated */
    bootmsg_1st_block[COMMAND_SIZE-1] = '\0';
}
Ejemplo n.º 12
0
int write_misc(unsigned page_offset, void *buf, unsigned size)
{
	const char *ptn_name = "misc";
	void *scratch_addr = target_get_scratch_address();
	unsigned offset;
	unsigned aligned_size;

	if (size == 0 || buf == NULL || scratch_addr == NULL)
		return -1;

	if (target_is_emmc_boot())
	{
		int index;
		unsigned long long ptn;
		unsigned long long ptn_size;

		index = partition_get_index(ptn_name);
		if (index == INVALID_PTN)
		{
			dprintf(CRITICAL, "No '%s' partition found\n", ptn_name);
			return -1;
		}

		ptn = partition_get_offset(index);
		ptn_size = partition_get_size(index);

		offset = page_offset * BLOCK_SIZE;
		aligned_size = ROUND_TO_PAGE(size, (unsigned)BLOCK_SIZE - 1);
		if (ptn_size < offset + aligned_size)
		{
			dprintf(CRITICAL, "Write request out of '%s' boundaries\n",
					ptn_name);
			return -1;
		}

		if (scratch_addr != buf)
			memcpy(scratch_addr, buf, size);
		if (mmc_write(ptn + offset, aligned_size, (unsigned int *)scratch_addr))
		{
			dprintf(CRITICAL, "Writing MMC failed\n");
			return -1;
		}
	}
	else
	{
		struct ptentry *ptn;
		struct ptable *ptable;
		unsigned pagesize = flash_page_size();

		ptable = flash_get_ptable();
		if (ptable == NULL)
		{
			dprintf(CRITICAL, "Partition table not found\n");
			return -1;
		}

		ptn = ptable_find(ptable, ptn_name);
		if (ptn == NULL)
		{
			dprintf(CRITICAL, "No '%s' partition found\n", ptn_name);
			return -1;
		}

		offset = page_offset * pagesize;
		aligned_size = ROUND_TO_PAGE(size, pagesize - 1);
		if (ptn->length < offset + aligned_size)
		{
			dprintf(CRITICAL, "Write request out of '%s' boundaries\n",
					ptn_name);
			return -1;
		}

		if (scratch_addr != buf)
			memcpy(scratch_addr, buf, size);
		if (flash_write(ptn, offset, scratch_addr, aligned_size)) {
			dprintf(CRITICAL, "Writing flash failed\n");
			return -1;
		}
	}

	return 0;
}
Ejemplo n.º 13
0
static AvbIOResult mmc_byte_io(AvbOps *ops,
			       const char *partition,
			       s64 offset,
			       size_t num_bytes,
			       void *buffer,
			       size_t *out_num_read,
			       enum mmc_io_type io_type)
{
	ulong ret;
	struct mmc_part *part;
	u64 start_offset, start_sector, sectors, residue;
	u8 *tmp_buf;
	size_t io_cnt = 0;

	if (!partition || !buffer || io_type > IO_WRITE)
		return AVB_IO_RESULT_ERROR_IO;

	part = get_partition(ops, partition);
	if (!part)
		return AVB_IO_RESULT_ERROR_NO_SUCH_PARTITION;

	start_offset = calc_offset(part, offset);
	while (num_bytes) {
		start_sector = start_offset / part->info.blksz;
		sectors = num_bytes / part->info.blksz;
		/* handle non block-aligned reads */
		if (start_offset % part->info.blksz ||
		    num_bytes < part->info.blksz) {
			tmp_buf = get_sector_buf();
			if (start_offset % part->info.blksz) {
				residue = part->info.blksz -
					(start_offset % part->info.blksz);
				if (residue > num_bytes)
					residue = num_bytes;
			} else {
				residue = num_bytes;
			}

			if (io_type == IO_READ) {
				ret = mmc_read_and_flush(part,
							 part->info.start +
							 start_sector,
							 1, tmp_buf);

				if (ret != 1) {
					printf("%s: read error (%ld, %lld)\n",
					       __func__, ret, start_sector);
					return AVB_IO_RESULT_ERROR_IO;
				}
				/*
				 * if this is not aligned at sector start,
				 * we have to adjust the tmp buffer
				 */
				tmp_buf += (start_offset % part->info.blksz);
				memcpy(buffer, (void *)tmp_buf, residue);
			} else {
				ret = mmc_read_and_flush(part,
							 part->info.start +
							 start_sector,
							 1, tmp_buf);

				if (ret != 1) {
					printf("%s: read error (%ld, %lld)\n",
					       __func__, ret, start_sector);
					return AVB_IO_RESULT_ERROR_IO;
				}
				memcpy((void *)tmp_buf +
					start_offset % part->info.blksz,
					buffer, residue);

				ret = mmc_write(part, part->info.start +
						start_sector, 1, tmp_buf);
				if (ret != 1) {
					printf("%s: write error (%ld, %lld)\n",
					       __func__, ret, start_sector);
					return AVB_IO_RESULT_ERROR_IO;
				}
			}

			io_cnt += residue;
			buffer += residue;
			start_offset += residue;
			num_bytes -= residue;
			continue;
		}

		if (sectors) {
			if (io_type == IO_READ) {
				ret = mmc_read_and_flush(part,
							 part->info.start +
							 start_sector,
							 sectors, buffer);
			} else {
				ret = mmc_write(part,
						part->info.start +
						start_sector,
						sectors, buffer);
			}

			if (!ret) {
				printf("%s: sector read error\n", __func__);
				return AVB_IO_RESULT_ERROR_IO;
			}

			io_cnt += ret * part->info.blksz;
			buffer += ret * part->info.blksz;
			start_offset += ret * part->info.blksz;
			num_bytes -= ret * part->info.blksz;
		}
	}

	/* Set counter for read operation */
	if (io_type == IO_READ && out_num_read)
		*out_num_read = io_cnt;

	return AVB_IO_RESULT_OK;
}
Ejemplo n.º 14
0
int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
	ulong	addr, dest, count;
	int	size;

	if (argc != 4) {
		printf ("Usage:\n%s\n", cmdtp->usage);
		return 1;
	}

	/* Check for size specification.
	*/
	if ((size = cmd_get_data_size(argv[0], 4)) < 0)
		return 1;

	addr = simple_strtoul(argv[1], NULL, 16);
	addr += base_address;

	dest = simple_strtoul(argv[2], NULL, 16);
	dest += base_address;

	count = simple_strtoul(argv[3], NULL, 16);

	if (count == 0) {
		puts ("Zero length ???\n");
		return 1;
	}

#ifndef CFG_NO_FLASH
	/* check if we are copying to Flash */
	if ( (addr2info(dest) != NULL)
#ifdef CONFIG_HAS_DATAFLASH
	   && (!addr_dataflash(dest))
#endif
	   ) {
		int rc;

		puts ("Copy to Flash... ");

		rc = flash_write ((char *)addr, dest, count*size);
		if (rc != 0) {
			flash_perror (rc);
			return (1);
		}
		puts ("done\n");
		return 0;
	}
#endif

#if defined(CONFIG_CMD_MMC)
	if (mmc2info(dest)) {
		int rc;

		puts ("Copy to MMC... ");
		switch (rc = mmc_write ((uchar *)addr, dest, count*size)) {
		case 0:
			putc ('\n');
			return 1;
		case -1:
			puts ("failed\n");
			return 1;
		default:
			printf ("%s[%d] FIXME: rc=%d\n",__FILE__,__LINE__,rc);
			return 1;
		}
		puts ("done\n");
		return 0;
	}

	if (mmc2info(addr)) {
		int rc;

		puts ("Copy from MMC... ");
		switch (rc = mmc_read (addr, (uchar *)dest, count*size)) {
		case 0:
			putc ('\n');
			return 1;
		case -1:
			puts ("failed\n");
			return 1;
		default:
			printf ("%s[%d] FIXME: rc=%d\n",__FILE__,__LINE__,rc);
			return 1;
		}
		puts ("done\n");
		return 0;
	}
#endif

#ifdef CONFIG_HAS_DATAFLASH
	/* Check if we are copying from RAM or Flash to DataFlash */
	if (addr_dataflash(dest) && !addr_dataflash(addr)){
		int rc;

		puts ("Copy to DataFlash... ");

		rc = write_dataflash (dest, addr, count*size);

		if (rc != 1) {
			dataflash_perror (rc);
			return (1);
		}
		puts ("done\n");
		return 0;
	}

	/* Check if we are copying from DataFlash to RAM */
	if (addr_dataflash(addr) && !addr_dataflash(dest) && (addr2info(dest)==NULL) ){
		int rc;
		rc = read_dataflash(addr, count * size, (char *) dest);
		if (rc != 1) {
			dataflash_perror (rc);
			return (1);
		}
		return 0;
	}

	if (addr_dataflash(addr) && addr_dataflash(dest)){
		puts ("Unsupported combination of source/destination.\n\r");
		return 1;
	}
#endif

#ifdef CONFIG_BLACKFIN
	/* See if we're copying to/from L1 inst */
	if (addr_bfin_on_chip_mem(dest) || addr_bfin_on_chip_mem(addr)) {
		memcpy((void *)dest, (void *)addr, count * size);
		return 0;
	}
#endif

	while (count-- > 0) {
		if (size == 4)
			*((ulong  *)dest) = *((ulong  *)addr);
		else if (size == 2)
			*((ushort *)dest) = *((ushort *)addr);
		else
			*((u_char *)dest) = *((u_char *)addr);
		addr += size;
		dest += size;
	}
	return 0;
}
Ejemplo n.º 15
0
int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
	ulong	addr = 0, dest = 0, count = 0;
	int	size;

	if(!memcmp(argv[0],"cp.linux",sizeof("cp.linux")))
	{
/* 8M/16 flash:
 *  -write linux kernel and file system separately
 *  -kernel starts at PHYS_FLASH_1 and file system starts at PHYS_FLASH_2
 */
#if (defined (RT2880_ASIC_BOARD) || defined (RT2880_FPGA_BOARD) || defined (RT3052_MP1)) && (defined ON_BOARD_8M_FLASH_COMPONENT || defined ON_BOARD_16M_FLASH_COMPONENT)
		int rc;
		ulong kernsz = 0x3B0000;

		addr += base_address;
		addr += CFG_LOAD_ADDR;
		dest = dest + CFG_KERN_ADDR + base_address;
		if (NetBootFileXferSize <= kernsz)
			count = NetBootFileXferSize;
		else
			count = kernsz;
		size = 1;

		printf("\n Copy linux image[%d byte] to Flash[0x%08X].... \n",count,dest);
		puts ("Copy to Flash... ");
		printf ("\n Copy %d bytes to Flash... ", count);

		rc = flash_write ((uchar *)addr, dest, count);
		if (rc != 0) {
			flash_perror (rc);
			return (1);
		}
		if (count < kernsz)
			return 0;

		addr += kernsz;
		dest = PHYS_FLASH_2;
		count = NetBootFileXferSize - kernsz;
		printf("\n Copy linux file system[%d byte] to Flash[0x%08X].... \n",count,dest);
		puts ("Copy to Flash... ");
		printf ("\n Copy %d bytes to Flash... ", count);

		rc = flash_write ((uchar *)addr, dest, count);
		if (rc != 0) {
			flash_perror (rc);
			return (1);
		}

		puts ("done\n");
		return 0;
#endif
		addr += base_address;
		addr += CFG_LOAD_ADDR;
		dest = dest + CFG_KERN_ADDR + base_address;
		printf("\n Copy linux image[%d byte] to Flash[0x%08X].... \n",NetBootFileXferSize,dest);
		count = NetBootFileXferSize;
		size = 1;
		goto RT2880_START_WRITE_FLASH;
	}
/* flash layout remove cramfs, by bruce */
/*
	else if(!memcmp(argv[0],"cp.cramfs",sizeof("cp.cramfs")))
	{
		addr += base_address;
		addr += CFG_LOAD_ADDR;
		dest = dest + 0xBC530000 + base_address;
		printf("\n Copy File System image[%d byte] to Flash[0x%08X].... \n",NetBootFileXferSize,dest);
		
		count = NetBootFileXferSize;
		size = 1;
		goto RT2880_START_WRITE_FLASH;
	}
*/
	else if(!memcmp(argv[0],"cp.uboot",sizeof("cp.uboot")))
	{
		addr += base_address;
		addr += CFG_LOAD_ADDR;
		dest = dest + CFG_FLASH_BASE + base_address;
		printf("\n Copy uboot[%d byte] to Flash[0x%08X].... \n",NetBootFileXferSize,dest);
		
		count = NetBootFileXferSize;
		size = 1;
		goto RT2880_START_WRITE_FLASH;
	}
	
	if (argc != 4) {
		printf ("Usage:\n%s\n", cmdtp->usage);
		return 1;
	}
	
	/* Check for size specification. */
	if ((size = cmd_get_data_size(argv[0], 4)) < 0)
	{
		puts (" cmd error\n");
		return 1;
	}	

	addr = simple_strtoul(argv[1], NULL, 16);
	addr += base_address;

	dest = simple_strtoul(argv[2], NULL, 16);
	dest += base_address;

	count = simple_strtoul(argv[3], NULL, 16);

RT2880_START_WRITE_FLASH:
		
	if (count == 0) {
		puts ("Zero length ???\n");
		return 1;
	}

#ifndef CFG_NO_FLASH
	/* check if we are copying to Flash */
	if ( (addr2info(dest) != NULL)
#ifdef CONFIG_HAS_DATAFLASH
	   && (!addr_dataflash(addr))
#endif
	   ) {
		int rc;

		puts ("Copy to Flash... ");
		printf ("\n Copy %d byte to Flash... ",count*size);

		rc = flash_write ((uchar *)addr, dest, count*size);
		if (rc != 0) {
			flash_perror (rc);
			return (1);
		}
		puts ("done\n");
		return 0;
	}
#endif

#if (CONFIG_COMMANDS & CFG_CMD_MMC)
	if (mmc2info(dest)) {
		int rc;

		puts ("Copy to MMC... ");
		switch (rc = mmc_write ((uchar *)addr, dest, count*size)) {
		case 0:
			putc ('\n');
			return 1;
		case -1:
			puts ("failed\n");
			return 1;
		default:
			printf ("%s[%d] FIXME: rc=%d\n",__FILE__,__LINE__,rc);
			return 1;
		}
		puts ("done\n");
		return 0;
	}

	if (mmc2info(addr)) {
		int rc;

		puts ("Copy from MMC... ");
		switch (rc = mmc_read (addr, (uchar *)dest, count*size)) {
		case 0:
			putc ('\n');
			return 1;
		case -1:
			puts ("failed\n");
			return 1;
		default:
			printf ("%s[%d] FIXME: rc=%d\n",__FILE__,__LINE__,rc);
			return 1;
		}
		puts ("done\n");
		return 0;
	}
#endif

#ifdef CONFIG_HAS_DATAFLASH
	/* Check if we are copying from RAM or Flash to DataFlash */
	if (addr_dataflash(dest) && !addr_dataflash(addr)){
		int rc;

		puts ("Copy to DataFlash... ");

		rc = write_dataflash (dest, addr, count*size);

		if (rc != 1) {
			dataflash_perror (rc);
			return (1);
		}
		puts ("done\n");
		return 0;
	}

	/* Check if we are copying from DataFlash to RAM */
	if (addr_dataflash(addr) && !addr_dataflash(dest) && (addr2info(dest)==NULL) ){
		int rc;
		rc = read_dataflash(addr, count * size, (char *) dest);
		if (rc != 1) {
			dataflash_perror (rc);
			return (1);
		}
		return 0;
	}

	if (addr_dataflash(addr) && addr_dataflash(dest)){
		puts ("Unsupported combination of source/destination.\n\r");
		return 1;
	}
#endif

	while (count-- > 0) {
		if (size == 4)
			*((ulong  *)dest) = *((ulong  *)addr);
		else if (size == 2)
			*((ushort *)dest) = *((ushort *)addr);
		else
			*((u_char *)dest) = *((u_char *)addr);
		addr += size;
		dest += size;
	}
	return 0;
}
Ejemplo n.º 16
0
static unsigned long mmc_bwrite(int dev_num, unsigned long blknr,
		                       lbaint_t blkcnt, const ulong *src)
{
	return mmc_write(dev_num, (unsigned char*)src, blknr, blkcnt * MMCSD_SECTOR_SIZE);
}
Ejemplo n.º 17
0
int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
	ulong src_addr, dst_addr, size;
	char *cmd;
	/*Default Setting to SLOT-0*/
	int slot_no = 0, mmc_cont = 0;
    static used_slots[3] = {0};
	if (argc < 2) {
		goto mmc_cmd_usage;
	} else if (argc == 2) {
		if (strncmp(argv[0],"mmcinit",7) !=0) {
			goto mmc_cmd_usage;
		} else {
			slot_no = simple_strtoul(argv[1], NULL, 16);
			if ((slot_no != 0) && (slot_no != 1))
				goto mmc_cmd_usage;
			if (used_slots[slot_no]==0) {
				/*Initialized... slot if never initialized*/
				used_slots[slot_no]=1;
			    if (mmc_init(slot_no) != 0) {
					printf("No MMC card found\n");
					return 1;
			    } else {
					mmc_flag[slot_no] = 1;
			    }
			}
		}
	} else {
		mmc_cont = simple_strtoul(argv[1], NULL, 16);
		if ((mmc_cont != 0) && (mmc_cont != 1))
			goto mmc_cmd_usage;

		if (!mmc_flag[mmc_cont]) {
			printf("Try to do init First b4 read/write\n");
			goto mmc_cmd_usage;
		}

		cmd = argv[2];

		if (strcmp(cmd, "erase") == 0) {
			if (argc != 5) {
				goto mmc_cmd_usage;
			} else {
				src_addr = simple_strtoul(argv[3], NULL, 16);
				size = simple_strtoul(argv[4], NULL, 16);
				mmc_erase(mmc_cont, src_addr, size);
			}

		} else if (strcmp(cmd, "read") == 0) {
			if (argc != 6) {
                                goto mmc_cmd_usage;
                        } else {
				src_addr = simple_strtoul(argv[3], NULL, 16);
				dst_addr = simple_strtoul(argv[4], NULL, 16);
				size = simple_strtoul(argv[5], NULL, 16);
				mmc_read(mmc_cont, src_addr,
					(unsigned char *)dst_addr, size);
			}

		} else if (strcmp(cmd, "write") == 0) {
			if (argc != 6) {
				goto mmc_cmd_usage;
			} else {
				src_addr = simple_strtoul(argv[3], NULL, 16);
				dst_addr = simple_strtoul(argv[4], NULL, 16);
				size = simple_strtoul(argv[5], NULL, 16);
				mmc_write(mmc_cont, (unsigned char *)src_addr,
							dst_addr, size);
			}

		} else if (strcmp(cmd,"part") == 0) {
			mmc_part(mmc_cont);

		} else
			goto mmc_cmd_usage;
	}
	return 0;

mmc_cmd_usage:
	printf("Usage:\n%s\n", cmdtp->usage);
	return 1;
}
Ejemplo n.º 18
0
int do_mem_cp ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
	ulong	addr, dest, count;
	int	size;

	if (argc != 4) {
		printf ("Usage:\n%s\n", cmdtp->usage);
		return 1;
	}

	/* Check for size specification.
	*/
	if ((size = cmd_get_data_size(argv[0], 4)) < 0)
		return 1;

	addr = simple_strtoul(argv[1], NULL, 16);
	addr += base_address;

	dest = simple_strtoul(argv[2], NULL, 16);
	dest += base_address;

	count = simple_strtoul(argv[3], NULL, 16);

	if (count == 0) {
		puts ("Zero length ???\n");
		return 1;
	}

#ifndef CFG_NO_FLASH
	/* check if we are copying to Flash */
	if ( (addr2info(dest) != NULL)
#ifdef CONFIG_HAS_DATAFLASH
	   && (!addr_dataflash(addr))
#endif
	   ) {
		int rc;

		puts ("Copy to Flash... ");
#if defined(CONFIG_MARVELL)
		/* If source addr is flash copy data to memory first */
		if (addr2info(addr) != NULL)
		{       char* tmp_buff;
			int i;
			if (NULL == (tmp_buff = malloc(count*size)))
			{
				puts (" Copy fail, NULL pointer buffer\n");
				return (1);
			}
			for( i = 0 ; i < (count*size); i++)
				*(tmp_buff + i) = *((char *)addr + i);

			rc = flash_write (tmp_buff, dest, count*size);
			free(tmp_buff);
		}
		else
#endif /* defined(CONFIG_MARVELL) */
			rc = flash_write ((char *)addr, dest, count*size);

		if (rc != 0) {
			flash_perror (rc);
			return (1);
		}
		puts ("done\n");
		return 0;
	}
#endif

#if (CONFIG_COMMANDS & CFG_CMD_MMC)
	if (mmc2info(dest)) {
		int rc;

		puts ("Copy to MMC... ");
		switch (rc = mmc_write ((uchar *)addr, dest, count*size)) {
		case 0:
			putc ('\n');
			return 1;
		case -1:
			puts ("failed\n");
			return 1;
		default:
			printf ("%s[%d] FIXME: rc=%d\n",__FILE__,__LINE__,rc);
			return 1;
		}
		puts ("done\n");
		return 0;
	}

	if (mmc2info(addr)) {
		int rc;

		puts ("Copy from MMC... ");
		switch (rc = mmc_read (addr, (uchar *)dest, count*size)) {
		case 0:
			putc ('\n');
			return 1;
		case -1:
			puts ("failed\n");
			return 1;
		default:
			printf ("%s[%d] FIXME: rc=%d\n",__FILE__,__LINE__,rc);
			return 1;
		}
		puts ("done\n");
		return 0;
	}
#endif

#ifdef CONFIG_HAS_DATAFLASH
	/* Check if we are copying from RAM or Flash to DataFlash */
	if (addr_dataflash(dest) && !addr_dataflash(addr)){
		int rc;

		puts ("Copy to DataFlash... ");

		rc = write_dataflash (dest, addr, count*size);

		if (rc != 1) {
			dataflash_perror (rc);
			return (1);
		}
		puts ("done\n");
		return 0;
	}

	/* Check if we are copying from DataFlash to RAM */
	if (addr_dataflash(addr) && !addr_dataflash(dest) && (addr2info(dest)==NULL) ){
		int rc;
		rc = read_dataflash(addr, count * size, (char *) dest);
		if (rc != 1) {
			dataflash_perror (rc);
			return (1);
		}
		return 0;
	}

	if (addr_dataflash(addr) && addr_dataflash(dest)){
		puts ("Unsupported combination of source/destination.\n\r");
		return 1;
	}
#endif

	while (count-- > 0) {
		if (size == 4)
			*((ulong  *)dest) = *((ulong  *)addr);
		else if (size == 2)
			*((ushort *)dest) = *((ushort *)addr);
		else
			*((u_char *)dest) = *((u_char *)addr);
		addr += size;
		dest += size;
	}
	return 0;
}
Ejemplo n.º 19
0
int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
	ulong src_addr, dst_addr, size;
	char *cmd;
	/*Default Setting to SLOT-0*/
	int slot_no = 0, mmc_cont = 0;

	if (argc < 2) {
		goto mmc_cmd_usage;
	} else if (argc == 2) {
		if (strncmp(argv[0], "mmcinit", 7) != 0) {
			goto mmc_cmd_usage;
		} else {
			slot_no = simple_strtoul(argv[1], NULL, 16);
			if ((slot_no != 0) && (slot_no != 1))
				goto mmc_cmd_usage;
			if (mmc_init(slot_no) != 0) {
				printf("No MMC card found\n");
				return 1;
			} else {
				mmc_flag[slot_no] = 1;
				printf("MMC%d Initalization OK\n", slot_no);
			}
		}
	} else {
		if ((strncmp(argv[0], "mmc", 3)==0) && (strncmp(argv[1], "init", 4)==0)) {
			slot_no = simple_strtoul(argv[2], NULL, 16);
			if ((slot_no != 0) && (slot_no != 1))
				goto mmc_cmd_usage;
			if (mmc_init(slot_no) != 0) {
				printf("No MMC card found\n");
				return 1;
			} else {
				mmc_flag[slot_no] = 1;
				printf("MMC%d Initalization OK\n", slot_no);
			}
			return 0;
		}	
	
		mmc_cont = simple_strtoul(argv[1], NULL, 16);
		if ((mmc_cont != 0) && (mmc_cont != 1))
			goto mmc_cmd_usage;

		if (!mmc_flag[mmc_cont]) {
			printf("Try to do init First b4 read/write\n");
			goto mmc_cmd_usage;
		}

		cmd = argv[2];
		if (strncmp(cmd, "read", 4) != 0 && strncmp(cmd, "write", 5) != 0
					&& strncmp(cmd, "erase", 5) != 0)
			goto mmc_cmd_usage;

		if (strcmp(cmd, "erase") == 0) {
			if (argc != 5) {
				goto mmc_cmd_usage;
			} else {
				src_addr = simple_strtoul(argv[3], NULL, 16);
				size = simple_strtoul(argv[4], NULL, 16);
				mmc_erase(mmc_cont, src_addr, size);
			}
		}
		if (strcmp(cmd, "read") == 0) {
			if (argc != 6) {
				goto mmc_cmd_usage;
			} else {
				dst_addr = simple_strtoul(argv[3], NULL, 16);
				src_addr = simple_strtoul(argv[4], NULL, 16);
				size = simple_strtoul(argv[5], NULL, 16);
				//printf("mmc_cont=%d,src_addr=0x%x,dst_addr=0x%x,size=0x%x\n", mmc_cont,src_addr,dst_addr,size);
				mmc_read(mmc_cont, src_addr,
					(unsigned char *)dst_addr, size);
			}
		}
		if (strcmp(cmd, "write") == 0) {
			if (argc != 6) {
				goto mmc_cmd_usage;
			} else {
				src_addr = simple_strtoul(argv[3], NULL, 16);
				dst_addr = simple_strtoul(argv[4], NULL, 16);
				size = simple_strtoul(argv[5], NULL, 16);
				//printf("mmc_cont=%d,src_addr=0x%x,dst_addr=0x%x,size=0x%x\n", mmc_cont,src_addr,dst_addr,size);
				
				mmc_write(mmc_cont, (unsigned char *)src_addr,
							dst_addr, size);
			}
		}
	}
	return 0;

mmc_cmd_usage:
	printf("Usage:\n%s\n", cmdtp->usage);
	return 1;
}