int status_code;
int i;
working_area_t *download_area;
- int retval = ERROR_OK;
+ int retval = ERROR_OK;
if (bank->target->state != TARGET_HALTED)
{
return ERROR_TARGET_NOT_HALTED;
}
-
- /* allocate a working area */
- if (target_alloc_working_area(target, lpc2000_info->cmd51_max_buffer, &download_area) != ERROR_OK)
- {
- LOG_ERROR("no working area specified, can't write LPC2000 internal flash");
- return ERROR_FLASH_OPERATION_FAILED;
- }
if (offset + count > bank->size)
- {
- retval = ERROR_FLASH_DST_OUT_OF_BANK;
- goto cleanup_working_area;
- }
-
+ return ERROR_FLASH_DST_OUT_OF_BANK;
+
if (lpc2000_info->cmd51_can_256b)
dst_min_alignment = 256;
else
if (offset % dst_min_alignment)
{
LOG_WARNING("offset 0x%x breaks required alignment 0x%x", offset, dst_min_alignment);
- retval = ERROR_FLASH_DST_BREAKS_ALIGNMENT;
- goto cleanup_working_area;
+ return ERROR_FLASH_DST_BREAKS_ALIGNMENT;
}
for (i = 0; i < bank->num_sectors; i++)
buf_set_u32(buffer + 0x14, 0, 32, checksum);
}
+ /* allocate a working area */
+ if (target_alloc_working_area(target, lpc2000_info->cmd51_max_buffer, &download_area) != ERROR_OK)
+ {
+ LOG_ERROR("no working area specified, can't write LPC2000 internal flash");
+ return ERROR_FLASH_OPERATION_FAILED;
+ }
+
while (bytes_remaining > 0)
{
u32 thisrun_bytes;
{
case ERROR_FLASH_OPERATION_FAILED:
retval = ERROR_FLASH_OPERATION_FAILED;
- break;
+ break;
case LPC2000_CMD_SUCCESS:
break;
case LPC2000_INVALID_SECTOR:
default:
LOG_WARNING("lpc2000 prepare sectors returned %i", status_code);
retval = ERROR_FLASH_OPERATION_FAILED;
- break;
+ break;
}
- /* Exit if error occured */
- if (retval != ERROR_OK)
- goto cleanup_working_area;
+ /* Exit if error occured */
+ if (retval != ERROR_OK)
+ break;
if (bytes_remaining >= thisrun_bytes)
{
- if (retval = target_write_buffer(bank->target, download_area->address, thisrun_bytes, buffer + bytes_written) != ERROR_OK)
+ if ((retval = target_write_buffer(bank->target, download_area->address, thisrun_bytes, buffer + bytes_written)) != ERROR_OK)
{
- goto cleanup_working_area;
+ retval = ERROR_FLASH_OPERATION_FAILED;
+ break;
}
}
else
{
case ERROR_FLASH_OPERATION_FAILED:
retval = ERROR_FLASH_OPERATION_FAILED;
- break;
+ break;
case LPC2000_CMD_SUCCESS:
break;
case LPC2000_INVALID_SECTOR:
default:
LOG_WARNING("lpc2000 returned %i", status_code);
retval = ERROR_FLASH_OPERATION_FAILED;
- break;
+ break;
}
- /* Exit if error occured */
- if (retval != ERROR_OK)
- goto cleanup_working_area;
-
+ /* Exit if error occured */
+ if (retval != ERROR_OK)
+ break;
+
if (bytes_remaining > thisrun_bytes)
bytes_remaining -= thisrun_bytes;
else
bytes_remaining = 0;
bytes_written += thisrun_bytes;
}
-
- cleanup_working_area:
+
target_free_working_area(target, download_area);
return retval;
if ((retval = target->type->run_algorithm(target, 0, NULL, 4, reg_params, str9x_info->write_algorithm->address, str9x_info->write_algorithm->address + (18 * 4), 10000, &armv4_5_info)) != ERROR_OK)
{
- target_free_working_area(target, source);
- target_free_working_area(target, str9x_info->write_algorithm);
LOG_ERROR("error executing str9x flash write algorithm");
+ retval = ERROR_FLASH_OPERATION_FAILED;
break;
}
if (buf_get_u32(reg_params[3].value, 0, 32) != 0x80)
{
retval = ERROR_FLASH_OPERATION_FAILED;
- break;
+ break;
}
buffer += thisrun_count * 2;