xref: /rk3399_rockchip-uboot/common/init/board_init.c (revision af6bbd4daefc314cc422381580f11fabc9cb222f)
1*af6bbd4dSSimon Glass /*
2*af6bbd4dSSimon Glass  * Code shared between SPL and U-Boot proper
3*af6bbd4dSSimon Glass  *
4*af6bbd4dSSimon Glass  * Copyright (c) 2015 Google, Inc
5*af6bbd4dSSimon Glass  * Written by Simon Glass <sjg@chromium.org>
6*af6bbd4dSSimon Glass  *
7*af6bbd4dSSimon Glass  * SPDX-License-Identifier:	GPL-2.0+
8*af6bbd4dSSimon Glass  */
9*af6bbd4dSSimon Glass 
10*af6bbd4dSSimon Glass #include <common.h>
11*af6bbd4dSSimon Glass 
12*af6bbd4dSSimon Glass DECLARE_GLOBAL_DATA_PTR;
13*af6bbd4dSSimon Glass 
14*af6bbd4dSSimon Glass /* Unfortunately x86 can't compile this code as gd cannot be assigned */
15*af6bbd4dSSimon Glass #ifndef CONFIG_X86
16*af6bbd4dSSimon Glass __weak void arch_setup_gd(struct global_data *gd_ptr)
17*af6bbd4dSSimon Glass {
18*af6bbd4dSSimon Glass 	gd = gd_ptr;
19*af6bbd4dSSimon Glass }
20*af6bbd4dSSimon Glass #endif /* !CONFIG_X86 */
21*af6bbd4dSSimon Glass 
22*af6bbd4dSSimon Glass ulong board_init_f_mem(ulong top)
23*af6bbd4dSSimon Glass {
24*af6bbd4dSSimon Glass 	struct global_data *gd_ptr;
25*af6bbd4dSSimon Glass 
26*af6bbd4dSSimon Glass 	/* Leave space for the stack we are running with now */
27*af6bbd4dSSimon Glass 	top -= 0x40;
28*af6bbd4dSSimon Glass 
29*af6bbd4dSSimon Glass 	top -= sizeof(struct global_data);
30*af6bbd4dSSimon Glass 	top = ALIGN(top, 16);
31*af6bbd4dSSimon Glass 	gd_ptr = (struct global_data *)top;
32*af6bbd4dSSimon Glass 	memset(gd_ptr, '\0', sizeof(*gd));
33*af6bbd4dSSimon Glass 	arch_setup_gd(gd_ptr);
34*af6bbd4dSSimon Glass 
35*af6bbd4dSSimon Glass #if defined(CONFIG_SYS_MALLOC_F)
36*af6bbd4dSSimon Glass 	top -= CONFIG_SYS_MALLOC_F_LEN;
37*af6bbd4dSSimon Glass 	gd->malloc_base = top;
38*af6bbd4dSSimon Glass #endif
39*af6bbd4dSSimon Glass 
40*af6bbd4dSSimon Glass 	return top;
41*af6bbd4dSSimon Glass }
42