]> git.ipfire.org Git - people/ms/u-boot.git/blame - arch/x86/lib/init_helpers.c
dts: re-write dts/Makefile more simply with Kbuild
[people/ms/u-boot.git] / arch / x86 / lib / init_helpers.c
CommitLineData
d47ab0ec
GR
1/*
2 * (C) Copyright 2011
3 * Graeme Russ, <graeme.russ@gmail.com>
4 *
1a459660 5 * SPDX-License-Identifier: GPL-2.0+
d47ab0ec
GR
6 */
7#include <common.h>
f697d528 8#include <fdtdec.h>
8313315b 9#include <spi.h>
86cfb6bd 10#include <asm/sections.h>
d47ab0ec
GR
11
12DECLARE_GLOBAL_DATA_PTR;
13
5e98947f
SG
14/* Get the top of usable RAM */
15__weak ulong board_get_usable_ram_top(ulong total_size)
a1d57b7a 16{
5e98947f
SG
17 return gd->ram_size;
18}
19
20int calculate_relocation_address(void)
21{
22 const ulong uboot_size = (uintptr_t)&__bss_end -
23 (uintptr_t)&__text_start;
24 ulong total_size;
a1d57b7a 25 ulong dest_addr;
f697d528 26 ulong fdt_size = 0;
a1d57b7a 27
f697d528
SG
28#if defined(CONFIG_OF_SEPARATE) && defined(CONFIG_OF_CONTROL)
29 if (gd->fdt_blob)
30 fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
31#endif
5e98947f 32 total_size = ALIGN(uboot_size, 1 << 12) + CONFIG_SYS_MALLOC_LEN +
f697d528 33 CONFIG_SYS_STACK_SIZE + fdt_size;
5e98947f 34
f697d528 35 dest_addr = board_get_usable_ram_top(total_size);
a1d57b7a
GR
36 /*
37 * NOTE: All destination address are rounded down to 16-byte
38 * boundary to satisfy various worst-case alignment
39 * requirements
40 */
f697d528 41 dest_addr &= ~15;
a1d57b7a 42
f697d528
SG
43#if defined(CONFIG_OF_SEPARATE) && defined(CONFIG_OF_CONTROL)
44 /*
45 * If the device tree is sitting immediate above our image then we
46 * must relocate it. If it is embedded in the data section, then it
47 * will be relocated with other data.
48 */
49 if (gd->fdt_blob) {
50 dest_addr -= fdt_size;
1938f4a5 51 gd->new_fdt = (void *)dest_addr;
f697d528
SG
52 dest_addr &= ~15;
53 }
54#endif
5e98947f
SG
55 /* U-Boot is below the FDT */
56 dest_addr -= uboot_size;
57 dest_addr &= ~((1 << 12) - 1);
a1d57b7a 58 gd->relocaddr = dest_addr;
5e98947f 59 gd->reloc_off = dest_addr - (uintptr_t)&__text_start;
a1d57b7a 60
32f98735
GB
61 /* Stack is at the bottom, so it can grow down */
62 gd->start_addr_sp = dest_addr - CONFIG_SYS_MALLOC_LEN;
63
a1d57b7a
GR
64 return 0;
65}
66
a1d57b7a
GR
67int init_cache_f_r(void)
68{
69 /* Initialise the CPU cache(s) */
70 return init_cache();
71}
72
d47ab0ec
GR
73bd_t bd_data;
74
75int init_bd_struct_r(void)
76{
77 gd->bd = &bd_data;
78 memset(gd->bd, 0, sizeof(bd_t));
79
80 return 0;
81}
82
8313315b
GB
83int init_func_spi(void)
84{
85 puts("SPI: ");
86 spi_init();
87 puts("ready\n");
88 return 0;
89}
b208c7f1 90
b208c7f1
GB
91int find_fdt(void)
92{
93#ifdef CONFIG_OF_EMBED
94 /* Get a pointer to the FDT */
6ab6b2af 95 gd->fdt_blob = __dtb_dt_begin;
b208c7f1
GB
96#elif defined CONFIG_OF_SEPARATE
97 /* FDT is at end of image */
4b491b8d 98 gd->fdt_blob = (ulong *)&_end;
b208c7f1
GB
99#endif
100 /* Allow the early environment to override the fdt address */
101 gd->fdt_blob = (void *)getenv_ulong("fdtcontroladdr", 16,
102 (uintptr_t)gd->fdt_blob);
103
104 return 0;
105}
106
107int prepare_fdt(void)
108{
109 /* For now, put this check after the console is ready */
110 if (fdtdec_prepare_fdt()) {
111 panic("** CONFIG_OF_CONTROL defined but no FDT - please see "
112 "doc/README.fdt-control");
113 }
114
115 return 0;
116}