Example #1
0
static vsf_err_t nuc100swj_iap_poll_finish(struct nuc100_fl_t *fl)
{
	uint32_t iap_cnt, iap_fail;
	
	// read fail
	if (adi_memap_read_reg32(NUC100_IAP_FAIL_ADDR, &iap_fail, 1))
	{
		LOG_ERROR(ERRMSG_FAILURE_OPERATION, "read iap fail");
		return ERRCODE_FAILURE_OPERATION;
	}
	if (iap_fail)
	{
		LOG_ERROR(ERRMSG_FAILURE_OPERATION, "run iap");
		cm_dump(NUC100_IAP_BASE, sizeof(iap_code));
		return VSFERR_FAIL;
	}
	
	// read busy
	if (adi_memap_read_reg32(NUC100_IAP_CNT_ADDR, &iap_cnt, 1))
	{
		LOG_ERROR(ERRMSG_FAILURE_OPERATION, "read iap sync");
		return ERRCODE_FAILURE_OPERATION;
	}
	iap_cnt = LE_TO_SYS_U32(iap_cnt);
	if (iap_cnt > fl->iap_cnt)
	{
		cm_dump(NUC100_IAP_BASE, sizeof(iap_code));
		return VSFERR_FAIL;
	}
	return (iap_cnt == fl->iap_cnt) ? VSFERR_NONE : VSFERR_NOT_READY;
}
Example #2
0
static vsf_err_t nuc400swj_iap_wait_finish(struct nuc400_fl_t *fl)
{
	vsf_err_t err;
	uint32_t start, end;
	
	if (!fl->iap_busy)
	{
		return VSFERR_NONE;
	}
	
	start = interfaces->tickclk.get_count();
	while (1)
	{
		err = nuc400swj_iap_poll_finish(fl);
		if (!err)
		{
			break;
		}
		if (err < 0)
		{
			LOG_ERROR(ERRMSG_FAILURE_OPERATION, "poll iap finish");
			return VSFERR_FAIL;
		}
		end = interfaces->tickclk.get_count();
		// wait 1s at most
		if ((end - start) > 1000)
		{
			cm_dump(NUC400_IAP_BASE, sizeof(iap_code));
			LOG_ERROR(ERRMSG_TIMEOUT, "wait for iap finish");
			return ERRCODE_FAILURE_OPERATION;
		}
	}
	
	return VSFERR_NONE;
}
Example #3
0
static vsf_err_t at91sam3swj_iap_wait_ready(struct at91sam3swj_iap_reply_t *reply)
{
	vsf_err_t err;
	uint32_t start, end;
	
	start = (uint32_t)(clock() / (CLOCKS_PER_SEC / 1000));
	while (1)
	{
		err = at91sam3swj_iap_poll_result(reply);
		if (!err)
		{
			break;
		}
		if (err < 0)
		{
			LOG_ERROR(ERRMSG_FAILURE_OPERATION, "poll iap result");
			return VSFERR_FAIL;
		}
		end = (uint32_t)(clock() / (CLOCKS_PER_SEC / 1000));
		
		// wait 1s at most
		if ((end - start) > 1000)
		{
			cm_dump(AT91SAM3_IAP_BASE, sizeof(iap_code) + 256);
			LOG_ERROR(ERRMSG_TIMEOUT, "wait for iap ready");
			return ERRCODE_FAILURE_OPERATION;
		}
	}
	
	return VSFERR_NONE;
}
Example #4
0
vsf_err_t stm32swj_fl_wait_ready(struct stm32_fl_t *fl,
								struct stm32_fl_result_t *result, bool last)
{
	vsf_err_t err;
	uint32_t start, end;
	
	start = interfaces->tickclk.get_count();
	while (1)
	{
		err = stm32swj_fl_poll_result(fl, result);
		if (!err && (!last || (result->result == fl->cnt)))
		{
			break;
		}
		if (err < 0)
		{
			LOG_ERROR(ERRMSG_FAILURE_OPERATION, "poll flashloader result");
			return VSFERR_FAIL;
		}
		end = interfaces->tickclk.get_count();
		// wait 20s at most
		if ((end - start) > 20000)
		{
			cm_dump(fl->base, sizeof(fl_code));
			LOG_ERROR(ERRMSG_TIMEOUT, "wait for flashloader ready");
			return ERRCODE_FAILURE_OPERATION;
		}
	}
	
	return VSFERR_NONE;
}
Example #5
0
static vsf_err_t at91sam3swj_iap_poll_result(struct at91sam3swj_iap_reply_t *reply)
{
	uint32_t buff_tmp[256 + 4];
	uint32_t data_size;
	
	if (NULL == fail)
	{
		LOG_BUG(ERRMSG_INVALID_PARAMETER, __FUNCTION__);
		return VSFERR_INVALID_PARAMETER;
	}
	
	if ((reply != NULL) && (reply->data_num > (dimof(buff_tmp) - 1)))
	{
		LOG_BUG("buff size is not enough for this call.");
		return VSFERR_FAIL;
	}
	
	data_size = 4;
	if (reply != NULL)
	{
		data_size = (1 + reply->data_num) * sizeof(uint32_t);
	}
	
	// read result and sync
	// sync is 4-byte BEFORE result
	if (adi_memap_read_buf(AT91SAM3_IAP_SYNC_ADDR,
										(uint8_t *)buff_tmp, data_size))
	{
		LOG_ERROR(ERRMSG_FAILURE_OPERATION, "read iap sync");
		return ERRCODE_FAILURE_OPERATION;
	}
	// buff_tmp[0] is sync, which is eefc_frr
	if (buff_tmp[0] != 0)
	{
		if (buff_tmp[0] != 1)
		{
			cm_dump(AT91SAM3_IAP_BASE, sizeof(iap_code) + 256);
			LOG_ERROR(ERRMSG_FAILURE_OPERATION_ERRCODE, "call iap",
						buff_tmp[1]);
			return ERRCODE_FAILURE_OPERATION;
		}
		
		if ((reply != NULL) && (reply->data != NULL))
		{
			memcpy(reply->data, &buff_tmp[1],
					reply->data_num * sizeof(uint32_t));
		}
		return VSFERR_NONE;
	}
	
	return VSFERR_NOT_READY;
}
Example #6
0
static vsf_err_t kinetisswj_iap_wait_ready(struct kinetis_fl_t *fl,
								struct kinetisswj_iap_rpl_t *reply, bool last)
{
	vsf_err_t err;
	uint32_t start, end;
	
	start = (uint32_t)(clock() / (CLOCKS_PER_SEC / 1000));
	while (1)
	{
		err = kinetisswj_iap_poll_result(fl, reply);
		if (!err && (!last || (reply->iap_cnt == fl->iap_cnt)))
		{
			if (reply->fail != 0)
			{
				LOG_ERROR(ERRMSG_FAILURE_OPERATION_ERRCODE, "run iap",
													reply->fail);
				return VSFERR_FAIL;
			}
			return VSFERR_NONE;
		}
		if (err < 0)
		{
			LOG_ERROR(ERRMSG_FAILURE_OPERATION, "poll iap result");
			return VSFERR_FAIL;
		}
		end = (uint32_t)(clock() / (CLOCKS_PER_SEC / 1000));
		// wait 1s at most
		if ((end - start) > 1000)
		{
			cm_dump(KINETIS_IAP_BASE, sizeof(iap_code));
			LOG_ERROR(ERRMSG_TIMEOUT, "wait for iap ready");
			return ERRCODE_FAILURE_OPERATION;
		}
	}
	
	return VSFERR_NONE;
}