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