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 74731C433F5 for ; Wed, 12 Jan 2022 17:22:52 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 06C4883495; Wed, 12 Jan 2022 18:21:56 +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="da8Nrv7h"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F2CE98343B; Wed, 12 Jan 2022 18:21:48 +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 10EA383294 for ; Wed, 12 Jan 2022 18:21:41 +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 F2777616C7; Wed, 12 Jan 2022 17:21:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79E68C36AE5; Wed, 12 Jan 2022 17:21:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642008099; bh=0n11uY6xes+O7NyZUSoyZL2lQVe5HUFsbAH3Igy3NuQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=da8Nrv7hmLgFGK2Tr/NVu+dSHRdZ542LF4TIa3ka7bz6Nks8E8siTa/jJdoju8yLU gVRyq9Gqid2ViSzcXw/0z868EIsVQiKo5FwZia/n1nuRHM2Cpf5dOzgxu1dj4I5GyN /UMv3E/k8nsxeGk6gNyod5buPQpNmMlSMcUzbnDWc5s/toynxstU/S6cFzuFRvcs/L s/3pH6N4UtQM1+kddZhh2cKP4auhfZqqpBdl9nJLBrdTamDhX/h+rnt+si+gUTZV1A TUFnQPZMuQDXiaVJelPES6M/i6Ed3NusHPR7Cn1LNpmb4gUjMTxKVk/tJtV6fxNU8W YCpE6C5FD6OmQ== Received: by pali.im (Postfix) id 343D8768; Wed, 12 Jan 2022 18:21:39 +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 v2 04/20] tools: kwbimage: Preserve order of BINARY, DATA and DATA_DELAY commands Date: Wed, 12 Jan 2022 18:20:38 +0100 Message-Id: <20220112172054.5961-5-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220112172054.5961-1-pali@kernel.org> References: <20211221155416.8557-1-pali@kernel.org> <20220112172054.5961-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.39 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 Preserve the order of BINARY, DATA and DATA_DELAY commands as they appear in the input file. They may depend on each other. Signed-off-by: Pali Rohár Reviewed-by: Marek Behún --- tools/kwbimage.c | 58 +++++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 6ee3d0aaa86c..17d3c3cf223c 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1017,7 +1017,8 @@ static size_t image_headersz_v1(int *hasext) if (e->type == IMAGE_CFG_DATA) count++; - if (e->type == IMAGE_CFG_DATA_DELAY) { + if (e->type == IMAGE_CFG_DATA_DELAY || + (e->type == IMAGE_CFG_BINARY && count > 0)) { headersz += sizeof(struct register_set_hdr_v1) + 8 * count + 4; count = 0; } @@ -1289,6 +1290,7 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, int hasext = 0; uint8_t *next_ext = NULL; int cfgi, datai; + uint8_t delay; /* * Calculate the size of the header and the size of the @@ -1382,34 +1384,50 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, for (cfgi = 0; cfgi < cfgn; cfgi++) { e = &image_cfg[cfgi]; if (e->type != IMAGE_CFG_DATA && - e->type != IMAGE_CFG_DATA_DELAY) + e->type != IMAGE_CFG_DATA_DELAY && + e->type != IMAGE_CFG_BINARY) continue; + if (datai == 0) register_set_hdr = (struct register_set_hdr_v1 *)cur; - if (e->type == IMAGE_CFG_DATA_DELAY) { + + /* If delay is not specified, use the smallest possible value. */ + if (e->type == IMAGE_CFG_DATA_DELAY) + delay = e->regdata_delay; + else + delay = REGISTER_SET_HDR_OPT_DELAY_MS(0); + + /* + * DATA_DELAY command is the last entry in the register set + * header and BINARY command inserts new binary header. + * Therefore BINARY command requires to finish register set + * header if some DATA command was specified. And DATA_DELAY + * command automatically finish register set header even when + * there was no DATA command. + */ + if (e->type == IMAGE_CFG_DATA_DELAY || + (e->type == IMAGE_CFG_BINARY && datai != 0)) finish_register_set_header_v1(&cur, &next_ext, register_set_hdr, - &datai, e->regdata_delay); - continue; + &datai, delay); + + if (e->type == IMAGE_CFG_DATA) { + register_set_hdr->data[datai].entry.address = + cpu_to_le32(e->regdata.raddr); + register_set_hdr->data[datai].entry.value = + cpu_to_le32(e->regdata.rdata); + datai++; + } + + if (e->type == IMAGE_CFG_BINARY) { + if (add_binary_header_v1(&cur, &next_ext, e, main_hdr)) + return NULL; } - register_set_hdr->data[datai].entry.address = - cpu_to_le32(e->regdata.raddr); - register_set_hdr->data[datai].entry.value = - cpu_to_le32(e->regdata.rdata); - datai++; } if (datai != 0) { /* Set delay to the smallest possible value. */ + delay = REGISTER_SET_HDR_OPT_DELAY_MS(0); 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++) { - e = &image_cfg[cfgi]; - if (e->type != IMAGE_CFG_BINARY) - continue; - - if (add_binary_header_v1(&cur, &next_ext, e, main_hdr)) - return NULL; + &datai, delay); } if (secure_hdr && add_secure_header_v1(params, ptr, payloadsz + headersz, -- 2.20.1