Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15F28C433EF for ; Wed, 10 Nov 2021 08:28:49 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 867FF61076 for ; Wed, 10 Nov 2021 08:28:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 867FF61076 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 962FB839BA; Wed, 10 Nov 2021 09:28:46 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1636532927; bh=msqbHODdU0l0nJUNWj2X0BmWnJbHHLe/cjFrFwvVQ0s=; h=Date:Subject:To:Cc:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=RzJ2XfyKeYC0TUVAiGFrhBoD9Rs4r8hE61u9gthtP4hK1FYAwKLBGc20h/7f4wDvM /ADWkf/JhXchZE45w4PayHGH7bJpWRi0/BRbsIdTvA1pMClDfZ32ux8OJUMQHaZOs1 tewCN0cUBeiV8/Y9PUxKaIzRxoA7ZPlpnVHw+NX8KSIZfhmSSYox/u+zsGDZvcWXCh Q8Z/+Tc5tmdmLzH5BUI6nv3RuboM7+E1xjIlWH2vo+ybc9OgKkW3wTIc4UuqoEBOEK TiCU5kaIa4jSkpyjqi+s3/BX92SU24SBnqHBo3BX/TfrrcbU7gfXl3eXrfKzpFZkC5 reqIUaajE/xuQ== Received: by phobos.denx.de (Postfix, from userid 109) id 6EADC839C2; Wed, 10 Nov 2021 09:28:43 +0100 (CET) Received: from mout-u-107.mailbox.org (mout-u-107.mailbox.org [IPv6:2001:67c:2050:1::465:107]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id BE346839B9 for ; Wed, 10 Nov 2021 09:28:36 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sr@denx.de Received: from smtp102.mailbox.org (unknown [91.198.250.119]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-107.mailbox.org (Postfix) with ESMTPS id 4Hpyfr2tNHzQkFr; Wed, 10 Nov 2021 09:28:36 +0100 (CET) Message-ID: <820afca4-5bd0-36d8-c08a-30ffb8e85e31@denx.de> Date: Wed, 10 Nov 2021 09:28:32 +0100 MIME-Version: 1.0 Subject: Re: [PATCH u-boot-marvell 07/11] tools: kwbimage: Do not put final image padding to the image data size Content-Language: en-US To: =?UTF-8?Q?Marek_Beh=c3=ban?= Cc: u-boot@lists.denx.de, =?UTF-8?Q?Pali_Roh=c3=a1r?= , =?UTF-8?Q?Marek_Beh=c3=ban?= References: <20211108171251.25382-1-kabel@kernel.org> <20211108171251.25382-8-kabel@kernel.org> From: Stefan Roese In-Reply-To: <20211108171251.25382-8-kabel@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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.103.2 at phobos.denx.de X-Virus-Status: Clean On 08.11.21 18:12, Marek Behún wrote: > From: Pali Rohár > > This change allows to convert image from one format to another without need > to include unnecessary padding (e.g. when target image format has smaller > alignment requirement as source image format). > > Do it by storing real image data size without padding to the kwbimage > header. > > Signed-off-by: Pali Rohár > Signed-off-by: Marek Behún Reviewed-by: Stefan Roese Thanks, Stefan > --- > tools/kwbimage.c | 30 +++++++++++++++++++++--------- > 1 file changed, 21 insertions(+), 9 deletions(-) > > diff --git a/tools/kwbimage.c b/tools/kwbimage.c > index b939b4cb49..a6f2659ab4 100644 > --- a/tools/kwbimage.c > +++ b/tools/kwbimage.c > @@ -890,7 +890,7 @@ static void *image_create_v0(size_t *imagesz, struct image_tool_params *params, > > /* Fill in the main header */ > main_hdr->blocksize = > - cpu_to_le32(payloadsz - headersz); > + cpu_to_le32(payloadsz); > main_hdr->srcaddr = cpu_to_le32(headersz); > main_hdr->ext = has_ext; > main_hdr->version = 0; > @@ -1234,7 +1234,7 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, > > /* Fill the main header */ > main_hdr->blocksize = > - cpu_to_le32(payloadsz - headersz); > + cpu_to_le32(payloadsz); > main_hdr->headersz_lsb = cpu_to_le16(headersz & 0xFFFF); > main_hdr->headersz_msb = (headersz & 0xFFFF0000) >> 16; > main_hdr->destaddr = cpu_to_le32(params->addr); > @@ -1345,7 +1345,7 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, > return NULL; > } > > - if (secure_hdr && add_secure_header_v1(params, ptr, payloadsz, > + if (secure_hdr && add_secure_header_v1(params, ptr, payloadsz + headersz, > headersz, image, secure_hdr)) > return NULL; > > @@ -1575,9 +1575,22 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, > void *image = NULL; > int version; > size_t headersz = 0; > + size_t datasz; > uint32_t checksum; > + struct stat s; > int ret; > > + /* > + * Do not use sbuf->st_size as it contains size with padding. > + * We need original image data size, so stat original file. > + */ > + if (stat(params->datafile, &s)) { > + fprintf(stderr, "Could not stat data file %s: %s\n", > + params->datafile, strerror(errno)); > + exit(EXIT_FAILURE); > + } > + datasz = ALIGN(s.st_size, 4); > + > fcfg = fopen(params->imagename, "r"); > if (!fcfg) { > fprintf(stderr, "Could not open input file %s\n", > @@ -1612,11 +1625,11 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, > */ > case -1: > case 0: > - image = image_create_v0(&headersz, params, sbuf->st_size); > + image = image_create_v0(&headersz, params, datasz + 4); > break; > > case 1: > - image = image_create_v1(&headersz, params, ptr, sbuf->st_size); > + image = image_create_v1(&headersz, params, ptr, datasz + 4); > break; > > default: > @@ -1633,11 +1646,10 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, > > free(image_cfg); > > - /* Build and add image checksum header */ > + /* Build and add image data checksum */ > checksum = cpu_to_le32(image_checksum32((uint8_t *)ptr + headersz, > - sbuf->st_size - headersz - sizeof(uint32_t))); > - memcpy((uint8_t *)ptr + sbuf->st_size - sizeof(uint32_t), &checksum, > - sizeof(uint32_t)); > + datasz)); > + memcpy((uint8_t *)ptr + headersz + datasz, &checksum, sizeof(uint32_t)); > > /* Finally copy the header into the image area */ > memcpy(ptr, image, headersz); > Viele Grüße, Stefan Roese -- DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr@denx.de