From patchwork Mon Aug 12 14:39:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 266554 X-Patchwork-Delegate: sbabic@denx.de 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 CBD4F2C0087 for ; Tue, 13 Aug 2013 00:41:12 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3B2F94A02F; Mon, 12 Aug 2013 16:40:50 +0200 (CEST) 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 sgnBco8+irJl; Mon, 12 Aug 2013 16:40:50 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9ED7C4A0A2; Mon, 12 Aug 2013 16:40:15 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id ED70B4A04C for ; Mon, 12 Aug 2013 16:40:02 +0200 (CEST) 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 mcB3cpbtgodd for ; Mon, 12 Aug 2013 16:40:00 +0200 (CEST) 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 smtpi1.ngi.it (smtpi1.ngi.it [88.149.128.20]) by theia.denx.de (Postfix) with ESMTP id 606734A03E for ; Mon, 12 Aug 2013 16:39:55 +0200 (CEST) Received: from babic.homelinux.org (88-149-182-160.v4.ngi.it [88.149.182.160]) by smtpi1.ngi.it (Postfix) with ESMTP id 821363181A8; Mon, 12 Aug 2013 16:39:55 +0200 (CEST) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 5DBE3454044A; Mon, 12 Aug 2013 16:39:55 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 75cBME42lAaU; Mon, 12 Aug 2013 16:39:49 +0200 (CEST) Received: from papero.lan (papero.lan [192.168.2.247]) by babic.homelinux.org (Postfix) with ESMTP id D684C4540844; Mon, 12 Aug 2013 16:39:39 +0200 (CEST) From: Stefano Babic To: U-Boot Mailing List Date: Mon, 12 Aug 2013 16:39:31 +0200 Message-Id: <1376318374-3497-5-git-send-email-sbabic@denx.de> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1376318374-3497-1-git-send-email-sbabic@denx.de> References: <1373548001-19728-1-git-send-email-sbabic@denx.de> <1376318374-3497-1-git-send-email-sbabic@denx.de> Cc: Tom Rini , Marek Vasut Subject: [U-Boot] [PATCH v2 4/7] tools: add variable padding of data image in mkimage 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 Use previously unused return value of function vrec_header to return a padding size to generic mkimage. This padding size is used in copy_files to pad with zeros after copying the data image. Signed-off-by: Stefano Babic --- Changes in v2: None tools/mkimage.c | 24 +++++++++++++++++++++--- tools/mkimage.h | 5 ++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/tools/mkimage.c b/tools/mkimage.c index b700b9e..58d25fa 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -137,6 +137,7 @@ main (int argc, char **argv) char *ptr; int retval = 0; struct image_type_params *tparams = NULL; + int pad_len = 0; /* Init Freescale PBL Boot image generation/list support */ init_pbl_image_type(); @@ -391,7 +392,7 @@ NXTARG: ; * allocate memory for the header itself. */ if (tparams->vrec_header) - tparams->vrec_header(¶ms, tparams); + pad_len = tparams->vrec_header(¶ms, tparams); else memset(tparams->hdr, 0, tparams->header_size); @@ -463,7 +464,7 @@ NXTARG: ; /* PBL has special Image format, implements its' own */ pbl_load_uboot(ifd, ¶ms); } else { - copy_file (ifd, params.datafile, 0); + copy_file(ifd, params.datafile, pad_len); } } @@ -537,10 +538,19 @@ copy_file (int ifd, const char *datafile, int pad) unsigned char *ptr; int tail; int zero = 0; + uint8_t zeros[4096]; int offset = 0; int size; struct image_type_params *tparams = mkimage_get_type (params.type); + if (pad >= sizeof(zeros)) { + fprintf(stderr, "%s: Can't pad to %d\n", + params.cmdname, pad); + exit(EXIT_FAILURE); + } + + memset(zeros, 0, sizeof(zeros)); + if (params.vflag) { fprintf (stderr, "Adding Image %s\n", datafile); } @@ -598,7 +608,8 @@ copy_file (int ifd, const char *datafile, int pad) exit (EXIT_FAILURE); } - if (pad && ((tail = size % 4) != 0)) { + tail = size % 4; + if ((pad == 1) && (tail != 0)) { if (write(ifd, (char *)&zero, 4-tail) != 4-tail) { fprintf (stderr, "%s: Write error on %s: %s\n", @@ -606,6 +617,13 @@ copy_file (int ifd, const char *datafile, int pad) strerror(errno)); exit (EXIT_FAILURE); } + } else if (pad > 1) { + if (write(ifd, (char *)&zeros, pad) != pad) { + fprintf(stderr, "%s: Write error on %s: %s\n", + params.cmdname, params.imagefile, + strerror(errno)); + exit(EXIT_FAILURE); + } } (void) munmap((void *)ptr, sbuf.st_size); diff --git a/tools/mkimage.h b/tools/mkimage.h index 950e190..ecb3032 100644 --- a/tools/mkimage.h +++ b/tools/mkimage.h @@ -132,7 +132,10 @@ struct image_type_params { /* * This callback function will be executed for variable size record * It is expected to build this header in memory and return its length - * and a pointer to it + * and a pointer to it by using image_type_params.header_size and + * image_type_params.hdr. The return value shall indicate if an + * additional padding should be used when copying the data image + * by returning the padding length. */ int (*vrec_header) (struct mkimage_params *, struct image_type_params *);