Replace the big stack-allocated buffer with a much bigger heap-allocated.
There was no explanation for the apparently arbitrary chunk size, and
performance was improved by increasing it, leveling out at about 4k.
Change-Id: I3b06d4469092ec8d89d0ce05bff0b7cf213c5062
Signed-off-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Reviewed-on: http://openocd.zylin.com/404
Tested-by: jenkins
Reviewed-by: Marti Bolivar <mbolivar@leaflabs.com>
Reviewed-by: Øyvind Harboe <oyvindharboe@gmail.com>
COMMAND_HANDLER(handle_dump_image_command)
{
struct fileio fileio;
COMMAND_HANDLER(handle_dump_image_command)
{
struct fileio fileio;
int retval, retvaltemp;
uint32_t address, size;
struct duration bench;
int retval, retvaltemp;
uint32_t address, size;
struct duration bench;
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], address);
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], size);
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], address);
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], size);
+ uint32_t buf_size = (size > 4096) ? 4096 : size;
+ buffer = malloc(buf_size);
+ if (!buffer)
+ return ERROR_FAIL;
+
retval = fileio_open(&fileio, CMD_ARGV[0], FILEIO_WRITE, FILEIO_BINARY);
retval = fileio_open(&fileio, CMD_ARGV[0], FILEIO_WRITE, FILEIO_BINARY);
- if (retval != ERROR_OK)
+ if (retval != ERROR_OK) {
+ free(buffer);
while (size > 0)
{
size_t size_written;
while (size > 0)
{
size_t size_written;
- uint32_t this_run_size = (size > 560) ? 560 : size;
+ uint32_t this_run_size = (size > buf_size) ? buf_size : size;
retval = target_read_buffer(target, address, this_run_size, buffer);
if (retval != ERROR_OK)
{
retval = target_read_buffer(target, address, this_run_size, buffer);
if (retval != ERROR_OK)
{
address += this_run_size;
}
address += this_run_size;
}
if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK))
{
int filesize;
if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK))
{
int filesize;