Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F3EDC48BD1 for ; Fri, 11 Jun 2021 02:10:22 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 0FF416124C for ; Fri, 11 Jun 2021 02:10:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0FF416124C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 720BD81DC0; Fri, 11 Jun 2021 04:10:18 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1623377418; bh=5bmS+qOzv4hdEcHAmnhv0aBDj0VjJDel8C5lsOHKyHQ=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=fLx4jMJZcbCJuN5vTjM/TNCCEGzNG3rwvY1dOt4MglUrB5ZnKLOufUmh/E0R9XUse 5eiKPe9Tm524jDF2vocK+LQGP0PQ+FvNArg4/uHjenSvEmKZjOdVPHOXJkFIJ4VSZ3 ftUFk+ha9dX4MKv/2e9AhN+Oz8gZF8GWDO54R2+J6aUkapXgsHkqlNKuKHrkBf2/qd JLGRPfERRxbpA3Oeo/hQvl/oEqpcgGm5aSVyRWVX0tA143dfAzMdtcpaT8iEmtVR0T oyi7z877ateOjw7/d/ndundefzwfFUggpIqxj74q9EygeOTO+yfR7TAfAMQJtq9WpR 09Bd36vVXswtw== Received: from tr.lan (ip-89-176-112-137.net.upcbroadband.cz [89.176.112.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 635DF80C9A; Fri, 11 Jun 2021 04:10:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1623377416; bh=5bmS+qOzv4hdEcHAmnhv0aBDj0VjJDel8C5lsOHKyHQ=; h=From:To:Cc:Subject:Date:From; b=BRBglfwa2sujoZUwvgfPEaHYVr6OJ/8aR7Bthyyg72ASrR4SWbKN5BZdcN42lB/UR GwZZmMoh7Cc7YcLq7x8DncefkDQqWjRyhmT+88EnJxz7R3X9HaZ+RzmhHga7QwcF4R tDIW1S9XEuHU8CNMa4lwyKe7ZSUGnbwgtvkvKfyYJ0vG/5iQHVCPrQYqVclTHT5tb1 c2+O8GEeVF/QYcf8w7AMQOVLxoGvPDd4vYz5dmXL6sgOc/xRfqSIZp4saS/liIqsac rzI8GzhKmRHu5Li8d1k8nLLt+t3Ud40amuF+FN0C5w0+8rMQbHUYP2CbG3SKeod6bT rNJ8V9y/LwzTw== From: Marek Vasut To: u-boot@lists.denx.de Cc: Marek Vasut , Pantelis Antoniou , Simon Glass , Tom Rini Subject: [PATCH] fit: Load DTO into temporary buffer and ignore load address Date: Fri, 11 Jun 2021 04:09:56 +0200 Message-Id: <20210611020956.277556-1-marex@denx.de> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.102.4 at phobos.denx.de X-Virus-Status: Clean The current fitImage DTO implementation expects each fitImage image subnode containing DTO to have 'load' property, pointing somewhere into memory where the DTO will be loaded. The address in the 'load' property must be different then the base DT load address and there must be sufficient amount of space between those two addresses. Selecting and using such hard-coded addresses is fragile, error prone and difficult to port even across devices with the same SoC and different DRAM sizes. The DTO cannot be applied in-place because fdt_overlay_apply_verbose() modifies the DTO when applying it onto the base DT, so if the DTO was used in place within the fitImage, call to fdt_overlay_apply_verbose() would corrupt the fitImage. Instead of copying the DTO to a specific hard-coded load address, allocate a buffer, copy the DTO into that buffer, apply the DTO onto the base DT, and free the buffer. The upside of this approach is that it is no longer necessary to select and hard-code specific DTO load address into the DTO. The slight downside is the new malloc()/free() overhead for each DTO, but that is negligible (*). (*) on iMX8MM/MN and STM32MP1 Signed-off-by: Marek Vasut Cc: Pantelis Antoniou Cc: Simon Glass Cc: Tom Rini --- common/image-fit.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/common/image-fit.c b/common/image-fit.c index e614643fe39..1e0aabddec6 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -2267,10 +2267,10 @@ int boot_get_fdt_fit(bootm_headers_t *images, ulong addr, ulong load, len; #ifdef CONFIG_OF_LIBFDT_OVERLAY ulong image_start, image_end; - ulong ovload, ovlen; + ulong ovload, ovlen, ovcopylen; const char *uconfig; const char *uname; - void *base, *ov; + void *base, *ov, *ovcopy = NULL; int i, err, noffset, ov_noffset; #endif @@ -2360,7 +2360,7 @@ int boot_get_fdt_fit(bootm_headers_t *images, ulong addr, addr, &uname, &uconfig, arch, IH_TYPE_FLATDT, BOOTSTAGE_ID_FIT_FDT_START, - FIT_LOAD_REQUIRED, &ovload, &ovlen); + FIT_LOAD_IGNORED, &ovload, &ovlen); if (ov_noffset < 0) { printf("load of %s failed\n", uname); continue; @@ -2369,6 +2369,21 @@ int boot_get_fdt_fit(bootm_headers_t *images, ulong addr, uname, ovload, ovlen); ov = map_sysmem(ovload, ovlen); + ovcopylen = ALIGN(fdt_totalsize(ov), SZ_4K); + ovcopy = malloc(ovcopylen); + if (!ovcopy) { + printf("failed to duplicate DTO before application\n"); + fdt_noffset = -ENOMEM; + goto out; + } + + err = fdt_open_into(ov, ovcopy, ovcopylen); + if (err < 0) { + printf("failed on fdt_open_into for DTO\n"); + fdt_noffset = err; + goto out; + } + base = map_sysmem(load, len + ovlen); err = fdt_open_into(base, base, len + ovlen); if (err < 0) { @@ -2376,14 +2391,18 @@ int boot_get_fdt_fit(bootm_headers_t *images, ulong addr, fdt_noffset = err; goto out; } + /* the verbose method prints out messages on error */ - err = fdt_overlay_apply_verbose(base, ov); + err = fdt_overlay_apply_verbose(base, ovcopy); if (err < 0) { fdt_noffset = err; goto out; } fdt_pack(base); len = fdt_totalsize(base); + + free(ovcopy); + ovcopy = NULL; } #else printf("config with overlays but CONFIG_OF_LIBFDT_OVERLAY not set\n"); @@ -2400,6 +2419,10 @@ out: if (fit_uname_configp) *fit_uname_configp = fit_uname_config; +#ifdef CONFIG_OF_LIBFDT_OVERLAY + if (ovcopy) + free(ovcopy); +#endif if (fit_uname_config_copy) free(fit_uname_config_copy); return fdt_noffset; -- 2.30.2