From: Øyvind H. <go...@us...> - 2009-11-22 13:42:52
|
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 700a60ec573e9cfdbcac3c1c30ee5e94aeddfa6a (commit) via 964c3639e2464b18d72f16fa175fee9beb843b36 (commit) via 31da0003dc6d307faa8fd66eb23319bd5e9ab7dd (commit) via 808e53368c2c1daee3f6a5eb59038b990534f1ac (commit) from d1fbcc35899f6071d097b8dfb76ab3125c3c4fac (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 700a60ec573e9cfdbcac3c1c30ee5e94aeddfa6a Author: Ãyvind Harboe <oyv...@zy...> Date: Sat Nov 21 23:29:58 2009 +0100 embedded: reduce stack usage Allocate working structures on stack to avoid issues with path lengths + reduce stack usage. Signed-off-by: Ãyvind Harboe <oyv...@zy...> diff --git a/src/helper/configuration.c b/src/helper/configuration.c index 2ea5da4..007246c 100644 --- a/src/helper/configuration.c +++ b/src/helper/configuration.c @@ -61,21 +61,23 @@ char *find_file(const char *file) char **search_dirs = script_search_dirs; char *dir; char const *mode="r"; - char full_path[1024]; + char *full_path; /* Check absolute and relative to current working dir first. * This keeps full_path reporting belowing working. */ - snprintf(full_path, 1024, "%s", file); + full_path = alloc_printf("%s", file); fp = fopen(full_path, mode); while (!fp) { + free(full_path); + full_path = NULL; dir = *search_dirs++; if (!dir) break; - snprintf(full_path, 1024, "%s/%s", dir, file); + full_path = alloc_printf("%s/%s", dir, file); fp = fopen(full_path, mode); } @@ -83,8 +85,11 @@ char *find_file(const char *file) { fclose(fp); LOG_DEBUG("found %s", full_path); - return strdup(full_path); + return full_path; } + + free(full_path); + return NULL; } commit 964c3639e2464b18d72f16fa175fee9beb843b36 Author: Ãyvind Harboe <oyv...@zy...> Date: Sat Nov 21 23:25:46 2009 +0100 embedded: do not allocate large temporary structures on stack With -O3 when inlining aggressively the total stack usage will be the sum of many fn's, which can easily get out of hand. Signed-off-by: Ãyvind Harboe <oyv...@zy...> diff --git a/src/target/image.c b/src/target/image.c index 76c8cc9..ca7123a 100644 --- a/src/target/image.c +++ b/src/target/image.c @@ -147,18 +147,16 @@ static int identify_image_type(struct image *image, const char *type_string, con return ERROR_OK; } -static int image_ihex_buffer_complete(struct image *image) +static int image_ihex_buffer_complete_inner(struct image *image, char *lpszLine, struct imageection *section) { struct image_ihex *ihex = image->type_private; struct fileio *fileio = &ihex->fileio; uint32_t full_address = 0x0; uint32_t cooked_bytes; int i; - char lpszLine[1023]; /* we can't determine the number of sections that we'll have to create ahead of time, * so we locally hold them until parsing is finished */ - struct imageection section[IMAGE_MAX_SECTIONS]; ihex->buffer = malloc(fileio->size >> 1); cooked_bytes = 0x0; @@ -357,6 +355,35 @@ static int image_ihex_buffer_complete(struct image *image) return ERROR_IMAGE_FORMAT_ERROR; } +/** + * Allocate memory dynamically instead of on the stack. This + * is important w/embedded hosts. + */ +static int image_ihex_buffer_complete(struct image *image) +{ + char *lpszLine = malloc(1023); + if (lpszLine == NULL) + { + LOG_ERROR("Out of memory"); + return ERROR_FAIL; + } + struct imageection *section = malloc(sizeof(struct imageection) * IMAGE_MAX_SECTIONS); + if (section == NULL) + { + free(lpszLine); + LOG_ERROR("Out of memory"); + return ERROR_FAIL; + } + int retval; + + retval = image_ihex_buffer_complete_inner(image, lpszLine, section); + + free(section); + free(lpszLine); + + return retval; +} + static int image_elf_read_headers(struct image *image) { struct image_elf *elf = image->type_private; @@ -499,18 +526,16 @@ static int image_elf_read_section(struct image *image, int section, uint32_t off return ERROR_OK; } -static int image_mot_buffer_complete(struct image *image) +static int image_mot_buffer_complete_inner(struct image *image, char *lpszLine, struct imageection *section) { struct image_mot *mot = image->type_private; struct fileio *fileio = &mot->fileio; uint32_t full_address = 0x0; uint32_t cooked_bytes; int i; - char lpszLine[1023]; /* we can't determine the number of sections that we'll have to create ahead of time, * so we locally hold them until parsing is finished */ - struct imageection section[IMAGE_MAX_SECTIONS]; mot->buffer = malloc(fileio->size >> 1); cooked_bytes = 0x0; @@ -669,6 +694,36 @@ static int image_mot_buffer_complete(struct image *image) return ERROR_IMAGE_FORMAT_ERROR; } +/** + * Allocate memory dynamically instead of on the stack. This + * is important w/embedded hosts. + */ +static int image_mot_buffer_complete(struct image *image) +{ + char *lpszLine = malloc(1023); + if (lpszLine == NULL) + { + LOG_ERROR("Out of memory"); + return ERROR_FAIL; + } + struct imageection *section = malloc(sizeof(struct imageection) * IMAGE_MAX_SECTIONS); + if (section == NULL) + { + free(lpszLine); + LOG_ERROR("Out of memory"); + return ERROR_FAIL; + } + int retval; + + retval = image_mot_buffer_complete_inner(image, lpszLine, section); + + free(section); + free(lpszLine); + + return retval; +} + + int image_open(struct image *image, const char *url, const char *type_string) { int retval = ERROR_OK; commit 31da0003dc6d307faa8fd66eb23319bd5e9ab7dd Author: Ãyvind Harboe <oyv...@zy...> Date: Sat Nov 21 23:45:36 2009 +0100 embedded: save stack and also do not recaluate the crc32_table upon every invocation. Signed-off-by: Ãyvind Harboe <oyv...@zy...> diff --git a/src/target/image.c b/src/target/image.c index 8774c25..76c8cc9 100644 --- a/src/target/image.c +++ b/src/target/image.c @@ -1023,17 +1023,23 @@ int image_calculate_checksum(uint8_t* buffer, uint32_t nbytes, uint32_t* checksu uint32_t crc = 0xffffffff; LOG_DEBUG("Calculating checksum"); - uint32_t crc32_table[256]; + static uint32_t crc32_table[256]; - /* Initialize the CRC table and the decoding table. */ - int i, j; - unsigned int c; - for (i = 0; i < 256; i++) + static bool first_init = false; + if (!first_init) { - /* as per gdb */ - for (c = i << 24, j = 8; j > 0; --j) - c = c & 0x80000000 ? (c << 1) ^ 0x04c11db7 : (c << 1); - crc32_table[i] = c; + /* Initialize the CRC table and the decoding table. */ + int i, j; + unsigned int c; + for (i = 0; i < 256; i++) + { + /* as per gdb */ + for (c = i << 24, j = 8; j > 0; --j) + c = c & 0x80000000 ? (c << 1) ^ 0x04c11db7 : (c << 1); + crc32_table[i] = c; + } + + first_init = true; } while (nbytes > 0) commit 808e53368c2c1daee3f6a5eb59038b990534f1ac Author: Ãyvind Harboe <oyv...@zy...> Date: Sun Nov 22 13:16:48 2009 +0100 zy1000: fix breakage in command parsing code for power command Signed-off-by: Ãyvind Harboe <oyv...@zy...> diff --git a/src/jtag/zy1000/zy1000.c b/src/jtag/zy1000/zy1000.c index 28515c7..8b5b753 100644 --- a/src/jtag/zy1000/zy1000.c +++ b/src/jtag/zy1000/zy1000.c @@ -235,7 +235,7 @@ COMMAND_HANDLER(handle_power_command) // fall through } case 0: - command_print(cmd_ctx, "Target power %s", savePower ? "on" : "off"); + LOG_INFO("Target power %s", savePower ? "on" : "off"); break; default: return ERROR_INVALID_ARGUMENTS; ----------------------------------------------------------------------- Summary of changes: src/helper/configuration.c | 13 ++++-- src/jtag/zy1000/zy1000.c | 2 +- src/target/image.c | 91 ++++++++++++++++++++++++++++++++++++------- 3 files changed, 86 insertions(+), 20 deletions(-) hooks/post-receive -- Main OpenOCD repository |