From patchwork Wed Aug 21 19:14:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Auer X-Patchwork-Id: 1151133 X-Patchwork-Delegate: uboot@andestech.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=aisec.fraunhofer.de Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 46DHVT4DBTz9s7T for ; Thu, 22 Aug 2019 05:17:37 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 366DCC2200F; Wed, 21 Aug 2019 19:16:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 567A4C22027; Wed, 21 Aug 2019 19:15:13 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id EEF14C21E0B; Wed, 21 Aug 2019 19:15:07 +0000 (UTC) Received: from mail-edgeS23.fraunhofer.de (mail-edges23.fraunhofer.de [153.97.7.23]) by lists.denx.de (Postfix) with ESMTPS id A2233C21F29 for ; Wed, 21 Aug 2019 19:15:07 +0000 (UTC) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2E5AQB4l11d/xoHYZlkHAEBAQQBAQcEAQGBVgQBAQsBgheBPyA8jRuGAottkTAJAQEBAQEBAQEBCC8BAYQ/AoJdIzcGDgIFAQEFAQEBAQEGBAICaYUnDIVMBicLAUYQUSEcGgYOBYMigWsDHAGsHTOIIA1hgUkJAYEqAYcUhFmBWD+DbgdsghqHayIEjDoDgiWcM0AHAoE6ZV8Ej12DbQwbgjGLHCyKTYQginGIJ45ZgWYjgVgzGiSDO4JOFxWDM4pcPQEyAY1FAQE X-IPAS-Result: A2E5AQB4l11d/xoHYZlkHAEBAQQBAQcEAQGBVgQBAQsBgheBPyA8jRuGAottkTAJAQEBAQEBAQEBCC8BAYQ/AoJdIzcGDgIFAQEFAQEBAQEGBAICaYUnDIVMBicLAUYQUSEcGgYOBYMigWsDHAGsHTOIIA1hgUkJAYEqAYcUhFmBWD+DbgdsghqHayIEjDoDgiWcM0AHAoE6ZV8Ej12DbQwbgjGLHCyKTYQginGIJ45ZgWYjgVgzGiSDO4JOFxWDM4pcPQEyAY1FAQE X-IronPort-AV: E=Sophos;i="5.64,412,1559512800"; d="scan'208";a="12659891" Received: from mail-mtas26.fraunhofer.de ([153.97.7.26]) by mail-edgeS23.fraunhofer.de with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Aug 2019 21:15:07 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0AUAQB4l11dfRBhWMBkHAEBAQQBAQcEAQGBVgQBAQsBg1YgPI0bkW+RMAkBAwEBAQEBCC8BAYQ/AoJ/NwYOAgUBAQQBAQECAQYEFAEBFjqFLgyFSwMDJwsBRhBRIRwaBg4FgyKBawMdrB0ziCANYYFJCQGBKgGHFIYxP4NuB2yCGodrIgSMOgOCJZwzQAcCgTplXwSPXYNtDBuCMYscLIpNhCCKcYgnjlmBZiGBWTMaJIM7gk4XFYMzilw9AzABjUUBAQ X-IronPort-AV: E=Sophos;i="5.64,412,1559512800"; d="scan'208";a="86123325" Received: from fgdemucivp01ltm.xch.fraunhofer.de (HELO FGDEMUCIMP11EXC.ads.fraunhofer.de) ([192.88.97.16]) by mail-mtaS26.fraunhofer.de with ESMTP/TLS/AES256-SHA; 21 Aug 2019 21:15:06 +0200 Received: from localhost.de (10.80.233.50) by FGDEMUCIMP11EXC.ads.fraunhofer.de (10.80.232.42) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 21 Aug 2019 21:15:06 +0200 From: Lukas Auer To: Date: Wed, 21 Aug 2019 21:14:42 +0200 Message-ID: <20190821191450.14507-4-lukas.auer@aisec.fraunhofer.de> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190821191450.14507-1-lukas.auer@aisec.fraunhofer.de> References: <20190821191450.14507-1-lukas.auer@aisec.fraunhofer.de> MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-11.0.0.4179-8.200.1013-24858.003 X-TM-AS-Result: No--7.382400-8.000000-31 X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No Cc: Alistair Francis Subject: [U-Boot] [RESEND PATCH v4 03/11] spl: fit: use U-Boot device tree when FIT image has no device tree X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" As part of the SPL FIT boot flow, the device tree is appended to U-Boot proper. The device tree is used to record information on the loadables to make them available to the SPL framework and U-Boot proper. Depending on the U-Boot device tree provider, the FIT image might not include a device tree. Information on the loadables is missing in this case. When booting via firmware bundled with the FIT image, U-Boot SPL loads the firmware binary and U-Boot proper before starting the firmware. The firmware, in turn, is responsible for starting U-Boot proper. Information on the memory location of the U-Boot proper loadable must be available to the SPL framework so that it can be passed to the firmware binary. To support this use case when no device tree is found in the FIT image, fall back to the U-Boot device tree in this situation. At the same time, update the comment to remove the note that the destination address must be aligned to ARCH_DMA_MINALIGN. Alignment is only required as an intermediate step when reading external data. This is automatically handled by spl_fit_append_fdt(). After reading the external data, it is copied to the specified address, which does not have to be aligned to ARCH_DMA_MINALIGN. Signed-off-by: Lukas Auer Reviewed-by: Bin Meng Tested-by: Bin Meng Reviewed-by: Anup Patel --- Changes in v4: None Changes in v3: None Changes in v2: None common/spl/spl_fit.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index 2e2e09eafb..b3e3ccd5a2 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -12,6 +12,8 @@ #include #include +DECLARE_GLOBAL_DATA_PTR; + #ifndef CONFIG_SYS_BOOTM_LEN #define CONFIG_SYS_BOOTM_LEN (64 << 20) #endif @@ -279,25 +281,34 @@ static int spl_fit_append_fdt(struct spl_image_info *spl_image, void *fit, int images, ulong base_offset) { struct spl_image_info image_info; - int node, ret; + int node, ret = 0; + + /* + * Use the address following the image as target address for the + * device tree. + */ + image_info.load_addr = spl_image->load_addr + spl_image->size; /* Figure out which device tree the board wants to use */ node = spl_fit_get_image_node(fit, images, FIT_FDT_PROP, 0); if (node < 0) { debug("%s: cannot find FDT node\n", __func__); - return node; - } - - /* - * Read the device tree and place it after the image. - * Align the destination address to ARCH_DMA_MINALIGN. - */ - image_info.load_addr = spl_image->load_addr + spl_image->size; - ret = spl_load_fit_image(info, sector, fit, base_offset, node, - &image_info); - if (ret < 0) - return ret; + /* + * U-Boot did not find a device tree inside the FIT image. Use + * the U-Boot device tree instead. + */ + if (gd->fdt_blob) + memcpy((void *)image_info.load_addr, gd->fdt_blob, + fdt_totalsize(gd->fdt_blob)); + else + return node; + } else { + ret = spl_load_fit_image(info, sector, fit, base_offset, node, + &image_info); + if (ret < 0) + return ret; + } /* Make the load-address of the FDT available for the SPL framework */ spl_image->fdt_addr = (void *)image_info.load_addr;