From patchwork Sun Jul 28 15:57:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Auer X-Patchwork-Id: 1138028 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 45xSDm4fYzz9s7T for ; Mon, 29 Jul 2019 01:59:20 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 47A2CC21CB6; Sun, 28 Jul 2019 15:58:11 +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 AD876C21DB6; Sun, 28 Jul 2019 15:57:54 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 89DFEC21C2C; Sun, 28 Jul 2019 15:57:49 +0000 (UTC) Received: from mail-edgeS23.fraunhofer.de (mail-edges23.fraunhofer.de [153.97.7.23]) by lists.denx.de (Postfix) with ESMTPS id 14785C21C2C for ; Sun, 28 Jul 2019 15:57:49 +0000 (UTC) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2FEAAB1xT1d/xwBYJllHAEBAQQBAQcEAQGBUwcBAQsBghaBPwEfPIw6YIgai2OPLYF7CQEBAQEBAQEBAQgvAQGEQAKCYyM0CQ4BAwEBBQEBAQEGAgJphR4MhUwGJwsBRhBRIRwaBg4FgyKBawMcAasLM4gHDV+BSAkBgSoBhwiEV4FXP4NuB2yCGodrIgSMIgOCJJtuQAcCgTljXQSPPINrDBuCLosGLIouhBaKVogOjj+BUDmBWDMaJIM7gk4XFIMzilw9ATIBjw8BAQ X-IPAS-Result: A2FEAAB1xT1d/xwBYJllHAEBAQQBAQcEAQGBUwcBAQsBghaBPwEfPIw6YIgai2OPLYF7CQEBAQEBAQEBAQgvAQGEQAKCYyM0CQ4BAwEBBQEBAQEGAgJphR4MhUwGJwsBRhBRIRwaBg4FgyKBawMcAasLM4gHDV+BSAkBgSoBhwiEV4FXP4NuB2yCGodrIgSMIgOCJJtuQAcCgTljXQSPPINrDBuCLosGLIouhBaKVogOjj+BUDmBWDMaJIM7gk4XFIMzilw9ATIBjw8BAQ X-IronPort-AV: E=Sophos;i="5.64,319,1559512800"; d="scan'208";a="12233458" Received: from mail-mtaka28.fraunhofer.de ([153.96.1.28]) by mail-edgeS23.fraunhofer.de with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Jul 2019 17:57:48 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0BGAACvxD1dfRBhWMBlHAEBAQQBAQcEAQGBUwcBAQsBg1UgPIw6YJN9jy2BewkBAwEBAQEBCC8BAYRAAoMFNAkOAQMBAQQBAQIBBhQBARY6hSUMhUsDAycLAUYQUSEcGgYOBYMigWsDHasKM4gHDV+BSAkBgSoBhwiGLj+DbgdsghqHayIEjCIDgiSbbkAHAoE5Y10EjzyDawwbgi6LBiyKLoQWilaIDo4/gVA3gVkzGiSDO4JOFxSDM4pcPQMwAY8PAQE X-IronPort-AV: E=Sophos;i="5.64,319,1559512800"; d="scan'208";a="20209986" Received: from fgdemucivp01ltm.xch.fraunhofer.de (HELO FGDEMUCIMP12EXC.ads.fraunhofer.de) ([192.88.97.16]) by mail-mtaKA28.fraunhofer.de with ESMTP/TLS/AES256-SHA; 28 Jul 2019 17:57:49 +0200 Received: from localhost.de (10.80.233.51) by FGDEMUCIMP12EXC.ads.fraunhofer.de (10.80.232.43) with Microsoft SMTP Server (TLS) id 14.3.439.0; Sun, 28 Jul 2019 17:57:47 +0200 From: Lukas Auer To: Date: Sun, 28 Jul 2019 17:57:15 +0200 Message-ID: <20190728155723.3412-4-lukas.auer@aisec.fraunhofer.de> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190728155723.3412-1-lukas.auer@aisec.fraunhofer.de> References: <20190728155723.3412-1-lukas.auer@aisec.fraunhofer.de> MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-11.0.0.4179-8.200.1013-24806.001 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: Marek Vasut , Michal Simek , Alistair Francis Subject: [U-Boot] [PATCH v2 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 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 969f7775c1..0bfb91d686 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -11,6 +11,8 @@ #include #include +DECLARE_GLOBAL_DATA_PTR; + #ifndef CONFIG_SYS_BOOTM_LEN #define CONFIG_SYS_BOOTM_LEN (64 << 20) #endif @@ -278,25 +280,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;