Move board_init_f_mem() into a common location
[platform/kernel/u-boot.git] / common / init / board_init.c
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
14 /* Unfortunately x86 can't compile this code as gd cannot be assigned */
15 #ifndef CONFIG_X86
16 __weak void arch_setup_gd(struct global_data *gd_ptr)
17 {
18         gd = gd_ptr;
19 }
20 #endif /* !CONFIG_X86 */
21
22 ulong board_init_f_mem(ulong top)
23 {
24         struct global_data *gd_ptr;
25
26         /* Leave space for the stack we are running with now */
27         top -= 0x40;
28
29         top -= sizeof(struct global_data);
30         top = ALIGN(top, 16);
31         gd_ptr = (struct global_data *)top;
32         memset(gd_ptr, '\0', sizeof(*gd));
33         arch_setup_gd(gd_ptr);
34
35 #if defined(CONFIG_SYS_MALLOC_F)
36         top -= CONFIG_SYS_MALLOC_F_LEN;
37         gd->malloc_base = top;
38 #endif
39
40         return top;
41 }