* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include "flash.h"
#include "command.h"
#include "log.h"
#include "target.h"
+#include "time_support.h"
#include <string.h>
#include <unistd.h>
u32 buf_cnt;
int retval;
flash_bank_t *p;
+ struct timeval start, end, duration;
+ gettimeofday(&start, NULL);
+
if (argc < 3)
{
command_print(cmd_ctx, "usage: flash write <bank> <file> <offset>");
return ERROR_OK;
}
- if (!(binary = fopen(args[1], "r")))
+ if (!(binary = fopen(args[1], "rb")))
{
ERROR("couldn't open %s: %s", args[1], strerror(errno));
command_print(cmd_ctx, "couldn't open %s", args[1]);
if ((retval = p->driver->write(p, buffer, offset, buf_cnt)) != ERROR_OK)
{
+ command_print(cmd_ctx, "failed writing file %s to flash bank %i at offset 0x%8.8x",
+ args[1], strtoul(args[0], NULL, 0), strtoul(args[2], NULL, 0));
switch (retval)
{
case ERROR_TARGET_NOT_HALTED:
command_print(cmd_ctx, "unknown error");
}
}
+ else
+ {
+ gettimeofday(&end, NULL);
+ timeval_subtract(&duration, &end, &start);
+
+ command_print(cmd_ctx, "wrote file %s to flash bank %i at offset 0x%8.8x in %is %ius", args[1], strtoul(args[0], NULL, 0), strtoul(args[2], NULL, 0), duration.tv_sec, duration.tv_usec);
+ }
+
free(buffer);
fclose(binary);
- command_print(cmd_ctx, "wrote file %s to flash bank %i at offset 0x%8.8x", args[1], strtoul(args[0], NULL, 0), strtoul(args[2], NULL, 0));
-
return ERROR_OK;
-
}