X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Ftarget%2Fimage.c;h=0612ea7e5a33c1ce423673be0f55ba515b78f1cf;hp=07420b1f5adfc34fe471eaaac9f7c158a12ce765;hb=d0e763ac7ef6aa17b17bd00ccdfbccfb4eacda69;hpb=9b2577742cc49683ab0ea8506d93e3e285b53bbd diff --git a/src/target/image.c b/src/target/image.c index 07420b1f5a..0612ea7e5a 100644 --- a/src/target/image.c +++ b/src/target/image.c @@ -22,9 +22,7 @@ * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * + * along with this program. If not, see . * ***************************************************************************/ #ifdef HAVE_CONFIG_H @@ -47,7 +45,7 @@ static int autodetect_image_type(struct image *image, const char *url) { int retval; - struct fileio fileio; + struct fileio *fileio; size_t read_bytes; uint8_t buffer[9]; @@ -55,13 +53,13 @@ static int autodetect_image_type(struct image *image, const char *url) retval = fileio_open(&fileio, url, FILEIO_READ, FILEIO_BINARY); if (retval != ERROR_OK) return retval; - retval = fileio_read(&fileio, 9, buffer, &read_bytes); + retval = fileio_read(fileio, 9, buffer, &read_bytes); if (retval == ERROR_OK) { if (read_bytes != 9) retval = ERROR_FILEIO_OPERATION_FAILED; } - fileio_close(&fileio); + fileio_close(fileio); if (retval != ERROR_OK) return retval; @@ -122,7 +120,7 @@ static int image_ihex_buffer_complete_inner(struct image *image, struct imagesection *section) { struct image_ihex *ihex = image->type_private; - struct fileio *fileio = &ihex->fileio; + struct fileio *fileio = ihex->fileio; uint32_t full_address = 0x0; uint32_t cooked_bytes; int i; @@ -130,7 +128,7 @@ static int image_ihex_buffer_complete_inner(struct image *image, /* 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 */ - int filesize; + size_t filesize; int retval; retval = fileio_size(fileio, &filesize); if (retval != ERROR_OK) @@ -352,7 +350,7 @@ static int image_elf_read_headers(struct image *image) return ERROR_FILEIO_OPERATION_FAILED; } - retval = fileio_read(&elf->fileio, sizeof(Elf32_Ehdr), (uint8_t *)elf->header, &read_bytes); + retval = fileio_read(elf->fileio, sizeof(Elf32_Ehdr), (uint8_t *)elf->header, &read_bytes); if (retval != ERROR_OK) { LOG_ERROR("cannot read ELF file header, read failed"); return ERROR_FILEIO_OPERATION_FAILED; @@ -384,7 +382,7 @@ static int image_elf_read_headers(struct image *image) return ERROR_IMAGE_FORMAT_ERROR; } - retval = fileio_seek(&elf->fileio, field32(elf, elf->header->e_phoff)); + retval = fileio_seek(elf->fileio, field32(elf, elf->header->e_phoff)); if (retval != ERROR_OK) { LOG_ERROR("cannot seek to ELF program header table, read failed"); return retval; @@ -396,7 +394,7 @@ static int image_elf_read_headers(struct image *image) return ERROR_FILEIO_OPERATION_FAILED; } - retval = fileio_read(&elf->fileio, elf->segment_count*sizeof(Elf32_Phdr), + retval = fileio_read(elf->fileio, elf->segment_count*sizeof(Elf32_Phdr), (uint8_t *)elf->segments, &read_bytes); if (retval != ERROR_OK) { LOG_ERROR("cannot read ELF segment headers, read failed"); @@ -486,12 +484,12 @@ static int image_elf_read_section(struct image *image, LOG_DEBUG("read elf: size = 0x%zu at 0x%" PRIx32 "", read_size, field32(elf, segment->p_offset) + offset); /* read initialized area of the segment */ - retval = fileio_seek(&elf->fileio, field32(elf, segment->p_offset) + offset); + retval = fileio_seek(elf->fileio, field32(elf, segment->p_offset) + offset); if (retval != ERROR_OK) { LOG_ERROR("cannot find ELF segment content, seek failed"); return retval; } - retval = fileio_read(&elf->fileio, read_size, buffer, &really_read); + retval = fileio_read(elf->fileio, read_size, buffer, &really_read); if (retval != ERROR_OK) { LOG_ERROR("cannot read ELF segment content, read failed"); return retval; @@ -511,7 +509,7 @@ static int image_mot_buffer_complete_inner(struct image *image, struct imagesection *section) { struct image_mot *mot = image->type_private; - struct fileio *fileio = &mot->fileio; + struct fileio *fileio = mot->fileio; uint32_t full_address = 0x0; uint32_t cooked_bytes; int i; @@ -520,7 +518,7 @@ static int image_mot_buffer_complete_inner(struct image *image, * so we locally hold them until parsing is finished */ int retval; - int filesize; + size_t filesize; retval = fileio_size(fileio, &filesize); if (retval != ERROR_OK) return retval; @@ -707,10 +705,10 @@ int image_open(struct image *image, const char *url, const char *type_string) retval = fileio_open(&image_binary->fileio, url, FILEIO_READ, FILEIO_BINARY); if (retval != ERROR_OK) return retval; - int filesize; - retval = fileio_size(&image_binary->fileio, &filesize); + size_t filesize; + retval = fileio_size(image_binary->fileio, &filesize); if (retval != ERROR_OK) { - fileio_close(&image_binary->fileio); + fileio_close(image_binary->fileio); return retval; } @@ -732,7 +730,7 @@ int image_open(struct image *image, const char *url, const char *type_string) if (retval != ERROR_OK) { LOG_ERROR( "failed buffering IHEX image, check daemon output for additional information"); - fileio_close(&image_ihex->fileio); + fileio_close(image_ihex->fileio); return retval; } } else if (image->type == IMAGE_ELF) { @@ -746,7 +744,7 @@ int image_open(struct image *image, const char *url, const char *type_string) retval = image_elf_read_headers(image); if (retval != ERROR_OK) { - fileio_close(&image_elf->fileio); + fileio_close(image_elf->fileio); return retval; } } else if (image->type == IMAGE_MEMORY) { @@ -783,11 +781,12 @@ int image_open(struct image *image, const char *url, const char *type_string) if (retval != ERROR_OK) { LOG_ERROR( "failed buffering S19 image, check daemon output for additional information"); - fileio_close(&image_mot->fileio); + fileio_close(image_mot->fileio); return retval; } } else if (image->type == IMAGE_BUILDER) { image->num_sections = 0; + image->base_address_set = 0; image->sections = NULL; image->type_private = NULL; } @@ -834,12 +833,12 @@ int image_read_section(struct image *image, return ERROR_COMMAND_SYNTAX_ERROR; /* seek to offset */ - retval = fileio_seek(&image_binary->fileio, offset); + retval = fileio_seek(image_binary->fileio, offset); if (retval != ERROR_OK) return retval; /* return requested bytes */ - retval = fileio_read(&image_binary->fileio, size, buffer, size_read); + retval = fileio_read(image_binary->fileio, size, buffer, size_read); if (retval != ERROR_OK) return retval; } else if (image->type == IMAGE_IHEX) { @@ -944,11 +943,11 @@ void image_close(struct image *image) if (image->type == IMAGE_BINARY) { struct image_binary *image_binary = image->type_private; - fileio_close(&image_binary->fileio); + fileio_close(image_binary->fileio); } else if (image->type == IMAGE_IHEX) { struct image_ihex *image_ihex = image->type_private; - fileio_close(&image_ihex->fileio); + fileio_close(image_ihex->fileio); if (image_ihex->buffer) { free(image_ihex->buffer); @@ -957,7 +956,7 @@ void image_close(struct image *image) } else if (image->type == IMAGE_ELF) { struct image_elf *image_elf = image->type_private; - fileio_close(&image_elf->fileio); + fileio_close(image_elf->fileio); if (image_elf->header) { free(image_elf->header); @@ -978,7 +977,7 @@ void image_close(struct image *image) } else if (image->type == IMAGE_SRECORD) { struct image_mot *image_mot = image->type_private; - fileio_close(&image_mot->fileio); + fileio_close(image_mot->fileio); if (image_mot->buffer) { free(image_mot->buffer);