From patchwork Wed Jul 8 09:52:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mylene Josserand X-Patchwork-Id: 1325137 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=collabora.com Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4B1vkh1SVFz9sRK for ; Wed, 8 Jul 2020 19:53:16 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8E9E081BFA; Wed, 8 Jul 2020 11:53:10 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 22AD981BFC; Wed, 8 Jul 2020 11:53:09 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 34BE581BF1 for ; Wed, 8 Jul 2020 11:53:06 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=mylene.josserand@collabora.com Received: from ni.home (unknown [IPv6:2a01:cb19:881c:ce00:a988:f08d:817b:c832]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: myjosserand) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 899B92A1836; Wed, 8 Jul 2020 10:53:05 +0100 (BST) From: =?utf-8?q?Myl=C3=A8ne_Josserand?= To: u-boot@lists.denx.de Cc: walter.lozano@collabora.com, kernel@collabora.com, mylene.josserand@collabora.com Subject: [PATCH v2] mkimage: Fix error message if write less data then expected Date: Wed, 8 Jul 2020 11:52:50 +0200 Message-Id: <20200708095250.9649-1-mylene.josserand@collabora.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean 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 Reviewed-by: Walter Lozano --- Changes since v1: Set the message to be more explicit and saying that it is probably a "No space left on device" tools/mkimage.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/mkimage.c b/tools/mkimage.c index d2cd1917874..7cb666d4822 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,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); }