From patchwork Tue Nov 8 22:19:54 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabe Black X-Patchwork-Id: 124446 X-Patchwork-Delegate: graeme.russ@gmail.com 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 8005BB6F7F for ; Wed, 9 Nov 2011 09:20:20 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id DD6E029302; Tue, 8 Nov 2011 23:20:16 +0100 (CET) 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 apTfJg2Q8j-A; Tue, 8 Nov 2011 23:20:16 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0E7DE29303; Tue, 8 Nov 2011 23:20:15 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 255A129303 for ; Tue, 8 Nov 2011 23:20:13 +0100 (CET) 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 rb3b7HJiXq4B for ; Tue, 8 Nov 2011 23:20:11 +0100 (CET) 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 smtp-out.google.com (smtp-out.google.com [216.239.44.51]) by theia.denx.de (Postfix) with ESMTPS id 9DC4B29302 for ; Tue, 8 Nov 2011 23:20:09 +0100 (CET) Received: from wpaz37.hot.corp.google.com (wpaz37.hot.corp.google.com [172.24.198.101]) by smtp-out.google.com with ESMTP id pA8MK73m004694; Tue, 8 Nov 2011 14:20:07 -0800 Received: from gabeblack.mtv.corp.google.com (gabeblack.mtv.corp.google.com [172.22.72.31]) by wpaz37.hot.corp.google.com with ESMTP id pA8MK3r9005361; Tue, 8 Nov 2011 14:20:03 -0800 Received: by gabeblack.mtv.corp.google.com (Postfix, from userid 134246) id 3A1D9201EA5; Tue, 8 Nov 2011 14:20:02 -0800 (PST) From: Gabe Black To: U-Boot Mailing List Date: Tue, 8 Nov 2011 14:19:54 -0800 Message-Id: <1320790794-21954-1-git-send-email-gabeblack@chromium.org> X-Mailer: git-send-email 1.7.3.1 In-Reply-To: <1320734950-19454-1-git-send-email-gabeblack@chromium.org> References: <1320734950-19454-1-git-send-email-gabeblack@chromium.org> X-System-Of-Record: true Cc: Graeme Russ Subject: [U-Boot] [PATCH v2] x86: Fix how the location of the realmode and bios blobs are calculated 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: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de There are two blobs embedded into the u-boot image which are linked to run at an address which is different from where they actually end up in the ROM, one called "realmode" and one called "bios". There are realmode_setup and bios_setup functions which prepare those blobs by copying them into the location they're supposed to run from, among other things. During u-boot relocation from ROM to RAM, the text and a few data segments are copied over. The realmode and bios sections are not copied, and so the only place they can be read from is their original location in the ROM. Looking specifically at the bios blob, there are symbols defined in the linker script called __bios_start and __bios_size which are defined to be the start and size of the blob in the ROM. In the bios_setup function, there seem to be two mistakes happening. First, the offset from ROM to RAM is being added to __bios_start which implies that this code expects to use the copy moved to RAM. No such copy is made, so that's wrong. More subtly, when u-boot relocates itself, it goes through all of the relocations stored in .rel.dyn and fixes them up. This has the effect of transforming the __bios_start reference in bios_setup so that it refers to the version in RAM (if one existed) instead of the one in ROM. To correct for that, the offset actually needs to be subtracted out again to translate the address back into the ROM. The net effect is that for both blobs, a + needs to be changed to a -. Signed-off-by: Gabe Black Acked-by: Graeme Russ --- Changes in v2: Update x86 tag. arch/x86/lib/bios_setup.c | 6 +++++- arch/x86/lib/realmode.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/arch/x86/lib/bios_setup.c b/arch/x86/lib/bios_setup.c index 9bf7e58..6c6b0fe 100644 --- a/arch/x86/lib/bios_setup.c +++ b/arch/x86/lib/bios_setup.c @@ -140,7 +140,11 @@ static void setvector(int vector, u16 segment, void *handler) int bios_setup(void) { - ulong bios_start = (ulong)&__bios_start + gd->reloc_off; + /* + * The BIOS section is not relocated and still in the ROM. The + * __bios_start symbol was adjusted, though, so adjust it back. + */ + ulong bios_start = (ulong)&__bios_start - gd->reloc_off; ulong bios_size = (ulong)&__bios_size; static int done=0; diff --git a/arch/x86/lib/realmode.c b/arch/x86/lib/realmode.c index 6aa0f23..f8f2251 100644 --- a/arch/x86/lib/realmode.c +++ b/arch/x86/lib/realmode.c @@ -34,7 +34,11 @@ extern char realmode_enter; int realmode_setup(void) { - ulong realmode_start = (ulong)&__realmode_start + gd->reloc_off; + /* + * The realmode section is not relocated and still in the ROM. The + * __realmode_start symbol was adjusted, though, so adjust it back. + */ + ulong realmode_start = (ulong)&__realmode_start - gd->reloc_off; ulong realmode_size = (ulong)&__realmode_size; /* copy the realmode switch code */