Simon Glass | b1beb11 | 2015-10-19 06:49:56 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Code shared between SPL and U-Boot proper |
| 3 | * |
| 4 | * Copyright (c) 2015 Google, Inc |
| 5 | * Written by Simon Glass <sjg@chromium.org> |
| 6 | * |
| 7 | * SPDX-License-Identifier: GPL-2.0+ |
| 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | |
| 12 | DECLARE_GLOBAL_DATA_PTR; |
| 13 | |
Simon Glass | 90a2fbb | 2015-10-19 06:49:57 -0600 | [diff] [blame] | 14 | /* |
| 15 | * It isn't trivial to figure out whether memcpy() exists. The arch-specific |
| 16 | * memcpy() is not normally available in SPL due to code size. |
| 17 | */ |
| 18 | #if !defined(CONFIG_SPL_BUILD) || \ |
| 19 | (defined(CONFIG_SPL_LIBGENERIC_SUPPORT) && \ |
| 20 | !defined(CONFIG_USE_ARCH_MEMSET)) |
| 21 | #define _USE_MEMCPY |
| 22 | #endif |
| 23 | |
Simon Glass | b1beb11 | 2015-10-19 06:49:56 -0600 | [diff] [blame] | 24 | /* Unfortunately x86 can't compile this code as gd cannot be assigned */ |
| 25 | #ifndef CONFIG_X86 |
| 26 | __weak void arch_setup_gd(struct global_data *gd_ptr) |
| 27 | { |
| 28 | gd = gd_ptr; |
| 29 | } |
| 30 | #endif /* !CONFIG_X86 */ |
| 31 | |
| 32 | ulong board_init_f_mem(ulong top) |
| 33 | { |
| 34 | struct global_data *gd_ptr; |
Simon Glass | 90a2fbb | 2015-10-19 06:49:57 -0600 | [diff] [blame] | 35 | #ifndef _USE_MEMCPY |
| 36 | int *ptr; |
| 37 | #endif |
Simon Glass | b1beb11 | 2015-10-19 06:49:56 -0600 | [diff] [blame] | 38 | |
| 39 | /* Leave space for the stack we are running with now */ |
| 40 | top -= 0x40; |
| 41 | |
| 42 | top -= sizeof(struct global_data); |
| 43 | top = ALIGN(top, 16); |
| 44 | gd_ptr = (struct global_data *)top; |
Simon Glass | 90a2fbb | 2015-10-19 06:49:57 -0600 | [diff] [blame] | 45 | #ifdef _USE_MEMCPY |
Simon Glass | b1beb11 | 2015-10-19 06:49:56 -0600 | [diff] [blame] | 46 | memset(gd_ptr, '\0', sizeof(*gd)); |
Simon Glass | 90a2fbb | 2015-10-19 06:49:57 -0600 | [diff] [blame] | 47 | #else |
| 48 | for (ptr = (int *)gd_ptr; ptr < (int *)(gd_ptr + 1); ) |
| 49 | *ptr++ = 0; |
| 50 | #endif |
Simon Glass | b1beb11 | 2015-10-19 06:49:56 -0600 | [diff] [blame] | 51 | arch_setup_gd(gd_ptr); |
| 52 | |
Simon Glass | 13a15e2 | 2015-10-19 06:49:58 -0600 | [diff] [blame] | 53 | #if defined(CONFIG_SYS_MALLOC_F) && \ |
| 54 | (!defined(CONFIG_SPL_BUILD) || !defined(CONFIG_SYS_SPL_MALLOC_START)) |
Simon Glass | b1beb11 | 2015-10-19 06:49:56 -0600 | [diff] [blame] | 55 | top -= CONFIG_SYS_MALLOC_F_LEN; |
| 56 | gd->malloc_base = top; |
| 57 | #endif |
| 58 | |
| 59 | return top; |
| 60 | } |