From patchwork Mon Nov 8 17:12:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1552451 X-Patchwork-Delegate: sr@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=ln1hXTpY; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HnyPJ3wXqz9sCD for ; Tue, 9 Nov 2021 04:13:24 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E0281838E5; Mon, 8 Nov 2021 18:13:12 +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="ln1hXTpY"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0270383904; Mon, 8 Nov 2021 18:13:09 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 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 322E2838D9 for ; Mon, 8 Nov 2021 18:12:57 +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 E795B61165; Mon, 8 Nov 2021 17:12:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636391575; bh=fSf5cKqsBESzB+Tt3ky7P8857ru3XJrvT/Uss9LBnUY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ln1hXTpYiDzTKR6FD768Cf5La/2WmHYfPd2EVHNMKRL/j1yk05Pw6N2t3UM34al54 jdncRvKkfhsfFYU59OUFzo/ihjOqjxFpaOpnOa7JrwU9xXfI8vpyRqYfXt7RCRiEho blx+7gN2T5f/H0Zu1ivVF2I1DiuGn8TWHbtks4d95i0IJo4/8V9lwUNyqWgsJj6ujk LdBw9yzCnLhL/AKHXD/lw1X+KIj2iZ+xqKiur+xVVgwfhfjSHQDu+F14aLBJ67g6Dh cNGcEUo20g8g8Jv/jZByUlIW0/1KDNWy8VHRzaVYZidGVsTjVNPlKJ3OAyZwAob28i iyhmNERsRA3fw== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Stefan Roese Cc: u-boot@lists.denx.de, =?utf-8?q?Pali_Roh=C3=A1r?= , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH u-boot-marvell 01/11] tools: kwbimage: Add support for new commands UART_PORT and UART_MPP Date: Mon, 8 Nov 2021 18:12:41 +0100 Message-Id: <20211108171251.25382-2-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 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 These two commands allow to specify custom setting of UART port used for printing BootROM messages. Signed-off-by: Pali Rohár Signed-off-by: Marek Behún Reviewed-by: Stefan Roese --- tools/kwbimage.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 67c0c628ae..f24d49496b 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -101,6 +101,8 @@ enum image_cfg_type { IMAGE_CFG_DATA, IMAGE_CFG_DATA_DELAY, IMAGE_CFG_BAUDRATE, + IMAGE_CFG_UART_PORT, + IMAGE_CFG_UART_MPP, IMAGE_CFG_DEBUG, IMAGE_CFG_KAK, IMAGE_CFG_CSK, @@ -129,6 +131,8 @@ static const char * const id_strs[] = { [IMAGE_CFG_DATA] = "DATA", [IMAGE_CFG_DATA_DELAY] = "DATA_DELAY", [IMAGE_CFG_BAUDRATE] = "BAUDRATE", + [IMAGE_CFG_UART_PORT] = "UART_PORT", + [IMAGE_CFG_UART_MPP] = "UART_MPP", [IMAGE_CFG_DEBUG] = "DEBUG", [IMAGE_CFG_KAK] = "KAK", [IMAGE_CFG_CSK] = "CSK", @@ -161,6 +165,8 @@ struct image_cfg_element { struct ext_hdr_v0_reg regdata; unsigned int regdata_delay; unsigned int baudrate; + unsigned int uart_port; + unsigned int uart_mpp; unsigned int debug; const char *key_name; int csk_idx; @@ -1239,7 +1245,13 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, main_hdr->nandbadblklocation = e->nandbadblklocation; e = image_find_option(IMAGE_CFG_BAUDRATE); if (e) - main_hdr->options = baudrate_to_option(e->baudrate); + main_hdr->options |= baudrate_to_option(e->baudrate); + e = image_find_option(IMAGE_CFG_UART_PORT); + if (e) + main_hdr->options |= (e->uart_port & 3) << 3; + e = image_find_option(IMAGE_CFG_UART_MPP); + if (e) + main_hdr->options |= (e->uart_mpp & 7) << 5; e = image_find_option(IMAGE_CFG_DEBUG); if (e) main_hdr->flags = e->debug ? 0x1 : 0; @@ -1441,6 +1453,12 @@ static int image_create_config_parse_oneline(char *line, case IMAGE_CFG_BAUDRATE: el->baudrate = strtoul(value1, NULL, 10); break; + case IMAGE_CFG_UART_PORT: + el->uart_port = strtoul(value1, NULL, 16); + break; + case IMAGE_CFG_UART_MPP: + el->uart_mpp = strtoul(value1, NULL, 16); + break; case IMAGE_CFG_DEBUG: el->debug = strtoul(value1, NULL, 10); break; From patchwork Mon Nov 8 17:12:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1552460 X-Patchwork-Delegate: sr@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=HFF0xxof; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HnyZd3wb0z9sCD for ; Tue, 9 Nov 2021 04:21:29 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0D01E838A1; Mon, 8 Nov 2021 18:21:23 +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="HFF0xxof"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 36A4383900; Mon, 8 Nov 2021 18:13:11 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 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 4DAFE838E5 for ; Mon, 8 Nov 2021 18:12:58 +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 30C866113D; Mon, 8 Nov 2021 17:12:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636391577; bh=tf9fo8AadjmsNnbbpszOIk7sm++a+XEYwfxeJfYNleA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HFF0xxofyVqALIrMGCUHNCwdWFC5R1AutWaEWl1gLzeXzIMU2sJ3QPSBhmUcp+3R4 YMH+1wVfsgq0gooWsR4WKvOL33pNxwP5u5Ta8pVlmZl1sMvxukny7eyin4qq/C4Srr oheAOuKNAXHsky7tSP+yGvwZ5Um7nVfN1H1g2qbZq8ggLwuNJvqc4CJHLBiS8xeGX0 sIkYTMkXm1NmeFmPqGoCNJrMjX9UtZNPniyoeXCj1QW3IuGSTr3xepX3xVV10NoxPV RKtRxlDrM0Cf/xDBC1iZmTsvR3EpxCgHrcpx8GancEYOLkalKG8PEbdvzHSRIhNQpk 72RxlJB3D/AbA== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Stefan Roese Cc: u-boot@lists.denx.de, =?utf-8?q?Pali_Roh=C3=A1r?= , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH u-boot-marvell 02/11] tools: kwbimage: Explicitly set version also for kwbimage v0 Date: Mon, 8 Nov 2021 18:12:42 +0100 Message-Id: <20211108171251.25382-3-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 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 For documentation purposes update struct main_hdr_v0 to include information where version of the image must be stored. For kwbimage v0 it obviously must be 0. By default all image header memory is initialized to zero, therefore this change has no functional effect. Signed-off-by: Pali Rohár Signed-off-by: Marek Behún Reviewed-by: Stefan Roese --- tools/kwbimage.c | 1 + tools/kwbimage.h | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/kwbimage.c b/tools/kwbimage.c index f24d49496b..d29f2cfcce 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -881,6 +881,7 @@ static void *image_create_v0(size_t *imagesz, struct image_tool_params *params, cpu_to_le32(payloadsz - headersz); main_hdr->srcaddr = cpu_to_le32(headersz); main_hdr->ext = has_ext; + main_hdr->version = 0; main_hdr->destaddr = cpu_to_le32(params->addr); main_hdr->execaddr = cpu_to_le32(params->ep); diff --git a/tools/kwbimage.h b/tools/kwbimage.h index f1ba95c2fa..f74767e633 100644 --- a/tools/kwbimage.h +++ b/tools/kwbimage.h @@ -42,7 +42,8 @@ struct main_hdr_v0 { uint8_t nandeccmode; /* 0x1 */ uint16_t nandpagesize; /* 0x2-0x3 */ uint32_t blocksize; /* 0x4-0x7 */ - uint32_t rsvd1; /* 0x8-0xB */ + uint8_t version; /* 0x8 */ + uint8_t rsvd1[3]; /* 0x9-0xB */ uint32_t srcaddr; /* 0xC-0xF */ uint32_t destaddr; /* 0x10-0x13 */ uint32_t execaddr; /* 0x14-0x17 */ From patchwork Mon Nov 8 17:12:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1552452 X-Patchwork-Delegate: sr@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=OC9v3hod; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HnyPV750lz9sCD for ; Tue, 9 Nov 2021 04:13:34 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C526D838EB; Mon, 8 Nov 2021 18:13:20 +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="OC9v3hod"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 319EE83894; Mon, 8 Nov 2021 18:13:18 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 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 8DAA6838EF for ; Mon, 8 Nov 2021 18:12:59 +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 6A6B361242; Mon, 8 Nov 2021 17:12:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636391578; bh=IQ7Arn+on9sl9g0hwYzY+uISp1nMTxOGv4xprwMZTTc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OC9v3hod8ulJoasa3fPY95Kx/2AG0htdUe92bdnifUPbMg1iCNTDDH/ys1Uae73v9 dJarcIWpkzvoCgkyaZ0Y5zUZDeR6f+2V9SP4urBPNJHNXs6y24N56ESHdSv/JBxJGr HkfquoXanyXsqlfc7/NdysaUE3SyA3TdtfHIzKlZ2DwfVWOHGU2vA0kF08wrlvMa6e iOBL3m96Mi5mx6R7Bnu3sBn1l8cNPMSQ2wrboWmhl/J1U796wT0ECxhnwdNIqe/gp2 hz2Bgg7s5LFzzHWPIOb0l71jms+/0a3HIbNt64zqlzS7gmf6ArRVlfjwo/SBJuYZQ8 ZK6Xv3VuTmIGQ== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Stefan Roese Cc: u-boot@lists.denx.de, =?utf-8?q?Pali_Roh=C3=A1r?= , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH u-boot-marvell 03/11] tools: kwbimage: Set BOOT_FROM by default to SPI Date: Mon, 8 Nov 2021 18:12:43 +0100 Message-Id: <20211108171251.25382-4-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 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 must have valid blockid member instead of zero value. Thus if config file does not contain BOOT_FROM command, use by default the value for SPI booting (which is probably the most common). Signed-off-by: Pali Rohár Signed-off-by: Marek Behún Reviewed-by: Stefan Roese --- tools/kwbimage.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/tools/kwbimage.c b/tools/kwbimage.c index d29f2cfcce..38b6e2fed2 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -266,6 +266,18 @@ static bool image_get_spezialized_img(void) return e->sec_specialized_img; } +static int image_get_bootfrom(void) +{ + struct image_cfg_element *e; + + e = image_find_option(IMAGE_CFG_BOOT_FROM); + if (!e) + /* fallback to SPI if no BOOT_FROM is not provided */ + return IBR_HDR_SPI_ID; + + return e->bootfrom; +} + /* * Compute a 8-bit checksum of a memory area. This algorithm follows * the requirements of the Marvell SoC BootROM specifications. @@ -884,10 +896,8 @@ static void *image_create_v0(size_t *imagesz, struct image_tool_params *params, main_hdr->version = 0; main_hdr->destaddr = cpu_to_le32(params->addr); main_hdr->execaddr = cpu_to_le32(params->ep); + main_hdr->blockid = image_get_bootfrom(); - e = image_find_option(IMAGE_CFG_BOOT_FROM); - if (e) - main_hdr->blockid = e->bootfrom; e = image_find_option(IMAGE_CFG_NAND_ECC_MODE); if (e) main_hdr->nandeccmode = e->nandeccmode; @@ -1232,9 +1242,8 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, main_hdr->srcaddr = cpu_to_le32(headersz); main_hdr->ext = hasext; main_hdr->version = 1; - e = image_find_option(IMAGE_CFG_BOOT_FROM); - if (e) - main_hdr->blockid = e->bootfrom; + main_hdr->blockid = image_get_bootfrom(); + e = image_find_option(IMAGE_CFG_NAND_BLKSZ); if (e) main_hdr->nandblocksize = e->nandblksz / (64 * 1024); @@ -1559,17 +1568,6 @@ static int image_get_version(void) return e->version; } -static int image_get_bootfrom(void) -{ - struct image_cfg_element *e; - - e = image_find_option(IMAGE_CFG_BOOT_FROM); - if (!e) - return -1; - - return e->bootfrom; -} - static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, struct image_tool_params *params) { From patchwork Mon Nov 8 17:12:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1552461 X-Patchwork-Delegate: sr@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=L0fYx4sT; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HnyZq0B84z9sCD for ; Tue, 9 Nov 2021 04:21:38 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7E1E2838E2; Mon, 8 Nov 2021 18:21:27 +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="L0fYx4sT"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4DDA5838EF; Mon, 8 Nov 2021 18:13:18 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 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 D33618388B for ; Mon, 8 Nov 2021 18:12:59 +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 A482861355; Mon, 8 Nov 2021 17:12:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636391579; bh=VDCCa0+fs0RWr7mD4chKqkpNNi9LA6Fgm+ImJkBQq/M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L0fYx4sTufLbPOxYnB6Lbm6nqAhN7go1cpjHroowZZZzNTYRI+Qc3igmmB6Bp+Xm/ 2V0CnFgYmhE9jorhlyAatug6skA5ias4WgKmJYEc6Xp53e1GTexM+gACAw4g3ylTjH otyldAK4KSsb1iDTA/m5t/fS2KgarGEgnZwYWOMZSoUhsw2mXCrffbT5blCvPDguPb HtiqDVyHIJ7dZPn+iVRjjrEosze0p2dYKUzTqz0cj3nk/sL1sc1R23oRLxT7564yEL S1WlOnzqo67Z2s0az2NSAz2VOHk8pE7cKdNI1vw98DlqDXp/k4S4I1k6RtJk9vjlfK OFIdxWwn8plPw== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Stefan Roese Cc: u-boot@lists.denx.de, =?utf-8?q?Pali_Roh=C3=A1r?= , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH u-boot-marvell 04/11] tools: kwbimage: Fix validation of kwbimage v0 Date: Mon, 8 Nov 2021 18:12:44 +0100 Message-Id: <20211108171251.25382-5-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 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 sldo has 32-bit data checksum at the end like kwbimage v1. Use same data checksum validation for both v0 and v1 image types. Signed-off-by: Pali Rohár Signed-off-by: Marek Behún Reviewed-by: Stefan Roese --- tools/kwbimage.c | 80 ++++++++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 37 deletions(-) diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 38b6e2fed2..a176b39b08 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1680,6 +1680,9 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size, struct image_tool_params *params) { size_t header_size = kwbheader_size(ptr); + uint8_t blockid; + uint32_t offset; + uint32_t size; uint8_t csum; if (header_size > image_size) @@ -1699,61 +1702,64 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size, if (csum != ext_hdr->checksum) return -FDT_ERR_BADSTRUCTURE; } + + blockid = mhdr->blockid; + offset = le32_to_cpu(mhdr->srcaddr); + size = le32_to_cpu(mhdr->blocksize); } else if (kwbimage_version(ptr) == 1) { struct main_hdr_v1 *mhdr = (struct main_hdr_v1 *)ptr; const uint8_t *mhdr_end; struct opt_hdr_v1 *ohdr; - uint32_t offset; - uint32_t size; mhdr_end = (uint8_t *)mhdr + header_size; for_each_opt_hdr_v1 (ohdr, ptr) if (!opt_hdr_v1_valid_size(ohdr, mhdr_end)) return -FDT_ERR_BADSTRUCTURE; + blockid = mhdr->blockid; offset = le32_to_cpu(mhdr->srcaddr); + size = le32_to_cpu(mhdr->blocksize); + } else { + return -FDT_ERR_BADSTRUCTURE; + } - /* - * For SATA srcaddr is specified in number of sectors. - * The main header is must be stored at sector number 1. - * This expects that sector size is 512 bytes and recalculates - * data offset to bytes relative to the main header. - */ - if (mhdr->blockid == IBR_HDR_SATA_ID) { - if (offset < 1) - return -FDT_ERR_BADSTRUCTURE; - offset -= 1; - offset *= 512; - } + /* + * For SATA srcaddr is specified in number of sectors. + * The main header is must be stored at sector number 1. + * This expects that sector size is 512 bytes and recalculates + * data offset to bytes relative to the main header. + */ + if (blockid == IBR_HDR_SATA_ID) { + if (offset < 1) + return -FDT_ERR_BADSTRUCTURE; + offset -= 1; + offset *= 512; + } - /* - * For SDIO srcaddr is specified in number of sectors. - * This expects that sector size is 512 bytes and recalculates - * data offset to bytes. - */ - if (mhdr->blockid == IBR_HDR_SDIO_ID) - offset *= 512; + /* + * For SDIO srcaddr is specified in number of sectors. + * This expects that sector size is 512 bytes and recalculates + * data offset to bytes. + */ + if (blockid == IBR_HDR_SDIO_ID) + offset *= 512; - /* - * For PCIe srcaddr is always set to 0xFFFFFFFF. - * This expects that data starts after all headers. - */ - if (mhdr->blockid == IBR_HDR_PEX_ID && offset == 0xFFFFFFFF) - offset = header_size; + /* + * For PCIe srcaddr is always set to 0xFFFFFFFF. + * This expects that data starts after all headers. + */ + if (blockid == IBR_HDR_PEX_ID && offset == 0xFFFFFFFF) + offset = header_size; - if (offset > image_size || offset % 4 != 0) - return -FDT_ERR_BADSTRUCTURE; + if (offset > image_size || offset % 4 != 0) + return -FDT_ERR_BADSTRUCTURE; - size = le32_to_cpu(mhdr->blocksize); - if (size < 4 || offset + size > image_size || size % 4 != 0) - return -FDT_ERR_BADSTRUCTURE; + if (size < 4 || offset + size > image_size || size % 4 != 0) + return -FDT_ERR_BADSTRUCTURE; - if (image_checksum32(ptr + offset, size - 4) != - *(uint32_t *)(ptr + offset + size - 4)) - return -FDT_ERR_BADSTRUCTURE; - } else { + if (image_checksum32(ptr + offset, size - 4) != + *(uint32_t *)(ptr + offset + size - 4)) return -FDT_ERR_BADSTRUCTURE; - } return 0; } From patchwork Mon Nov 8 17:12:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1552453 X-Patchwork-Delegate: sr@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=RoDKSpSD; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HnyPm6rFKz9sCD for ; Tue, 9 Nov 2021 04:13:48 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4305C838F1; Mon, 8 Nov 2021 18:13:25 +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="RoDKSpSD"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5E3FD8383A; Mon, 8 Nov 2021 18:13:20 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 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 EC5FF83895 for ; Mon, 8 Nov 2021 18:13:02 +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 DDFB361406; Mon, 8 Nov 2021 17:12:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636391580; bh=5oLHeCbteTYH7m6jytCqVFFUUQkU9e+5pp+LYxO3b9k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RoDKSpSDj/5DswnZw5V+um5pxtBoHqJuaxPYqK9j7xQLCoEatAbl9gWfnxDFvTFAc Nw3jo8het5xVifEbe7e0EullKmxPWYWyIbL6MMpqHklhrVz9qTGS8CniV6/F+cDj8Q O8G+bbWZppRCgces7RtTqbM3bkqaJ+LQC94sYeXP/T+rLhyvnslgLwD4hA6R//9FYN z4finn8YuV9EQsGwLBdeVstmj5PuRj6f4GFSFOmDA5a4oRBa9jqaTI9KjRnpUx7w8W vJG04DwWFQ1mO+htY025t5vCnhQBcRbdt2LWEfVB7LFPUFH9osO4uwrU0xelaIw401 wUZrdav97uCDw== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Stefan Roese Cc: u-boot@lists.denx.de, =?utf-8?q?Pali_Roh=C3=A1r?= , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH u-boot-marvell 05/11] tools: kwbimage: Remove unused enums and prototypes Date: Mon, 8 Nov 2021 18:12:45 +0100 Message-Id: <20211108171251.25382-6-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 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 There are more unused enums and function prototypes. Remove them. The function kwbimage_check_params() does not return enum kwbimage_cmd_types, but a boolean value returned as int. Signed-off-by: Pali Rohár Signed-off-by: Marek Behún Reviewed-by: Stefan Roese --- tools/kwbimage.c | 2 +- tools/kwbimage.h | 22 ---------------------- 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/tools/kwbimage.c b/tools/kwbimage.c index a176b39b08..864625d788 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1916,7 +1916,7 @@ static int kwbimage_check_params(struct image_tool_params *params) char *msg = "Configuration file for kwbimage creation omitted"; fprintf(stderr, "Error:%s - %s\n", params->cmdname, msg); - return CFG_INVALID; + return 1; } return (params->dflag && (params->fflag || params->lflag)) || diff --git a/tools/kwbimage.h b/tools/kwbimage.h index f74767e633..8d37357e5a 100644 --- a/tools/kwbimage.h +++ b/tools/kwbimage.h @@ -191,28 +191,6 @@ struct register_set_hdr_v1 { #define OPT_HDR_V1_BINARY_TYPE 0x2 #define OPT_HDR_V1_REGISTER_TYPE 0x3 -enum kwbimage_cmd { - CMD_INVALID, - CMD_BOOT_FROM, - CMD_NAND_ECC_MODE, - CMD_NAND_PAGE_SIZE, - CMD_SATA_PIO_MODE, - CMD_DDR_INIT_DELAY, - CMD_DATA -}; - -enum kwbimage_cmd_types { - CFG_INVALID = -1, - CFG_COMMAND, - CFG_DATA0, - CFG_DATA1 -}; - -/* - * functions - */ -void init_kwb_image_type (void); - /* * Byte 8 of the image header contains the version number. In the v0 * header, byte 8 was reserved, and always set to 0. In the v1 header, From patchwork Mon Nov 8 17:12:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1552454 X-Patchwork-Delegate: sr@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=Qhul5yIy; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HnyQ04gHCz9sCD for ; Tue, 9 Nov 2021 04:14:00 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D924F838D3; Mon, 8 Nov 2021 18:13:28 +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="Qhul5yIy"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4AA6483894; Mon, 8 Nov 2021 18:13:21 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 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 500BD838ED for ; Mon, 8 Nov 2021 18:13:03 +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 2351061165; Mon, 8 Nov 2021 17:13:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636391582; bh=6unlBaV+e3+5y3u7FJnLcTrf7k0NFi/4NMCdkcsyS5U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qhul5yIyGd3vACA3Zazhs/FD45hibwz9w/kyNYzxPMlICUiHTmywUol9u7gSOfzW6 Vt+QDaflzk1d2eZmIphG7ZkK6kLQ6Nf2/1QCDpk3mJ4167L7ubIZmsZERmlH9jw4KU WbPztgES+4K0vZUDbP7ArHCH+utR/1LY7Ce6pZKghNKX7jzgT7B/QyUCKizrVX20ok b9xAhUOSfn0gm6C0QA+DjuGGzbdTecHfXFGZiZz4V2cFqrEGjrCs3DLy1bZY3gNuyl E6I6Vkdduy9lydrnTEUiUOWCNDxYR6IfUy7YRGznHvHm94HDBwMNVG4UBIqc6D7znE uCcOwDykqyTEg== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Stefan Roese Cc: u-boot@lists.denx.de, =?utf-8?q?Pali_Roh=C3=A1r?= , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH u-boot-marvell 06/11] tools: kwbimage: Align final UART image to 128 bytes Date: Mon, 8 Nov 2021 18:12:46 +0100 Message-Id: <20211108171251.25382-7-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 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 xmodem block size is 128 bytes, therefore it is possible to transfer only images with size multiple of 128 bytes. kwboot automatically pads image with zero bytes at the end to align it to 128 bytes boundary. Do this padding when generating image to allow uploading with other xmodem tools or older kwboot versions. Signed-off-by: Pali Rohár Signed-off-by: Marek Behún Reviewed-by: Stefan Roese --- tools/kwbimage.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 864625d788..b939b4cb49 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1847,6 +1847,7 @@ static int kwbimage_generate(struct image_tool_params *params, * The resulting image needs to be 4-byte aligned. At least * the Marvell hdrparser tool complains if its unaligned. * After the image data is stored 4-byte checksum. + * Final UART image must be aligned to 128 bytes. * Final SPI and NAND images must be aligned to 256 bytes. * Final SATA and SDIO images must be aligned to 512 bytes. */ @@ -1854,6 +1855,8 @@ static int kwbimage_generate(struct image_tool_params *params, return 4 + (256 - (alloc_len + s.st_size + 4) % 256) % 256; else if (bootfrom == IBR_HDR_SATA_ID || bootfrom == IBR_HDR_SDIO_ID) return 4 + (512 - (alloc_len + s.st_size + 4) % 512) % 512; + else if (bootfrom == IBR_HDR_UART_ID) + return 4 + (128 - (alloc_len + s.st_size + 4) % 128) % 128; else return 4 + (4 - s.st_size % 4) % 4; } From patchwork Mon Nov 8 17:12:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1552455 X-Patchwork-Delegate: sr@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=mWI4QvZO; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HnyQD1Nv3z9sCD for ; Tue, 9 Nov 2021 04:14:11 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D9777838D7; Mon, 8 Nov 2021 18:13:33 +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="mWI4QvZO"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9917A838ED; Mon, 8 Nov 2021 18:13:22 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 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 95BCB838F6 for ; Mon, 8 Nov 2021 18:13:04 +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 5CD7361458; Mon, 8 Nov 2021 17:13:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636391583; bh=xAFgolTvgaDUZr8/BP3hYP03teH5t38kupu+rNVWCKw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mWI4QvZOw5qQl8L7mvokOfY/CJvUI4pQK72+p7DaZWTja+IKAVM6Av2H+ArUqacVO 1OJmSx/q23zKU4UIJDn4aki7DLqqEY9qvKIHa7APzw5/ii6Xa86Fb4FDAIIDyih8mA 4r2FagFrgKMGc/tC9SriQUDkUXydbZZDtSV2PXplzRa9K8j9YlT0Gz8CY95JQtiv7z fbLv8UjoEg903D+Bp8npuq4C/3FQPPXpaQN+YWpwmLzoK672/lxd08gJJrv9N6qtVe 9cxbWXwCRjE+JFL0Rd7jw78K2BS22i7hEu8oDfQ4ujNx+eVXwuEp95Oi0KGMsk/7Wg SRxQ5fk8rR0vA== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Stefan Roese Cc: u-boot@lists.denx.de, =?utf-8?q?Pali_Roh=C3=A1r?= , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH u-boot-marvell 07/11] tools: kwbimage: Do not put final image padding to the image data size Date: Mon, 8 Nov 2021 18:12:47 +0100 Message-Id: <20211108171251.25382-8-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 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 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 --- 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); From patchwork Mon Nov 8 17:12:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1552456 X-Patchwork-Delegate: sr@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=NYnnXWFu; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HnyQc1ys9z9sCD for ; Tue, 9 Nov 2021 04:14:32 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5E4AC83903; Mon, 8 Nov 2021 18:13:47 +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="NYnnXWFu"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5019D838D7; Mon, 8 Nov 2021 18:13:27 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 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 C433E838FD for ; Mon, 8 Nov 2021 18:13:05 +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 9723E61242; Mon, 8 Nov 2021 17:13:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636391584; bh=wZAPyrw+w+xJS49xmWPpitLKplPLgMr4DHBlDD7xGWE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NYnnXWFuY6qIVKFa0bYkN4CF3+sInTQSWctdC4Ya4J1NJrcrv9f4PGPjjh4/p+8+z EEAwdoICSpaUGeFGHiyqHUwjVCJ/RC8w3ZskQzpzBKWtYssW+oTxtjeuUUKV+Htvvg 1uriDmV/GydS6uKzFMgM9yAqASLnHJPuzknC8fGrmPSOO6kM7UfiSTVuYpgpPHOGkO N+BOY2TkIq1l+D1Bg6PwNvwKlhDr8ZuuCtFNt9bum+iLJVtPbsj5wI46ynyNQSTuji jSiNK5c7fvEwGiOIUEoKn2RCYnqmh825DlJni+hYyfGHUv/wRij596LqCuJvVgF2Y9 WC1xiuOJ5pYRQ== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Stefan Roese Cc: u-boot@lists.denx.de, =?utf-8?q?Pali_Roh=C3=A1r?= , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH u-boot-marvell 08/11] tools: kwbimage: Align kwbimage header to proper size Date: Mon, 8 Nov 2021 18:12:48 +0100 Message-Id: <20211108171251.25382-9-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 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 Currently kwbimage header is always aligned to 4096 bytes. But it does not have to be aligned to such a high value. The header needs to be just 4-byte aligned, while some image types have additional alignment restrictions. This change reduces size of kwbimage binaries by removing extra padding between header and data part. Signed-off-by: Pali Rohár Signed-off-by: Marek Behún Reviewed-by: Stefan Roese --- tools/kwbimage.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/tools/kwbimage.c b/tools/kwbimage.c index a6f2659ab4..8dcfebcb57 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -858,6 +858,27 @@ done: return ret; } +static size_t image_headersz_align(size_t headersz, uint8_t blockid) +{ + /* + * Header needs to be 4-byte aligned, which is already ensured by code + * above. Moreover UART images must have header aligned to 128 bytes + * (xmodem block size), NAND images to 256 bytes (ECC calculation), + * and SATA and SDIO images to 512 bytes (storage block size). + * Note that SPI images do not have to have header size aligned + * to 256 bytes because it is possible to read from SPI storage from + * any offset (read offset does not have to be aligned to block size). + */ + if (blockid == IBR_HDR_UART_ID) + return ALIGN(headersz, 128); + else if (blockid == IBR_HDR_NAND_ID) + return ALIGN(headersz, 256); + else if (blockid == IBR_HDR_SATA_ID || blockid == IBR_HDR_SDIO_ID) + return ALIGN(headersz, 512); + else + return headersz; +} + static void *image_create_v0(size_t *imagesz, struct image_tool_params *params, int payloadsz) { @@ -994,11 +1015,7 @@ static size_t image_headersz_v1(int *hasext) *hasext = 1; } - /* - * The payload should be aligned on some reasonable - * boundary - */ - return ALIGN(headersz, 4096); + return image_headersz_align(headersz, image_get_bootfrom()); } int add_binary_header_v1(uint8_t **cur, uint8_t **next_ext, From patchwork Mon Nov 8 17:12:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1552458 X-Patchwork-Delegate: sr@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=U9BRHE5p; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HnyQz4Pm8z9sCD for ; Tue, 9 Nov 2021 04:14:51 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0A10283919; Mon, 8 Nov 2021 18:13:53 +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="U9BRHE5p"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F1CD98385E; Mon, 8 Nov 2021 18:13:32 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 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 1158B83903 for ; Mon, 8 Nov 2021 18:13:06 +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 D101E61130; Mon, 8 Nov 2021 17:13:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636391585; bh=h3xn05WwxmXtjljA96hlAPoSG5c8MqBRXAftrfXVk+U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U9BRHE5pbVh/rgjpC6z/nH46+k1i80EM448v82iJShP436h6dkirAwIyymf15c25/ oNsh8KAraONsel47xS0f6wBisw8ptume2bZa5T66H976o1vLqSvqrX5izSYIJOTvE0 h1VKlAD7UHQFh2g7CD+oThvr2XrV/F/6n9vfu0nbO4gF+w7BfqoPeRYNc4YdCC0SCR 1YeHowQpkVZwkNLL58RszLVGLFk7VtndQ1aMSwxOs723aWp0FIXRh7im6X+xV2nVQZ GfeNunsRdDV4SAwBJ3a2HAfNd9l6hOQTgmqdGzvH1n7W3ITNBApt8LcIGPjmWNfWky mm3TIA1LdBgyQ== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Stefan Roese Cc: u-boot@lists.denx.de, =?utf-8?q?Pali_Roh=C3=A1r?= , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH u-boot-marvell 09/11] tools: kwbimage: Fill the real header size into the main header Date: Mon, 8 Nov 2021 18:12:49 +0100 Message-Id: <20211108171251.25382-10-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 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 Fill the real header size without padding into the main header This allows to reduce final image when converting image to another format which does not need additional padding. Signed-off-by: Pali Rohár Signed-off-by: Marek Behún Reviewed-by: Stefan Roese --- tools/kwbimage.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 8dcfebcb57..114b313b4d 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1220,6 +1220,7 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, { struct image_cfg_element *e; struct main_hdr_v1 *main_hdr; + struct opt_hdr_v1 *ohdr; struct register_set_hdr_v1 *register_set_hdr; struct secure_hdr_v1 *secure_hdr = NULL; size_t headersz; @@ -1370,6 +1371,14 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, main_hdr->checksum = image_checksum8(main_hdr, headersz); *imagesz = headersz; + + /* Fill the real header size without padding into the main header */ + headersz = sizeof(*main_hdr); + for_each_opt_hdr_v1 (ohdr, main_hdr) + headersz += opt_hdr_v1_size(ohdr); + main_hdr->headersz_lsb = cpu_to_le16(headersz & 0xFFFF); + main_hdr->headersz_msb = (headersz & 0xFFFF0000) >> 16; + return image; } From patchwork Mon Nov 8 17:12:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1552457 X-Patchwork-Delegate: sr@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=b0VNJWDu; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HnyQp4MMhz9sCD for ; Tue, 9 Nov 2021 04:14:42 +1100 (AEDT) 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) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 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_Beh=C3=BAn?= To: Stefan Roese Cc: u-boot@lists.denx.de, =?utf-8?q?Pali_Roh=C3=A1r?= , =?utf-8?q?Marek_Beh=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 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 Reviewed-by: Stefan Roese --- 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: From patchwork Mon Nov 8 17:12:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1552459 X-Patchwork-Delegate: sr@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=FGbJD8WO; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HnyR906gXz9sCD for ; Tue, 9 Nov 2021 04:15:00 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0B0CD83922; Mon, 8 Nov 2021 18:13: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="FGbJD8WO"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7F0818385E; Mon, 8 Nov 2021 18:13:38 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 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 7AB508390A for ; Mon, 8 Nov 2021 18:13:09 +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 534DA6108E; Mon, 8 Nov 2021 17:13:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636391588; bh=IOLY4bImlxwcLM34Cj7gS4uZQR+uXr9X9Ud5EYzOU8g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FGbJD8WOQ7Ze41CQe7RI/6o6NIZW7Z9hACmQ4YsVH6XbwNlsYH5LvQq5zcS+SoOzv NyoAtYALXzMhFJBe+vgB03mvL/lv6DtbqXxPOPD+onPUL1XdPt27LNSndT6pXNH1rn qHW7fOvYr9eMz0dPbyOsoK5NRHTer1gr0iShpvinbAbKCJOiRqCrHPH+NlI/8sTdO/ l6dRfHEksZ+K1wD60GqUe0y2Ve+s2COw3Cz7M566OuoyxboVN73fYVkUt77fWFQdGp ViWMlNHHnF93Dk/4u2D2QeTwvJ6OCnJ+EnGcdlMbwtwzJW6W3L/V8LMU4kcO7CIVOJ 5oAgp2uboi5Aw== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Stefan Roese Cc: u-boot@lists.denx.de, =?utf-8?q?Pali_Roh=C3=A1r?= , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH u-boot-marvell 11/11] tools: kwbimage: Properly set srcaddr in kwbimage v0 Date: Mon, 8 Nov 2021 18:12:51 +0100 Message-Id: <20211108171251.25382-12-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 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 Field srcaddr in kwbimage v0 needs to be adjusted similarly like in v1. Signed-off-by: Pali Rohár Signed-off-by: Marek Behún Reviewed-by: Stefan Roese --- tools/kwbimage.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 952023c14c..875f636c7a 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -937,6 +937,28 @@ static void *image_create_v0(size_t *imagesz, struct image_tool_params *params, main_hdr->checksum = image_checksum8(image, sizeof(struct main_hdr_v0)); + /* + * For SATA srcaddr is specified in number of sectors starting from + * sector 0. The main header is stored at sector number 1. + * This expects the sector size to be 512 bytes. + * Header size is already aligned. + */ + if (main_hdr->blockid == IBR_HDR_SATA_ID) + main_hdr->srcaddr = cpu_to_le32(headersz / 512 + 1); + + /* + * For SDIO srcaddr is specified in number of sectors starting from + * sector 0. The main header is stored at sector number 0. + * This expects sector size to be 512 bytes. + * Header size is already aligned. + */ + if (main_hdr->blockid == IBR_HDR_SDIO_ID) + main_hdr->srcaddr = cpu_to_le32(headersz / 512); + + /* For PCIe srcaddr is not used and must be set to 0xFFFFFFFF. */ + if (main_hdr->blockid == IBR_HDR_PEX_ID) + main_hdr->srcaddr = cpu_to_le32(0xFFFFFFFF); + /* Generate the ext header */ if (has_ext) { struct ext_hdr_v0 *ext_hdr;