From mboxrd@z Thu Jan 1 00:00:00 1970 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 8A085C433EF for ; Mon, 8 Nov 2021 17:14:40 +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 0B0566108E for ; Mon, 8 Nov 2021 17:14:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0B0566108E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org 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 A47AF838F2; Mon, 8 Nov 2021 18:13:50 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="b0VNJWDu"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9BA33838FB; Mon, 8 Nov 2021 18:13:32 +0100 (CET) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) (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 3F56783906 for ; Mon, 8 Nov 2021 18:13:08 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kabel@kernel.org Received: by mail.kernel.org (Postfix) with ESMTPSA id 19D8C610A6; Mon, 8 Nov 2021 17:13:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636391586; bh=Lc6xt9/bzf/l1Uhw0dCG/ER1Iheyf5PgiGJC8syfeQE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b0VNJWDuvYwzN9T6SSOC+8dOXX9/24yfo4vidayr+gyiSt66zPyDcuK7VIpKQ975z d1loYJ3OQlBgAPqIVv49m1+kIzRObJIrNsL0kDxmJuF9nDPxYM91pyWM/661AxuJ83 0INox3sYvg76yF8DKGSj/Jj+5kjqbDjyaUDMJvvTm9bNbNeZBptfKqhJ2Vz3PvqxYP 8JVs13wmjetKlAhZ2nosZDBos41ONJ66L6TbHhlfdK9VWQGiJWDtBXbp6J9BnWed4Q 2zKZ+j0ekgFigIeEqcBSHKIIaowQ4DSHNBI9smfKjMIkYuHF1zJooHUpnMiziDVSB3 VhNwlbm1X6/6w== From: =?UTF-8?q?Marek=20Beh=C3=BAn?= To: Stefan Roese Cc: u-boot@lists.denx.de, =?UTF-8?q?Pali=20Roh=C3=A1r?= , =?UTF-8?q?Marek=20Beh=C3=BAn?= Subject: [PATCH u-boot-marvell 10/11] tools: kwbimage: Properly calculate and align kwbimage v0 header size Date: Mon, 8 Nov 2021 18:12:50 +0100 Message-Id: <20211108171251.25382-11-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211108171251.25382-1-kabel@kernel.org> References: <20211108171251.25382-1-kabel@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 From: Pali Rohár Kwbimage v0 has similar alignment requirements as v1. Signed-off-by: Pali Rohár Signed-off-by: Marek Behún --- tools/kwbimage.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 114b313b4d..952023c14c 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -879,6 +879,20 @@ static size_t image_headersz_align(size_t headersz, uint8_t blockid) return headersz; } +static size_t image_headersz_v0(int *hasext) +{ + size_t headersz; + + headersz = sizeof(struct main_hdr_v0); + if (image_count_options(IMAGE_CFG_DATA) > 0) { + headersz += sizeof(struct ext_hdr_v0); + if (hasext) + *hasext = 1; + } + + return image_headersz_align(headersz, image_get_bootfrom()); +} + static void *image_create_v0(size_t *imagesz, struct image_tool_params *params, int payloadsz) { @@ -892,12 +906,7 @@ static void *image_create_v0(size_t *imagesz, struct image_tool_params *params, * Calculate the size of the header and the size of the * payload */ - headersz = sizeof(struct main_hdr_v0); - - if (image_count_options(IMAGE_CFG_DATA) > 0) { - has_ext = 1; - headersz += sizeof(struct ext_hdr_v0); - } + headersz = image_headersz_v0(&has_ext); image = malloc(headersz); if (!image) { @@ -1854,8 +1863,7 @@ static int kwbimage_generate(struct image_tool_params *params, */ case -1: case 0: - alloc_len = sizeof(struct main_hdr_v0) + - sizeof(struct ext_hdr_v0); + alloc_len = image_headersz_v0(NULL); break; case 1: -- 2.32.0