aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Vrbka <marek.vrbka@codasip.com>2023-08-31 08:30:37 +0200
committerAntonio Borneo <borneo.antonio@gmail.com>2023-09-08 22:01:59 +0000
commitd41a204d8224dad66265e694e5ccf3379de0d494 (patch)
treed7370f230ee82fb224259b7b2ea4a48f395c8a11
parent62f76b2169302b9500deea737a017168271824ac (diff)
downloadriscv-openocd-d41a204d8224dad66265e694e5ccf3379de0d494.zip
riscv-openocd-d41a204d8224dad66265e694e5ccf3379de0d494.tar.gz
riscv-openocd-d41a204d8224dad66265e694e5ccf3379de0d494.tar.bz2
image: fix binary detection for small files
Previously, if the image file was less than 9 bytes long, it was assumed to be an error when it could be a binary image file. This patch makes OpenOCD detect these cases as binary files. Change-Id: I5b4dad2b547786246887812ac75907378fe58671 Signed-off-by: Marek Vrbka <marek.vrbka@codasip.com> Reviewed-on: https://review.openocd.org/c/openocd/+/7880 Tested-by: jenkins Reviewed-by: Tomas Vanek <vanekt@fbl.cz> Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
-rw-r--r--src/target/image.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/target/image.c b/src/target/image.c
index f8de7a2..ad2d856 100644
--- a/src/target/image.c
+++ b/src/target/image.c
@@ -50,12 +50,15 @@ static int autodetect_image_type(struct image *image, const char *url)
if (retval != ERROR_OK)
return retval;
retval = fileio_read(fileio, 9, buffer, &read_bytes);
+ fileio_close(fileio);
- if (retval == ERROR_OK) {
- if (read_bytes != 9)
- retval = ERROR_FILEIO_OPERATION_FAILED;
+ /* If the file is smaller than 9 bytes, it can only be bin */
+ if (retval == ERROR_OK && read_bytes != 9) {
+ LOG_DEBUG("Less than 9 bytes in the image file found.");
+ LOG_DEBUG("BIN image detected.");
+ image->type = IMAGE_BINARY;
+ return ERROR_OK;
}
- fileio_close(fileio);
if (retval != ERROR_OK)
return retval;
@@ -82,8 +85,10 @@ static int autodetect_image_type(struct image *image, const char *url)
&& (buffer[1] >= '0') && (buffer[1] < '9')) {
LOG_DEBUG("S19 image detected.");
image->type = IMAGE_SRECORD;
- } else
+ } else {
+ LOG_DEBUG("BIN image detected.");
image->type = IMAGE_BINARY;
+ }
return ERROR_OK;
}