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 2E59BC433F5 for ; Wed, 12 Jan 2022 17:25:21 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 76CAC83592; Wed, 12 Jan 2022 18:22: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="kKBCY1kK"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5E513834C3; Wed, 12 Jan 2022 18:22:14 +0100 (CET) Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) (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 605F98349D for ; Wed, 12 Jan 2022 18:22:00 +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 4727561826; Wed, 12 Jan 2022 17:21:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 898C7C36AEA; Wed, 12 Jan 2022 17:21:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642008118; bh=hAL2JfW061X+G4qdiDd8dnaZofjY8xTb4+ZHfAyiBOk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kKBCY1kKeo5eY5dtZE26I1Ce4BqiIR3h9tQ5hNRm2bzCyAPMm8eqphHxoww90hFTA C0oj0FYcgbucGcKYBYjw4BD9j/pXFaeLxocyaFkud/O/Uzaoc9+dz+zdJ+quSPIHyR bomnT9rGvd5HRRZzify7YyxFX00yKbZrqa8ZDatLIfOg1kqFYbAO8z4gZKaDrvGriT oo16a3DcIarI9DOEQI9Tw4ic0Rmx4VST6ufZMWYZRo+kHGszsYm+v7aYtM5L38NzNG RAGtyZuKtIGYoMJNhPC95SBLfjb2FYlQf1KMycrcFpx1t0llyTIHgLyIx0ml2M1emH WI7tnZiGkmoCQ== Received: by pali.im (Postfix) id 3FFA0768; Wed, 12 Jan 2022 18:21:58 +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 19/20] tools: kwbimage: Extract main data image without -p arg for dumpimage Date: Wed, 12 Jan 2022 18:20:53 +0100 Message-Id: <20220112172054.5961-20-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 When there is no -p argument for dumpimage tool specified, extract the main data image from kwbimage file. This makes dumpimage consistent with other image formats. Signed-off-by: Pali Rohár Reviewed-by: Marek Behún --- tools/kwbimage.c | 67 +++++++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 92d163b6050e..d159087d9dd6 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -2266,7 +2266,7 @@ static int kwbimage_extract_subimage(void *ptr, struct image_tool_params *params size_t header_size = kwbheader_size(ptr); struct opt_hdr_v1 *ohdr; int idx = params->pflag; - int cur_idx = 0; + int cur_idx; uint32_t offset; ulong image; ulong size; @@ -2275,41 +2275,54 @@ static int kwbimage_extract_subimage(void *ptr, struct image_tool_params *params if (idx == -1) return kwbimage_generate_config(ptr, params); - for_each_opt_hdr_v1 (ohdr, ptr) { - if (ohdr->headertype != OPT_HDR_V1_BINARY_TYPE) - continue; + image = 0; + size = 0; + + if (idx == 0) { + /* Extract data image when -p is not specified or when '-p 0' is specified */ + offset = le32_to_cpu(mhdr->srcaddr); - if (idx == cur_idx) { - image = (ulong)&ohdr->data[4 + 4 * ohdr->data[0]]; - size = opt_hdr_v1_size(ohdr) - 12 - 4 * ohdr->data[0]; - goto extract; + if (mhdr->blockid == IBR_HDR_SATA_ID) { + offset -= 1; + offset *= 512; } - ++cur_idx; - } + if (mhdr->blockid == IBR_HDR_SDIO_ID) + offset *= 512; - if (idx != cur_idx) { - printf("Image %d is not present\n", idx); - return -1; - } - - offset = le32_to_cpu(mhdr->srcaddr); + if (mhdr->blockid == IBR_HDR_PEX_ID && offset == 0xFFFFFFFF) + offset = header_size; - if (mhdr->blockid == IBR_HDR_SATA_ID) { - offset -= 1; - offset *= 512; - } + image = (ulong)((uint8_t *)ptr + offset); + size = le32_to_cpu(mhdr->blocksize) - 4; + } else { + /* Extract N-th binary header executabe image when other '-p N' is specified */ + cur_idx = 1; + for_each_opt_hdr_v1(ohdr, ptr) { + if (ohdr->headertype != OPT_HDR_V1_BINARY_TYPE) + continue; - if (mhdr->blockid == IBR_HDR_SDIO_ID) - offset *= 512; + if (idx == cur_idx) { + image = (ulong)&ohdr->data[4 + 4 * ohdr->data[0]]; + size = opt_hdr_v1_size(ohdr) - 12 - 4 * ohdr->data[0]; + break; + } - if (mhdr->blockid == IBR_HDR_PEX_ID && offset == 0xFFFFFFFF) - offset = header_size; + ++cur_idx; + } - image = (ulong)((uint8_t *)ptr + offset); - size = le32_to_cpu(mhdr->blocksize) - 4; + if (!image) { + fprintf(stderr, "Argument -p %d is invalid\n", idx); + fprintf(stderr, "Available subimages:\n"); + fprintf(stderr, " -p -1 - kwbimage config file\n"); + fprintf(stderr, " -p 0 - data image\n"); + if (cur_idx - 1 > 0) + fprintf(stderr, " -p N - Nth binary header image (totally: %d)\n", + cur_idx - 1); + return -1; + } + } -extract: return imagetool_save_subimage(params->outfile, image, size); } -- 2.20.1