From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marek Vasut Date: Tue, 13 Aug 2013 07:10:17 +0200 Subject: [U-Boot] [PATCH v2 5/7] tools: add padding of data image file for imximage In-Reply-To: <1376318374-3497-6-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> <1376318374-3497-6-git-send-email-sbabic@denx.de> Message-ID: <201308130710.17878.marex@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Dear Stefano Babic, > Implement function vrec_header to be able to pad the final > data image file according the what has been calculated for > boot_data.length. > > Signed-off-by: Stefano Babic > --- [...] > + if (!imxhdr) { > + fprintf(stderr, "%s: malloc return failure: %s\n", > + params->cmdname, strerror(errno)); > + exit(EXIT_FAILURE); > + } > + > + memset(imxhdr, 0, alloc_len); > + > + tparams->header_size = alloc_len; > + tparams->hdr = imxhdr; > + > + /* determine data image file length */ Why dont you just call stat(2) here instead of the open+fstat+close combo? > + dfd = open(datafile, O_RDONLY|O_BINARY); > + if (dfd < 0) { > + fprintf(stderr, "%s: Can't open %s: %s\n", > + params->cmdname, datafile, strerror(errno)); > + exit(EXIT_FAILURE); > + } > + > + if (fstat(dfd, &sbuf) < 0) { > + fprintf(stderr, "%s: Can't stat %s: %s\n", > + params->cmdname, datafile, strerror(errno)); > + exit(EXIT_FAILURE); > + } > + > + pad_len = ROUND(sbuf.st_size, 4096) - sbuf.st_size; > + > + close(dfd); > + > + /* TODO: check i.MX image V1 handling, for now use 'old' style */ [...] Best regards, Marek Vasut