Blame view

common/board_f.c 24.4 KB
83d290c56   Tom Rini   SPDX: Convert all...
1
  // SPDX-License-Identifier: GPL-2.0+
1938f4a5b   Simon Glass   Introduce generic...
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>
1938f4a5b   Simon Glass   Introduce generic...
10
11
12
   */
  
  #include <common.h>
f0293d33b   Simon Glass   bloblist: Locate ...
13
  #include <bloblist.h>
24b852a7a   Simon Glass   Move console defi...
14
  #include <console.h>
5d6c61ac4   Mario Six   board_f: Use stat...
15
  #include <cpu.h>
ab7cd6279   Simon Glass   dm: Support drive...
16
  #include <dm.h>
138181a55   Mario Six   common: board_f: ...
17
  #include <environment.h>
1938f4a5b   Simon Glass   Introduce generic...
18
  #include <fdtdec.h>
f828bf25f   Simon Glass   sandbox: Add CONF...
19
  #include <fs.h>
e4fef6cfc   Simon Glass   Adjust board_f.c ...
20
  #include <i2c.h>
1938f4a5b   Simon Glass   Introduce generic...
21
  #include <initcall.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>
b0edea3c2   Simon Glass   spl: Add support ...
27
28
29
  #ifdef CONFIG_SPL
  #include <spl.h>
  #endif
c5d4001a1   Jeroen Hofstee   common: board_f: ...
30
  #include <status_led.h>
23471aed5   Mario Six   board_f: Add rese...
31
  #include <sysreset.h>
1057e6cfe   Simon Glass   timer: Set up the...
32
  #include <timer.h>
71c52dba2   Simon Glass   Add trace support...
33
  #include <trace.h>
5a5419451   Simon Glass   dm: common: Add m...
34
  #include <video.h>
e4fef6cfc   Simon Glass   Adjust board_f.c ...
35
  #include <watchdog.h>
b885d02e2   Simon Glass   arm: Remove inclu...
36
37
38
  #ifdef CONFIG_MACH_TYPE
  #include <asm/mach-types.h>
  #endif
1fbf97dc4   Simon Glass   board_f: powerpc:...
39
40
41
  #if defined(CONFIG_MP) && defined(CONFIG_PPC)
  #include <asm/mp.h>
  #endif
1938f4a5b   Simon Glass   Introduce generic...
42
43
  #include <asm/io.h>
  #include <asm/sections.h>
ab7cd6279   Simon Glass   dm: Support drive...
44
  #include <dm/root.h>
056285fd4   Simon Glass   board_f: Move err...
45
  #include <linux/errno.h>
1938f4a5b   Simon Glass   Introduce generic...
46
47
48
49
50
51
52
53
54
  
  /*
   * 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: ...
55
  DECLARE_GLOBAL_DATA_PTR = (gd_t *)(CONFIG_SYS_INIT_GD_ADDR);
1938f4a5b   Simon Glass   Introduce generic...
56
57
58
59
60
  #else
  DECLARE_GLOBAL_DATA_PTR;
  #endif
  
  /*
4c509343a   Simon Glass   Fix comment nits ...
61
   * TODO(sjg@chromium.org): IMO this code should be
1938f4a5b   Simon Glass   Introduce generic...
62
63
64
65
66
67
68
69
70
   * 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: ...
71
72
73
74
75
76
77
78
79
  __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...
80
81
82
83
84
85
86
87
88
89
90
  
  /*
   * 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 ...
91
  #if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
e4fef6cfc   Simon Glass   Adjust board_f.c ...
92
93
  static int init_func_watchdog_init(void)
  {
ea3310e8a   Tom Rini   Blackfin: Remove
94
95
  # if defined(CONFIG_HW_WATCHDOG) && \
  	(defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \
1473f6ac8   Prasanthi Chellakumar   arm: at91: wdt: C...
96
  	defined(CONFIG_SH) || \
46d7a3b3d   Anatolij Gustschin   board_f: init des...
97
  	defined(CONFIG_DESIGNWARE_WATCHDOG) || \
14a380a8f   Stefan Roese   common/board_f.c:...
98
  	defined(CONFIG_IMX_WATCHDOG))
d54d7eb96   Sonic Zhang   support blackfin ...
99
  	hw_watchdog_init();
e4fef6cfc   Simon Glass   Adjust board_f.c ...
100
101
  	puts("       Watchdog enabled
  ");
ba169d981   Anatolij Gustschin   board_f: prevent ...
102
  # endif
e4fef6cfc   Simon Glass   Adjust board_f.c ...
103
104
105
106
107
108
109
110
111
112
113
114
  	WATCHDOG_RESET();
  
  	return 0;
  }
  
  int init_func_watchdog_reset(void)
  {
  	WATCHDOG_RESET();
  
  	return 0;
  }
  #endif /* CONFIG_WATCHDOG */
dd2a6cd0f   Jeroen Hofstee   common: board: us...
115
  __weak void board_add_ram_info(int use_default)
e4fef6cfc   Simon Glass   Adjust board_f.c ...
116
117
118
  {
  	/* please define platform specific board_add_ram_info() */
  }
1938f4a5b   Simon Glass   Introduce generic...
119
120
  static int init_baud_rate(void)
  {
bfebc8c96   Simon Glass   env: Rename geten...
121
  	gd->baudrate = env_get_ulong("baudrate", 10, CONFIG_BAUDRATE);
1938f4a5b   Simon Glass   Introduce generic...
122
123
124
125
126
  	return 0;
  }
  
  static int display_text_info(void)
  {
9b2174984   Ben Stoltz   efi: Avoid using ...
127
  #if !defined(CONFIG_SANDBOX) && !defined(CONFIG_EFI_APP)
9fdee7d73   Daniel Schwierzeck   common/board_f: f...
128
  	ulong bss_start, bss_end, text_base;
1938f4a5b   Simon Glass   Introduce generic...
129

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

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

1938f4a5b   Simon Glass   Introduce generic...
144
145
  	return 0;
  }
23471aed5   Mario Six   board_f: Add rese...
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
  #ifdef CONFIG_SYSRESET
  static int print_resetinfo(void)
  {
  	struct udevice *dev;
  	char status[256];
  	int ret;
  
  	ret = uclass_first_device_err(UCLASS_SYSRESET, &dev);
  	if (ret) {
  		debug("%s: No sysreset device found (error: %d)
  ",
  		      __func__, ret);
  		/* Not all boards have sysreset drivers available during early
  		 * boot, so don't fail if one can't be found.
  		 */
  		return 0;
  	}
  
  	if (!sysreset_get_status(dev, status, sizeof(status)))
  		printf("%s", status);
  
  	return 0;
  }
  #endif
5d6c61ac4   Mario Six   board_f: Use stat...
170
171
172
173
174
175
  #if defined(CONFIG_DISPLAY_CPUINFO) && CONFIG_IS_ENABLED(CPU)
  static int print_cpuinfo(void)
  {
  	struct udevice *dev;
  	char desc[512];
  	int ret;
30b9f6f88   Ye Li   MLK-21828-2 commo...
176
177
178
179
180
181
  	dev = cpu_get_current_dev();
  	if (!dev) {
  		debug("%s: Could not get CPU device
  ",
  		      __func__);
  		return -ENODEV;
5d6c61ac4   Mario Six   board_f: Use stat...
182
183
184
185
186
187
188
189
190
  	}
  
  	ret = cpu_get_desc(dev, desc, sizeof(desc));
  	if (ret) {
  		debug("%s: Could not get CPU description (err = %d)
  ",
  		      dev->name, ret);
  		return ret;
  	}
ecfe66330   Bin Meng   dm: cpu: Fix prin...
191
192
  	printf("CPU:   %s
  ", desc);
5d6c61ac4   Mario Six   board_f: Use stat...
193
194
195
196
  
  	return 0;
  }
  #endif
1938f4a5b   Simon Glass   Introduce generic...
197
198
199
200
201
202
203
204
  static int announce_dram_init(void)
  {
  	puts("DRAM:  ");
  	return 0;
  }
  
  static int show_dram_config(void)
  {
fa39ffe5d   York Sun   common/board_f: F...
205
  	unsigned long long size;
1938f4a5b   Simon Glass   Introduce generic...
206
207
208
209
210
211
212
213
214
  
  #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 >...
215
216
  		debug("Bank #%d: %llx ", i,
  		      (unsigned long long)(gd->bd->bi_dram[i].start));
1938f4a5b   Simon Glass   Introduce generic...
217
218
219
220
221
222
223
224
225
226
  #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 ...
227
228
229
230
  	print_size(size, "");
  	board_add_ram_info(0);
  	putc('
  ');
1938f4a5b   Simon Glass   Introduce generic...
231
232
233
  
  	return 0;
  }
76b00aca4   Simon Glass   board_f: Drop set...
234
  __weak int dram_init_banksize(void)
1938f4a5b   Simon Glass   Introduce generic...
235
236
237
238
239
  {
  #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...
240
241
  
  	return 0;
1938f4a5b   Simon Glass   Introduce generic...
242
  }
69153988a   Simon Glass   i2c: Finish dropp...
243
  #if defined(CONFIG_SYS_I2C)
e4fef6cfc   Simon Glass   Adjust board_f.c ...
244
245
246
  static int init_func_i2c(void)
  {
  	puts("I2C:   ");
815a76f2e   trem   i2c: fix init on ...
247
248
249
  #ifdef CONFIG_SYS_I2C
  	i2c_init_all();
  #else
e4fef6cfc   Simon Glass   Adjust board_f.c ...
250
  	i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
815a76f2e   trem   i2c: fix init on ...
251
  #endif
e4fef6cfc   Simon Glass   Adjust board_f.c ...
252
253
254
255
256
  	puts("ready
  ");
  	return 0;
  }
  #endif
1fab98fb9   Rajesh Bhagat   common: board_f: ...
257
258
259
260
261
262
  #if defined(CONFIG_VID)
  __weak int init_func_vid(void)
  {
  	return 0;
  }
  #endif
1938f4a5b   Simon Glass   Introduce generic...
263
264
  static int setup_mon_len(void)
  {
e945f6dc2   Michal Simek   microblaze: Move ...
265
  #if defined(__ARM__) || defined(__MICROBLAZE__)
b60eff31f   Albert ARIBAUD   arm: remove unnee...
266
  	gd->mon_len = (ulong)&__bss_end - (ulong)_start;
9b2174984   Ben Stoltz   efi: Avoid using ...
267
  #elif defined(CONFIG_SANDBOX) || defined(CONFIG_EFI_APP)
a733b06b6   Simon Glass   sandbox: Switch o...
268
  	gd->mon_len = (ulong)&_end - (ulong)_init;
ea3310e8a   Tom Rini   Blackfin: Remove
269
  #elif defined(CONFIG_NIOS2) || defined(CONFIG_XTENSA)
d54d7eb96   Sonic Zhang   support blackfin ...
270
  	gd->mon_len = CONFIG_SYS_MONITOR_LEN;
068feb9b8   Rick Chen   riscv: Modify gen...
271
  #elif defined(CONFIG_NDS32) || defined(CONFIG_SH) || defined(CONFIG_RISCV)
2e88bb28d   Kun-Hua Huang   NDS32: Generic Bo...
272
  	gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start);
b0b359536   Simon Glass   board_f: Don't re...
273
  #elif defined(CONFIG_SYS_MONITOR_BASE)
e4fef6cfc   Simon Glass   Adjust board_f.c ...
274
275
  	/* 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...
276
  #endif
1938f4a5b   Simon Glass   Introduce generic...
277
278
  	return 0;
  }
b0edea3c2   Simon Glass   spl: Add support ...
279
280
281
282
283
284
285
286
287
288
289
  static int setup_spl_handoff(void)
  {
  #if CONFIG_IS_ENABLED(HANDOFF)
  	gd->spl_handoff = bloblist_find(BLOBLISTT_SPL_HANDOFF,
  					sizeof(struct spl_handoff));
  	debug("Found SPL hand-off info %p
  ", gd->spl_handoff);
  #endif
  
  	return 0;
  }
1938f4a5b   Simon Glass   Introduce generic...
290
291
292
293
  __weak int arch_cpu_init(void)
  {
  	return 0;
  }
8ebf50692   Paul Burton   board_f: Add a ma...
294
295
296
297
  __weak int mach_cpu_init(void)
  {
  	return 0;
  }
1938f4a5b   Simon Glass   Introduce generic...
298
299
300
  /* Get the top of usable RAM */
  __weak ulong board_get_usable_ram_top(ulong total_size)
  {
1e4d11a58   Stephen Warren   common: board: su...
301
302
  #ifdef CONFIG_SYS_SDRAM_BASE
  	/*
4c509343a   Simon Glass   Fix comment nits ...
303
  	 * Detect whether we have so much RAM that it goes past the end of our
1e4d11a58   Stephen Warren   common: board: su...
304
305
306
307
308
309
310
311
312
  	 * 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...
313
314
315
316
317
318
319
320
321
322
323
324
  	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...
325
  #if defined(CONFIG_SYS_MEM_TOP_HIDE)
1938f4a5b   Simon Glass   Introduce generic...
326
327
328
329
  	/*
  	 * 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...
330
331
332
333
334
  	 * 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...
335
  	 */
36cc0de0b   York Sun   armv8: layerscape...
336
337
  	gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
  #endif
1938f4a5b   Simon Glass   Introduce generic...
338
  #ifdef CONFIG_SYS_SDRAM_BASE
1473b12ad   Siva Durga Prasad Paladugu   lib: fdtdec: Upda...
339
  	gd->ram_base = CONFIG_SYS_SDRAM_BASE;
1938f4a5b   Simon Glass   Introduce generic...
340
  #endif
1473b12ad   Siva Durga Prasad Paladugu   lib: fdtdec: Upda...
341
  	gd->ram_top = gd->ram_base + get_effective_memsize();
1938f4a5b   Simon Glass   Introduce generic...
342
  	gd->ram_top = board_get_usable_ram_top(gd->mon_len);
a0ba279ac   Masahiro Yamada   generic_board: re...
343
  	gd->relocaddr = gd->ram_top;
1938f4a5b   Simon Glass   Introduce generic...
344
345
  	debug("Ram top: %08lX
  ", (ulong)gd->ram_top);
ec3b48201   Gabriel Huau   common: fix inclu...
346
  #if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
e4fef6cfc   Simon Glass   Adjust board_f.c ...
347
348
349
350
  	/*
  	 * 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...
351
352
353
354
  	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 ...
355
356
  	}
  #endif
1938f4a5b   Simon Glass   Introduce generic...
357
358
  	return 0;
  }
1938f4a5b   Simon Glass   Introduce generic...
359
360
361
362
363
  #ifdef CONFIG_PRAM
  /* reserve protected RAM */
  static int reserve_pram(void)
  {
  	ulong reg;
bfebc8c96   Simon Glass   env: Rename geten...
364
  	reg = env_get_ulong("pram", 10, CONFIG_PRAM);
a0ba279ac   Masahiro Yamada   generic_board: re...
365
  	gd->relocaddr -= (reg << 10);		/* size is in kB */
1938f4a5b   Simon Glass   Introduce generic...
366
367
  	debug("Reserving %ldk for protected RAM at %08lx
  ", reg,
a0ba279ac   Masahiro Yamada   generic_board: re...
368
  	      gd->relocaddr);
1938f4a5b   Simon Glass   Introduce generic...
369
370
371
372
373
374
375
  	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...
376
  	gd->relocaddr &= ~(4096 - 1);
1938f4a5b   Simon Glass   Introduce generic...
377
378
  	return 0;
  }
80d4bcd3e   Simon Glass   board_f: Move the...
379
  #ifdef CONFIG_ARM
60873f736   Siva Durga Prasad Paladugu   common: board_f: ...
380
  __weak int reserve_mmu(void)
1938f4a5b   Simon Glass   Introduce generic...
381
  {
80d4bcd3e   Simon Glass   board_f: Move the...
382
  #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
1938f4a5b   Simon Glass   Introduce generic...
383
  	/* reserve TLB table */
cce6be7f0   David Feng   arm64: generic bo...
384
  	gd->arch.tlb_size = PGTABLE_SIZE;
a0ba279ac   Masahiro Yamada   generic_board: re...
385
  	gd->relocaddr -= gd->arch.tlb_size;
1938f4a5b   Simon Glass   Introduce generic...
386
387
  
  	/* round down to next 64 kB limit */
a0ba279ac   Masahiro Yamada   generic_board: re...
388
  	gd->relocaddr &= ~(0x10000 - 1);
1938f4a5b   Simon Glass   Introduce generic...
389

a0ba279ac   Masahiro Yamada   generic_board: re...
390
  	gd->arch.tlb_addr = gd->relocaddr;
1938f4a5b   Simon Glass   Introduce generic...
391
392
393
  	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...
394
395
396
397
398
399
400
401
  
  #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...
402
  #endif
50e93b956   York Sun   armv8: Add tlb_al...
403

1938f4a5b   Simon Glass   Introduce generic...
404
405
406
  	return 0;
  }
  #endif
5a5419451   Simon Glass   dm: common: Add m...
407
408
  static int reserve_video(void)
  {
0f079eb51   Simon Glass   board_f: Put vide...
409
  #ifdef CONFIG_DM_VIDEO
5a5419451   Simon Glass   dm: common: Add m...
410
411
412
413
414
415
416
417
  	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...
418
  #elif defined(CONFIG_LCD)
5a5419451   Simon Glass   dm: common: Add m...
419
  #  ifdef CONFIG_FB_ADDR
1938f4a5b   Simon Glass   Introduce generic...
420
  	gd->fb_base = CONFIG_FB_ADDR;
5a5419451   Simon Glass   dm: common: Add m...
421
  #  else
1938f4a5b   Simon Glass   Introduce generic...
422
  	/* reserve memory for LCD display (always full pages) */
a0ba279ac   Masahiro Yamada   generic_board: re...
423
424
  	gd->relocaddr = lcd_setmem(gd->relocaddr);
  	gd->fb_base = gd->relocaddr;
5a5419451   Simon Glass   dm: common: Add m...
425
  #  endif /* CONFIG_FB_ADDR */
0f079eb51   Simon Glass   board_f: Put vide...
426
  #elif defined(CONFIG_VIDEO) && \
5b8e76c35   Heiko Schocher   powerpc, 8xx: rem...
427
  		(!defined(CONFIG_PPC)) && \
d54d7eb96   Sonic Zhang   support blackfin ...
428
  		!defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
ea3310e8a   Tom Rini   Blackfin: Remove
429
  		!defined(CONFIG_M68K)
e4fef6cfc   Simon Glass   Adjust board_f.c ...
430
  	/* reserve memory for video display (always full pages) */
a0ba279ac   Masahiro Yamada   generic_board: re...
431
432
  	gd->relocaddr = video_setmem(gd->relocaddr);
  	gd->fb_base = gd->relocaddr;
0f079eb51   Simon Glass   board_f: Put vide...
433
  #endif
e4fef6cfc   Simon Glass   Adjust board_f.c ...
434
435
436
  
  	return 0;
  }
e4fef6cfc   Simon Glass   Adjust board_f.c ...
437

8703ef3fd   Simon Glass   common: Move LCD ...
438
439
440
441
442
443
444
445
446
447
448
449
  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...
450
451
  static int reserve_uboot(void)
  {
ff2b2ba84   Alexey Brodkin   board_f: Only res...
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
  	if (!(gd->flags & GD_FLG_SKIP_RELOC)) {
  		/*
  		 * reserve memory for U-Boot code, data & bss
  		 * round down to next 4 kB limit
  		 */
  		gd->relocaddr -= gd->mon_len;
  		gd->relocaddr &= ~(4096 - 1);
  	#if defined(CONFIG_E500) || defined(CONFIG_MIPS)
  		/* round down to next 64 kB limit so that IVPR stays aligned */
  		gd->relocaddr &= ~(65536 - 1);
  	#endif
  
  		debug("Reserving %ldk for U-Boot at: %08lx
  ",
  		      gd->mon_len >> 10, gd->relocaddr);
  	}
a0ba279ac   Masahiro Yamada   generic_board: re...
468
469
  
  	gd->start_addr_sp = gd->relocaddr;
1938f4a5b   Simon Glass   Introduce generic...
470
471
472
473
474
475
  	return 0;
  }
  
  /* reserve memory for malloc() area */
  static int reserve_malloc(void)
  {
a0ba279ac   Masahiro Yamada   generic_board: re...
476
  	gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN;
1938f4a5b   Simon Glass   Introduce generic...
477
478
  	debug("Reserving %dk for malloc() at: %08lx
  ",
16ef14742   Mario Six   common: board_f: ...
479
  	      TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
1938f4a5b   Simon Glass   Introduce generic...
480
481
482
483
484
485
  	return 0;
  }
  
  /* (permanently) allocate a Board Info struct */
  static int reserve_board(void)
  {
d54d7eb96   Sonic Zhang   support blackfin ...
486
487
488
489
490
491
492
493
  	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...
494
495
496
497
498
499
500
501
502
503
504
505
506
  	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...
507
508
  	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...
509
510
  	debug("Reserving %zu Bytes for Global Data at: %08lx
  ",
16ef14742   Mario Six   common: board_f: ...
511
  	      sizeof(gd_t), gd->start_addr_sp);
1938f4a5b   Simon Glass   Introduce generic...
512
513
514
515
516
  	return 0;
  }
  
  static int reserve_fdt(void)
  {
e9acb9ea4   Siva Durga Prasad Paladugu   common: board: Do...
517
  #ifndef CONFIG_OF_EMBED
1938f4a5b   Simon Glass   Introduce generic...
518
  	/*
4c509343a   Simon Glass   Fix comment nits ...
519
  	 * If the device tree is sitting immediately above our image then we
1938f4a5b   Simon Glass   Introduce generic...
520
521
522
523
524
  	 * 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...
525
526
  		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...
527
528
  		debug("Reserving %lu Bytes for FDT at: %08lx
  ",
a0ba279ac   Masahiro Yamada   generic_board: re...
529
  		      gd->fdt_size, gd->start_addr_sp);
1938f4a5b   Simon Glass   Introduce generic...
530
  	}
e9acb9ea4   Siva Durga Prasad Paladugu   common: board: Do...
531
  #endif
1938f4a5b   Simon Glass   Introduce generic...
532
533
534
  
  	return 0;
  }
25e7dc6a6   Simon Glass   bootstage: Suppor...
535
536
537
538
539
540
541
542
543
544
545
546
547
548
  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;
  }
d6f877123   Patrick Delaunay   common: move boar...
549
  __weak int arch_reserve_stacks(void)
1938f4a5b   Simon Glass   Introduce generic...
550
  {
68145d4c7   Andreas Bießmann   common/board_f: f...
551
552
  	return 0;
  }
8cae8a68e   Simon Glass   Add spl load feature
553

68145d4c7   Andreas Bießmann   common/board_f: f...
554
555
556
  static int reserve_stacks(void)
  {
  	/* make stack pointer 16-byte aligned */
a0ba279ac   Masahiro Yamada   generic_board: re...
557
558
  	gd->start_addr_sp -= 16;
  	gd->start_addr_sp &= ~0xf;
1938f4a5b   Simon Glass   Introduce generic...
559
560
  
  	/*
4c509343a   Simon Glass   Fix comment nits ...
561
  	 * let the architecture-specific code tailor gd->start_addr_sp and
68145d4c7   Andreas Bießmann   common/board_f: f...
562
  	 * gd->irq_sp
1938f4a5b   Simon Glass   Introduce generic...
563
  	 */
68145d4c7   Andreas Bießmann   common/board_f: f...
564
  	return arch_reserve_stacks();
1938f4a5b   Simon Glass   Introduce generic...
565
  }
f0293d33b   Simon Glass   bloblist: Locate ...
566
567
568
569
570
571
572
573
574
  static int reserve_bloblist(void)
  {
  #ifdef CONFIG_BLOBLIST
  	gd->start_addr_sp -= CONFIG_BLOBLIST_SIZE;
  	gd->new_bloblist = map_sysmem(gd->start_addr_sp, CONFIG_BLOBLIST_SIZE);
  #endif
  
  	return 0;
  }
1938f4a5b   Simon Glass   Introduce generic...
575
576
  static int display_new_sp(void)
  {
a0ba279ac   Masahiro Yamada   generic_board: re...
577
578
  	debug("New Stack Pointer is: %08lx
  ", gd->start_addr_sp);
1938f4a5b   Simon Glass   Introduce generic...
579
580
581
  
  	return 0;
  }
e2099d78c   Vladimir Zapolskiy   common: sh: add n...
582
583
  #if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
  	defined(CONFIG_SH)
e4fef6cfc   Simon Glass   Adjust board_f.c ...
584
585
586
587
588
589
590
  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 ...
591
592
593
594
595
596
597
  	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...
598
  #if defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
e4fef6cfc   Simon Glass   Adjust board_f.c ...
599
600
  	bd->bi_immr_base = CONFIG_SYS_IMMR;	/* base  of IMMR register     */
  #endif
064b55cfc   Heiko Schocher   powerpc, 5xxx, 51...
601
  #if defined(CONFIG_M68K)
e4fef6cfc   Simon Glass   Adjust board_f.c ...
602
603
604
605
606
  	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 ...
607
608
609
  
  	return 0;
  }
fb3db6357   Daniel Schwierzeck   common/board_f: e...
610
  #endif
e4fef6cfc   Simon Glass   Adjust board_f.c ...
611

fb3db6357   Daniel Schwierzeck   common/board_f: e...
612
  #if defined(CONFIG_PPC) || defined(CONFIG_M68K)
e4fef6cfc   Simon Glass   Adjust board_f.c ...
613
614
615
616
617
618
619
620
621
622
623
624
  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...
625
626
627
628
629
630
631
632
  #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 ...
633
634
635
636
  
  	return 0;
  }
  #endif
1938f4a5b   Simon Glass   Introduce generic...
637
638
639
640
641
642
643
644
645
  #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...
646
647
  static int reloc_fdt(void)
  {
e9acb9ea4   Siva Durga Prasad Paladugu   common: board: Do...
648
  #ifndef CONFIG_OF_EMBED
f05ad9ba4   Simon Glass   Add a way to skip...
649
650
  	if (gd->flags & GD_FLG_SKIP_RELOC)
  		return 0;
1938f4a5b   Simon Glass   Introduce generic...
651
652
653
654
  	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...
655
  #endif
1938f4a5b   Simon Glass   Introduce generic...
656
657
658
  
  	return 0;
  }
25e7dc6a6   Simon Glass   bootstage: Suppor...
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
  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;
  }
f0293d33b   Simon Glass   bloblist: Locate ...
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
  static int reloc_bloblist(void)
  {
  #ifdef CONFIG_BLOBLIST
  	if (gd->flags & GD_FLG_SKIP_RELOC)
  		return 0;
  	if (gd->new_bloblist) {
  		int size = CONFIG_BLOBLIST_SIZE;
  
  		debug("Copying bloblist from %p to %p, size %x
  ",
  		      gd->bloblist, gd->new_bloblist, size);
  		memcpy(gd->new_bloblist, gd->bloblist, size);
  		gd->bloblist = gd->new_bloblist;
  	}
  #endif
  
  	return 0;
  }
1938f4a5b   Simon Glass   Introduce generic...
695
696
  static int setup_reloc(void)
  {
f05ad9ba4   Simon Glass   Add a way to skip...
697
698
699
700
701
  	if (gd->flags & GD_FLG_SKIP_RELOC) {
  		debug("Skipping relocation due to flag
  ");
  		return 0;
  	}
d54d7eb96   Sonic Zhang   support blackfin ...
702
  #ifdef CONFIG_SYS_TEXT_BASE
53207bfd7   Lothar Waßmann   board_f: fix calc...
703
704
705
  #ifdef ARM
  	gd->reloc_off = gd->relocaddr - (unsigned long)__image_copy_start;
  #elif defined(CONFIG_M68K)
e310b93ec   angelo@sysam.it   m68k: add generic...
706
707
708
709
710
  	/*
  	 * 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...
711
712
  #else
  	gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
e310b93ec   angelo@sysam.it   m68k: add generic...
713
  #endif
d54d7eb96   Sonic Zhang   support blackfin ...
714
  #endif
1938f4a5b   Simon Glass   Introduce generic...
715
716
717
718
  	memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
  
  	debug("Relocation Offset is: %08lx
  ", gd->reloc_off);
a733b06b6   Simon Glass   sandbox: Switch o...
719
720
  	debug("Relocating to %08lx, new gd at %08lx, sp at %08lx
  ",
a0ba279ac   Masahiro Yamada   generic_board: re...
721
722
  	      gd->relocaddr, (ulong)map_to_sysmem(gd->new_gd),
  	      gd->start_addr_sp);
1938f4a5b   Simon Glass   Introduce generic...
723
724
725
  
  	return 0;
  }
2a792753d   mario.six@gdsys.cc   dm: Add callback ...
726
727
728
729
730
731
  #ifdef CONFIG_OF_BOARD_FIXUP
  static int fix_fdt(void)
  {
  	return board_fix_fdt((void *)gd->fdt_blob);
  }
  #endif
1938f4a5b   Simon Glass   Introduce generic...
732
  /* ARM calls relocate_code from its crt0.S */
530f27eab   Simon Glass   x86: board_f: Upd...
733
734
  #if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
  		!CONFIG_IS_ENABLED(X86_64)
1938f4a5b   Simon Glass   Introduce generic...
735
736
737
  
  static int jump_to_copy(void)
  {
f05ad9ba4   Simon Glass   Add a way to skip...
738
739
  	if (gd->flags & GD_FLG_SKIP_RELOC)
  		return 0;
48a338067   Simon Glass   x86: Adjust board...
740
741
742
743
744
745
746
747
  	/*
  	 * 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...
748
  #if defined(CONFIG_X86) || defined(CONFIG_ARC)
48a338067   Simon Glass   x86: Adjust board...
749
750
751
752
753
754
  	/*
  	 * 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...
755
  	arch_setup_gd(gd->new_gd);
48a338067   Simon Glass   x86: Adjust board...
756
757
  	board_init_f_r_trampoline(gd->start_addr_sp);
  #else
a0ba279ac   Masahiro Yamada   generic_board: re...
758
  	relocate_code(gd->start_addr_sp, gd->new_gd, gd->relocaddr);
48a338067   Simon Glass   x86: Adjust board...
759
  #endif
1938f4a5b   Simon Glass   Introduce generic...
760
761
762
763
764
765
  
  	return 0;
  }
  #endif
  
  /* Record the board_init_f() bootstage (after arch_cpu_init()) */
b383d6c05   Simon Glass   bootstage: Conver...
766
  static int initf_bootstage(void)
1938f4a5b   Simon Glass   Introduce generic...
767
  {
baa7d345f   Simon Glass   board_f: Use IS_E...
768
769
  	bool from_spl = IS_ENABLED(CONFIG_SPL_BOOTSTAGE) &&
  			IS_ENABLED(CONFIG_BOOTSTAGE_STASH);
b383d6c05   Simon Glass   bootstage: Conver...
770
  	int ret;
824bb1b45   Simon Glass   bootstage: Suppor...
771
  	ret = bootstage_init(!from_spl);
b383d6c05   Simon Glass   bootstage: Conver...
772
773
  	if (ret)
  		return ret;
824bb1b45   Simon Glass   bootstage: Suppor...
774
775
776
777
778
779
780
781
782
783
784
  	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...
785

1938f4a5b   Simon Glass   Introduce generic...
786
787
788
789
  	bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
  
  	return 0;
  }
9854a8748   Simon Glass   console: Add a co...
790
791
  static int initf_console_record(void)
  {
f1896c45c   Andy Yan   spl: make SPL and...
792
  #if defined(CONFIG_CONSOLE_RECORD) && CONFIG_VAL(SYS_MALLOC_F_LEN)
9854a8748   Simon Glass   console: Add a co...
793
794
795
796
797
  	return console_record_init();
  #else
  	return 0;
  #endif
  }
ab7cd6279   Simon Glass   dm: Support drive...
798
799
  static int initf_dm(void)
  {
f1896c45c   Andy Yan   spl: make SPL and...
800
  #if defined(CONFIG_DM) && CONFIG_VAL(SYS_MALLOC_F_LEN)
ab7cd6279   Simon Glass   dm: Support drive...
801
  	int ret;
63c5bf48d   Simon Glass   bootstage: Record...
802
  	bootstage_start(BOOTSTATE_ID_ACCUM_DM_F, "dm_f");
ab7cd6279   Simon Glass   dm: Support drive...
803
  	ret = dm_init_and_scan(true);
63c5bf48d   Simon Glass   bootstage: Record...
804
  	bootstage_accum(BOOTSTATE_ID_ACCUM_DM_F);
ab7cd6279   Simon Glass   dm: Support drive...
805
806
807
  	if (ret)
  		return ret;
  #endif
1057e6cfe   Simon Glass   timer: Set up the...
808
809
810
811
812
  #ifdef CONFIG_TIMER_EARLY
  	ret = dm_timer_init();
  	if (ret)
  		return ret;
  #endif
ab7cd6279   Simon Glass   dm: Support drive...
813
814
815
  
  	return 0;
  }
146251f87   Simon Glass   Allow architectur...
816
817
818
819
820
  /* Architecture-specific memory reservation */
  __weak int reserve_arch(void)
  {
  	return 0;
  }
d4c671cc2   Simon Glass   dm: Add a new CPU...
821
822
823
824
  __weak int arch_cpu_init_dm(void)
  {
  	return 0;
  }
4acff4524   Simon Glass   board_f/r: Use st...
825
  static const init_fnc_t init_sequence_f[] = {
1938f4a5b   Simon Glass   Introduce generic...
826
  	setup_mon_len,
b45122fdf   Simon Glass   fdt: sandbox: Mov...
827
  #ifdef CONFIG_OF_CONTROL
0879361fd   Simon Glass   fdt: Rename setup...
828
  	fdtdec_setup,
b45122fdf   Simon Glass   fdt: sandbox: Mov...
829
  #endif
d210718d9   Kevin Hilman   common/board_f.c:...
830
  #ifdef CONFIG_TRACE
71c52dba2   Simon Glass   Add trace support...
831
  	trace_early_init,
d210718d9   Kevin Hilman   common/board_f.c:...
832
  #endif
768e0f52f   Simon Glass   Move early malloc...
833
  	initf_malloc,
af1bc0cf4   Simon Glass   log: Plumb loggin...
834
  	log_init,
5ac44a554   Simon Glass   bootstage: Init a...
835
  	initf_bootstage,	/* uses its own timer, so does not need DM */
f0293d33b   Simon Glass   bloblist: Locate ...
836
837
838
  #ifdef CONFIG_BLOBLIST
  	bloblist_init,
  #endif
b0edea3c2   Simon Glass   spl: Add support ...
839
  	setup_spl_handoff,
9854a8748   Simon Glass   console: Add a co...
840
  	initf_console_record,
671549e5b   Simon Glass   board_f: x86: Ren...
841
842
  #if defined(CONFIG_HAVE_FSP)
  	arch_fsp_init,
a52a068eb   Bin Meng   x86: fsp: Delay x...
843
  #endif
1938f4a5b   Simon Glass   Introduce generic...
844
  	arch_cpu_init,		/* basic arch cpu dependent setup */
8ebf50692   Paul Burton   board_f: Add a ma...
845
  	mach_cpu_init,		/* SoC/machine dependent CPU setup */
3ea0953d3   Simon Glass   dm: Move pre-relo...
846
  	initf_dm,
d4c671cc2   Simon Glass   dm: Add a new CPU...
847
  	arch_cpu_init_dm,
1938f4a5b   Simon Glass   Introduce generic...
848
849
850
  #if defined(CONFIG_BOARD_EARLY_INIT_F)
  	board_early_init_f,
  #endif
727e94a4a   Simon Glass   powerpc: freescal...
851
  #if defined(CONFIG_PPC) || defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K)
c252c0685   Simon Glass   board_f: powerpc:...
852
  	/* get CPU and bus clocks according to the environment variable */
e4fef6cfc   Simon Glass   Adjust board_f.c ...
853
  	get_clocks,		/* get CPU and bus clocks (etc.) */
1793e7822   Simon Glass   board_f: powerpc:...
854
  #endif
0ce452872   Angelo Dureghello   board_f: skip tim...
855
  #if !defined(CONFIG_M68K)
1938f4a5b   Simon Glass   Introduce generic...
856
  	timer_init,		/* initialize timer */
0ce452872   Angelo Dureghello   board_f: skip tim...
857
  #endif
e4fef6cfc   Simon Glass   Adjust board_f.c ...
858
859
860
  #if defined(CONFIG_BOARD_POSTCLK_INIT)
  	board_postclk_init,
  #endif
1938f4a5b   Simon Glass   Introduce generic...
861
862
  	env_init,		/* initialize environment */
  	init_baud_rate,		/* initialze baudrate settings */
e6c03a825   Ji Luo   MA-12973 [AUTO] S...
863
  #ifndef CONFIG_ANDROID_AUTO_SUPPORT
1938f4a5b   Simon Glass   Introduce generic...
864
  	serial_init,		/* serial communications setup */
e6c03a825   Ji Luo   MA-12973 [AUTO] S...
865
  #endif
1938f4a5b   Simon Glass   Introduce generic...
866
867
868
  	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:...
869
  #if defined(CONFIG_PPC) || defined(CONFIG_SH) || defined(CONFIG_X86)
e4fef6cfc   Simon Glass   Adjust board_f.c ...
870
871
  	checkcpu,
  #endif
23471aed5   Mario Six   board_f: Add rese...
872
873
874
  #if defined(CONFIG_SYSRESET)
  	print_resetinfo,
  #endif
cc664000c   Simon Glass   Drop the static i...
875
  #if defined(CONFIG_DISPLAY_CPUINFO)
1938f4a5b   Simon Glass   Introduce generic...
876
  	print_cpuinfo,		/* display cpu info (and speed) */
cc664000c   Simon Glass   Drop the static i...
877
  #endif
af9e6ad4a   Cooper Jr., Franklin   board_f: Add new ...
878
879
880
  #if defined(CONFIG_DTB_RESELECT)
  	embedded_dtb_select,
  #endif
1938f4a5b   Simon Glass   Introduce generic...
881
  #if defined(CONFIG_DISPLAY_BOARDINFO)
0365ffcc0   Masahiro Yamada   generic-board: sh...
882
  	show_board_info,
1938f4a5b   Simon Glass   Introduce generic...
883
  #endif
e4fef6cfc   Simon Glass   Adjust board_f.c ...
884
885
886
887
888
  	INIT_FUNC_WATCHDOG_INIT
  #if defined(CONFIG_MISC_INIT_F)
  	misc_init_f,
  #endif
  	INIT_FUNC_WATCHDOG_RESET
69153988a   Simon Glass   i2c: Finish dropp...
889
  #if defined(CONFIG_SYS_I2C)
e4fef6cfc   Simon Glass   Adjust board_f.c ...
890
891
  	init_func_i2c,
  #endif
1fab98fb9   Rajesh Bhagat   common: board_f: ...
892
893
894
  #if defined(CONFIG_VID) && !defined(CONFIG_SPL)
  	init_func_vid,
  #endif
1938f4a5b   Simon Glass   Introduce generic...
895
  	announce_dram_init,
1938f4a5b   Simon Glass   Introduce generic...
896
  	dram_init,		/* configure available RAM banks */
e4fef6cfc   Simon Glass   Adjust board_f.c ...
897
898
899
900
901
902
903
904
  #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...
905
906
907
  #ifdef CONFIG_POST
  	init_post,
  #endif
e4fef6cfc   Simon Glass   Adjust board_f.c ...
908
  	INIT_FUNC_WATCHDOG_RESET
1938f4a5b   Simon Glass   Introduce generic...
909
910
911
912
913
914
915
916
917
918
919
920
921
  	/*
  	 * 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...
922
923
924
925
  #ifdef CONFIG_PRAM
  	reserve_pram,
  #endif
  	reserve_round_4k,
80d4bcd3e   Simon Glass   board_f: Move the...
926
  #ifdef CONFIG_ARM
1938f4a5b   Simon Glass   Introduce generic...
927
928
  	reserve_mmu,
  #endif
5a5419451   Simon Glass   dm: common: Add m...
929
  	reserve_video,
8703ef3fd   Simon Glass   common: Move LCD ...
930
  	reserve_trace,
1938f4a5b   Simon Glass   Introduce generic...
931
932
933
934
935
936
  	reserve_uboot,
  	reserve_malloc,
  	reserve_board,
  	setup_machine,
  	reserve_global_data,
  	reserve_fdt,
25e7dc6a6   Simon Glass   bootstage: Suppor...
937
  	reserve_bootstage,
f0293d33b   Simon Glass   bloblist: Locate ...
938
  	reserve_bloblist,
146251f87   Simon Glass   Allow architectur...
939
  	reserve_arch,
1938f4a5b   Simon Glass   Introduce generic...
940
  	reserve_stacks,
76b00aca4   Simon Glass   board_f: Drop set...
941
  	dram_init_banksize,
1938f4a5b   Simon Glass   Introduce generic...
942
  	show_dram_config,
e2099d78c   Vladimir Zapolskiy   common: sh: add n...
943
944
  #if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
  	defined(CONFIG_SH)
e4fef6cfc   Simon Glass   Adjust board_f.c ...
945
  	setup_board_part1,
fb3db6357   Daniel Schwierzeck   common/board_f: e...
946
947
  #endif
  #if defined(CONFIG_PPC) || defined(CONFIG_M68K)
e4fef6cfc   Simon Glass   Adjust board_f.c ...
948
949
950
  	INIT_FUNC_WATCHDOG_RESET
  	setup_board_part2,
  #endif
1938f4a5b   Simon Glass   Introduce generic...
951
  	display_new_sp,
2a792753d   mario.six@gdsys.cc   dm: Add callback ...
952
953
954
  #ifdef CONFIG_OF_BOARD_FIXUP
  	fix_fdt,
  #endif
e4fef6cfc   Simon Glass   Adjust board_f.c ...
955
  	INIT_FUNC_WATCHDOG_RESET
1938f4a5b   Simon Glass   Introduce generic...
956
  	reloc_fdt,
25e7dc6a6   Simon Glass   bootstage: Suppor...
957
  	reloc_bootstage,
f0293d33b   Simon Glass   bloblist: Locate ...
958
  	reloc_bloblist,
1938f4a5b   Simon Glass   Introduce generic...
959
  	setup_reloc,
3fb801636   Alexey Brodkin   arc: clean-up ini...
960
  #if defined(CONFIG_X86) || defined(CONFIG_ARC)
313aef37a   Simon Glass   x86: board_f: Adj...
961
  	copy_uboot_to_ram,
313aef37a   Simon Glass   x86: board_f: Adj...
962
  	do_elf_reloc_fixups,
6bda55a38   Simon Glass   x86: Do relocatio...
963
  	clear_bss,
313aef37a   Simon Glass   x86: board_f: Adj...
964
  #endif
de5e5cea0   Chris Zankel   xtensa: add suppo...
965
966
967
  #if defined(CONFIG_XTENSA)
  	clear_bss,
  #endif
530f27eab   Simon Glass   x86: board_f: Upd...
968
969
  #if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
  		!CONFIG_IS_ENABLED(X86_64)
1938f4a5b   Simon Glass   Introduce generic...
970
971
972
973
974
975
976
  	jump_to_copy,
  #endif
  	NULL,
  };
  
  void board_init_f(ulong boot_flags)
  {
1938f4a5b   Simon Glass   Introduce generic...
977
  	gd->flags = boot_flags;
9aed5a277   Alexey Brodkin   board_f: explicit...
978
  	gd->have_console = 0;
1938f4a5b   Simon Glass   Introduce generic...
979
980
981
  
  	if (initcall_run_list(init_sequence_f))
  		hang();
9b2174984   Ben Stoltz   efi: Avoid using ...
982
  #if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \
264d298fd   Alexey Brodkin   arc: Introduce a ...
983
984
  		!defined(CONFIG_EFI_APP) && !CONFIG_IS_ENABLED(X86_64) && \
  		!defined(CONFIG_ARC)
1938f4a5b   Simon Glass   Introduce generic...
985
986
987
988
  	/* NOTREACHED - jump_to_copy() does not return */
  	hang();
  #endif
  }
3fb801636   Alexey Brodkin   arc: clean-up ini...
989
  #if defined(CONFIG_X86) || defined(CONFIG_ARC)
48a338067   Simon Glass   x86: Adjust board...
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
  /*
   * 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...
1007
  static const init_fnc_t init_sequence_f_r[] = {
530f27eab   Simon Glass   x86: board_f: Upd...
1008
  #if !CONFIG_IS_ENABLED(X86_64)
48a338067   Simon Glass   x86: Adjust board...
1009
  	init_cache_f_r,
530f27eab   Simon Glass   x86: board_f: Upd...
1010
  #endif
48a338067   Simon Glass   x86: Adjust board...
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
  
  	NULL,
  };
  
  void board_init_f_r(void)
  {
  	if (initcall_run_list(init_sequence_f_r))
  		hang();
  
  	/*
e4d6ab0c2   Simon Glass   x86: Allow use of...
1021
1022
1023
  	 * 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...
1024
1025
  	 *
  	 * Do the same with log drivers since the memory may not be available.
e4d6ab0c2   Simon Glass   x86: Allow use of...
1026
  	 */
af1bc0cf4   Simon Glass   log: Plumb loggin...
1027
  	gd->flags &= ~(GD_FLG_SERIAL_READY | GD_FLG_LOG_READY);
5ee94b4f4   Simon Glass   board_f: Drop the...
1028
1029
1030
  #ifdef CONFIG_TIMER
  	gd->timer = NULL;
  #endif
e4d6ab0c2   Simon Glass   x86: Allow use of...
1031
1032
  
  	/*
48a338067   Simon Glass   x86: Adjust board...
1033
1034
1035
1036
  	 * 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...
1037
  	(board_init_r + gd->reloc_off)((gd_t *)gd, gd->relocaddr);
48a338067   Simon Glass   x86: Adjust board...
1038
1039
1040
1041
  
  	/* NOTREACHED - board_init_r() does not return */
  	hang();
  }
5bcd19aa2   Alexey Brodkin   common/board_f: m...
1042
  #endif /* CONFIG_X86 */