Skip to content

Commit

Permalink
mkimage: Fix error message if write less data then expected
Browse files Browse the repository at this point in the history
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 more understandable message:

"mkimage: Write only 4202432/4682240 bytes, probably no space left on the device"

Signed-off-by: Mylène Josserand <[email protected]>
Reviewed-by: Walter Lozano <[email protected]>
  • Loading branch information
Mylène Josserand authored and trini committed Jul 17, 2020
1 parent 5c6a4d5 commit dd85dc5
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions tools/mkimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -730,9 +730,16 @@ 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: Write only %d/%d bytes, "\
"probably no space left on the device\n",
params.cmdname, ret, size);
exit (EXIT_FAILURE);
}

Expand Down

0 comments on commit dd85dc5

Please sign in to comment.