Exemple #1
0
static int aduc702x_erase(struct flash_bank *bank, int first, int last)
{
        //int res;
	int x;
	int count;
	//uint32_t v;
	struct target *target = bank->target;

        aduc702x_set_write_enable(target, 1);

	/* mass erase */
	if (((first | last) == 0) || ((first == 0) && (last >= bank->num_sectors))) {
		LOG_DEBUG("performing mass erase.\n");
		target_write_u16(target, ADUC702x_FLASH + ADUC702x_FLASH_FEEDAT, 0x3cff);
		target_write_u16(target, ADUC702x_FLASH + ADUC702x_FLASH_FEEADR, 0xffc3);
		target_write_u8(target, ADUC702x_FLASH + ADUC702x_FLASH_FEECON, 0x06);

                if (aduc702x_check_flash_completion(target, 3500) != ERROR_OK)
		{
			LOG_ERROR("mass erase failed\n");
                        aduc702x_set_write_enable(target, 0);
			return ERROR_FLASH_OPERATION_FAILED;
		}

		LOG_DEBUG("mass erase successful.\n");
		return ERROR_OK;
	} else {
                unsigned long adr;

                count = last - first + 1;
                for (x = 0; x < count; ++x)
                {
                        adr = bank->base + ((first + x) * 512);

                        target_write_u16(target, ADUC702x_FLASH + ADUC702x_FLASH_FEEADR, adr);
                        target_write_u8(target, ADUC702x_FLASH + ADUC702x_FLASH_FEECON, 0x05);

                        if (aduc702x_check_flash_completion(target, 50) != ERROR_OK)
                        {
                                LOG_ERROR("failed to erase sector at address 0x%08lX\n", adr);
                                aduc702x_set_write_enable(target, 0);
                                return ERROR_FLASH_SECTOR_NOT_ERASED;
                        }

                        LOG_DEBUG("erased sector at address 0x%08lX\n", adr);
                }
        }

        aduc702x_set_write_enable(target, 0);

	return ERROR_OK;
}
Exemple #2
0
int s3c2440_write_block_data(struct nand_device *nand, uint8_t *data, int data_size)
{
	struct s3c24xx_nand_controller *s3c24xx_info = nand->controller_priv;
	struct target *target = nand->target;
	uint32_t nfdata = s3c24xx_info->data;
	uint32_t tmp;

	if (target->state != TARGET_HALTED) {
		LOG_ERROR("target must be halted to use S3C24XX NAND flash controller");
		return ERROR_NAND_OPERATION_FAILED;
	}

	while (data_size >= 4) {
		tmp = le_to_h_u32(data);
		target_write_u32(target, nfdata, tmp);

		data_size -= 4;
		data += 4;
	}

	while (data_size > 0) {
		target_write_u8(target, nfdata, *data);

		data_size -= 1;
		data += 1;
	}

	return ERROR_OK;
}
/* write a byte (8bit) from the pc to the netx */
int fn_write_data08(void *pvHandle, unsigned long ulNetxAddress, unsigned char ucData)
{
	command_context_t *cmd_ctx;
	target_t *target;
	int iResult;


	/* cast the handle to the command context */
	cmd_ctx = (command_context_t*)pvHandle;

	/* get the target from the command context */
	target = get_current_target(cmd_ctx);

	/* read the data from the netX */
	iResult = target_write_u8(target, ulNetxAddress, ucData);
	if( iResult==ERROR_OK )
	{
		iResult = 0;
	}
	else
	{
		iResult = 1;
	}

	wxMilliSleep(1);

	return iResult;
}
Exemple #4
0
/**
 * Write data directly to the NAND device attached to an AT91SAM9 NAND
 * controller.
 *
 * @param nand NAND device to be written to.
 * @param data Data to be written.
 * @return Success or failure of the data write.
 */
static int at91sam9_write_data(struct nand_device *nand, uint16_t data)
{
	struct at91sam9_nand *info = nand->controller_priv;
	struct target *target = nand->target;

	if (!at91sam9_halted(target, "write data"))
		return ERROR_NAND_OPERATION_FAILED;

	return target_write_u8(target, info->data, data);
}
Exemple #5
0
/**
 * Send an address to the NAND device attached to an AT91SAM9 NAND controller.
 *
 * @param nand NAND device to send the address to.
 * @param address Address to be sent.
 * @return Success or failure of sending the address.
 */
static int at91sam9_address(struct nand_device *nand, uint8_t address)
{
	struct at91sam9_nand *info = nand->controller_priv;
	struct target *target = nand->target;

	if (!at91sam9_halted(nand->target, "address"))
		return ERROR_NAND_OPERATION_FAILED;

	return target_write_u8(target, info->addr, address);
}
Exemple #6
0
static int nuc910_nand_write(struct nand_device *nand, uint16_t data)
{
	struct target *target = nand->target;
	int result;

	if ((result = validate_target_state(nand)) != ERROR_OK)
		return result;

	target_write_u8(target, NUC910_SMDATA, data);
	return ERROR_OK;
}
Exemple #7
0
static int nuc910_nand_command(struct nand_device *nand, uint8_t command)
{
	struct target *target = nand->target;
	int result;

	if ((result = validate_target_state(nand)) != ERROR_OK)
		return result;

	target_write_u8(target, NUC910_SMCMD, command);
	return ERROR_OK;
}
Exemple #8
0
/**
 * Send a command to the NAND device.
 *
 * @param nand NAND device to write the command to.
 * @param command Command to be written.
 * @return Success or failure of writing the command.
 */
static int at91sam9_command(struct nand_device *nand, uint8_t command)
{
	struct at91sam9_nand *info = nand->controller_priv;
	struct target *target = nand->target;

	if (!at91sam9_halted(target, "command"))
		return ERROR_NAND_OPERATION_FAILED;

	at91sam9_enable(nand);

	return target_write_u8(target, info->cmd, command);
}
Exemple #9
0
int s3c24xx_write_data(struct nand_device *nand, uint16_t data)
{
	struct s3c24xx_nand_controller *s3c24xx_info = nand->controller_priv;
	struct target *target = nand->target;

	if (target->state != TARGET_HALTED) {
		LOG_ERROR("target must be halted to use S3C24XX NAND flash controller");
		return ERROR_NAND_OPERATION_FAILED;
	}

	target_write_u8(target, s3c24xx_info->data, data);
	return ERROR_OK;
}
Exemple #10
0
/* All-JTAG, single-access method.  Very slow.  Used only if there is no
 * working area available. */
static int aduc702x_write_single(struct flash_bank *bank,
	const uint8_t *buffer,
	uint32_t offset,
	uint32_t count)
{
	uint32_t x;
	uint8_t b;
	struct target *target = bank->target;

	aduc702x_set_write_enable(target, 1);

	for (x = 0; x < count; x += 2) {
		/* FEEADR = address */
		target_write_u16(target, ADUC702x_FLASH + ADUC702x_FLASH_FEEADR, offset + x);

		/* set up data */
		if ((x + 1) == count) {
			/* last byte */
			target_read_u8(target, offset + x + 1, &b);
		} else
			b = buffer[x + 1];

		target_write_u16(target, ADUC702x_FLASH + ADUC702x_FLASH_FEEDAT, buffer[x] | (b << 8));

		/* do single-write command */
		target_write_u8(target, ADUC702x_FLASH + ADUC702x_FLASH_FEECON, 0x02);

		if (aduc702x_check_flash_completion(target, 1) != ERROR_OK) {
			LOG_ERROR("single write failed for address 0x%08lX",
				(unsigned long)(offset + x));
			aduc702x_set_write_enable(target, 0);
			return ERROR_FLASH_OPERATION_FAILED;
		}

	}
	LOG_DEBUG("wrote %d bytes at address 0x%08lX", (int)count, (unsigned long)(offset + x));

	aduc702x_set_write_enable(target, 0);

	return ERROR_OK;
}