2011-08-20 23:32 keltezéssel, Mike Frysinger írta:
On Sunday, August 07, 2011 07:48:27 Márton Miklós wrote:
The flash programming speed can be improved by skipping the write
of the
blocks which contains only 0xFF.
I have added time measuring feature to the flashing rutine.
in general i like the idea, but i think it needs to be optional
rather than
always skipping 0xFF bytes.
optional +1
-mike
Please recommend an argument name to the flashmem command.
I would vote on a boolean argument called fastwrite.
I have implemented this, the attached patch adds a fastwrite argument to
the flashmem command.
Regards,
Miklós
Index: src/flash/flash.c
===================================================================
--- src/flash/flash.c (revision 2003)
+++ src/flash/flash.c (working copy)
@@ -39,6 +39,7 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+#include <time.h>
#include <urjtag/error.h>
#include <urjtag/log.h>
@@ -108,7 +109,7 @@
} while (0)
int
-urj_flashmsbin (urj_bus_t *bus, FILE *f, int noverify)
+urj_flashmsbin (urj_bus_t *bus, FILE *f, int noverify, int fastwrite)
{
uint32_t adr;
urj_flash_cfi_query_structure_t *cfi;
@@ -193,10 +194,13 @@
(long unsigned) a);
urj_log (URJ_LOG_LEVEL_NORMAL, "\r");
fread_ret (&data, sizeof data, 1, f);
- if (flash_driver->program (urj_flash_cfi_array, a, &data, 1)
- != URJ_STATUS_OK)
- // retain error state
- return URJ_STATUS_FAIL;
+ if ((!fastwrite) || (fastwrite && data != 0xFFFFFFFF))
+ {
+ if (flash_driver->program (urj_flash_cfi_array, a, &data, 1)
+ != URJ_STATUS_OK)
+ // retain error state
+ return URJ_STATUS_FAIL;
+ }
a += 4;
l -= 4;
}
@@ -295,7 +299,7 @@
}
int
-urj_flashmem (urj_bus_t *bus, FILE *f, uint32_t addr, int noverify)
+urj_flashmem (urj_bus_t *bus, FILE *f, uint32_t addr, int noverify, int fastwrite)
{
uint32_t adr;
urj_flash_cfi_query_structure_t *cfi;
@@ -308,7 +312,11 @@
uint32_t write_buffer[BSIZE];
int write_buffer_count;
uint32_t write_buffer_adr;
+ time_t write_start, write_end;
+ size_t bytes_written = 0;
+ time (&write_start);
+
set_flash_driver ();
if (!urj_flash_cfi_array || !flash_driver)
{
@@ -341,10 +349,17 @@
{
uint32_t data;
uint8_t b[BSIZE];
+ uint8_t write_need = 1;
+
int bc = 0, bn = 0, btr = BSIZE;
int block_no = find_block (cfi, adr - urj_flash_cfi_array->address,
bus_width, chip_width, &btr);
+ if (fastwrite)
+ {
+ write_need = 0;
+ }
+
write_buffer_count = 0;
write_buffer_adr = adr;
@@ -352,6 +367,7 @@
btr = BSIZE;
// @@@@ RFHH check error state?
bn = fread (b, 1, btr, f);
+ bytes_written += bn;
if (bn > 0 && !erased[block_no])
{
@@ -380,11 +396,17 @@
data = 0;
for (j = 0; j < flash_driver->bus_width; j++)
+ {
if (urj_get_file_endian () == URJ_ENDIAN_BIG)
data = (data << 8) | b[bc + j];
else
data |= b[bc + j] << (j * 8);
+
+ if (b[bc + j] != 0xFF)
+ write_need = 1;
+ }
+
/* store data in write buffer, will be programmed to flash later */
write_buffer[write_buffer_count++] = data;
@@ -392,18 +414,30 @@
}
if (write_buffer_count > 0)
- if (flash_driver->program (urj_flash_cfi_array, write_buffer_adr,
- write_buffer, write_buffer_count))
+ {
+ if (write_need)
{
- // retain error state
- return URJ_STATUS_FAIL;
+ if (flash_driver->program (urj_flash_cfi_array, write_buffer_adr,
+ write_buffer, write_buffer_count))
+ {
+ // retain error state
+ return URJ_STATUS_FAIL;
+ }
}
+ else
+ {
+ urj_log (URJ_LOG_LEVEL_NORMAL, _("empty block skip programming\n"));
+ }
+ }
}
free (erased);
- urj_log (URJ_LOG_LEVEL_NORMAL, _("addr: 0x%08lX\n"),
- (long unsigned) adr - flash_driver->bus_width);
+ time(&write_end);
+ urj_log (URJ_LOG_LEVEL_NORMAL, _("addr: 0x%08lX\nDone: %lu bytes written in %.2lf seconds.\n"),
+ (long unsigned) adr - flash_driver->bus_width,
+ (long unsigned) bytes_written,
+ difftime (write_end, write_start));
flash_driver->readarray (urj_flash_cfi_array);
@@ -467,9 +501,13 @@
finish condition twice within the loop */
(void) URJ_BUS_READ_END (bus);
}
- urj_log (URJ_LOG_LEVEL_NORMAL, _("addr: 0x%08lX\nDone.\n"),
- (long unsigned) adr - flash_driver->bus_width);
+ time(&write_end);
+
+ urj_log (URJ_LOG_LEVEL_NORMAL, _("addr: 0x%08lX\nDone: %lu bytes written and verified in %.2lf seconds.\n"),
+ (long unsigned) adr - flash_driver->bus_width,
+ (long unsigned) bytes_written,
+ difftime (write_end, write_start));
return URJ_STATUS_OK;
}
Index: src/cmd/cmd_flashmem.c
===================================================================
--- src/cmd/cmd_flashmem.c (revision 2003)
+++ src/cmd/cmd_flashmem.c (working copy)
@@ -42,6 +42,8 @@
{
int msbin;
int noverify = 0;
+ int fastwrite = 0;
+ int i = 0;
long unsigned adr = 0;
FILE *f;
int paramc = urj_cmd_params (params);
@@ -51,7 +53,7 @@
{
urj_error_set (URJ_ERROR_SYNTAX,
"%s: #parameters should be >= %d, not %d",
- params[0], 3, urj_cmd_params (params));
+ params[0], 2, urj_cmd_params (params));
return URJ_STATUS_FAIL;
}
@@ -65,11 +67,18 @@
if (!msbin && urj_cmd_get_number (params[1], &adr) != URJ_STATUS_OK)
return URJ_STATUS_FAIL;
- if (paramc > 3)
- noverify = strcasecmp ("noverify", params[3]) == 0;
- else
- noverify = 0;
+ if (paramc > 2)
+ {
+ for (;i<paramc; i++)
+ {
+ if (strcasecmp ("noverify", params[i]) == 0)
+ noverify = 1;
+ if (strcasecmp ("fastwrite", params[i]) == 0)
+ fastwrite = 1;
+ }
+ }
+
f = fopen (params[2], FOPEN_R);
if (!f)
{
@@ -78,9 +87,9 @@
}
if (msbin)
- r = urj_flashmsbin (urj_bus, f, noverify);
+ r = urj_flashmsbin (urj_bus, f, noverify, fastwrite);
else
- r = urj_flashmem (urj_bus, f, adr, noverify);
+ r = urj_flashmem (urj_bus, f, adr, noverify, fastwrite);
fclose (f);
@@ -91,19 +100,20 @@
cmd_flashmem_help (void)
{
urj_log (URJ_LOG_LEVEL_NORMAL,
- _("Usage: %s ADDR FILENAME [noverify]\n"
- "Usage: %s FILENAME [noverify]\n"
+ _("Usage: %s ADDR FILENAME [noverify] [fastwrite]\n"
+ "Usage: %s FILENAME [noverify] [fastwrite]\n"
"Program FILENAME content to flash memory.\n"
"\n"
"ADDR target address for raw binary image\n"
"FILENAME name of the input file\n"
"%-10s FILENAME is in MS .bin format (for WinCE)\n"
"%-10s if specified, verification is skipped\n"
+ "%-10s if specified, the writing of all 0xFF blocks will be skipped\n"
"\n"
"ADDR could be in decimal or hexadecimal (prefixed with 0x) form.\n"
"\n"
"Supported Flash Memories:\n"),
- "flashmem", "flashmem msbin", "msbin", "noverify");
+ "flashmem", "flashmem msbin", "msbin", "noverify", "fastwrite");
urj_cmd_show_list (urj_flash_flash_drivers);
}
@@ -113,6 +123,11 @@
char * const *tokens, const char *text, size_t text_len,
size_t token_point)
{
+ static const char * const arguments[] = {
+ "noverify",
+ "fastwrite",
+ };
+
switch (token_point)
{
case 1: /* [addr|msbin] */
@@ -123,8 +138,9 @@
text_len, false);
break;
- case 3: /* [noverify] */
- urj_completion_mayben_add_match (matches, match_cnt, text, text_len, "noverify");
+ case 3: /* [noverify] [fastwrite] */
+ case 4:
+ urj_completion_mayben_add_matches (matches, match_cnt, text, text_len, arguments);
break;
}
}
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2d-oct
_______________________________________________
UrJTAG-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/urjtag-development