Fix mkimage error message
cover Fix mkimage error message
Hello everyone,
While using mkimage with debos, I noticed a wierd error:
"mkimage: Write error on uImage: Success"
After some investications, I found that this error is in fact a "No space left" error.
This patch is updating mkimage's code to print a new error message in case the size written is less than the expected size. We can't write all the data probably because of of not enough space on the device.
Thank you in advance,
Best regards
Myl?ne
Myl?ne Josserand (1):
mkimage: Fix error message if write less data then expected
tools/mkimage.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
Signature · 1 line
2.26.2
PATCH 1/1 mkimage: Fix error message if write less data then expected
Add a new error message in case the size of data written are shorter than the one expected.
Currently, it will lead to the following error message:
"mkimage: Write error on uImage: Success"
This is not explicit when the error is because the device doesn't have enough space. Let's use a "No space left on the device" error message in that case.
--- tools/mkimage.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
tools/mkimage.c +10 -4
@@ -674,7 +674,7 @@ copy_file (int ifd, const char *datafile, int pad)int zero =0 ;uint8_t zeros[4096 ];int offset =0 ; -int size; +int size, ret;struct image_type_params *tparams =imagetool_get_type (params.type);memset (zeros,0 ,sizeof (zeros));
@@ -730,9 +730,15 @@ copy_file (int ifd, const char *datafile, int pad) } size = sbuf.st_size - offset; -if (write (ifd, ptr + offset, size) != size) { -fprintf (stderr,"%s: Write error on %s: %s\n" , - params.cmdname, params.imagefile,strerror (errno)); + + ret =write (ifd, ptr + offset, size); +if (ret != size) { +if (ret <0 ) +fprintf (stderr,"%s: Write error on %s: %s\n" , + params.cmdname, params.imagefile,strerror (errno)); +else if (ret < size) +fprintf (stderr,"%s: No space left on the device\n" , + params.cmdname);exit (EXIT_FAILURE ); }
Signature · 1 line
2.26.2
PATCH 1/1 mkimage: Fix error message if write less data then expected
Hi Mylene,
Thanks for you patch.
Quoted 34 lines · Myl?ne Josserand
Add a new error message in case the size of data written are shorter than the one expected.
Currently, it will lead to the following error message:
"mkimage: Write error on uImage: Success"This is not explicit when the error is because the device doesn't have enough space. Let's use a "No space left on the device" error message in that case.
Signed-off-by Myl?ne Josserand <[email protected]>--- tools/mkimage.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)tools/mkimage.c +1
-3@@ -674,7 +674,7 @@ copy_file (int ifd, const char *datafile, int pad)int zero =0 ;uint8_t zeros[4096 ];int offset =0 ; -int size; +int size, ret;struct image_type_params *tparams =imagetool_get_type (params.type);memset (zeros,0 ,sizeof (zeros));@@ -730,9 +730,15 @@ copy_file (int ifd, const char *datafile, int pad) } size = sbuf.st_size - offset; -if (write (ifd, ptr + offset, size) != size) { - fprintf (stderr, "%s: Write error on %s: %s\n",
tools/mkimage.c copy_file (int ifd, const char *datafile, int pad) · line 741
Quoted 10 lines
tools/mkimage.c +9
-1- params.cmdname, params.imagefile, strerror(errno)); + + ret =write (ifd, ptr + offset, size); +if (ret != size) { +if (ret <0 ) +fprintf (stderr,"%s: Write error on %s: %s\n" , + params.cmdname, params.imagefile,strerror (errno)); +else if (ret < size) +fprintf (stderr,"%s: No space left on the device\n" , + params.cmdname);
Thanks for improving the error message, it is much more clear now. The only question I have is if "no space left on the device" is the only possible cause for this situation, for sure it is the most probable.
tools/mkimage.c copy_file (int ifd, const char *datafile, int pad) · line 744
Quoted 3 lines
tools/mkimage.c +0
-0exit (EXIT_FAILURE ); }
Regards,
Walter
PATCH 1/1 mkimage: Fix error message if write less data then expected
Hi,
Quoted 45 lines · Walter Lozano
Hi Mylene,
Thanks for you patch.
Quoted 40 lines · Myl?ne Josserand
Add a new error message in case the size of data written are shorter than the one expected.
Currently, it will lead to the following error message:
??? "mkimage: Write error on uImage: Success"This is not explicit when the error is because the device doesn't have enough space. Let's use a "No space left on the device" error message in that case.
Signed-off-by Myl?ne Josserand <[email protected]>---
?tools/mkimage.c| 14 ++++++++++----
? 1 file changed, 10 insertions(+), 4 deletions(-)tools/mkimage.c +1
-1@@ -674,7 +674,7 @@ copy_file (int ifd, const char *datafile, int pad) ????? int zero = 0; ????? uint8_t zeros[4096]; ????? int offset = 0; -??? int size; +??? int size, ret;????? struct
image_type_params*tparams =imagetool_get_type(params.type);
?????memset(zeros, 0, sizeof(zeros));tools/mkimage.c +6
-3@@ -730,9 +730,15 @@ copy_file (int ifd, const char *datafile, int pad) ????? } ????? size = sbuf.st_size - offset; -??? if (write(ifd, ptr + offset, size) != size) { -??????? fprintf (stderr, "%s: Write error on %s: %s\n", -??????????? params.cmdname, params.imagefile, strerror(errno)); + +??? ret = write(ifd, ptr + offset, size); +??? if (ret != size) { +??????? if (ret < 0) +??????????? fprintf (stderr, "%s: Write error on %s: %s\n", +???????????????? params.cmdname, params.imagefile, strerror(errno));
Quoted 8 lines
tools/mkimage.c copy_file (int ifd, const char *datafile, int pad) · line 740
Quoted 3 lines
tools/mkimage.c +3
-0+??????? else if (ret < size) +??????????? fprintf (stderr, "%s: No space left on the device\n", +???????????????? params.cmdname);Thanks for improving the error message, it is much more clear now. The only question I have is if "no space left on the device" is the only possible cause for this situation, for sure it is the most probable.
Thanks for your review. Indeed, it is the most probable I guess.
Quoted 9 lines
tools/mkimage.c copy_file (int ifd, const char *datafile, int pad) · line 742
Quoted 3 lines
tools/mkimage.c +0
-0????????? exit (EXIT_FAILURE); ????? }Regards,
Walter
Best regards,
Myl?ne
PATCH 1/1 mkimage: Fix error message if write less data then expected
Hi Mylene,
Quoted 58 lines · Mylene Josserand
Hi,
Quoted 46 lines · Walter Lozano
Hi Mylene,
Thanks for you patch.
Quoted 41 lines · Myl?ne Josserand
Add a new error message in case the size of data written are shorter than the one expected.
Currently, it will lead to the following error message:
??? "mkimage: Write error on uImage: Success"This is not explicit when the error is because the device doesn't have enough space. Let's use a "No space left on the device" error message in that case.
Signed-off-by Myl?ne Josserand <[email protected]>---
?tools/mkimage.c| 14 ++++++++++----
? 1 file changed, 10 insertions(+), 4 deletions(-)tools/mkimage.c +1
-1@@ -674,7 +674,7 @@ copy_file (int ifd, const char *datafile, int pad) ????? int zero = 0; ????? uint8_t zeros[4096]; ????? int offset = 0; -??? int size; +??? int size, ret;????? struct
image_type_params*tparams =imagetool_get_type(params.type);
?????memset(zeros, 0, sizeof(zeros));tools/mkimage.c +7
-3@@ -730,9 +730,15 @@ copy_file (int ifd, const char *datafile, int pad) ????? } ????? size = sbuf.st_size - offset; -??? if (write(ifd, ptr + offset, size) != size) { -??????? fprintf (stderr, "%s: Write error on %s: %s\n", -??????????? params.cmdname, params.imagefile, strerror(errno)); + +??? ret = write(ifd, ptr + offset, size); +??? if (ret != size) { +??????? if (ret < 0) +??????????? fprintf (stderr, "%s: Write error on %s: %s\n", +???????????????? params.cmdname, params.imagefile, strerror(errno)); +??????? else if (ret < size)Quoted 8 lines
tools/mkimage.c copy_file (int ifd, const char *datafile, int pad) · line 740
Quoted 2 lines
tools/mkimage.c +2
-0+??????????? fprintf (stderr, "%s: No space left on the device\n", +???????????????? params.cmdname);Thanks for improving the error message, it is much more clear now. The only question I have is if "no space left on the device" is the only possible cause for this situation, for sure it is the most probable.
Quoted 1 line
Thanks for your review. Indeed, it is the most probable I guess.
Yes, I agree. However, in order to be more accurate, and probably avoid future patches to correct a misleading message I would improve the error message with something like "Fewer bytes written than expected, probably no space left on the device" or something similar.
What do you think?
Besides that
Quoted 5 lines
Quoted 5 lines
tools/mkimage.c copy_file (int ifd, const char *datafile, int pad) · line 742
Quoted 4 lines
tools/mkimage.c +0
-0????????? exit (EXIT_FAILURE); ????? }
Regards,
Walter
PATCH 1/1 mkimage: Fix error message if write less data then expected
Hello,
Quoted 64 lines · Walter Lozano
Hi Mylene,
Quoted 58 lines · Mylene Josserand
Hi,
Quoted 46 lines · Walter Lozano
Hi Mylene,
Thanks for you patch.
Quoted 41 lines · Myl?ne Josserand
Add a new error message in case the size of data written are shorter than the one expected.
Currently, it will lead to the following error message:
??? "mkimage: Write error on uImage: Success"This is not explicit when the error is because the device doesn't have enough space. Let's use a "No space left on the device" error message in that case.
Signed-off-by Myl?ne Josserand <[email protected]>---
?tools/mkimage.c| 14 ++++++++++----
? 1 file changed, 10 insertions(+), 4 deletions(-)tools/mkimage.c +1
-1@@ -674,7 +674,7 @@ copy_file (int ifd, const char *datafile, int pad) ????? int zero = 0; ????? uint8_t zeros[4096]; ????? int offset = 0; -??? int size; +??? int size, ret;????? struct
image_type_params*tparams =imagetool_get_type(params.type);
?????memset(zeros, 0, sizeof(zeros));tools/mkimage.c +7
-3@@ -730,9 +730,15 @@ copy_file (int ifd, const char *datafile, int pad) ????? } ????? size = sbuf.st_size - offset; -??? if (write(ifd, ptr + offset, size) != size) { -??????? fprintf (stderr, "%s: Write error on %s: %s\n", -??????????? params.cmdname, params.imagefile, strerror(errno)); + +??? ret = write(ifd, ptr + offset, size); +??? if (ret != size) { +??????? if (ret < 0) +??????????? fprintf (stderr, "%s: Write error on %s: %s\n", +???????????????? params.cmdname, params.imagefile, strerror(errno)); +??????? else if (ret < size)Quoted 8 lines
tools/mkimage.c copy_file (int ifd, const char *datafile, int pad) · line 740
Quoted 2 lines
tools/mkimage.c +2
-0+??????????? fprintf (stderr, "%s: No space left on the device\n", +???????????????? params.cmdname);Thanks for improving the error message, it is much more clear now. The only question I have is if "no space left on the device" is the only possible cause for this situation, for sure it is the most probable.
Quoted 1 line
Thanks for your review. Indeed, it is the most probable I guess.
Quoted 6 lines
Yes, I agree. However, in order to be more accurate, and probably avoid future patches to correct a misleading message I would improve the error message with something like "Fewer bytes written than expected, probably no space left on the device" or something similar.
What do you think?
Yes, why not. I thought that "No space left" is a more common error message but let's change that with more details about how many written/expected bytes.
Quoted 4 lines
Besides that
Reviewed-by Walter Lozano <[email protected]>
Thanks!
Quoted 10 lines
Quoted 6 lines
Quoted 6 lines
tools/mkimage.c copy_file (int ifd, const char *datafile, int pad) · line 742
Quoted 5 lines
tools/mkimage.c +0
-0????????? exit (EXIT_FAILURE); ????? }Regards,
Walter
Best regards,
Myl?ne