From patchwork Thu Jan 5 18:44:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wagner X-Patchwork-Id: 134529 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3132F1007D7 for ; Fri, 6 Jan 2012 05:46:06 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0AA8228585; Thu, 5 Jan 2012 19:45:48 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OlC9jHzHJslX; Thu, 5 Jan 2012 19:45:47 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 183EB2855C; Thu, 5 Jan 2012 19:45:32 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9D2DD28554 for ; Thu, 5 Jan 2012 19:45:27 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JX5Jygb7Jsir for ; Thu, 5 Jan 2012 19:45:27 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail.free-electrons.com (mail.free-electrons.com [88.190.12.23]) by theia.denx.de (Postfix) with ESMTP id 2BCDA28552 for ; Thu, 5 Jan 2012 19:45:21 +0100 (CET) Received: by mail.free-electrons.com (Postfix, from userid 106) id 948DA1C6; Thu, 5 Jan 2012 19:40:43 +0100 (CET) Received: from localhost.localdomain (bon31-3-82-226-48-55.fbx.proxad.net [82.226.48.55]) by mail.free-electrons.com (Postfix) with ESMTPSA id C185C16D; Thu, 5 Jan 2012 19:40:32 +0100 (CET) From: David Wagner To: u-boot@lists.denx.de Date: Thu, 5 Jan 2012 19:44:53 +0100 Message-Id: <1325789099-9260-2-git-send-email-david.wagner@free-electrons.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1325789099-9260-1-git-send-email-david.wagner@free-electrons.com> References: <20120105162831.E91BE1FD3DA@gemini.denx.de> <1325789099-9260-1-git-send-email-david.wagner@free-electrons.com> Cc: Thomas Petazzoni Subject: [U-Boot] [PATCHv3 2/8] mkenvimage: correct and clarify comments and error messages X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Also, don't split error messages over several lines as per a coding style exception making them easier to grep. Signed-off-by: David Wagner --- tools/mkenvimage.c | 41 +++++++++++++++-------------------------- 1 files changed, 15 insertions(+), 26 deletions(-) diff --git a/tools/mkenvimage.c b/tools/mkenvimage.c index c5ed373..7d33143 100644 --- a/tools/mkenvimage.c +++ b/tools/mkenvimage.c @@ -45,12 +45,9 @@ static void usage(const char *exec_name) { - fprintf(stderr, "%s [-h] [-r] [-b] [-p ] " - "-s -o \n" + fprintf(stderr, "%s [-h] [-r] [-b] [-p ] -s -o \n" "\n" - "This tool takes a key=value input file (same as would a " - "`printenv' show) and generates the corresponding environment " - "image, ready to be flashed.\n" + "This tool takes a key=value input file (same as would a `printenv' show) and generates the corresponding environment image, ready to be flashed.\n" "\n" "\tThe input file is in format:\n" "\t\tkey1=value1\n" @@ -58,8 +55,7 @@ static void usage(const char *exec_name) "\t\t...\n" "\t-r : the environment has multiple copies in flash\n" "\t-b : the target is big endian (default is little endian)\n" - "\t-p : fill the image with bytes instead of " - "0xff bytes\n" + "\t-p : fill the image with bytes instead of 0xff bytes\n" "\t-V : print version information and exit\n" "\n" "If the input file is \"-\", data is read from standard input\n", @@ -100,8 +96,7 @@ int main(int argc, char **argv) case 'o': bin_filename = strdup(optarg); if (!bin_filename) { - fprintf(stderr, "Can't strdup() the output " - "filename\n"); + fprintf(stderr, "Can't strdup() the output filename\n"); return EXIT_FAILURE; } break; @@ -118,7 +113,7 @@ int main(int argc, char **argv) usage(prg); return EXIT_SUCCESS; case 'V': - printf("%s version %s\n", prg, PLAIN_VERSION); + printf("%s version %s\n", argv[0], PLAIN_VERSION); return EXIT_SUCCESS; case ':': fprintf(stderr, "Missing argument for option -%c\n", @@ -134,22 +129,21 @@ int main(int argc, char **argv) /* Check datasize and allocate the data */ if (datasize == 0) { - fprintf(stderr, - "Please specify the size of the environment " - "partition.\n"); + fprintf(stderr, "Please specify the size of the environment partition.\n"); usage(prg); return EXIT_FAILURE; } dataptr = malloc(datasize * sizeof(*dataptr)); if (!dataptr) { - fprintf(stderr, "Can't alloc dataptr.\n"); + fprintf(stderr, "Can't alloc %d bytes for dataptr.\n", + datasize); return EXIT_FAILURE; } /* * envptr points to the beginning of the actual environment (after the - * crc and possible `redundant' bit + * crc and possible `redundant' byte */ envsize = datasize - (CRC_SIZE + redundant); envptr = dataptr + CRC_SIZE + redundant; @@ -185,8 +179,8 @@ int main(int argc, char **argv) /* ... and check it */ ret = fstat(txt_fd, &txt_file_stat); if (ret == -1) { - fprintf(stderr, "Can't stat() on \"%s\": " - "%s\n", txt_filename, strerror(errno)); + fprintf(stderr, "Can't stat() on \"%s\": %s\n", + txt_filename, strerror(errno)); return EXIT_FAILURE; } @@ -200,13 +194,9 @@ int main(int argc, char **argv) } ret = close(txt_fd); } - /* - * The right test to do is "=>" (not ">") because of the additional - * ending \0. See below. - */ - if (filesize >= envsize) { - fprintf(stderr, "The input file is larger than the " - "environment partition size\n"); + /* The +1 is for the additionnal ending \0. See below. */ + if (filesize + 1 > envsize) { + fprintf(stderr, "The input file is larger than the environment partition size\n"); return EXIT_FAILURE; } @@ -255,8 +245,7 @@ int main(int argc, char **argv) * check the env size again to make sure we have room for two \0 */ if (ep >= envsize) { - fprintf(stderr, "The environment file is too large for " - "the target environment storage\n"); + fprintf(stderr, "The environment file is too large for the target environment storage\n"); return EXIT_FAILURE; } envptr[ep] = '\0';