From patchwork Mon Apr 18 09:20:53 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alessandro Rubini X-Patchwork-Id: 91704 X-Patchwork-Delegate: albert.aribaud@free.fr Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 6FABEB7008 for ; Mon, 18 Apr 2011 19:21:03 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0FB6228147; Mon, 18 Apr 2011 11:21:02 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LaRsFNufYwD6; Mon, 18 Apr 2011 11:21:01 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A832B28139; Mon, 18 Apr 2011 11:20:58 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D213C28139 for ; Mon, 18 Apr 2011 11:20:56 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 60mnOmdv0+Kq for ; Mon, 18 Apr 2011 11:20:56 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail.gnudd.com (mail2.gnudd.com [213.203.150.91]) by theia.denx.de (Postfix) with ESMTPS id 020B828127 for ; Mon, 18 Apr 2011 11:20:54 +0200 (CEST) Received: from mail.gnudd.com (localhost [127.0.0.1]) by mail.gnudd.com (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id p3I9KroT015419 for ; Mon, 18 Apr 2011 11:20:53 +0200 Received: (from rubini@localhost) by mail.gnudd.com (8.14.3/8.14.3/Submit) id p3I9KrBU015418 for u-boot@lists.denx.de; Mon, 18 Apr 2011 11:20:53 +0200 Date: Mon, 18 Apr 2011 11:20:53 +0200 From: Alessandro Rubini To: u-boot@lists.denx.de Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Face: #Q; A)@_4.#>0+_%y]7aBr:c"ndLp&#+2?]J; lkse\^)FP^Lr5@O0{)J; 'nny4%74.fM'n)M >ISCj.KmsL/HTxz!:Ju'pnj'Gz&. Organization: GnuDD, Device Drivers, Embedded Systems, Courses References: <82e06e94bd8fce0bb50e7e4347dfaffa43c4b2d3.1303118067.git.rubini@gnudd.com> In-Reply-To: <82e06e94bd8fce0bb50e7e4347dfaffa43c4b2d3.1303118067.git.rubini@gnudd.com> Subject: [U-Boot] [PATCH 2/4] ARM: don't relocate if we are already too high X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Signed-off-by: Alessandro Rubini --- arch/arm/lib/board.c | 23 ++++++++++++++++++++++- 1 files changed, 22 insertions(+), 1 deletions(-) diff --git a/arch/arm/lib/board.c b/arch/arm/lib/board.c index dc46e21..dab70b5 100644 --- a/arch/arm/lib/board.c +++ b/arch/arm/lib/board.c @@ -423,8 +423,29 @@ void board_init_f (ulong bootflag) gd->relocaddr = addr; gd->start_addr_sp = addr_sp; gd->reloc_off = addr - _TEXT_BASE; + + /* + * Destination is higher than current address, but may overlap + * our address range. If so, pass the source address as destination + * address so the asm will not relocate and only clear bss + */ + if ((addr_sp - 256) < _bss_start_ofs+_TEXT_BASE) { + debug("Won't fit above us: disabling relocation\n"); + if (gd->reloc_off < 0) { + printf("Can't relocate to lower ram, currently\n"); + hang(); + } + addr -= gd->reloc_off; + addr_sp -= gd->reloc_off; + gd->start_addr_sp = addr_sp; + id -= gd->reloc_off; + gd->reloc_off = 0; + } + + debug ("relocation Offset is: %08lx\n", gd->reloc_off); - memcpy (id, (void *)gd, sizeof (gd_t)); + if (id != (void *)gd) + memcpy (id, (void *)gd, sizeof (gd_t)); relocate_code (addr_sp, id, addr);