From: Øyvind H. <go...@us...> - 2010-05-05 15:42:58
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via 31b050108a1cd740b326dddfa7a2f1322ee8c186 (commit) via 91b9f3de0b8e3277ab5c584c6076ddfe491ffc86 (commit) via 7e33f87b3d25331f3ac366c88e0b0ebb196422ec (commit) via 0d8f60e28f0f6e2bf65c674154b129fffae9eca8 (commit) from ca0f6a5c58fb94d590362d9a7d99543919fbbf43 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 31b050108a1cd740b326dddfa7a2f1322ee8c186 Author: Matthias Bode <pap...@go...> Date: Mon May 3 22:35:38 2010 +0200 Fixed bug in tcl-server No segmentationfault when sending commands to tcl-server. modified: src/server/server.c modified: src/server/tcl_server.c modified: src/server/tcl_server.h diff --git a/src/server/server.c b/src/server/server.c index 0d3273b..7e57228 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -513,7 +513,7 @@ int server_preinit(void) int server_init(struct command_context *cmd_ctx) { - int ret = tcl_init(cmd_ctx); + int ret = tcl_init(); if (ERROR_OK != ret) return ret; diff --git a/src/server/tcl_server.c b/src/server/tcl_server.c index a88c436..7c8e130 100644 --- a/src/server/tcl_server.c +++ b/src/server/tcl_server.c @@ -81,7 +81,7 @@ static int tcl_new_connection(struct connection *connection) static int tcl_input(struct connection *connection) { - Jim_Interp *interp = (Jim_Interp *)connection->priv; + Jim_Interp *interp = (Jim_Interp *)connection->cmd_ctx->interp; int retval; int i; ssize_t rlen; @@ -157,7 +157,7 @@ static int tcl_closed(struct connection *connection) return ERROR_OK; } -int tcl_init(struct command_context *cmd_ctx) +int tcl_init(void) { int retval; @@ -169,7 +169,7 @@ int tcl_init(struct command_context *cmd_ctx) retval = add_service("tcl", CONNECTION_TCP, tcl_port, 1, &tcl_new_connection, &tcl_input, - &tcl_closed, cmd_ctx->interp); + &tcl_closed, NULL); return retval; } diff --git a/src/server/tcl_server.h b/src/server/tcl_server.h index 68ad821..8035a04 100644 --- a/src/server/tcl_server.h +++ b/src/server/tcl_server.h @@ -22,7 +22,7 @@ #include <server/server.h> -int tcl_init(struct command_context *cmd_ctx); +int tcl_init(void); int tcl_register_commands(struct command_context *cmd_ctx); #endif /* _TCL_SERVER_H_ */ commit 91b9f3de0b8e3277ab5c584c6076ddfe491ffc86 Author: Ãyvind Harboe <oyv...@zy...> Date: Mon May 3 17:01:53 2010 +0200 command context: fix errors when running certain commands on startup Various commands, e.g. "arm mcr xxxx" would fail if invoked upon startup since it there was no command context defined for the jim interpreter in that case. A Jim interpreter is now associated with a command context(telnet, gdb server's) or the default global command context. Signed-off-by: Ãyvind Harboe <oyv...@zy...> diff --git a/src/helper/command.c b/src/helper/command.c index 3625508..be262f2 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -167,14 +167,18 @@ static const char **script_command_args_alloc( return words; } -static struct command_context *current_command_context(Jim_Interp *interp) +struct command_context *current_command_context(Jim_Interp *interp) { /* grab the command context from the associated data */ struct command_context *cmd_ctx = Jim_GetAssocData(interp, "context"); if (NULL == cmd_ctx) { /* Tcl can invoke commands directly instead of via command_run_line(). This would - * happen when the Jim Tcl interpreter is provided by eCos. + * happen when the Jim Tcl interpreter is provided by eCos or if we are running + * commands in a startup script. + * + * A telnet or gdb server would provide a non-default command context to + * handle piping of error output, have a separate current target, etc. */ cmd_ctx = global_cmd_ctx; } diff --git a/src/helper/command.h b/src/helper/command.h index 8a418d3..2c19241 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -311,6 +311,10 @@ void command_set_output_handler(struct command_context* context, int command_context_mode(struct command_context *context, enum command_mode mode); +/* Return the current command context associated with the Jim interpreter or + * alternatively the global default command interpreter + */ +struct command_context *current_command_context(Jim_Interp *interp); /** * Creates a new command context using the startup TCL provided and * the existing Jim interpreter, if any. If interp == NULL, then command_init diff --git a/src/jtag/tcl.c b/src/jtag/tcl.c index 579ca9e..ea6d07e 100644 --- a/src/jtag/tcl.c +++ b/src/jtag/tcl.c @@ -684,7 +684,7 @@ static int jim_jtag_arp_init(Jim_Interp *interp, int argc, Jim_Obj *const *argv) Jim_WrongNumArgs(goi.interp, 1, goi.argv-1, "(no params)"); return JIM_ERR; } - struct command_context *context = Jim_GetAssocData(interp, "context"); + struct command_context *context = current_command_context(interp); int e = jtag_init_inner(context); if (e != ERROR_OK) { Jim_SetResult_sprintf(goi.interp, "error: %d", e); @@ -701,7 +701,7 @@ static int jim_jtag_arp_init_reset(Jim_Interp *interp, int argc, Jim_Obj *const Jim_WrongNumArgs(goi.interp, 1, goi.argv-1, "(no params)"); return JIM_ERR; } - struct command_context *context = Jim_GetAssocData(interp, "context"); + struct command_context *context = current_command_context(interp); int e = jtag_init_reset(context); if (e != ERROR_OK) { Jim_SetResult_sprintf(goi.interp, "error: %d", e); diff --git a/src/target/armv4_5.c b/src/target/armv4_5.c index eeb6694..1a84a5f 100644 --- a/src/target/armv4_5.c +++ b/src/target/armv4_5.c @@ -820,11 +820,9 @@ static int jim_mcrmrc(Jim_Interp *interp, int argc, Jim_Obj *const *argv) struct arm *arm; int retval; - context = Jim_GetAssocData(interp, "context"); - if (context == NULL) { - LOG_ERROR("%s: no command context", __func__); - return JIM_ERR; - } + context = current_command_context(interp); + assert( context != NULL); + target = get_current_target(context); if (target == NULL) { LOG_ERROR("%s: no current target", __func__); diff --git a/src/target/target.c b/src/target/target.c index a3a1b0a..d17bb74 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -3236,12 +3236,9 @@ static int jim_mem2array(Jim_Interp *interp, int argc, Jim_Obj *const *argv) struct command_context *context; struct target *target; - context = Jim_GetAssocData(interp, "context"); - if (context == NULL) - { - LOG_ERROR("mem2array: no command context"); - return JIM_ERR; - } + context = current_command_context(interp); + assert (context != NULL); + target = get_current_target(context); if (target == NULL) { @@ -3432,11 +3429,9 @@ static int jim_array2mem(Jim_Interp *interp, int argc, Jim_Obj *const *argv) struct command_context *context; struct target *target; - context = Jim_GetAssocData(interp, "context"); - if (context == NULL) { - LOG_ERROR("array2mem: no command context"); - return JIM_ERR; - } + context = current_command_context(interp); + assert (context != NULL); + target = get_current_target(context); if (target == NULL) { LOG_ERROR("array2mem: no current target"); @@ -4318,7 +4313,9 @@ static int jim_target_wait_state(Jim_Interp *interp, int argc, Jim_Obj *const *a */ static int jim_target_event_list(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { - struct command_context *cmd_ctx = Jim_GetAssocData(interp, "context"); + struct command_context *cmd_ctx = current_command_context(interp); + assert (cmd_ctx != NULL); + struct target *target = Jim_CmdPrivData(interp); struct target_event_action *teap = target->event_action; command_print(cmd_ctx, "Event actions for target (%d) %s\n", @@ -4512,7 +4509,9 @@ static int target_create(Jim_GetOptInfo *goi) struct target *target; struct command_context *cmd_ctx; - cmd_ctx = Jim_GetAssocData(goi->interp, "context"); + cmd_ctx = current_command_context(goi->interp); + assert (cmd_ctx != NULL); + if (goi->argc < 3) { Jim_WrongNumArgs(goi->interp, 1, goi->argv, "?name? ?type? ..options..."); return JIM_ERR; @@ -4686,7 +4685,9 @@ static int jim_target_current(Jim_Interp *interp, int argc, Jim_Obj *const *argv Jim_WrongNumArgs(interp, 1, argv, "Too many parameters"); return JIM_ERR; } - struct command_context *cmd_ctx = Jim_GetAssocData(interp, "context"); + struct command_context *cmd_ctx = current_command_context(interp); + assert (cmd_ctx != NULL); + Jim_SetResultString(interp, get_current_target(cmd_ctx)->cmd_name, -1); return JIM_OK; } commit 7e33f87b3d25331f3ac366c88e0b0ebb196422ec Author: Ãyvind Harboe <oyv...@zy...> Date: Tue May 4 07:29:40 2010 +0200 flash: more flash write_image bugfixes Remove/fix lots of bugs in handling of non-contigious sections and out of order sections. Fix a gaffe introduced in previous commit to src/flash/nor/core.c Signed-off-by: Ãyvind Harboe <oyv...@zy...> diff --git a/src/flash/nor/core.c b/src/flash/nor/core.c index 9a77353..e6c0eeb 100644 --- a/src/flash/nor/core.c +++ b/src/flash/nor/core.c @@ -602,15 +602,12 @@ int flash_write_unlock(struct target *target, struct image *image, while ((run_address + run_size - 1 < c->base + c->size - 1) && (section_last + 1 < image->num_sections)) { - if (sections[section_last + 1]->base_address < (run_address + run_size)) + /* sections are sorted */ + assert(sections[section_last + 1]->base_address >= c->base); + if (sections[section_last + 1]->base_address >= (c->base + c->size)) { - LOG_DEBUG("section %d out of order " - "(surprising, but supported)", - section_last + 1); - /* REVISIT this can break with autoerase ... - * clobbering data after it's written. - */ - break; + /* Done with this bank */ + break; } /* FIXME This needlessly touches sectors BETWEEN the @@ -631,8 +628,6 @@ int flash_write_unlock(struct target *target, struct image *image, * flash programming could fail due to alignment issues * attempt to rebuild a consecutive buffer for the flash loader */ pad_bytes = (sections[section_last + 1]->base_address) - (run_address + run_size); - if ((run_address + run_size + pad_bytes) > (c->base + c->size)) - break; padding[section_last] = pad_bytes; run_size += sections[++section_last]->size; run_size += pad_bytes; @@ -641,16 +636,7 @@ int flash_write_unlock(struct target *target, struct image *image, LOG_INFO("Padding image section %d with %d bytes", section_last-1, pad_bytes); } - /* fit the run into bank constraints */ - if (run_address + run_size - 1 > c->base + c->size - 1) - { - /* REVISIT isn't this superfluous, given the while() - * loop conditions above?? - */ - LOG_WARNING("writing %d bytes only - as image section is %d bytes and bank is only %d bytes", \ - (int)(c->base + c->size - run_address), (int)(run_size), (int)(c->size)); - run_size = c->base + c->size - run_address; - } + assert (run_address + run_size - 1 <= c->base + c->size - 1); /* If we're applying any sector automagic, then pad this * (maybe-combined) segment to the end of its last sector. @@ -691,8 +677,12 @@ int flash_write_unlock(struct target *target, struct image *image, * #¤%#"%¤% we have to figure out the section # from the sorted * list of pointers to sections to invoke image_read_section()... */ - int t_section_num = (sections[section] - image->sections) / sizeof(struct imageection); + intptr_t diff = (intptr_t)sections[section] - (intptr_t)image->sections; + int t_section_num = diff / sizeof(struct imageection); + LOG_DEBUG("image_read_section: section = %d, t_section_num = %d, section_offset = %d, buffer_size = %d, size_read = %d", + (int)section, +(int)t_section_num, (int)section_offset, (int)buffer_size, (int)size_read); if ((retval = image_read_section(image, t_section_num, section_offset, size_read, buffer + buffer_size, &size_read)) != ERROR_OK || size_read == 0) { commit 0d8f60e28f0f6e2bf65c674154b129fffae9eca8 Author: Ãyvind Harboe <oyv...@zy...> Date: Mon May 3 15:25:35 2010 +0200 str7x: improve error handling clean up error handling a bit. No change in behavior. Signed-off-by: Ãyvind Harboe <oyv...@zy...> diff --git a/src/flash/nor/str7x.c b/src/flash/nor/str7x.c index adabad7..3d52341 100644 --- a/src/flash/nor/str7x.c +++ b/src/flash/nor/str7x.c @@ -5,6 +5,9 @@ * Copyright (C) 2008 by Spencer Oliver * * sp...@sp... * * * + * Copyright (C) 2010 Ãyvind Harboe * + * oyv...@zy... * + * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * @@ -162,22 +165,88 @@ FLASH_BANK_COMMAND_HANDLER(str7x_flash_bank_command) return ERROR_OK; } -static uint32_t str7x_status(struct flash_bank *bank) +/* wait for flash to become idle or report errors. + + FIX!!! what's the maximum timeout??? The documentation doesn't + state any maximum time.... by inspection it seems > 1000ms is to be + expected. + + 10000ms is long enough that it should cover anything, yet not + quite be equivalent to an infinite loop. + + */ +static int str7x_waitbusy(struct flash_bank *bank) { + int err; + int i; struct target *target = bank->target; - uint32_t retval; + struct str7x_flash_bank *str7x_info = bank->driver_priv; - target_read_u32(target, str7x_get_flash_adr(bank, FLASH_CR0), &retval); + for (i = 0 ; i < 10000; i++) + { + uint32_t retval; + err = target_read_u32(target, str7x_get_flash_adr(bank, FLASH_CR0), &retval); + if (err != ERROR_OK) + return err; - return retval; + if ((retval & str7x_info->busy_bits) == 0) + return ERROR_OK; + + alive_sleep(1); + } + LOG_ERROR("Timed out waiting for str7x flash"); + return ERROR_FAIL; } -static uint32_t str7x_result(struct flash_bank *bank) + +static int str7x_result(struct flash_bank *bank) { struct target *target = bank->target; uint32_t retval; - target_read_u32(target, str7x_get_flash_adr(bank, FLASH_ER), &retval); + int err; + err = target_read_u32(target, str7x_get_flash_adr(bank, FLASH_ER), &retval); + if (err != ERROR_OK) + return err; + + if (retval & FLASH_WPF) + { + LOG_ERROR("str7x hw write protection set"); + err = ERROR_FAIL; + } + if (retval & FLASH_RESER) + { + LOG_ERROR("str7x suspended program erase not resumed"); + err = ERROR_FAIL; + } + if (retval & FLASH_10ER) + { + LOG_ERROR("str7x trying to set bit to 1 when it is already 0"); + err = ERROR_FAIL; + } + if (retval & FLASH_PGER) + { + LOG_ERROR("str7x program error"); + err = ERROR_FAIL; + } + if (retval & FLASH_ERER) + { + LOG_ERROR("str7x erase error"); + err = ERROR_FAIL; + } + if (err == ERROR_OK) + { + if (retval & FLASH_ERR) + { + /* this should always be set if one of the others are set... */ + LOG_ERROR("str7x write operation failed / bad setup"); + err = ERROR_FAIL; + } + } + if (err != ERROR_OK) + { + LOG_ERROR("FLASH_ER register contents: 0x%" PRIx32, retval); + } return retval; } @@ -216,8 +285,8 @@ static int str7x_erase(struct flash_bank *bank, int first, int last) int i; uint32_t cmd; - uint32_t retval; uint32_t sectors = 0; + int err; if (bank->target->state != TARGET_HALTED) { @@ -233,28 +302,32 @@ static int str7x_erase(struct flash_bank *bank, int first, int last) LOG_DEBUG("sectors: 0x%" PRIx32 "", sectors); /* clear FLASH_ER register */ - target_write_u32(target, str7x_get_flash_adr(bank, FLASH_ER), 0x0); + err = target_write_u32(target, str7x_get_flash_adr(bank, FLASH_ER), 0x0); + if (err != ERROR_OK) + return err; cmd = FLASH_SER; - target_write_u32(target, str7x_get_flash_adr(bank, FLASH_CR0), cmd); + err = target_write_u32(target, str7x_get_flash_adr(bank, FLASH_CR0), cmd); + if (err != ERROR_OK) + return err; cmd = sectors; - target_write_u32(target, str7x_get_flash_adr(bank, FLASH_CR1), cmd); + err = target_write_u32(target, str7x_get_flash_adr(bank, FLASH_CR1), cmd); + if (err != ERROR_OK) + return err; cmd = FLASH_SER | FLASH_WMS; - target_write_u32(target, str7x_get_flash_adr(bank, FLASH_CR0), cmd); + err = target_write_u32(target, str7x_get_flash_adr(bank, FLASH_CR0), cmd); + if (err != ERROR_OK) + return err; - while (((retval = str7x_status(bank)) & str7x_info->busy_bits)) { - alive_sleep(1); - } + err = str7x_waitbusy(bank); + if (err != ERROR_OK) + return err; - retval = str7x_result(bank); - - if (retval) - { - LOG_ERROR("error erasing flash bank, FLASH_ER: 0x%" PRIx32 "", retval); - return ERROR_FLASH_OPERATION_FAILED; - } + err = str7x_result(bank); + if (err != ERROR_OK) + return err; for (i = first; i <= last; i++) bank->sectors[i].is_erased = 1; @@ -268,7 +341,6 @@ static int str7x_protect(struct flash_bank *bank, int set, int first, int last) struct target *target = bank->target; int i; uint32_t cmd; - uint32_t retval; uint32_t protect_blocks; if (bank->target->state != TARGET_HALTED) @@ -286,37 +358,43 @@ static int str7x_protect(struct flash_bank *bank, int set, int first, int last) } /* clear FLASH_ER register */ - target_write_u32(target, str7x_get_flash_adr(bank, FLASH_ER), 0x0); + int err; + err = target_write_u32(target, str7x_get_flash_adr(bank, FLASH_ER), 0x0); + if (err != ERROR_OK) + return err; cmd = FLASH_SPR; - target_write_u32(target, str7x_get_flash_adr(bank, FLASH_CR0), cmd); + err = target_write_u32(target, str7x_get_flash_adr(bank, FLASH_CR0), cmd); + if (err != ERROR_OK) + return err; cmd = str7x_get_flash_adr(bank, FLASH_NVWPAR); - target_write_u32(target, str7x_get_flash_adr(bank, FLASH_AR), cmd); + err = target_write_u32(target, str7x_get_flash_adr(bank, FLASH_AR), cmd); + if (err != ERROR_OK) + return err; cmd = protect_blocks; - target_write_u32(target, str7x_get_flash_adr(bank, FLASH_DR0), cmd); + err = target_write_u32(target, str7x_get_flash_adr(bank, FLASH_DR0), cmd); + if (err != ERROR_OK) + return err; cmd = FLASH_SPR | FLASH_WMS; - target_write_u32(target, str7x_get_flash_adr(bank, FLASH_CR0), cmd); - - while (((retval = str7x_status(bank)) & str7x_info->busy_bits)) { - alive_sleep(1); - } + err = target_write_u32(target, str7x_get_flash_adr(bank, FLASH_CR0), cmd); + if (err != ERROR_OK) + return err; - retval = str7x_result(bank); + err = str7x_waitbusy(bank); + if (err != ERROR_OK) + return err; - LOG_DEBUG("retval: 0x%8.8" PRIx32 "", retval); - - if (retval & FLASH_ERER) - return ERROR_FLASH_SECTOR_NOT_ERASED; - else if (retval & FLASH_WPF) - return ERROR_FLASH_OPERATION_FAILED; + err = str7x_result(bank); + if (err != ERROR_OK) + return err; return ERROR_OK; } -static int str7x_write_block(struct flash_bank *bank, uint8_t *buffer, +int str7x_write_block(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count) { struct str7x_flash_bank *str7x_info = bank->driver_priv; @@ -409,14 +487,12 @@ static int str7x_write_block(struct flash_bank *bank, uint8_t *buffer, str7x_info->write_algorithm->address + (sizeof(str7x_flash_write_code) - 4), 10000, &armv4_5_info)) != ERROR_OK) { - LOG_ERROR("error executing str7x flash write algorithm"); - retval = ERROR_FLASH_OPERATION_FAILED; break; } if (buf_get_u32(reg_params[4].value, 0, 32) != 0x00) { - retval = ERROR_FLASH_OPERATION_FAILED; + retval = str7x_result(bank); break; } @@ -442,7 +518,6 @@ static int str7x_write(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count) { struct target *target = bank->target; - struct str7x_flash_bank *str7x_info = bank->driver_priv; uint32_t dwords_remaining = (count / 8); uint32_t bytes_remaining = (count & 0x00000007); uint32_t address = bank->base + offset; @@ -498,16 +573,7 @@ static int str7x_write(struct flash_bank *bank, uint8_t *buffer, /* if block write failed (no sufficient working area), * we use normal (slow) single dword accesses */ LOG_WARNING("couldn't use block writes, falling back to single memory accesses"); - } - else if (retval == ERROR_FLASH_OPERATION_FAILED) - { - /* if an error occured, we examine the reason, and quit */ - retval = str7x_result(bank); - - LOG_ERROR("flash writing failed with error code: 0x%x", retval); - return ERROR_FLASH_OPERATION_FAILED; - } - else + } else { return retval; } @@ -543,17 +609,14 @@ static int str7x_write(struct flash_bank *bank, uint8_t *buffer, cmd = FLASH_DWPG | FLASH_WMS; target_write_u32(target, str7x_get_flash_adr(bank, FLASH_CR0), cmd); - while (((retval = str7x_status(bank)) & str7x_info->busy_bits)) - { - alive_sleep(1); - } - - retval = str7x_result(bank); + int err; + err = str7x_waitbusy(bank); + if (err != ERROR_OK) + return err; - if (retval & FLASH_PGER) - return ERROR_FLASH_OPERATION_FAILED; - else if (retval & FLASH_WPF) - return ERROR_FLASH_OPERATION_FAILED; + err = str7x_result(bank); + if (err != ERROR_OK) + return err; dwords_remaining--; address += 8; @@ -592,17 +655,14 @@ static int str7x_write(struct flash_bank *bank, uint8_t *buffer, cmd = FLASH_DWPG | FLASH_WMS; target_write_u32(target, str7x_get_flash_adr(bank, FLASH_CR0), cmd); - while (((retval = str7x_status(bank)) & str7x_info->busy_bits)) - { - alive_sleep(1); - } - - retval = str7x_result(bank); + int err; + err = str7x_waitbusy(bank); + if (err != ERROR_OK) + return err; - if (retval & FLASH_PGER) - return ERROR_FLASH_OPERATION_FAILED; - else if (retval & FLASH_WPF) - return ERROR_FLASH_OPERATION_FAILED; + err = str7x_result(bank); + if (err != ERROR_OK) + return err; } return ERROR_OK; ----------------------------------------------------------------------- Summary of changes: src/flash/nor/core.c | 32 +++----- src/flash/nor/str7x.c | 206 ++++++++++++++++++++++++++++++----------------- src/helper/command.c | 8 ++- src/helper/command.h | 4 + src/jtag/tcl.c | 4 +- src/server/server.c | 2 +- src/server/tcl_server.c | 6 +- src/server/tcl_server.h | 2 +- src/target/armv4_5.c | 8 +- src/target/target.c | 29 ++++--- 10 files changed, 179 insertions(+), 122 deletions(-) hooks/post-receive -- Main OpenOCD repository |