Message ID | 20200605080127.10156-2-mylene.josserand@collabora.com |
---|---|
State | Accepted |
Commit | dd85dc55eb147cdcced1a4ee143b487d4aa6afa6 |
Headers | show |
Series | Fix mkimage error message | expand |
Hi Mylene, Thanks for you patch. On 5/6/20 05:01, Myl?ne Josserand wrote: > 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 <mylene.josserand at collabora.com> > --- > tools/mkimage.c | 14 ++++++++++---- > 1 file changed, 10 insertions(+), 4 deletions(-) > > diff --git a/tools/mkimage.c b/tools/mkimage.c > index d2cd1917874..ef0cc889a92 100644 > --- a/tools/mkimage.c > +++ b/tools/mkimage.c > @@ -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); 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. > exit (EXIT_FAILURE); > } > Regards, Walter
diff --git a/tools/mkimage.c b/tools/mkimage.c index d2cd1917874..ef0cc889a92 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -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); }
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 <mylene.josserand at collabora.com> --- tools/mkimage.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)