From patchwork Wed Apr 20 15:18:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ariel D'Alessandro X-Patchwork-Id: 1619620 X-Patchwork-Delegate: sbabic@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=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=AdaALJ4d; 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 4Kk48h11rWz9sG0 for ; Thu, 21 Apr 2022 01:19:32 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1F29083C13; Wed, 20 Apr 2022 17:19:29 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=collabora.com 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=collabora.com header.i=@collabora.com header.b="AdaALJ4d"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 81E4B83C13; Wed, 20 Apr 2022 17:19:26 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.2 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) (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 13E1C83968 for ; Wed, 20 Apr 2022 17:19:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ariel.dalessandro@collabora.com Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: adalessandro) with ESMTPSA id 4274D1F43749 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1650467961; bh=Kq/cmLCNF9qSa0BuXOYdyGHf+vzwgui1I3jNWdwd5pg=; h=From:To:Cc:Subject:Date:From; b=AdaALJ4dxp45EQsPxcy671sOIbN/tA0for0uPjid85dSLyCGiGm1WQePfaFP/Gaxs 6+4gmZV88VZiVoJCuq3UUospCKYwkN7arn0FL/6bArjvWSGx3CtNTuEMt19ZhSgBxE flJhsnl9F7waXr/5jHjPH5PTOp1qKtQomsOAOmei8Cnlg6I1BXHO1GycTVs1SmGkWh tvQcGpyD628q6ineP37MOTNKC2v81VkoHewTLrJkprn3fRXKgQ0u0DTTVMKwp/SAuB CcVZed0Q0f+LieB9XpynQvgdegNZiofz2t57nRUbVKViLwv+BdlSkNHzNkLs8qrYeO XpGsScjESiFzw== From: Ariel D'Alessandro To: u-boot@lists.denx.de, uboot-imx@nxp.com Cc: ariel.dalessandro@collabora.com, chiawei_wang@aspeedtech.com, festevam@gmail.com, mr.nuke.me@gmail.com, philippe.reynes@softathome.com, sbabic@denx.de, sjg@chromium.org, xypron.glpk@gmx.de Subject: [RFC PATCH] imx: hab: Support FIT images with external data Date: Wed, 20 Apr 2022 12:18:31 -0300 Message-Id: <20220420151831.32683-1-ariel.dalessandro@collabora.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 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.5 at phobos.denx.de X-Virus-Status: Clean The IVT table is located right after the FIT image. If the FIT image is generated using external data, the total size needs to be computed including the FIT struct and external data lengths. Signed-off-by: Ariel D'Alessandro --- arch/arm/mach-imx/hab.c | 3 ++- boot/image-fit.c | 44 +++++++++++++++++++++++++++++++++++++++++ include/image.h | 9 +++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/arch/arm/mach-imx/hab.c b/arch/arm/mach-imx/hab.c index 55317abba23..d0bee716772 100644 --- a/arch/arm/mach-imx/hab.c +++ b/arch/arm/mach-imx/hab.c @@ -593,7 +593,8 @@ static ulong get_image_ivt_offset(ulong img_addr) #endif #if CONFIG_IS_ENABLED(FIT) case IMAGE_FORMAT_FIT: - return (fit_get_size(buf) + 0x1000 - 1) & ~(0x1000 - 1); + return (fit_get_size_external(buf) + + 0x1000 - 1) & ~(0x1000 - 1); #endif default: return 0; diff --git a/boot/image-fit.c b/boot/image-fit.c index 6610035d0ad..7a9b6b6c71d 100644 --- a/boot/image-fit.c +++ b/boot/image-fit.c @@ -1168,6 +1168,50 @@ ulong fit_get_end(const void *fit) return map_to_sysmem((void *)(fit + fdt_totalsize(fit))); } +ulong fit_get_size_external(const void *fit) +{ + int images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH); + unsigned int ret = fit_get_size(fit); + int noffset, ndepth, offset; + const void *data; + size_t size; + + /* Find images parent node offset */ + if (images_noffset < 0) { + printf("Can't find images parent node '%s' (%s)\n", + FIT_IMAGES_PATH, fdt_strerror(images_noffset)); + return 0; + } + + /* Process its subnodes, print out component images details */ + for (ndepth = 0, noffset = fdt_next_node(fit, images_noffset, &ndepth); + (noffset >= 0) && (ndepth > 0); + noffset = fdt_next_node(fit, noffset, &ndepth)) { + /* + * Omit indirect child nodes of the images parent node, as it's + * not a component image node. + */ + if (ndepth != 1) + continue; + + /* Omit images that are not external, as its size is already + * included in the FIT image. + */ + if (fit_image_get_data_position(fit, noffset, &offset) && + fit_image_get_data_offset(fit, noffset, &offset)) + continue; + + if (fit_image_get_data_and_size(fit, noffset, &data, &size)) { + printf("Couldn't get image data/size (noffset=%d)\n", + noffset); + return 0; + } + ret += size; + } + + return ret; +} + /** * fit_set_timestamp - set node timestamp property * @fit: pointer to the FIT format image header diff --git a/include/image.h b/include/image.h index e4c6a50b885..012ea28ba1b 100644 --- a/include/image.h +++ b/include/image.h @@ -979,6 +979,15 @@ static inline ulong fit_get_size(const void *fit) */ ulong fit_get_end(const void *fit); +/** + * fit_get_size_external - get FIT image size including external data + * @fit: pointer to the FIT format image header + * + * returns: + * size of the FIT image (including external data) in memory + */ +ulong fit_get_size_external(const void *fit); + /** * fit_get_name - get FIT node name * @fit: pointer to the FIT format image header