blob: 28541a72cb1808685d6d2a71890092a7d0ab16dd [file] [log] [blame]
Po Liueb6b4582014-01-10 10:10:59 +08001/* Copyright 2013 Freescale Semiconductor, Inc.
2 *
3 * SPDX-License-Identifier: GPL-2.0+
4 */
5
6#include <common.h>
Simon Glass24b852a2015-11-08 23:47:45 -07007#include <console.h>
Simon Glass203e94f2017-08-03 12:21:56 -06008#include <environment.h>
Po Liueb6b4582014-01-10 10:10:59 +08009#include <ns16550.h>
10#include <malloc.h>
11#include <mmc.h>
12#include <nand.h>
13#include <i2c.h>
14
15DECLARE_GLOBAL_DATA_PTR;
16
York Sune3866162014-02-11 11:57:26 -080017phys_size_t get_effective_memsize(void)
Po Liueb6b4582014-01-10 10:10:59 +080018{
19 return CONFIG_SYS_L2_SIZE;
20}
21
22void board_init_f(ulong bootflag)
23{
24 u32 plat_ratio;
25 ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
26
27 console_init_f();
28
29 /* initialize selected port with appropriate baud rate */
30 plat_ratio = in_be32(&gur->porpllsr) & MPC85xx_PORPLLSR_PLAT_RATIO;
31 plat_ratio >>= 1;
32 gd->bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio;
33
34 NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
35 gd->bus_clk / 16 / CONFIG_BAUDRATE);
36
37 /* copy code to RAM and jump to it - this should not return */
38 /* NOTE - code has to be copied out of NAND buffer before
39 * other blocks can be read.
40 */
41 relocate_code(CONFIG_SPL_RELOC_STACK, 0, CONFIG_SPL_RELOC_TEXT_BASE);
42}
43
44void board_init_r(gd_t *gd, ulong dest_addr)
45{
46 /* Pointer is writable since we allocated a register for it */
47 gd = (gd_t *)CONFIG_SPL_GD_ADDR;
48 bd_t *bd;
49
50 memset(gd, 0, sizeof(gd_t));
51 bd = (bd_t *)(CONFIG_SPL_GD_ADDR + sizeof(gd_t));
52 memset(bd, 0, sizeof(bd_t));
53 gd->bd = bd;
54 bd->bi_memstart = CONFIG_SYS_INIT_L2_ADDR;
55 bd->bi_memsize = CONFIG_SYS_L2_SIZE;
56
Simon Glasscbcbf712017-01-23 13:31:22 -070057 arch_cpu_init();
Po Liueb6b4582014-01-10 10:10:59 +080058 get_clocks();
59 mem_malloc_init(CONFIG_SPL_RELOC_MALLOC_ADDR,
60 CONFIG_SPL_RELOC_MALLOC_SIZE);
Sumit Garged4708a2016-05-25 12:41:48 -040061 gd->flags |= GD_FLG_FULL_MALLOC_INIT;
Po Liueb6b4582014-01-10 10:10:59 +080062
63 /* relocate environment function pointers etc. */
64 nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
65 (uchar *)CONFIG_ENV_ADDR);
66 gd->env_addr = (ulong)(CONFIG_ENV_ADDR);
Simon Glass203e94f2017-08-03 12:21:56 -060067 gd->env_valid = ENV_VALID;
Po Liueb6b4582014-01-10 10:10:59 +080068
69 i2c_init_all();
70
Simon Glassf1683aa2017-04-06 12:47:05 -060071 dram_init();
Po Liueb6b4582014-01-10 10:10:59 +080072
73#ifdef CONFIG_SPL_NAND_BOOT
74 puts("TPL\n");
75#else
76 puts("SPL\n");
77#endif
78
79 nand_boot();
80}