Blame view

common/board_f.c 22.6 KB
1938f4a5b   Simon Glass   Introduce generic...
1
2
3
4
5
6
7
8
9
  /*
   * Copyright (c) 2011 The Chromium OS Authors.
   * (C) Copyright 2002-2006
   * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
   *
   * (C) Copyright 2002
   * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
   * Marius Groeger <mgroeger@sysgo.de>
   *
1a4596601   Wolfgang Denk   Add GPL-2.0+ SPDX...
10
   * SPDX-License-Identifier:	GPL-2.0+
1938f4a5b   Simon Glass   Introduce generic...
11
12
13
   */
  
  #include <common.h>
24b852a7a   Simon Glass   Move console defi...
14
  #include <console.h>
1938f4a5b   Simon Glass   Introduce generic...
15
  #include <environment.h>
ab7cd6279   Simon Glass   dm: Support drive...
16
  #include <dm.h>
1938f4a5b   Simon Glass   Introduce generic...
17
  #include <fdtdec.h>
f828bf25f   Simon Glass   sandbox: Add CONF...
18
  #include <fs.h>
e4fef6cfc   Simon Glass   Adjust board_f.c ...
19
  #include <i2c.h>
1938f4a5b   Simon Glass   Introduce generic...
20
  #include <initcall.h>
96d4b75c0   Simon Glass   board_f: Make ini...
21
  #include <init_helpers.h>
fb5cf7f16   Simon Glass   Move initf_malloc...
22
  #include <malloc.h>
0eb25b619   Joe Hershberger   common: Make sure...
23
  #include <mapmem.h>
a733b06b6   Simon Glass   sandbox: Switch o...
24
  #include <os.h>
1938f4a5b   Simon Glass   Introduce generic...
25
  #include <post.h>
e47b2d674   Simon Glass   board_f: Make rel...
26
  #include <relocate.h>
e4fef6cfc   Simon Glass   Adjust board_f.c ...
27
  #include <spi.h>
c5d4001a1   Jeroen Hofstee   common: board_f: ...
28
  #include <status_led.h>
1057e6cfe   Simon Glass   timer: Set up the...
29
  #include <timer.h>
71c52dba2   Simon Glass   Add trace support...
30
  #include <trace.h>
5a5419451   Simon Glass   dm: common: Add m...
31
  #include <video.h>
e4fef6cfc   Simon Glass   Adjust board_f.c ...
32
  #include <watchdog.h>
b885d02e2   Simon Glass   arm: Remove inclu...
33
34
35
  #ifdef CONFIG_MACH_TYPE
  #include <asm/mach-types.h>
  #endif
1fbf97dc4   Simon Glass   board_f: powerpc:...
36
37
38
  #if defined(CONFIG_MP) && defined(CONFIG_PPC)
  #include <asm/mp.h>
  #endif
1938f4a5b   Simon Glass   Introduce generic...
39
40
  #include <asm/io.h>
  #include <asm/sections.h>
ab7cd6279   Simon Glass   dm: Support drive...
41
  #include <dm/root.h>
056285fd4   Simon Glass   board_f: Move err...
42
  #include <linux/errno.h>
1938f4a5b   Simon Glass   Introduce generic...
43
44
45
46
47
48
49
50
51
  
  /*
   * Pointer to initial global data area
   *
   * Here we initialize it if needed.
   */
  #ifdef XTRN_DECLARE_GLOBAL_DATA_PTR
  #undef	XTRN_DECLARE_GLOBAL_DATA_PTR
  #define XTRN_DECLARE_GLOBAL_DATA_PTR	/* empty = allocate here */
16ef14742   Mario Six   common: board_f: ...
52
  DECLARE_GLOBAL_DATA_PTR = (gd_t *)(CONFIG_SYS_INIT_GD_ADDR);
1938f4a5b   Simon Glass   Introduce generic...
53
54
55
56
57
  #else
  DECLARE_GLOBAL_DATA_PTR;
  #endif
  
  /*
4c509343a   Simon Glass   Fix comment nits ...
58
   * TODO(sjg@chromium.org): IMO this code should be
1938f4a5b   Simon Glass   Introduce generic...
59
60
61
62
63
64
65
66
67
   * refactored to a single function, something like:
   *
   * void led_set_state(enum led_colour_t colour, int on);
   */
  /************************************************************************
   * Coloured LED functionality
   ************************************************************************
   * May be supplied by boards if desired
   */
c5d4001a1   Jeroen Hofstee   common: board_f: ...
68
69
70
71
72
73
74
75
76
  __weak void coloured_LED_init(void) {}
  __weak void red_led_on(void) {}
  __weak void red_led_off(void) {}
  __weak void green_led_on(void) {}
  __weak void green_led_off(void) {}
  __weak void yellow_led_on(void) {}
  __weak void yellow_led_off(void) {}
  __weak void blue_led_on(void) {}
  __weak void blue_led_off(void) {}
1938f4a5b   Simon Glass   Introduce generic...
77
78
79
80
81
82
83
84
85
86
87
  
  /*
   * Why is gd allocated a register? Prior to reloc it might be better to
   * just pass it around to each function in this file?
   *
   * After reloc one could argue that it is hardly used and doesn't need
   * to be in a register. Or if it is it should perhaps hold pointers to all
   * global data for all modules, so that post-reloc we can avoid the massive
   * literal pool we get on ARM. Or perhaps just encourage each module to use
   * a structure...
   */
d54d7eb96   Sonic Zhang   support blackfin ...
88
  #if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
e4fef6cfc   Simon Glass   Adjust board_f.c ...
89
90
  static int init_func_watchdog_init(void)
  {
ea3310e8a   Tom Rini   Blackfin: Remove
91
92
  # if defined(CONFIG_HW_WATCHDOG) && \
  	(defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \
14a380a8f   Stefan Roese   common/board_f.c:...
93
  	defined(CONFIG_SH) || defined(CONFIG_AT91SAM9_WATCHDOG) || \
46d7a3b3d   Anatolij Gustschin   board_f: init des...
94
  	defined(CONFIG_DESIGNWARE_WATCHDOG) || \
14a380a8f   Stefan Roese   common/board_f.c:...
95
  	defined(CONFIG_IMX_WATCHDOG))
d54d7eb96   Sonic Zhang   support blackfin ...
96
  	hw_watchdog_init();
e4fef6cfc   Simon Glass   Adjust board_f.c ...
97
98
  	puts("       Watchdog enabled
  ");
ba169d981   Anatolij Gustschin   board_f: prevent ...
99
  # endif
e4fef6cfc   Simon Glass   Adjust board_f.c ...
100
101
102
103
104
105
106
107
108
109
110
111
  	WATCHDOG_RESET();
  
  	return 0;
  }
  
  int init_func_watchdog_reset(void)
  {
  	WATCHDOG_RESET();
  
  	return 0;
  }
  #endif /* CONFIG_WATCHDOG */
dd2a6cd0f   Jeroen Hofstee   common: board: us...
112
  __weak void board_add_ram_info(int use_default)
e4fef6cfc   Simon Glass   Adjust board_f.c ...
113
114
115
  {
  	/* please define platform specific board_add_ram_info() */
  }
1938f4a5b   Simon Glass   Introduce generic...
116
117
  static int init_baud_rate(void)
  {
bfebc8c96   Simon Glass   env: Rename geten...
118
  	gd->baudrate = env_get_ulong("baudrate", 10, CONFIG_BAUDRATE);
1938f4a5b   Simon Glass   Introduce generic...
119
120
121
122
123
  	return 0;
  }
  
  static int display_text_info(void)
  {
9b2174984   Ben Stoltz   efi: Avoid using ...
124
  #if !defined(CONFIG_SANDBOX) && !defined(CONFIG_EFI_APP)
9fdee7d73   Daniel Schwierzeck   common/board_f: f...
125
  	ulong bss_start, bss_end, text_base;
1938f4a5b   Simon Glass   Introduce generic...
126

632efa744   Simon Glass   Add CONFIG_SYS_SY...
127
128
  	bss_start = (ulong)&__bss_start;
  	bss_end = (ulong)&__bss_end;
b60eff31f   Albert ARIBAUD   arm: remove unnee...
129

d54d7eb96   Sonic Zhang   support blackfin ...
130
  #ifdef CONFIG_SYS_TEXT_BASE
9fdee7d73   Daniel Schwierzeck   common/board_f: f...
131
  	text_base = CONFIG_SYS_TEXT_BASE;
d54d7eb96   Sonic Zhang   support blackfin ...
132
  #else
9fdee7d73   Daniel Schwierzeck   common/board_f: f...
133
  	text_base = CONFIG_SYS_MONITOR_BASE;
d54d7eb96   Sonic Zhang   support blackfin ...
134
  #endif
9fdee7d73   Daniel Schwierzeck   common/board_f: f...
135
136
137
  
  	debug("U-Boot code: %08lX -> %08lX  BSS: -> %08lX
  ",
16ef14742   Mario Six   common: board_f: ...
138
  	      text_base, bss_start, bss_end);
a733b06b6   Simon Glass   sandbox: Switch o...
139
  #endif
1938f4a5b   Simon Glass   Introduce generic...
140

1938f4a5b   Simon Glass   Introduce generic...
141
142
143
144
145
146
147
148
149
150
151
  	return 0;
  }
  
  static int announce_dram_init(void)
  {
  	puts("DRAM:  ");
  	return 0;
  }
  
  static int show_dram_config(void)
  {
fa39ffe5d   York Sun   common/board_f: F...
152
  	unsigned long long size;
1938f4a5b   Simon Glass   Introduce generic...
153
154
155
156
157
158
159
160
161
  
  #ifdef CONFIG_NR_DRAM_BANKS
  	int i;
  
  	debug("
  RAM Configuration:
  ");
  	for (i = size = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  		size += gd->bd->bi_dram[i].size;
715f599f8   Bin Meng   common: Display >...
162
163
  		debug("Bank #%d: %llx ", i,
  		      (unsigned long long)(gd->bd->bi_dram[i].start));
1938f4a5b   Simon Glass   Introduce generic...
164
165
166
167
168
169
170
171
172
173
  #ifdef DEBUG
  		print_size(gd->bd->bi_dram[i].size, "
  ");
  #endif
  	}
  	debug("
  DRAM:  ");
  #else
  	size = gd->ram_size;
  #endif
e4fef6cfc   Simon Glass   Adjust board_f.c ...
174
175
176
177
  	print_size(size, "");
  	board_add_ram_info(0);
  	putc('
  ');
1938f4a5b   Simon Glass   Introduce generic...
178
179
180
  
  	return 0;
  }
76b00aca4   Simon Glass   board_f: Drop set...
181
  __weak int dram_init_banksize(void)
1938f4a5b   Simon Glass   Introduce generic...
182
183
184
185
186
  {
  #if defined(CONFIG_NR_DRAM_BANKS) && defined(CONFIG_SYS_SDRAM_BASE)
  	gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
  	gd->bd->bi_dram[0].size = get_effective_memsize();
  #endif
76b00aca4   Simon Glass   board_f: Drop set...
187
188
  
  	return 0;
1938f4a5b   Simon Glass   Introduce generic...
189
  }
69153988a   Simon Glass   i2c: Finish dropp...
190
  #if defined(CONFIG_SYS_I2C)
e4fef6cfc   Simon Glass   Adjust board_f.c ...
191
192
193
  static int init_func_i2c(void)
  {
  	puts("I2C:   ");
815a76f2e   trem   i2c: fix init on ...
194
195
196
  #ifdef CONFIG_SYS_I2C
  	i2c_init_all();
  #else
e4fef6cfc   Simon Glass   Adjust board_f.c ...
197
  	i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
815a76f2e   trem   i2c: fix init on ...
198
  #endif
e4fef6cfc   Simon Glass   Adjust board_f.c ...
199
200
201
202
203
  	puts("ready
  ");
  	return 0;
  }
  #endif
1fab98fb9   Rajesh Bhagat   common: board_f: ...
204
205
206
207
208
209
  #if defined(CONFIG_VID)
  __weak int init_func_vid(void)
  {
  	return 0;
  }
  #endif
e4fef6cfc   Simon Glass   Adjust board_f.c ...
210
211
212
213
214
215
216
217
218
219
  #if defined(CONFIG_HARD_SPI)
  static int init_func_spi(void)
  {
  	puts("SPI:   ");
  	spi_init();
  	puts("ready
  ");
  	return 0;
  }
  #endif
1938f4a5b   Simon Glass   Introduce generic...
220
221
  static int setup_mon_len(void)
  {
e945f6dc2   Michal Simek   microblaze: Move ...
222
  #if defined(__ARM__) || defined(__MICROBLAZE__)
b60eff31f   Albert ARIBAUD   arm: remove unnee...
223
  	gd->mon_len = (ulong)&__bss_end - (ulong)_start;
9b2174984   Ben Stoltz   efi: Avoid using ...
224
  #elif defined(CONFIG_SANDBOX) || defined(CONFIG_EFI_APP)
a733b06b6   Simon Glass   sandbox: Switch o...
225
  	gd->mon_len = (ulong)&_end - (ulong)_init;
ea3310e8a   Tom Rini   Blackfin: Remove
226
  #elif defined(CONFIG_NIOS2) || defined(CONFIG_XTENSA)
d54d7eb96   Sonic Zhang   support blackfin ...
227
  	gd->mon_len = CONFIG_SYS_MONITOR_LEN;
068feb9b8   Rick Chen   riscv: Modify gen...
228
  #elif defined(CONFIG_NDS32) || defined(CONFIG_SH) || defined(CONFIG_RISCV)
2e88bb28d   Kun-Hua Huang   NDS32: Generic Bo...
229
  	gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start);
b0b359536   Simon Glass   board_f: Don't re...
230
  #elif defined(CONFIG_SYS_MONITOR_BASE)
e4fef6cfc   Simon Glass   Adjust board_f.c ...
231
232
  	/* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */
  	gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
632efa744   Simon Glass   Add CONFIG_SYS_SY...
233
  #endif
1938f4a5b   Simon Glass   Introduce generic...
234
235
236
237
238
239
240
  	return 0;
  }
  
  __weak int arch_cpu_init(void)
  {
  	return 0;
  }
8ebf50692   Paul Burton   board_f: Add a ma...
241
242
243
244
  __weak int mach_cpu_init(void)
  {
  	return 0;
  }
1938f4a5b   Simon Glass   Introduce generic...
245
246
247
  /* Get the top of usable RAM */
  __weak ulong board_get_usable_ram_top(ulong total_size)
  {
1e4d11a58   Stephen Warren   common: board: su...
248
249
  #ifdef CONFIG_SYS_SDRAM_BASE
  	/*
4c509343a   Simon Glass   Fix comment nits ...
250
  	 * Detect whether we have so much RAM that it goes past the end of our
1e4d11a58   Stephen Warren   common: board: su...
251
252
253
254
255
256
257
258
259
  	 * 32-bit address space. If so, clip the usable RAM so it doesn't.
  	 */
  	if (gd->ram_top < CONFIG_SYS_SDRAM_BASE)
  		/*
  		 * Will wrap back to top of 32-bit space when reservations
  		 * are made.
  		 */
  		return 0;
  #endif
1938f4a5b   Simon Glass   Introduce generic...
260
261
262
263
264
265
266
267
268
269
270
271
  	return gd->ram_top;
  }
  
  static int setup_dest_addr(void)
  {
  	debug("Monitor len: %08lX
  ", gd->mon_len);
  	/*
  	 * Ram is setup, size stored in gd !!
  	 */
  	debug("Ram size: %08lX
  ", (ulong)gd->ram_size);
36cc0de0b   York Sun   armv8: layerscape...
272
  #if defined(CONFIG_SYS_MEM_TOP_HIDE)
1938f4a5b   Simon Glass   Introduce generic...
273
274
275
276
  	/*
  	 * Subtract specified amount of memory to hide so that it won't
  	 * get "touched" at all by U-Boot. By fixing up gd->ram_size
  	 * the Linux kernel should now get passed the now "corrected"
36cc0de0b   York Sun   armv8: layerscape...
277
278
279
280
281
  	 * memory size and won't touch it either. This should work
  	 * for arch/ppc and arch/powerpc. Only Linux board ports in
  	 * arch/powerpc with bootwrapper support, that recalculate the
  	 * memory size from the SDRAM controller setup will have to
  	 * get fixed.
1938f4a5b   Simon Glass   Introduce generic...
282
  	 */
36cc0de0b   York Sun   armv8: layerscape...
283
284
  	gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
  #endif
1938f4a5b   Simon Glass   Introduce generic...
285
286
287
  #ifdef CONFIG_SYS_SDRAM_BASE
  	gd->ram_top = CONFIG_SYS_SDRAM_BASE;
  #endif
e4fef6cfc   Simon Glass   Adjust board_f.c ...
288
  	gd->ram_top += get_effective_memsize();
1938f4a5b   Simon Glass   Introduce generic...
289
  	gd->ram_top = board_get_usable_ram_top(gd->mon_len);
a0ba279ac   Masahiro Yamada   generic_board: re...
290
  	gd->relocaddr = gd->ram_top;
1938f4a5b   Simon Glass   Introduce generic...
291
292
  	debug("Ram top: %08lX
  ", (ulong)gd->ram_top);
ec3b48201   Gabriel Huau   common: fix inclu...
293
  #if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
e4fef6cfc   Simon Glass   Adjust board_f.c ...
294
295
296
297
  	/*
  	 * We need to make sure the location we intend to put secondary core
  	 * boot code is reserved and not used by any part of u-boot
  	 */
a0ba279ac   Masahiro Yamada   generic_board: re...
298
299
300
301
  	if (gd->relocaddr > determine_mp_bootpg(NULL)) {
  		gd->relocaddr = determine_mp_bootpg(NULL);
  		debug("Reserving MP boot page to %08lx
  ", gd->relocaddr);
e4fef6cfc   Simon Glass   Adjust board_f.c ...
302
303
  	}
  #endif
1938f4a5b   Simon Glass   Introduce generic...
304
305
  	return 0;
  }
1938f4a5b   Simon Glass   Introduce generic...
306
307
308
309
310
  #ifdef CONFIG_PRAM
  /* reserve protected RAM */
  static int reserve_pram(void)
  {
  	ulong reg;
bfebc8c96   Simon Glass   env: Rename geten...
311
  	reg = env_get_ulong("pram", 10, CONFIG_PRAM);
a0ba279ac   Masahiro Yamada   generic_board: re...
312
  	gd->relocaddr -= (reg << 10);		/* size is in kB */
1938f4a5b   Simon Glass   Introduce generic...
313
314
  	debug("Reserving %ldk for protected RAM at %08lx
  ", reg,
a0ba279ac   Masahiro Yamada   generic_board: re...
315
  	      gd->relocaddr);
1938f4a5b   Simon Glass   Introduce generic...
316
317
318
319
320
321
322
  	return 0;
  }
  #endif /* CONFIG_PRAM */
  
  /* Round memory pointer down to next 4 kB limit */
  static int reserve_round_4k(void)
  {
a0ba279ac   Masahiro Yamada   generic_board: re...
323
  	gd->relocaddr &= ~(4096 - 1);
1938f4a5b   Simon Glass   Introduce generic...
324
325
  	return 0;
  }
80d4bcd3e   Simon Glass   board_f: Move the...
326
  #ifdef CONFIG_ARM
60873f736   Siva Durga Prasad Paladugu   common: board_f: ...
327
  __weak int reserve_mmu(void)
1938f4a5b   Simon Glass   Introduce generic...
328
  {
80d4bcd3e   Simon Glass   board_f: Move the...
329
  #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
1938f4a5b   Simon Glass   Introduce generic...
330
  	/* reserve TLB table */
cce6be7f0   David Feng   arm64: generic bo...
331
  	gd->arch.tlb_size = PGTABLE_SIZE;
a0ba279ac   Masahiro Yamada   generic_board: re...
332
  	gd->relocaddr -= gd->arch.tlb_size;
1938f4a5b   Simon Glass   Introduce generic...
333
334
  
  	/* round down to next 64 kB limit */
a0ba279ac   Masahiro Yamada   generic_board: re...
335
  	gd->relocaddr &= ~(0x10000 - 1);
1938f4a5b   Simon Glass   Introduce generic...
336

a0ba279ac   Masahiro Yamada   generic_board: re...
337
  	gd->arch.tlb_addr = gd->relocaddr;
1938f4a5b   Simon Glass   Introduce generic...
338
339
340
  	debug("TLB table from %08lx to %08lx
  ", gd->arch.tlb_addr,
  	      gd->arch.tlb_addr + gd->arch.tlb_size);
50e93b956   York Sun   armv8: Add tlb_al...
341
342
343
344
345
346
347
348
  
  #ifdef CONFIG_SYS_MEM_RESERVE_SECURE
  	/*
  	 * Record allocated tlb_addr in case gd->tlb_addr to be overwritten
  	 * with location within secure ram.
  	 */
  	gd->arch.tlb_allocated = gd->arch.tlb_addr;
  #endif
80d4bcd3e   Simon Glass   board_f: Move the...
349
  #endif
50e93b956   York Sun   armv8: Add tlb_al...
350

1938f4a5b   Simon Glass   Introduce generic...
351
352
353
  	return 0;
  }
  #endif
5a5419451   Simon Glass   dm: common: Add m...
354
355
  static int reserve_video(void)
  {
0f079eb51   Simon Glass   board_f: Put vide...
356
  #ifdef CONFIG_DM_VIDEO
5a5419451   Simon Glass   dm: common: Add m...
357
358
359
360
361
362
363
364
  	ulong addr;
  	int ret;
  
  	addr = gd->relocaddr;
  	ret = video_reserve(&addr);
  	if (ret)
  		return ret;
  	gd->relocaddr = addr;
0f079eb51   Simon Glass   board_f: Put vide...
365
  #elif defined(CONFIG_LCD)
5a5419451   Simon Glass   dm: common: Add m...
366
  #  ifdef CONFIG_FB_ADDR
1938f4a5b   Simon Glass   Introduce generic...
367
  	gd->fb_base = CONFIG_FB_ADDR;
5a5419451   Simon Glass   dm: common: Add m...
368
  #  else
1938f4a5b   Simon Glass   Introduce generic...
369
  	/* reserve memory for LCD display (always full pages) */
a0ba279ac   Masahiro Yamada   generic_board: re...
370
371
  	gd->relocaddr = lcd_setmem(gd->relocaddr);
  	gd->fb_base = gd->relocaddr;
5a5419451   Simon Glass   dm: common: Add m...
372
  #  endif /* CONFIG_FB_ADDR */
0f079eb51   Simon Glass   board_f: Put vide...
373
  #elif defined(CONFIG_VIDEO) && \
5b8e76c35   Heiko Schocher   powerpc, 8xx: rem...
374
  		(!defined(CONFIG_PPC)) && \
d54d7eb96   Sonic Zhang   support blackfin ...
375
  		!defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
ea3310e8a   Tom Rini   Blackfin: Remove
376
  		!defined(CONFIG_M68K)
e4fef6cfc   Simon Glass   Adjust board_f.c ...
377
  	/* reserve memory for video display (always full pages) */
a0ba279ac   Masahiro Yamada   generic_board: re...
378
379
  	gd->relocaddr = video_setmem(gd->relocaddr);
  	gd->fb_base = gd->relocaddr;
0f079eb51   Simon Glass   board_f: Put vide...
380
  #endif
e4fef6cfc   Simon Glass   Adjust board_f.c ...
381
382
383
  
  	return 0;
  }
e4fef6cfc   Simon Glass   Adjust board_f.c ...
384

8703ef3fd   Simon Glass   common: Move LCD ...
385
386
387
388
389
390
391
392
393
394
395
396
  static int reserve_trace(void)
  {
  #ifdef CONFIG_TRACE
  	gd->relocaddr -= CONFIG_TRACE_BUFFER_SIZE;
  	gd->trace_buff = map_sysmem(gd->relocaddr, CONFIG_TRACE_BUFFER_SIZE);
  	debug("Reserving %dk for trace data at: %08lx
  ",
  	      CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr);
  #endif
  
  	return 0;
  }
1938f4a5b   Simon Glass   Introduce generic...
397
398
399
400
401
402
  static int reserve_uboot(void)
  {
  	/*
  	 * reserve memory for U-Boot code, data & bss
  	 * round down to next 4 kB limit
  	 */
a0ba279ac   Masahiro Yamada   generic_board: re...
403
404
  	gd->relocaddr -= gd->mon_len;
  	gd->relocaddr &= ~(4096 - 1);
703ec9ddf   Paul Burton   MIPS: Stop buildi...
405
  #if defined(CONFIG_E500) || defined(CONFIG_MIPS)
e4fef6cfc   Simon Glass   Adjust board_f.c ...
406
  	/* round down to next 64 kB limit so that IVPR stays aligned */
a0ba279ac   Masahiro Yamada   generic_board: re...
407
  	gd->relocaddr &= ~(65536 - 1);
e4fef6cfc   Simon Glass   Adjust board_f.c ...
408
  #endif
1938f4a5b   Simon Glass   Introduce generic...
409
410
411
  
  	debug("Reserving %ldk for U-Boot at: %08lx
  ", gd->mon_len >> 10,
a0ba279ac   Masahiro Yamada   generic_board: re...
412
413
414
  	      gd->relocaddr);
  
  	gd->start_addr_sp = gd->relocaddr;
1938f4a5b   Simon Glass   Introduce generic...
415
416
417
418
419
420
  	return 0;
  }
  
  /* reserve memory for malloc() area */
  static int reserve_malloc(void)
  {
a0ba279ac   Masahiro Yamada   generic_board: re...
421
  	gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN;
1938f4a5b   Simon Glass   Introduce generic...
422
423
  	debug("Reserving %dk for malloc() at: %08lx
  ",
16ef14742   Mario Six   common: board_f: ...
424
  	      TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
1938f4a5b   Simon Glass   Introduce generic...
425
426
427
428
429
430
  	return 0;
  }
  
  /* (permanently) allocate a Board Info struct */
  static int reserve_board(void)
  {
d54d7eb96   Sonic Zhang   support blackfin ...
431
432
433
434
435
436
437
438
  	if (!gd->bd) {
  		gd->start_addr_sp -= sizeof(bd_t);
  		gd->bd = (bd_t *)map_sysmem(gd->start_addr_sp, sizeof(bd_t));
  		memset(gd->bd, '\0', sizeof(bd_t));
  		debug("Reserving %zu Bytes for Board Info at: %08lx
  ",
  		      sizeof(bd_t), gd->start_addr_sp);
  	}
1938f4a5b   Simon Glass   Introduce generic...
439
440
441
442
443
444
445
446
447
448
449
450
451
  	return 0;
  }
  
  static int setup_machine(void)
  {
  #ifdef CONFIG_MACH_TYPE
  	gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */
  #endif
  	return 0;
  }
  
  static int reserve_global_data(void)
  {
a0ba279ac   Masahiro Yamada   generic_board: re...
452
453
  	gd->start_addr_sp -= sizeof(gd_t);
  	gd->new_gd = (gd_t *)map_sysmem(gd->start_addr_sp, sizeof(gd_t));
1938f4a5b   Simon Glass   Introduce generic...
454
455
  	debug("Reserving %zu Bytes for Global Data at: %08lx
  ",
16ef14742   Mario Six   common: board_f: ...
456
  	      sizeof(gd_t), gd->start_addr_sp);
1938f4a5b   Simon Glass   Introduce generic...
457
458
459
460
461
  	return 0;
  }
  
  static int reserve_fdt(void)
  {
e9acb9ea4   Siva Durga Prasad Paladugu   common: board: Do...
462
  #ifndef CONFIG_OF_EMBED
1938f4a5b   Simon Glass   Introduce generic...
463
  	/*
4c509343a   Simon Glass   Fix comment nits ...
464
  	 * If the device tree is sitting immediately above our image then we
1938f4a5b   Simon Glass   Introduce generic...
465
466
467
468
469
  	 * must relocate it. If it is embedded in the data section, then it
  	 * will be relocated with other data.
  	 */
  	if (gd->fdt_blob) {
  		gd->fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32);
a0ba279ac   Masahiro Yamada   generic_board: re...
470
471
  		gd->start_addr_sp -= gd->fdt_size;
  		gd->new_fdt = map_sysmem(gd->start_addr_sp, gd->fdt_size);
a733b06b6   Simon Glass   sandbox: Switch o...
472
473
  		debug("Reserving %lu Bytes for FDT at: %08lx
  ",
a0ba279ac   Masahiro Yamada   generic_board: re...
474
  		      gd->fdt_size, gd->start_addr_sp);
1938f4a5b   Simon Glass   Introduce generic...
475
  	}
e9acb9ea4   Siva Durga Prasad Paladugu   common: board: Do...
476
  #endif
1938f4a5b   Simon Glass   Introduce generic...
477
478
479
  
  	return 0;
  }
25e7dc6a6   Simon Glass   bootstage: Suppor...
480
481
482
483
484
485
486
487
488
489
490
491
492
493
  static int reserve_bootstage(void)
  {
  #ifdef CONFIG_BOOTSTAGE
  	int size = bootstage_get_size();
  
  	gd->start_addr_sp -= size;
  	gd->new_bootstage = map_sysmem(gd->start_addr_sp, size);
  	debug("Reserving %#x Bytes for bootstage at: %08lx
  ", size,
  	      gd->start_addr_sp);
  #endif
  
  	return 0;
  }
68145d4c7   Andreas Bießmann   common/board_f: f...
494
  int arch_reserve_stacks(void)
1938f4a5b   Simon Glass   Introduce generic...
495
  {
68145d4c7   Andreas Bießmann   common/board_f: f...
496
497
  	return 0;
  }
8cae8a68e   Simon Glass   Add spl load feature
498

68145d4c7   Andreas Bießmann   common/board_f: f...
499
500
501
  static int reserve_stacks(void)
  {
  	/* make stack pointer 16-byte aligned */
a0ba279ac   Masahiro Yamada   generic_board: re...
502
503
  	gd->start_addr_sp -= 16;
  	gd->start_addr_sp &= ~0xf;
1938f4a5b   Simon Glass   Introduce generic...
504
505
  
  	/*
4c509343a   Simon Glass   Fix comment nits ...
506
  	 * let the architecture-specific code tailor gd->start_addr_sp and
68145d4c7   Andreas Bießmann   common/board_f: f...
507
  	 * gd->irq_sp
1938f4a5b   Simon Glass   Introduce generic...
508
  	 */
68145d4c7   Andreas Bießmann   common/board_f: f...
509
  	return arch_reserve_stacks();
1938f4a5b   Simon Glass   Introduce generic...
510
511
512
513
  }
  
  static int display_new_sp(void)
  {
a0ba279ac   Masahiro Yamada   generic_board: re...
514
515
  	debug("New Stack Pointer is: %08lx
  ", gd->start_addr_sp);
1938f4a5b   Simon Glass   Introduce generic...
516
517
518
  
  	return 0;
  }
e2099d78c   Vladimir Zapolskiy   common: sh: add n...
519
520
  #if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
  	defined(CONFIG_SH)
e4fef6cfc   Simon Glass   Adjust board_f.c ...
521
522
523
524
525
526
527
  static int setup_board_part1(void)
  {
  	bd_t *bd = gd->bd;
  
  	/*
  	 * Save local variables to board info struct
  	 */
e4fef6cfc   Simon Glass   Adjust board_f.c ...
528
529
530
531
532
533
534
  	bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;	/* start of memory */
  	bd->bi_memsize = gd->ram_size;			/* size in bytes */
  
  #ifdef CONFIG_SYS_SRAM_BASE
  	bd->bi_sramstart = CONFIG_SYS_SRAM_BASE;	/* start of SRAM */
  	bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE;		/* size  of SRAM */
  #endif
502589777   Heiko Schocher   powerpc, 5xx: rem...
535
  #if defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
e4fef6cfc   Simon Glass   Adjust board_f.c ...
536
537
  	bd->bi_immr_base = CONFIG_SYS_IMMR;	/* base  of IMMR register     */
  #endif
064b55cfc   Heiko Schocher   powerpc, 5xxx, 51...
538
  #if defined(CONFIG_M68K)
e4fef6cfc   Simon Glass   Adjust board_f.c ...
539
540
541
542
543
  	bd->bi_mbar_base = CONFIG_SYS_MBAR;	/* base of internal registers */
  #endif
  #if defined(CONFIG_MPC83xx)
  	bd->bi_immrbar = CONFIG_SYS_IMMR;
  #endif
e4fef6cfc   Simon Glass   Adjust board_f.c ...
544
545
546
  
  	return 0;
  }
fb3db6357   Daniel Schwierzeck   common/board_f: e...
547
  #endif
e4fef6cfc   Simon Glass   Adjust board_f.c ...
548

fb3db6357   Daniel Schwierzeck   common/board_f: e...
549
  #if defined(CONFIG_PPC) || defined(CONFIG_M68K)
e4fef6cfc   Simon Glass   Adjust board_f.c ...
550
551
552
553
554
555
556
557
558
559
560
561
  static int setup_board_part2(void)
  {
  	bd_t *bd = gd->bd;
  
  	bd->bi_intfreq = gd->cpu_clk;	/* Internal Freq, in Hz */
  	bd->bi_busfreq = gd->bus_clk;	/* Bus Freq,      in Hz */
  #if defined(CONFIG_CPM2)
  	bd->bi_cpmfreq = gd->arch.cpm_clk;
  	bd->bi_brgfreq = gd->arch.brg_clk;
  	bd->bi_sccfreq = gd->arch.scc_clk;
  	bd->bi_vco = gd->arch.vco_out;
  #endif /* CONFIG_CPM2 */
1313db48e   Alison Wang   m68k: Add generic...
562
563
564
565
566
567
568
569
  #if defined(CONFIG_M68K) && defined(CONFIG_PCI)
  	bd->bi_pcifreq = gd->pci_clk;
  #endif
  #if defined(CONFIG_EXTRA_CLOCK)
  	bd->bi_inpfreq = gd->arch.inp_clk;	/* input Freq in Hz */
  	bd->bi_vcofreq = gd->arch.vco_clk;	/* vco Freq in Hz */
  	bd->bi_flbfreq = gd->arch.flb_clk;	/* flexbus Freq in Hz */
  #endif
e4fef6cfc   Simon Glass   Adjust board_f.c ...
570
571
572
573
  
  	return 0;
  }
  #endif
1938f4a5b   Simon Glass   Introduce generic...
574
575
576
577
578
579
580
581
582
  #ifdef CONFIG_POST
  static int init_post(void)
  {
  	post_bootmode_init();
  	post_run(NULL, POST_ROM | post_bootmode_get(0));
  
  	return 0;
  }
  #endif
1938f4a5b   Simon Glass   Introduce generic...
583
584
  static int reloc_fdt(void)
  {
e9acb9ea4   Siva Durga Prasad Paladugu   common: board: Do...
585
  #ifndef CONFIG_OF_EMBED
f05ad9ba4   Simon Glass   Add a way to skip...
586
587
  	if (gd->flags & GD_FLG_SKIP_RELOC)
  		return 0;
1938f4a5b   Simon Glass   Introduce generic...
588
589
590
591
  	if (gd->new_fdt) {
  		memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size);
  		gd->fdt_blob = gd->new_fdt;
  	}
e9acb9ea4   Siva Durga Prasad Paladugu   common: board: Do...
592
  #endif
1938f4a5b   Simon Glass   Introduce generic...
593
594
595
  
  	return 0;
  }
25e7dc6a6   Simon Glass   bootstage: Suppor...
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
  static int reloc_bootstage(void)
  {
  #ifdef CONFIG_BOOTSTAGE
  	if (gd->flags & GD_FLG_SKIP_RELOC)
  		return 0;
  	if (gd->new_bootstage) {
  		int size = bootstage_get_size();
  
  		debug("Copying bootstage from %p to %p, size %x
  ",
  		      gd->bootstage, gd->new_bootstage, size);
  		memcpy(gd->new_bootstage, gd->bootstage, size);
  		gd->bootstage = gd->new_bootstage;
  	}
  #endif
  
  	return 0;
  }
1938f4a5b   Simon Glass   Introduce generic...
614
615
  static int setup_reloc(void)
  {
f05ad9ba4   Simon Glass   Add a way to skip...
616
617
618
619
620
  	if (gd->flags & GD_FLG_SKIP_RELOC) {
  		debug("Skipping relocation due to flag
  ");
  		return 0;
  	}
d54d7eb96   Sonic Zhang   support blackfin ...
621
  #ifdef CONFIG_SYS_TEXT_BASE
53207bfd7   Lothar Waßmann   board_f: fix calc...
622
623
624
  #ifdef ARM
  	gd->reloc_off = gd->relocaddr - (unsigned long)__image_copy_start;
  #elif defined(CONFIG_M68K)
e310b93ec   angelo@sysam.it   m68k: add generic...
625
626
627
628
629
  	/*
  	 * On all ColdFire arch cpu, monitor code starts always
  	 * just after the default vector table location, so at 0x400
  	 */
  	gd->reloc_off = gd->relocaddr - (CONFIG_SYS_TEXT_BASE + 0x400);
53207bfd7   Lothar Waßmann   board_f: fix calc...
630
631
  #else
  	gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
e310b93ec   angelo@sysam.it   m68k: add generic...
632
  #endif
d54d7eb96   Sonic Zhang   support blackfin ...
633
  #endif
1938f4a5b   Simon Glass   Introduce generic...
634
635
636
637
  	memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
  
  	debug("Relocation Offset is: %08lx
  ", gd->reloc_off);
a733b06b6   Simon Glass   sandbox: Switch o...
638
639
  	debug("Relocating to %08lx, new gd at %08lx, sp at %08lx
  ",
a0ba279ac   Masahiro Yamada   generic_board: re...
640
641
  	      gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd),
  	      gd->start_addr_sp);
1938f4a5b   Simon Glass   Introduce generic...
642
643
644
  
  	return 0;
  }
2a792753d   mario.six@gdsys.cc   dm: Add callback ...
645
646
647
648
649
650
  #ifdef CONFIG_OF_BOARD_FIXUP
  static int fix_fdt(void)
  {
  	return board_fix_fdt((void *)gd->fdt_blob);
  }
  #endif
1938f4a5b   Simon Glass   Introduce generic...
651
  /* ARM calls relocate_code from its crt0.S */
530f27eab   Simon Glass   x86: board_f: Upd...
652
653
  #if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
  		!CONFIG_IS_ENABLED(X86_64)
1938f4a5b   Simon Glass   Introduce generic...
654
655
656
  
  static int jump_to_copy(void)
  {
f05ad9ba4   Simon Glass   Add a way to skip...
657
658
  	if (gd->flags & GD_FLG_SKIP_RELOC)
  		return 0;
48a338067   Simon Glass   x86: Adjust board...
659
660
661
662
663
664
665
666
  	/*
  	 * x86 is special, but in a nice way. It uses a trampoline which
  	 * enables the dcache if possible.
  	 *
  	 * For now, other archs use relocate_code(), which is implemented
  	 * similarly for all archs. When we do generic relocation, hopefully
  	 * we can make all archs enable the dcache prior to relocation.
  	 */
3fb801636   Alexey Brodkin   arc: clean-up ini...
667
  #if defined(CONFIG_X86) || defined(CONFIG_ARC)
48a338067   Simon Glass   x86: Adjust board...
668
669
670
671
672
673
  	/*
  	 * SDRAM and console are now initialised. The final stack can now
  	 * be setup in SDRAM. Code execution will continue in Flash, but
  	 * with the stack in SDRAM and Global Data in temporary memory
  	 * (CPU cache)
  	 */
f0c7d9c74   Simon Glass   x86: Switch to us...
674
  	arch_setup_gd(gd->new_gd);
48a338067   Simon Glass   x86: Adjust board...
675
676
  	board_init_f_r_trampoline(gd->start_addr_sp);
  #else
a0ba279ac   Masahiro Yamada   generic_board: re...
677
  	relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr);
48a338067   Simon Glass   x86: Adjust board...
678
  #endif
1938f4a5b   Simon Glass   Introduce generic...
679
680
681
682
683
684
  
  	return 0;
  }
  #endif
  
  /* Record the board_init_f() bootstage (after arch_cpu_init()) */
b383d6c05   Simon Glass   bootstage: Conver...
685
  static int initf_bootstage(void)
1938f4a5b   Simon Glass   Introduce generic...
686
  {
baa7d345f   Simon Glass   board_f: Use IS_E...
687
688
  	bool from_spl = IS_ENABLED(CONFIG_SPL_BOOTSTAGE) &&
  			IS_ENABLED(CONFIG_BOOTSTAGE_STASH);
b383d6c05   Simon Glass   bootstage: Conver...
689
  	int ret;
824bb1b45   Simon Glass   bootstage: Suppor...
690
  	ret = bootstage_init(!from_spl);
b383d6c05   Simon Glass   bootstage: Conver...
691
692
  	if (ret)
  		return ret;
824bb1b45   Simon Glass   bootstage: Suppor...
693
694
695
696
697
698
699
700
701
702
703
  	if (from_spl) {
  		const void *stash = map_sysmem(CONFIG_BOOTSTAGE_STASH_ADDR,
  					       CONFIG_BOOTSTAGE_STASH_SIZE);
  
  		ret = bootstage_unstash(stash, CONFIG_BOOTSTAGE_STASH_SIZE);
  		if (ret && ret != -ENOENT) {
  			debug("Failed to unstash bootstage: err=%d
  ", ret);
  			return ret;
  		}
  	}
b383d6c05   Simon Glass   bootstage: Conver...
704

1938f4a5b   Simon Glass   Introduce generic...
705
706
707
708
  	bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
  
  	return 0;
  }
9854a8748   Simon Glass   console: Add a co...
709
710
  static int initf_console_record(void)
  {
f1896c45c   Andy Yan   spl: make SPL and...
711
  #if defined(CONFIG_CONSOLE_RECORD) && CONFIG_VAL(SYS_MALLOC_F_LEN)
9854a8748   Simon Glass   console: Add a co...
712
713
714
715
716
  	return console_record_init();
  #else
  	return 0;
  #endif
  }
ab7cd6279   Simon Glass   dm: Support drive...
717
718
  static int initf_dm(void)
  {
f1896c45c   Andy Yan   spl: make SPL and...
719
  #if defined(CONFIG_DM) && CONFIG_VAL(SYS_MALLOC_F_LEN)
ab7cd6279   Simon Glass   dm: Support drive...
720
  	int ret;
63c5bf48d   Simon Glass   bootstage: Record...
721
  	bootstage_start(BOOTSTATE_ID_ACCUM_DM_F, "dm_f");
ab7cd6279   Simon Glass   dm: Support drive...
722
  	ret = dm_init_and_scan(true);
63c5bf48d   Simon Glass   bootstage: Record...
723
  	bootstage_accum(BOOTSTATE_ID_ACCUM_DM_F);
ab7cd6279   Simon Glass   dm: Support drive...
724
725
726
  	if (ret)
  		return ret;
  #endif
1057e6cfe   Simon Glass   timer: Set up the...
727
728
729
730
731
  #ifdef CONFIG_TIMER_EARLY
  	ret = dm_timer_init();
  	if (ret)
  		return ret;
  #endif
ab7cd6279   Simon Glass   dm: Support drive...
732
733
734
  
  	return 0;
  }
146251f87   Simon Glass   Allow architectur...
735
736
737
738
739
  /* Architecture-specific memory reservation */
  __weak int reserve_arch(void)
  {
  	return 0;
  }
d4c671cc2   Simon Glass   dm: Add a new CPU...
740
741
742
743
  __weak int arch_cpu_init_dm(void)
  {
  	return 0;
  }
4acff4524   Simon Glass   board_f/r: Use st...
744
  static const init_fnc_t init_sequence_f[] = {
1938f4a5b   Simon Glass   Introduce generic...
745
  	setup_mon_len,
b45122fdf   Simon Glass   fdt: sandbox: Mov...
746
  #ifdef CONFIG_OF_CONTROL
0879361fd   Simon Glass   fdt: Rename setup...
747
  	fdtdec_setup,
b45122fdf   Simon Glass   fdt: sandbox: Mov...
748
  #endif
d210718d9   Kevin Hilman   common/board_f.c:...
749
  #ifdef CONFIG_TRACE
71c52dba2   Simon Glass   Add trace support...
750
  	trace_early_init,
d210718d9   Kevin Hilman   common/board_f.c:...
751
  #endif
768e0f52f   Simon Glass   Move early malloc...
752
  	initf_malloc,
af1bc0cf4   Simon Glass   log: Plumb loggin...
753
  	log_init,
5ac44a554   Simon Glass   bootstage: Init a...
754
  	initf_bootstage,	/* uses its own timer, so does not need DM */
9854a8748   Simon Glass   console: Add a co...
755
  	initf_console_record,
671549e5b   Simon Glass   board_f: x86: Ren...
756
757
  #if defined(CONFIG_HAVE_FSP)
  	arch_fsp_init,
a52a068eb   Bin Meng   x86: fsp: Delay x...
758
  #endif
1938f4a5b   Simon Glass   Introduce generic...
759
  	arch_cpu_init,		/* basic arch cpu dependent setup */
8ebf50692   Paul Burton   board_f: Add a ma...
760
  	mach_cpu_init,		/* SoC/machine dependent CPU setup */
3ea0953d3   Simon Glass   dm: Move pre-relo...
761
  	initf_dm,
d4c671cc2   Simon Glass   dm: Add a new CPU...
762
  	arch_cpu_init_dm,
1938f4a5b   Simon Glass   Introduce generic...
763
764
765
  #if defined(CONFIG_BOARD_EARLY_INIT_F)
  	board_early_init_f,
  #endif
727e94a4a   Simon Glass   powerpc: freescal...
766
  #if defined(CONFIG_PPC) || defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K)
c252c0685   Simon Glass   board_f: powerpc:...
767
  	/* get CPU and bus clocks according to the environment variable */
e4fef6cfc   Simon Glass   Adjust board_f.c ...
768
  	get_clocks,		/* get CPU and bus clocks (etc.) */
1793e7822   Simon Glass   board_f: powerpc:...
769
  #endif
0ce452872   Angelo Dureghello   board_f: skip tim...
770
  #if !defined(CONFIG_M68K)
1938f4a5b   Simon Glass   Introduce generic...
771
  	timer_init,		/* initialize timer */
0ce452872   Angelo Dureghello   board_f: skip tim...
772
  #endif
e4fef6cfc   Simon Glass   Adjust board_f.c ...
773
774
775
  #if defined(CONFIG_BOARD_POSTCLK_INIT)
  	board_postclk_init,
  #endif
1938f4a5b   Simon Glass   Introduce generic...
776
777
  	env_init,		/* initialize environment */
  	init_baud_rate,		/* initialze baudrate settings */
b8296e64d   Ji Luo   MA-12973 [AUTO] S...
778
  #ifndef CONFIG_ANDROID_AUTO_SUPPORT
1938f4a5b   Simon Glass   Introduce generic...
779
  	serial_init,		/* serial communications setup */
b8296e64d   Ji Luo   MA-12973 [AUTO] S...
780
  #endif
1938f4a5b   Simon Glass   Introduce generic...
781
782
783
  	console_init_f,		/* stage 1 init of console */
  	display_options,	/* say that we are here */
  	display_text_info,	/* show debugging info if required */
b9153fe30   Angelo Dureghello   common/board_f.c:...
784
  #if defined(CONFIG_PPC) || defined(CONFIG_SH) || defined(CONFIG_X86)
e4fef6cfc   Simon Glass   Adjust board_f.c ...
785
786
  	checkcpu,
  #endif
cc664000c   Simon Glass   Drop the static i...
787
  #if defined(CONFIG_DISPLAY_CPUINFO)
1938f4a5b   Simon Glass   Introduce generic...
788
  	print_cpuinfo,		/* display cpu info (and speed) */
cc664000c   Simon Glass   Drop the static i...
789
  #endif
af9e6ad4a   Cooper Jr., Franklin   board_f: Add new ...
790
791
792
  #if defined(CONFIG_DTB_RESELECT)
  	embedded_dtb_select,
  #endif
1938f4a5b   Simon Glass   Introduce generic...
793
  #if defined(CONFIG_DISPLAY_BOARDINFO)
0365ffcc0   Masahiro Yamada   generic-board: sh...
794
  	show_board_info,
1938f4a5b   Simon Glass   Introduce generic...
795
  #endif
e4fef6cfc   Simon Glass   Adjust board_f.c ...
796
797
798
799
800
  	INIT_FUNC_WATCHDOG_INIT
  #if defined(CONFIG_MISC_INIT_F)
  	misc_init_f,
  #endif
  	INIT_FUNC_WATCHDOG_RESET
69153988a   Simon Glass   i2c: Finish dropp...
801
  #if defined(CONFIG_SYS_I2C)
e4fef6cfc   Simon Glass   Adjust board_f.c ...
802
803
  	init_func_i2c,
  #endif
1fab98fb9   Rajesh Bhagat   common: board_f: ...
804
805
806
  #if defined(CONFIG_VID) && !defined(CONFIG_SPL)
  	init_func_vid,
  #endif
e4fef6cfc   Simon Glass   Adjust board_f.c ...
807
808
809
  #if defined(CONFIG_HARD_SPI)
  	init_func_spi,
  #endif
1938f4a5b   Simon Glass   Introduce generic...
810
  	announce_dram_init,
1938f4a5b   Simon Glass   Introduce generic...
811
  	dram_init,		/* configure available RAM banks */
e4fef6cfc   Simon Glass   Adjust board_f.c ...
812
813
814
815
816
817
818
819
  #ifdef CONFIG_POST
  	post_init_f,
  #endif
  	INIT_FUNC_WATCHDOG_RESET
  #if defined(CONFIG_SYS_DRAM_TEST)
  	testdram,
  #endif /* CONFIG_SYS_DRAM_TEST */
  	INIT_FUNC_WATCHDOG_RESET
1938f4a5b   Simon Glass   Introduce generic...
820
821
822
  #ifdef CONFIG_POST
  	init_post,
  #endif
e4fef6cfc   Simon Glass   Adjust board_f.c ...
823
  	INIT_FUNC_WATCHDOG_RESET
1938f4a5b   Simon Glass   Introduce generic...
824
825
826
827
828
829
830
831
832
833
834
835
836
  	/*
  	 * Now that we have DRAM mapped and working, we can
  	 * relocate the code and continue running from DRAM.
  	 *
  	 * Reserve memory at end of RAM for (top down in that order):
  	 *  - area that won't get touched by U-Boot and Linux (optional)
  	 *  - kernel log buffer
  	 *  - protected RAM
  	 *  - LCD framebuffer
  	 *  - monitor code
  	 *  - board info struct
  	 */
  	setup_dest_addr,
1938f4a5b   Simon Glass   Introduce generic...
837
838
839
840
  #ifdef CONFIG_PRAM
  	reserve_pram,
  #endif
  	reserve_round_4k,
80d4bcd3e   Simon Glass   board_f: Move the...
841
  #ifdef CONFIG_ARM
1938f4a5b   Simon Glass   Introduce generic...
842
843
  	reserve_mmu,
  #endif
5a5419451   Simon Glass   dm: common: Add m...
844
  	reserve_video,
8703ef3fd   Simon Glass   common: Move LCD ...
845
  	reserve_trace,
1938f4a5b   Simon Glass   Introduce generic...
846
847
848
849
850
851
  	reserve_uboot,
  	reserve_malloc,
  	reserve_board,
  	setup_machine,
  	reserve_global_data,
  	reserve_fdt,
25e7dc6a6   Simon Glass   bootstage: Suppor...
852
  	reserve_bootstage,
146251f87   Simon Glass   Allow architectur...
853
  	reserve_arch,
1938f4a5b   Simon Glass   Introduce generic...
854
  	reserve_stacks,
76b00aca4   Simon Glass   board_f: Drop set...
855
  	dram_init_banksize,
1938f4a5b   Simon Glass   Introduce generic...
856
  	show_dram_config,
e2099d78c   Vladimir Zapolskiy   common: sh: add n...
857
858
  #if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
  	defined(CONFIG_SH)
e4fef6cfc   Simon Glass   Adjust board_f.c ...
859
  	setup_board_part1,
fb3db6357   Daniel Schwierzeck   common/board_f: e...
860
861
  #endif
  #if defined(CONFIG_PPC) || defined(CONFIG_M68K)
e4fef6cfc   Simon Glass   Adjust board_f.c ...
862
863
864
  	INIT_FUNC_WATCHDOG_RESET
  	setup_board_part2,
  #endif
1938f4a5b   Simon Glass   Introduce generic...
865
  	display_new_sp,
2a792753d   mario.six@gdsys.cc   dm: Add callback ...
866
867
868
  #ifdef CONFIG_OF_BOARD_FIXUP
  	fix_fdt,
  #endif
e4fef6cfc   Simon Glass   Adjust board_f.c ...
869
  	INIT_FUNC_WATCHDOG_RESET
1938f4a5b   Simon Glass   Introduce generic...
870
  	reloc_fdt,
25e7dc6a6   Simon Glass   bootstage: Suppor...
871
  	reloc_bootstage,
1938f4a5b   Simon Glass   Introduce generic...
872
  	setup_reloc,
3fb801636   Alexey Brodkin   arc: clean-up ini...
873
  #if defined(CONFIG_X86) || defined(CONFIG_ARC)
313aef37a   Simon Glass   x86: board_f: Adj...
874
  	copy_uboot_to_ram,
313aef37a   Simon Glass   x86: board_f: Adj...
875
  	do_elf_reloc_fixups,
6bda55a38   Simon Glass   x86: Do relocatio...
876
  	clear_bss,
313aef37a   Simon Glass   x86: board_f: Adj...
877
  #endif
de5e5cea0   Chris Zankel   xtensa: add suppo...
878
879
880
  #if defined(CONFIG_XTENSA)
  	clear_bss,
  #endif
530f27eab   Simon Glass   x86: board_f: Upd...
881
882
  #if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
  		!CONFIG_IS_ENABLED(X86_64)
1938f4a5b   Simon Glass   Introduce generic...
883
884
885
886
887
888
889
  	jump_to_copy,
  #endif
  	NULL,
  };
  
  void board_init_f(ulong boot_flags)
  {
1938f4a5b   Simon Glass   Introduce generic...
890
  	gd->flags = boot_flags;
9aed5a277   Alexey Brodkin   board_f: explicit...
891
  	gd->have_console = 0;
1938f4a5b   Simon Glass   Introduce generic...
892
893
894
  
  	if (initcall_run_list(init_sequence_f))
  		hang();
9b2174984   Ben Stoltz   efi: Avoid using ...
895
  #if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
530f27eab   Simon Glass   x86: board_f: Upd...
896
  		!defined(CONFIG_EFI_APP) && !CONFIG_IS_ENABLED(X86_64)
1938f4a5b   Simon Glass   Introduce generic...
897
898
899
900
  	/* NOTREACHED - jump_to_copy() does not return */
  	hang();
  #endif
  }
3fb801636   Alexey Brodkin   arc: clean-up ini...
901
  #if defined(CONFIG_X86) || defined(CONFIG_ARC)
48a338067   Simon Glass   x86: Adjust board...
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
  /*
   * For now this code is only used on x86.
   *
   * init_sequence_f_r is the list of init functions which are run when
   * U-Boot is executing from Flash with a semi-limited 'C' environment.
   * The following limitations must be considered when implementing an
   * '_f_r' function:
   *  - 'static' variables are read-only
   *  - Global Data (gd->xxx) is read/write
   *
   * The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if
   * supported).  It _should_, if possible, copy global data to RAM and
   * initialise the CPU caches (to speed up the relocation process)
   *
   * NOTE: At present only x86 uses this route, but it is intended that
   * all archs will move to this when generic relocation is implemented.
   */
4acff4524   Simon Glass   board_f/r: Use st...
919
  static const init_fnc_t init_sequence_f_r[] = {
530f27eab   Simon Glass   x86: board_f: Upd...
920
  #if !CONFIG_IS_ENABLED(X86_64)
48a338067   Simon Glass   x86: Adjust board...
921
  	init_cache_f_r,
530f27eab   Simon Glass   x86: board_f: Upd...
922
  #endif
48a338067   Simon Glass   x86: Adjust board...
923
924
925
926
927
928
929
930
931
932
  
  	NULL,
  };
  
  void board_init_f_r(void)
  {
  	if (initcall_run_list(init_sequence_f_r))
  		hang();
  
  	/*
e4d6ab0c2   Simon Glass   x86: Allow use of...
933
934
935
  	 * The pre-relocation drivers may be using memory that has now gone
  	 * away. Mark serial as unavailable - this will fall back to the debug
  	 * UART if available.
af1bc0cf4   Simon Glass   log: Plumb loggin...
936
937
  	 *
  	 * Do the same with log drivers since the memory may not be available.
e4d6ab0c2   Simon Glass   x86: Allow use of...
938
  	 */
af1bc0cf4   Simon Glass   log: Plumb loggin...
939
  	gd->flags &= ~(GD_FLG_SERIAL_READY | GD_FLG_LOG_READY);
5ee94b4f4   Simon Glass   board_f: Drop the...
940
941
942
  #ifdef CONFIG_TIMER
  	gd->timer = NULL;
  #endif
e4d6ab0c2   Simon Glass   x86: Allow use of...
943
944
  
  	/*
48a338067   Simon Glass   x86: Adjust board...
945
946
947
948
  	 * U-Boot has been copied into SDRAM, the BSS has been cleared etc.
  	 * Transfer execution from Flash to RAM by calculating the address
  	 * of the in-RAM copy of board_init_r() and calling it
  	 */
7bf9f20d0   Alexey Brodkin   common/board_f: i...
949
  	(board_init_r + gd->reloc_off)((gd_t *)gd, gd->relocaddr);
48a338067   Simon Glass   x86: Adjust board...
950
951
952
953
  
  	/* NOTREACHED - board_init_r() does not return */
  	hang();
  }
5bcd19aa2   Alexey Brodkin   common/board_f: m...
954
  #endif /* CONFIG_X86 */