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 86557C636D7 for ; Tue, 21 Feb 2023 20:31:24 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8BEA985AA2; Tue, 21 Feb 2023 21:24:13 +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="E4QO1NxS"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 60C6985B18; Tue, 21 Feb 2023 21:23:44 +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 9502C85ADD for ; Tue, 21 Feb 2023 21:22:44 +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 8BA84611FB; Tue, 21 Feb 2023 20:22:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5A9CC4339C; Tue, 21 Feb 2023 20:22:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1677010956; bh=CiN3c38fPjZTl6BQhPLlr6ML2LRri8rciAF2pmqcRpo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E4QO1NxSyxkvAUVLWBQHzNlJeaQdtsmycXrJ6rJbjHCyVUntRfo0hvcsbDvMosM7F s3KsvO8ERyd+9cEnI4rNh1uvxfDVXz1J+Z3C8l4nAcF61V1PXDy4z1rt1iIN0HSz4x 0KgLdOzIx+dg0XNI9NQcSKP/hywIv03G56TuVmnZRGUTZMQER7gfkcm55rLhp4zUfT 74mTZYV6GApko9LtE6bySEYuvB55rFujRgbchhbwfnj4yrCSQ6x40P6gvApcYB6udB XqLTwMy3tJ6r4dyK17DQSJegdcvSLZqngxUA3zuoN8hy+4IqifeUav3Qv0/86hrR7L u8JdsRB/DVq8w== Received: by pali.im (Postfix) id 925319E0; Tue, 21 Feb 2023 21:22:35 +0100 (CET) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: u-boot@lists.denx.de Cc: Stefan Roese , Tony Dinh , Josua Mayer Subject: [PATCH RFC u-boot-mvebu 49/59] tools: kwbimage: Add support for creating an image with no data Date: Tue, 21 Feb 2023 21:19:15 +0100 Message-Id: <20230221201925.9644-50-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230221201925.9644-1-pali@kernel.org> References: <20230221201925.9644-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.6 at phobos.denx.de X-Virus-Status: Clean This change add support for mkimage's -s option to kwbimage format. It will create an kwbimage with empty data part of image (data part would contain only required 32-bit checksum). mkimage's -s option is indicated by skipcpy flag and it is basically in conflict with mkimage's -d (datafile) option. "Empty" kwbimage with no data can still contain headers. For example it can contain binary executable header which is copied by BootROM into L2SRAM. This is useful for example for small images which can do not require DDR RAM and can be run in L2SRAM (which do not require any initialization). Signed-off-by: Pali Rohár --- tools/kwbimage.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 7ebb625d03b9..309657a5637b 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -1887,7 +1887,9 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, * 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)) { + if (params->skipcpy) { + s.st_size = 0; + } else if (stat(params->datafile, &s)) { fprintf(stderr, "Could not stat data file %s: %s\n", params->datafile, strerror(errno)); exit(EXIT_FAILURE); @@ -2106,6 +2108,8 @@ static int kwbimage_verify_header(unsigned char *ptr, int image_size, return 0; } +static int kwbimage_align_size(int bootfrom, int alloc_len, struct stat s); + static int kwbimage_generate(struct image_tool_params *params, struct image_type_params *tparams) { @@ -2124,7 +2128,9 @@ static int kwbimage_generate(struct image_tool_params *params, exit(EXIT_FAILURE); } - if (stat(params->datafile, &s)) { + if (params->skipcpy) { + s.st_size = 0; + } else if (stat(params->datafile, &s)) { fprintf(stderr, "Could not stat data file %s: %s\n", params->datafile, strerror(errno)); exit(EXIT_FAILURE); @@ -2195,6 +2201,22 @@ static int kwbimage_generate(struct image_tool_params *params, tparams->header_size = alloc_len; tparams->hdr = hdr; + /* + * This function should return aligned size of the datafile. + * When skipcpy is set (datafile is skipped) then return value of this + * function is ignored, so we have to put required kwbimage aligning + * into the preallocated header size. + */ + if (params->skipcpy) { + tparams->header_size += kwbimage_align_size(bootfrom, alloc_len, s); + return 0; + } else { + return kwbimage_align_size(bootfrom, alloc_len, s); + } +} + +static int kwbimage_align_size(int bootfrom, int alloc_len, struct stat s) +{ /* * The resulting image needs to be 4-byte aligned. At least * the Marvell hdrparser tool complains if its unaligned. @@ -2510,7 +2532,7 @@ static int kwbimage_check_params(struct image_tool_params *params) return 1; } - return (params->dflag && (params->fflag || params->lflag)) || + return (params->dflag && (params->fflag || params->lflag || params->skipcpy)) || (params->fflag) || (params->lflag && (params->dflag || params->fflag)); } -- 2.20.1