From patchwork Sat Nov 3 21:41:27 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 196949 X-Patchwork-Delegate: sjg@chromium.org 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 721682C00D6 for ; Sun, 4 Nov 2012 08:45:14 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B51944A2CA; Sat, 3 Nov 2012 22:44:04 +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 VDyhuUYJ92TA; Sat, 3 Nov 2012 22:44:04 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1165B4A1A1; Sat, 3 Nov 2012 22:42:33 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 943284A17C for ; Sat, 3 Nov 2012 22:42:21 +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 e7kNqWEUUy2j for ; Sat, 3 Nov 2012 22:42:19 +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 mail-ye0-f202.google.com (mail-ye0-f202.google.com [209.85.213.202]) by theia.denx.de (Postfix) with ESMTPS id 5C2404A15E for ; Sat, 3 Nov 2012 22:42:05 +0100 (CET) Received: by mail-ye0-f202.google.com with SMTP id r11so545166yen.3 for ; Sat, 03 Nov 2012 14:42:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=y/BFRq5c+51vy2qvtw+LzuUrClIklsFZMoEhpK+UAW0=; b=UDNgWQxDjs0By9/oP6WPkvexX2PxRaTEbXq8/zfaz6b8MCQx8HvO2JkETeicfRiJlo iVEw9L6pxQ6hJaakwtgZpSQYGkE1wi5jmL1RUiR6s8ZEzlIrGLYnpsPFMHr61/bQtI2F +4ZWLxHJ/OVv8Y1tVJEotqlhOiJ85b0YTZ/G0tckr7njioe5bJ74Ooa04Ou38W7xUPLD nMvE2PlGFHLzws1LGhiLe2BnkhvUsYaUzwlk6GApQ3hXIXi25pX+2/IMIJyJgnYnANRv f2oPAM7BAUQdC7KMeFKB5GKpRg00Uo7auiRu3HN0//pVttoL8Vvujt+rjcLgoF8TLrFJ q9KQ== Received: by 10.236.134.232 with SMTP id s68mr3906016yhi.31.1351978923522; Sat, 03 Nov 2012 14:42:03 -0700 (PDT) Received: from wpzn3.hot.corp.google.com (216-239-44-65.google.com [216.239.44.65]) by gmr-mx.google.com with ESMTPS id l20si821593yhi.2.2012.11.03.14.42.03 (version=TLSv1/SSLv3 cipher=AES128-SHA); Sat, 03 Nov 2012 14:42:03 -0700 (PDT) Received: from kaka.mtv.corp.google.com (kaka.mtv.corp.google.com [172.22.73.79]) by wpzn3.hot.corp.google.com (Postfix) with ESMTP id BB01F100049; Sat, 3 Nov 2012 14:42:02 -0700 (PDT) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id 7168C161954; Sat, 3 Nov 2012 14:42:02 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Sat, 3 Nov 2012 14:41:27 -0700 Message-Id: <1351978902-23719-6-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1351978902-23719-1-git-send-email-sjg@chromium.org> References: <1351978902-23719-1-git-send-email-sjg@chromium.org> X-Gm-Message-State: ALoCoQmxbKACSoR3hXzBU6+LzgDJDSS91BoHML64MODJ6kDF0bHlkrxlEd0uHQ5nLcbIr5PRuBH9up/h9kuEigbbxlGaN4Rm3cBFyIvCEgrqV4lfo072ZKckoMVGPUIQDAfWshBkLUd3AFnWVrd9lEBAVI+nELrgknJ1GMnUm0aaZBay+rtLleSUMyf3PPE+TrHrRdPrjSzv Cc: Gabe Black Subject: [U-Boot] [PATCH 05/20] x86: Override calculate_relocation_address to use the e820 map X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 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 From: Gabe Black Because calculate_relocation_address now uses the e820 map, it will be able to avoid addresses over 32 bits and regions that are at high addresses but not big enough for U-Boot. It also means we can remove the hack which limitted U-Boot's idea of the size of memory to less than 4GB. Also take into account the space needed for the heap and stack, so we avoid picking a very small region those areas might overlap with something it shouldn't. Signed-off-by: Gabe Black Signed-off-by: Gabe Black Signed-off-by: Simon Glass --- arch/x86/cpu/coreboot/sdram.c | 53 +++++++++++++++++++++++++++++++++++++--- 1 files changed, 49 insertions(+), 4 deletions(-) diff --git a/arch/x86/cpu/coreboot/sdram.c b/arch/x86/cpu/coreboot/sdram.c index 5d3da99..611f554 100644 --- a/arch/x86/cpu/coreboot/sdram.c +++ b/arch/x86/cpu/coreboot/sdram.c @@ -51,6 +51,55 @@ unsigned install_e820_map(unsigned max_entries, struct e820entry *entries) return num_entries; } +/* + * This function looks for the highest region of memory lower than 4GB which + * has enough space for U-Boot where U-Boot is aligned on a page boundary. It + * overrides the default implementation found elsewhere which simply picks the + * end of ram, wherever that may be. The location of the stack, the relocation + * address, and how far U-Boot is moved by relocation are set in the global + * data structure. + */ +int calculate_relocation_address(void) +{ + const uint64_t uboot_size = &__bss_end - &__text_start; + const uint64_t total_size = uboot_size + CONFIG_SYS_MALLOC_LEN + + CONFIG_SYS_STACK_SIZE; + uintptr_t dest_addr = 0; + int i; + + for (i = 0; i < lib_sysinfo.n_memranges; i++) { + struct memrange *memrange = &lib_sysinfo.memrange[i]; + /* Force U-Boot to relocate to a page aligned address. */ + uint64_t start = roundup(memrange->base, 1 << 12); + uint64_t end = memrange->base + memrange->size; + + /* Ignore non-memory regions. */ + if (memrange->type != CB_MEM_RAM) + continue; + + /* Filter memory over 4GB. */ + if (end > 0xffffffffULL) + end = 0x100000000ULL; + /* Skip this region if it's too small. */ + if (end - start < total_size) + continue; + + /* Use this address if it's the largest so far. */ + if (end - uboot_size > dest_addr) + dest_addr = (end - uboot_size) & ~((1 << 12) - 1); + } + + /* If no suitable area was found, return an error. */ + if (!dest_addr) + return 1; + + gd->start_addr_sp = dest_addr - CONFIG_SYS_MALLOC_LEN; + gd->relocaddr = dest_addr; + gd->reloc_off = dest_addr - (uintptr_t)&__text_start; + + return 0; +} + int dram_init_f(void) { int i; @@ -60,10 +109,6 @@ int dram_init_f(void) struct memrange *memrange = &lib_sysinfo.memrange[i]; unsigned long long end = memrange->base + memrange->size; - /* Ignore memory over 4GB, we can't use it. */ - if (memrange->base > 0xffffffff) - continue; - if (memrange->type == CB_MEM_RAM && end > ram_size) ram_size = end; }