From patchwork Thu May 16 12:21:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Yan X-Patchwork-Id: 1100525 X-Patchwork-Delegate: trini@ti.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=rock-chips.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 454VtR5rNkz9s9T for ; Thu, 16 May 2019 22:22:39 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 76E11C21DFB; Thu, 16 May 2019 12:22:33 +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.6 required=5.0 tests=KHOP_BIG_TO_CC, RCVD_IN_SORBS_WEB autolearn=no autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 9DDB0C21DEC; Thu, 16 May 2019 12:22:19 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 1F2E2C21D74; Thu, 16 May 2019 12:22:17 +0000 (UTC) Received: from lucky1.263xmail.com (lucky1.263xmail.com [211.157.147.135]) by lists.denx.de (Postfix) with ESMTPS id 81D3AC21D74 for ; Thu, 16 May 2019 12:22:05 +0000 (UTC) Received: from andy.yan?rock-chips.com (unknown [192.168.167.205]) by lucky1.263xmail.com (Postfix) with ESMTP id BBA8631FC1; Thu, 16 May 2019 20:22:01 +0800 (CST) X-263anti-spam: KSV:0;BIG:0; X-MAIL-GRAY: 1 X-MAIL-DELIVERY: 0 X-KSVirus-check: 0 X-ADDR-CHECKED4: 1 X-ABS-CHECKED: 1 X-SKE-CHECKED: 1 X-ANTISPAM-LEVEL: 2 Received: from localhost.localdomain (unknown [58.22.7.114]) by smtp.263.net (postfix) whith ESMTP id P29630T140215005890304S1558009313115884_; Thu, 16 May 2019 20:22:01 +0800 (CST) X-IP-DOMAINF: 1 X-UNIQUE-TAG: <2f1e23df868243a02769631f788c4fb3> X-RL-SENDER: andy.yan@rock-chips.com X-SENDER: yxj@rock-chips.com X-LOGIN-NAME: andy.yan@rock-chips.com X-FST-TO: poonam.aggrwal@nxp.com X-SENDER-IP: 58.22.7.114 X-ATTACHMENT-NUM: 0 X-DNS-TYPE: 0 From: Andy Yan To: poonam.aggrwal@nxp.com, naveen.burmi@nxp.com, po.liu@nxp.com, qiang.zhao@nxp.com, timur@tabi.org, sjg@chromium.org, simon.k.r.goldschmidt@gmail.com, jagan@openedev.co, lokeshvutla@ti.com, tien.fong.chee@intel.com, vigneshr@ti.com, fabio.estevam@nxp.com, afd@ti.com, abel.vesa@nxp.com, aford173@gmail.com, michal.simek@xilinx.com, joe.hershberger@ni.com, patrick.delaunay@st.com, york.sun@nxp.com, prabhakar.kushwaha@nxp.com, rajesh.bhagat@nxp.com, xypron.glpk@gmx.de, ran.wang_1@nxp.com, u-boot@lists.denx.de, philipp.tomsich@theobroma-systems.com, marex@denx.de, kever.yang@rock-chips.com, andre.przywara@arm.com, mbrugger@suse.com, daniel.schwierzeck@gmail.com Date: Thu, 16 May 2019 20:21:50 +0800 Message-Id: <20190516122150.32163-1-andy.yan@rock-chips.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190516121926.31927-1-andy.yan@rock-chips.com> References: <20190516121926.31927-1-andy.yan@rock-chips.com> Cc: Andy Yan Subject: [U-Boot] [PATCH v2 2/3] spl: add relocation support 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Some times we want to relocate spl code to dram after dram initialization or relocate spl code to a high memory to avoid code overid. For example on Rockchip armv8 platform, we run with boot flow TPL->SPL->ATF->U-Boot. TPL run in sram and is responsible for dram initialization. SPL run from the start address of dram and is responsible for loading ATF and U-Boot. The case here is that the ATF load address is from 64KB of dram, which overlaps with spl code itself. So we want to relocate spl itself to high memory to aovid this. Signed-off-by: Andy Yan --- Changes in v2: - Move Kconfig modification to PATCH 1/3 common/spl/spl.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/common/spl/spl.c b/common/spl/spl.c index 88d4b8a9bf..affb65ccbd 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -439,6 +440,28 @@ static int spl_common_init(bool setup_malloc) return 0; } +#if !defined(CONFIG_SPL_SKIP_RELOCATE) && !defined(CONFIG_TPL_BUILD) +static void spl_setup_relocate(void) +{ + gd->relocaddr = CONFIG_SPL_RELOC_TEXT_BASE; + gd->new_gd = (gd_t *)gd; + gd->start_addr_sp = gd->relocaddr; + gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32); + + gd->start_addr_sp -= gd->fdt_size; + gd->new_fdt = (void *)gd->start_addr_sp; + memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size); + gd->fdt_blob = gd->new_fdt; + + gd->reloc_off = gd->relocaddr - (unsigned long)__image_copy_start; +} +#else +static void spl_setup_relocate(void) +{ + +} +#endif + void spl_set_bd(void) { /* @@ -460,6 +483,8 @@ int spl_early_init(void) return ret; gd->flags |= GD_FLG_SPL_EARLY_INIT; + spl_setup_relocate(); + return 0; } @@ -563,6 +588,34 @@ static int boot_from_devices(struct spl_image_info *spl_image, return -ENODEV; } +#if defined(CONFIG_DM) && !defined(CONFIG_SPL_SKIP_RELOCATE) && !defined(CONFIG_TPL_BUILD) +static int spl_initr_dm(void) +{ + int ret; + + /* Save the pre-reloc driver model and start a new one */ + gd->dm_root_f = gd->dm_root; + gd->dm_root = NULL; + bootstage_start(BOOTSTATE_ID_ACCUM_DM_R, "dm_r"); + ret = dm_init_and_scan(false); + bootstage_accum(BOOTSTATE_ID_ACCUM_DM_R); + if (ret) + return ret; + +#if defined(CONFIG_TIMER) + gd->timer = NULL; +#endif + serial_init(); + + return 0; +} +#else +static int spl_initr_dm(void) +{ + return 0; +} +#endif + void board_init_r(gd_t *dummy1, ulong dummy2) { u32 spl_boot_list[] = { @@ -577,6 +630,8 @@ void board_init_r(gd_t *dummy1, ulong dummy2) debug(">>" SPL_TPL_PROMPT "board_init_r()\n"); + spl_initr_dm(); + spl_set_bd(); #if defined(CONFIG_SYS_SPL_MALLOC_START)