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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 88394C433EF for ; Tue, 21 Dec 2021 15:56:58 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 22513834E4; Tue, 21 Dec 2021 16:56:16 +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="bhcFyRFl"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EFE7480FD2; Tue, 21 Dec 2021 16:56:02 +0100 (CET) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) (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 3F6928309A for ; Tue, 21 Dec 2021 16:55:48 +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=pali@kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BB9916164E; Tue, 21 Dec 2021 15:55:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08135C36AEC; Tue, 21 Dec 2021 15:55:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1640102146; bh=rOui2PehyjmtIcgC+TCrMG4PYztaR6eNv5+QuUI9z+8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bhcFyRFlHfW9Xyw2si+K2XN7TiC/+c6yKciPXi06OMXunC0tuMuIpYA0Bl5Z+6ddc sWlz8YZTmvrOwJL9Xu639cW61eaxuw42fzsIrSe0PdEiLw7BorRSfAy35ZeBJeaBqH km3wQb7YIJlfWQ8dxYvSrU045Q2YHVK7YzofYqYVRH/K/M9AwwCR11A8n8G7LSw2UK vYkwwc5T/jXhkxm4jr7VkPo2tyw0lWgWRZRUxv3JSaKuiKytcJBoZNAKam9N/8YUEW apjX1vj34K+/mYsdcYcGbkB0JdHkrc7fNaacwqanyCUfmuy/VQ9uG673uYXc3Yle4Y 0V5Wv7SH/mBSg== Received: by pali.im (Postfix) id A6B89284E; Tue, 21 Dec 2021 16:55:43 +0100 (CET) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Stefan Roese , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Chris Packham Cc: u-boot@lists.denx.de Subject: [PATCH u-boot-marvell 02/16] tools: kwbimage: Deduplicate v1 regtype header finishing Date: Tue, 21 Dec 2021 16:54:02 +0100 Message-Id: <20211221155416.8557-3-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211221155416.8557-1-pali@kernel.org> References: <20211221155416.8557-1-pali@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.38 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 Deduplicate code that finishes OPT_HDR_V1_REGISTER_TYPE header by extracing it into separate function. Signed-off-by: Pali Rohár Reviewed-by: Marek Behún --- tools/kwbimage.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 9f852923dc61..9ac74cfbe514 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1247,6 +1247,22 @@ static int add_secure_header_v1(struct image_tool_params *params, uint8_t *ptr, return 0; } +static void finish_register_set_header_v1(uint8_t **cur, uint8_t **next_ext, + struct register_set_hdr_v1 *register_set_hdr, + int *datai, uint8_t delay) +{ + int size = sizeof(struct register_set_hdr_v1) + 8 * (*datai) + 4; + + register_set_hdr->headertype = OPT_HDR_V1_REGISTER_TYPE; + register_set_hdr->headersz_lsb = cpu_to_le16(size & 0xFFFF); + register_set_hdr->headersz_msb = size >> 16; + register_set_hdr->data[*datai].last_entry.delay = delay; + *cur += size; + **next_ext = 1; + *next_ext = ®ister_set_hdr->data[*datai].last_entry.next; + *datai = 0; +} + static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, uint8_t *ptr, int payloadsz) { @@ -1259,7 +1275,7 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, uint8_t *image, *cur; int hasext = 0; uint8_t *next_ext = NULL; - int cfgi, datai, size; + int cfgi, datai; /* * Calculate the size of the header and the size of the @@ -1357,15 +1373,8 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, e->type != IMAGE_CFG_DATA_DELAY) continue; if (e->type == IMAGE_CFG_DATA_DELAY) { - size = sizeof(struct register_set_hdr_v1) + 8 * datai + 4; - register_set_hdr->headertype = OPT_HDR_V1_REGISTER_TYPE; - register_set_hdr->headersz_lsb = cpu_to_le16(size & 0xFFFF); - register_set_hdr->headersz_msb = size >> 16; - register_set_hdr->data[datai].last_entry.delay = e->regdata_delay; - cur += size; - *next_ext = 1; - next_ext = ®ister_set_hdr->data[datai].last_entry.next; - datai = 0; + finish_register_set_header_v1(&cur, &next_ext, register_set_hdr, + &datai, e->regdata_delay); continue; } register_set_hdr->data[datai].entry.address = @@ -1375,15 +1384,9 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, datai++; } if (datai != 0) { - size = sizeof(struct register_set_hdr_v1) + 8 * datai + 4; - register_set_hdr->headertype = OPT_HDR_V1_REGISTER_TYPE; - register_set_hdr->headersz_lsb = cpu_to_le16(size & 0xFFFF); - register_set_hdr->headersz_msb = size >> 16; - /* Set delay to the smallest possible value 1ms. */ - register_set_hdr->data[datai].last_entry.delay = 1; - cur += size; - *next_ext = 1; - next_ext = ®ister_set_hdr->data[datai].last_entry.next; + /* Set delay to the smallest possible value. */ + finish_register_set_header_v1(&cur, &next_ext, register_set_hdr, + &datai, REGISTER_SET_HDR_OPT_DELAY_MS(0)); } for (cfgi = 0; cfgi < cfgn; cfgi++) { -- 2.20.1