From patchwork Fri Jun 5 08:01:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mylene Josserand X-Patchwork-Id: 1304092 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=2a01:238:438b:c500:173d:9f52:ddab:ee01; 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 [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 49dgzQ1Fptz9sSF for ; Fri, 5 Jun 2020 21:54:10 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2CB8C81E4B; Fri, 5 Jun 2020 13:53:56 +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 DAFCB81DBE; Fri, 5 Jun 2020 10:06:21 +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 [46.235.227.227]) (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 2823981CD7 for ; Fri, 5 Jun 2020 10:06:19 +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:8092:cf00:aaa1:59ff:fe08:91d5]) (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 8C3282A0DE4; Fri, 5 Jun 2020 09:06:18 +0100 (BST) From: =?utf-8?q?Myl=C3=A8ne_Josserand?= To: u-boot@lists.denx.de Cc: kernel@collabora.com, mylene.josserand@collabora.com Subject: [PATCH v1 1/1] mkimage: Fix error message if write less data then expected Date: Fri, 5 Jun 2020 10:01:27 +0200 Message-Id: <20200605080127.10156-2-mylene.josserand@collabora.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200605080127.10156-1-mylene.josserand@collabora.com> References: <20200605080127.10156-1-mylene.josserand@collabora.com> MIME-Version: 1.0 X-Mailman-Approved-At: Fri, 05 Jun 2020 13:53:52 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.2 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 "No space left on the device" error message in that case. Signed-off-by: Mylène Josserand Reviewed-by: Walter Lozano --- 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); exit (EXIT_FAILURE); }