summaryrefslogtreecommitdiff
path: root/arch/x86
diff options
context:
space:
mode:
authorGabe Black <gabeblack@chromium.org>2012-01-15 06:47:10 -0800
committerGabe Black (Do Not Use) <gabeblack@google.com>2012-01-18 20:55:20 -0800
commitedc55109a42662c7e661070433b478f74ebb4165 (patch)
tree1fa034c15917721a891df294dcd9a7a8fb89e5e5 /arch/x86
parent59201d4d0b578940b6e719544de904e20f956b2d (diff)
X86: Fix some minor bugs in the code that picks a relocation address
When this code picked an area for U-Boot to relocate to, it was making sure that there was enough space for U-Boot's various sections. It wasn't taking into account the space needed for the heap and stack, however, so if it happened to pick a very small region those areas might overlap with something they shouldn't. This change fixes that. Also, this change replaces the ROUND macro with the new rounddown introduced in a previous change. It was assumed that ROUND rounded down, in contrast to the other rounding function in common.h, roundup. It turns out that ROUND rounds up even more agressively than roundup. If the value being rounded is already exactly a multiple of the rounding amount, ROUND will still increase it to the next multiple. Because the region U-Boot had been choosing has plenty of space, there should be no functional difference with this change. BUG=chrome-os-partner:7579 TEST=Built and booted on Lumpy, Stumpy, and Kaen. Change-Id: I39a45be6487ed0f60ea0900fb10632da5b312ebe Signed-off-by: Gabe Black <gabeblack@google.com> Reviewed-on: https://gerrit.chromium.org/gerrit/14222
Diffstat (limited to 'arch/x86')
-rw-r--r--arch/x86/cpu/coreboot/sdram.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/arch/x86/cpu/coreboot/sdram.c b/arch/x86/cpu/coreboot/sdram.c
index f9693b1bfe2..e70681f87b5 100644
--- a/arch/x86/cpu/coreboot/sdram.c
+++ b/arch/x86/cpu/coreboot/sdram.c
@@ -66,7 +66,9 @@ int __calculate_relocation_address(void);
*/
int calculate_relocation_address(void)
{
- uint64_t uboot_size = &__bss_end - &__text_start;
+ 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;
@@ -80,14 +82,16 @@ int calculate_relocation_address(void)
if (memrange->type != CB_MEM_RAM)
continue;
- /* Filter memory over 4GB and regions that are too small. */
+ /* Filter memory over 4GB. */
if (end > 0xffffffffULL)
end = 0x100000000ULL;
- if (end - start < uboot_size)
+ /* 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 = ROUND((end - uboot_size), 1 << 12);
+ dest_addr = (end - uboot_size) & ~((1 << 12) - 1);
}
/* If no suitable area was found, return an error. */