From patchwork Thu May 16 12:22:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Yan X-Patchwork-Id: 1100526 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 454Vts2VKQz9s9y for ; Thu, 16 May 2019 22:23:01 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 0D3F4C21DEC; Thu, 16 May 2019 12:22:46 +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 31AFFC21D8A; Thu, 16 May 2019 12:22:36 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id BF6A2C21D72; Thu, 16 May 2019 12:22:33 +0000 (UTC) Received: from lucky1.263xmail.com (lucky1.263xmail.com [211.157.147.135]) by lists.denx.de (Postfix) with ESMTPS id A71C3C21D83 for ; Thu, 16 May 2019 12:22:23 +0000 (UTC) Received: from andy.yan?rock-chips.com (unknown [192.168.167.42]) by lucky1.263xmail.com (Postfix) with ESMTP id 656CB31FCD; Thu, 16 May 2019 20:22:20 +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 P10230T140170301642496S1558009331939446_; Thu, 16 May 2019 20:22:20 +0800 (CST) X-IP-DOMAINF: 1 X-UNIQUE-TAG: 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:22:10 +0800 Message-Id: <20190516122210.32250-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 3/3] arm: add spl relocation support for arm 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: - Add more detial commit message arch/arm/config.mk | 6 ++++++ arch/arm/cpu/armv8/start.S | 4 ++++ arch/arm/cpu/armv8/u-boot-spl.lds | 17 +++++++++++++++++ arch/arm/lib/Makefile | 2 +- arch/arm/lib/crt0_64.S | 3 ++- 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/arch/arm/config.mk b/arch/arm/config.mk index f25603109e..7f6ad89601 100644 --- a/arch/arm/config.mk +++ b/arch/arm/config.mk @@ -102,6 +102,12 @@ endif # needed for relocation LDFLAGS_u-boot += -pie +ifndef CONFIG_SPL_SKIP_RELOCATE +LDFLAGS_u-boot-spl = -pie +else +SPL_LDFLAGS_u-boot-spl = +endif + # # FIXME: binutils versions < 2.22 have a bug in the assembler where # branches to weak symbols can be incorrectly optimized in thumb mode diff --git a/arch/arm/cpu/armv8/start.S b/arch/arm/cpu/armv8/start.S index fe52166e28..a7dad3cd69 100644 --- a/arch/arm/cpu/armv8/start.S +++ b/arch/arm/cpu/armv8/start.S @@ -35,7 +35,11 @@ _start: .globl _TEXT_BASE _TEXT_BASE: +#if defined(CONFIG_SPL_BUILD) + .quad CONFIG_SPL_TEXT_BASE +#else .quad CONFIG_SYS_TEXT_BASE +#endif /* * These are defined in the linker script. diff --git a/arch/arm/cpu/armv8/u-boot-spl.lds b/arch/arm/cpu/armv8/u-boot-spl.lds index ccbf359bd1..64102afc8b 100644 --- a/arch/arm/cpu/armv8/u-boot-spl.lds +++ b/arch/arm/cpu/armv8/u-boot-spl.lds @@ -53,6 +53,23 @@ SECTIONS *(.__end) } >.sram +#ifndef CONFIG_SPL_SKIP_RELOCATE + . = ALIGN(8); + + .rel_dyn_start : + { + *(.__rel_dyn_start) + } >.sram + + .rela.dyn : { + *(.rela*) + } >.sram + + .rel_dyn_end : + { + *(.__rel_dyn_end) + } >.sram +#endif _image_binary_end = .; .bss_start (NOLOAD) : { diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile index 48ee6c3c60..f27b3fb79f 100644 --- a/arch/arm/lib/Makefile +++ b/arch/arm/lib/Makefile @@ -21,7 +21,7 @@ else obj-y += setjmp.o endif -ifndef CONFIG_SPL_BUILD +ifndef CONFIG_TPL_BUILD ifdef CONFIG_ARM64 obj-y += relocate_64.o else diff --git a/arch/arm/lib/crt0_64.S b/arch/arm/lib/crt0_64.S index d6b632aa87..e5605fe325 100644 --- a/arch/arm/lib/crt0_64.S +++ b/arch/arm/lib/crt0_64.S @@ -89,7 +89,8 @@ ENTRY(_main) mov x0, #0 bl board_init_f -#if !defined(CONFIG_SPL_BUILD) +#if (defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD) && !defined(CONFIG_SPL_SKIP_RELOCATE)) || \ + !defined(CONFIG_SPL_BUILD) /* * Set up intermediate environment (new sp and gd) and call * relocate_code(addr_moni). Trick here is that we'll return