diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/flash/flash.c | 116 | ||||
-rw-r--r-- | src/jtag/Makefile.am | 2 | ||||
-rw-r--r-- | src/jtag/jtag.c | 68 |
3 files changed, 161 insertions, 25 deletions
diff --git a/src/flash/flash.c b/src/flash/flash.c index b3d1aa75..a0c89841 100644 --- a/src/flash/flash.c +++ b/src/flash/flash.c @@ -49,6 +49,7 @@ int handle_flash_erase_command(struct command_context_s *cmd_ctx, char *cmd, cha int handle_flash_write_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); int handle_flash_write_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); +int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); int handle_flash_protect_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); int handle_flash_auto_erase_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); flash_bank_t *get_flash_bank_by_addr(target_t *target, u32 addr); @@ -154,6 +155,14 @@ int flash_init_drivers(struct command_context_s *cmd_ctx) "erase sectors at <bank> <first> <last>"); register_command(cmd_ctx, flash_cmd, "erase_address", handle_flash_erase_address_command, COMMAND_EXEC, "erase address range <address> <length>"); + + register_command(cmd_ctx, flash_cmd, "fillw", handle_flash_fill_command, COMMAND_EXEC, + "fill with pattern <address> <word_pattern> <count>"); + register_command(cmd_ctx, flash_cmd, "fillh", handle_flash_fill_command, COMMAND_EXEC, + "fill with pattern <address> <halfword_pattern> <count>"); + register_command(cmd_ctx, flash_cmd, "fillb", handle_flash_fill_command, COMMAND_EXEC, + "fill with pattern <address> <byte_pattern> <count>"); + register_command(cmd_ctx, flash_cmd, "write_bank", handle_flash_write_bank_command, COMMAND_EXEC, "write binary data to <bank> <file> <offset>"); register_command(cmd_ctx, flash_cmd, "write_image", handle_flash_write_image_command, COMMAND_EXEC, @@ -645,6 +654,113 @@ int handle_flash_write_image_command(struct command_context_s *cmd_ctx, char *cm return retval; } +int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +{ + int err = ERROR_OK; + u32 address; + u32 pattern; + u32 count; + u8 chunk[1024]; + u32 wrote = 0; + int chunk_count; + char *duration_text; + duration_t duration; + target_t *target = get_current_target(cmd_ctx); + u32 i; + int wordsize; + + if (argc != 3) + { + return ERROR_COMMAND_SYNTAX_ERROR; + } + + address = strtoul(args[0], NULL, 0); + pattern = strtoul(args[1], NULL, 0); + count = strtoul(args[2], NULL, 0); + + if(count == 0) + return ERROR_OK; + + + switch(cmd[4]) + { + case 'w': + wordsize=4; + break; + case 'h': + wordsize=2; + break; + case 'b': + wordsize=1; + break; + default: + return ERROR_COMMAND_SYNTAX_ERROR; + } + + chunk_count = MIN(count, (1024 / wordsize)); + switch(wordsize) + { + case 4: + for(i = 0; i < chunk_count; i++) + { + target_buffer_set_u32(target, chunk + i * wordsize, pattern); + } + break; + case 2: + for(i = 0; i < chunk_count; i++) + { + target_buffer_set_u16(target, chunk + i * wordsize, pattern); + } + break; + case 1: + memset(chunk, pattern, chunk_count); + break; + default: + LOG_ERROR("BUG: can't happen"); + exit(-1); + } + + duration_start_measure(&duration); + + flash_set_dirty(); + err = flash_erase_address_range( target, address, count*wordsize ); + if (err == ERROR_OK) + { + for (wrote=0; wrote<(count*wordsize); wrote+=sizeof(chunk)) + { + int cur_size = MIN( (count*wordsize - wrote) , 1024 ); + if (err == ERROR_OK) + { + flash_bank_t *bank; + bank = get_flash_bank_by_addr(target, address); + if(bank == NULL) + { + err = ERROR_FAIL; + break; + } + err = flash_driver_write(bank, chunk, address - bank->base + wrote, cur_size); + wrote += cur_size; + } + if (err!=ERROR_OK) + break; + } + } + + duration_stop_measure(&duration, &duration_text); + + if(err == ERROR_OK) + { + float speed; + speed=wrote / 1024.0; + speed/=((float)duration.duration.tv_sec + ((float)duration.duration.tv_usec / 1000000.0)); + command_print(cmd_ctx, "wrote %d bytes to 0x%8.8x in %s (%f kb/s)", + count*wordsize, address, duration_text, + speed); + } + free(duration_text); + return ERROR_OK; +} + int handle_flash_write_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { u32 offset; diff --git a/src/jtag/Makefile.am b/src/jtag/Makefile.am index 4a0f5d27..04c06e2f 100644 --- a/src/jtag/Makefile.am +++ b/src/jtag/Makefile.am @@ -48,7 +48,7 @@ EP93XXFILES = endif if ECOSBOARD -ECOSBOARDFILES = eCosBoard.c +ECOSBOARDFILES = zy1000.c else ECOSBOARDFILES = endif diff --git a/src/jtag/jtag.c b/src/jtag/jtag.c index 34147651..884cf2f3 100644 --- a/src/jtag/jtag.c +++ b/src/jtag/jtag.c @@ -136,6 +136,11 @@ int jtag_ntrst_delay = 0; /* default to no nTRST delay */ /* callbacks to inform high-level handlers about JTAG state changes */ jtag_event_callback_t *jtag_event_callbacks; +/* speed in kHz*/ +static int speed1 = 0, speed2 = 0; +/* flag if the kHz speed was defined */ +static int hasKHz = 0; + /* jtag interfaces (parport, FTDI-USB, TI-USB, ...) */ @@ -1448,10 +1453,21 @@ int jtag_interface_init(struct command_context_s *cmd_ctx) LOG_ERROR("JTAG interface has to be specified, see \"interface\" command"); return ERROR_JTAG_INVALID_INTERFACE; } + if(hasKHz) + { + /*stay on "reset speed"*/ + if (jtag_interface->khz(speed1, &speed1) == ERROR_OK) + jtag_speed = speed1; + if (jtag_interface->khz(speed2, &speed2) == ERROR_OK) + jtag_speed_post_reset = speed2; + hasKHz = 0; + } if (jtag_interface->init() != ERROR_OK) return ERROR_JTAG_INIT_FAILED; + + jtag = jtag_interface; return ERROR_OK; } @@ -1488,6 +1504,7 @@ int jtag_init(struct command_context_s *cmd_ctx) while (jtag_validate_chain() != ERROR_OK) { validate_tries++; + if (validate_tries > 5) { LOG_ERROR("Could not validate JTAG chain, exit"); @@ -1495,7 +1512,7 @@ int jtag_init(struct command_context_s *cmd_ctx) } usleep(10000); } - + return ERROR_OK; } @@ -1719,6 +1736,8 @@ int handle_jtag_speed_command(struct command_context_s *cmd_ctx, char *cmd, char if ((argc<1) || (argc>2)) return ERROR_COMMAND_SYNTAX_ERROR; + LOG_DEBUG("handle jtag speed"); + if (argc >= 1) cur_speed = jtag_speed = jtag_speed_post_reset = strtoul(args[0], NULL, 0); if (argc == 2) @@ -1734,36 +1753,37 @@ int handle_jtag_speed_command(struct command_context_s *cmd_ctx, char *cmd, char int handle_jtag_khz_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { - int cur_speed = 0; - int speed1, speed2; + LOG_DEBUG("handle jtag khz"); + if ((argc<1) || (argc>2)) return ERROR_COMMAND_SYNTAX_ERROR; - if (jtag == NULL) - { - LOG_ERROR("Interface not selected yet"); - return ERROR_COMMAND_SYNTAX_ERROR; - } - if (argc >= 1) - speed1 = strtoul(args[0], NULL, 0); + speed1 = speed2 = strtoul(args[0], NULL, 0); if (argc == 2) speed2 = strtoul(args[1], NULL, 0); - - if (jtag->khz(speed1, &speed1)!=ERROR_OK) - return ERROR_OK; - - if (jtag->khz(speed2, &speed2)!=ERROR_OK) - return ERROR_OK; - - if (argc >= 1) - cur_speed = jtag_speed = jtag_speed_post_reset = speed1; - - if (argc == 2) - cur_speed = jtag_speed_post_reset = speed2; - - jtag->speed(cur_speed); + if (jtag != NULL) + { + int cur_speed = 0; + LOG_DEBUG("have interface set up"); + int speed_div1, speed_div2; + if (jtag->khz(speed1, &speed_div1)!=ERROR_OK) + return ERROR_OK; + if (jtag->khz(speed2, &speed_div2)!=ERROR_OK) + return ERROR_OK; + + if (argc >= 1) + cur_speed = jtag_speed = jtag_speed_post_reset = speed_div1; + if (argc == 2) + cur_speed = jtag_speed_post_reset = speed_div2; + + jtag->speed(cur_speed); + } else + { + hasKHz = 1; + } + return ERROR_OK; } |