blob: 58973185ecdae7951ed324dd49fdb27ad76a781d [file] [log] [blame]
David Feng3b5458c2013-12-14 11:47:37 +08001/*
2 * (C) Copyright 2013
3 * David Feng <fenghua@phytium.com.cn>
4 * Sharma Bhupesh <bhupesh.sharma@freescale.com>
5 *
6 * SPDX-License-Identifier: GPL-2.0+
7 */
8#include <common.h>
9#include <malloc.h>
10#include <errno.h>
11#include <netdev.h>
12#include <asm/io.h>
13#include <linux/compiler.h>
Darwin Rambod32d4112014-06-09 11:12:59 -070014#include <asm/semihosting.h>
David Feng3b5458c2013-12-14 11:47:37 +080015
16DECLARE_GLOBAL_DATA_PTR;
17
18int board_init(void)
19{
20 return 0;
21}
22
23int dram_init(void)
24{
25 /*
26 * Clear spin table so that secondary processors
27 * observe the correct value after waken up from wfe.
28 */
29 *(unsigned long *)CPU_RELEASE_ADDR = 0;
30
31 gd->ram_size = PHYS_SDRAM_1_SIZE;
32 return 0;
33}
34
David Feng3b5458c2013-12-14 11:47:37 +080035/*
36 * Board specific reset that is system reset.
37 */
38void reset_cpu(ulong addr)
39{
Darwin Rambod32d4112014-06-09 11:12:59 -070040}
41
42#ifdef CONFIG_BOARD_LATE_INIT
43int board_late_init(void)
44{
45#ifdef CONFIG_SEMIHOSTING
46 /*
47 * Please refer to doc/README.semihosting for a more complete
48 * description.
49 *
50 * We require that the board include file defines these env variables:
51 * - kernel_name
52 * - kernel_addr_r
53 * - initrd_name
54 * - initrd_addr_r
55 * - fdt_name
56 * - fdt_addr_r
57 *
58 * For the "fdt chosen" startup macro, this code will then define:
59 * - initrd_end (based on initrd_addr_r plus actual initrd_size)
60 *
61 * We will then load the kernel, initrd, and fdt into the specified
62 * locations in memory in a similar way that the ATF fastmodel code
63 * uses semihosting calls to load other boot stages and u-boot itself.
64 */
65
66 /* Env variable strings */
67 char *kernel_name = getenv("kernel_name");
68 char *kernel_addr_str = getenv("kernel_addr_r");
69 char *initrd_name = getenv("initrd_name");
70 char *initrd_addr_str = getenv("initrd_addr_r");
71 char *fdt_name = getenv("fdt_name");
72 char *fdt_addr_str = getenv("fdt_addr_r");
73 char initrd_end_str[64];
74
75 /* Actual addresses converted from env variables */
76 void *kernel_addr_r;
77 void *initrd_addr_r;
78 void *fdt_addr_r;
79
80 /* Actual initrd base and size */
81 unsigned long initrd_base;
82 unsigned long initrd_size;
83
84 /* Space available */
85 int avail;
86
87 /* Make sure the environment variables needed are set */
88 if (!(kernel_addr_str && initrd_addr_str && fdt_addr_str)) {
89 printf("%s: Define {kernel/initrd/fdt}_addr_r\n", __func__);
90 return -1;
91 }
92 if (!(kernel_name && initrd_name && fdt_name)) {
93 printf("%s: Define {kernel/initrd/fdt}_name\n", __func__);
94 return -1;
95 }
96
97 /* Get exact initrd_size */
98 initrd_size = smh_len(initrd_name);
99 if (initrd_size == -1) {
100 printf("%s: Can't get file size for \'%s\'\n", __func__,
101 initrd_name);
102 return -1;
103 }
104
105 /* Set initrd_end */
106 initrd_base = simple_strtoul(initrd_addr_str, NULL, 16);
107 initrd_addr_r = (void *)initrd_base;
108 sprintf(initrd_end_str, "0x%lx", initrd_base + initrd_size - 1);
109 setenv("initrd_end", initrd_end_str);
110
111 /* Load kernel to memory */
112 fdt_addr_r = (void *)simple_strtoul(fdt_addr_str, NULL, 16);
113 kernel_addr_r = (void *)simple_strtoul(kernel_addr_str, NULL, 16);
114
115 /*
116 * The kernel must be lower in memory than fdt and loading the
117 * kernel must not trample the fdt or vice versa.
118 */
119 avail = fdt_addr_r - kernel_addr_r;
120 if (avail < 0) {
121 printf("%s: fdt must be after kernel\n", __func__);
122 return -1;
123 }
124 smh_load(kernel_name, kernel_addr_r, avail, 1);
125
126 /* Load fdt to memory */
127 smh_load(fdt_name, fdt_addr_r, 0x20000, 1);
128
129 /* Load initrd to memory */
130 smh_load(initrd_name, initrd_addr_r, initrd_size, 1);
131
132#endif /* CONFIG_SEMIHOSTING */
133 return 0;
David Feng3b5458c2013-12-14 11:47:37 +0800134}
Darwin Rambod32d4112014-06-09 11:12:59 -0700135#endif /* CONFIG_BOARD_LATE_INIT */
David Feng3b5458c2013-12-14 11:47:37 +0800136
137/*
138 * Board specific ethernet initialization routine.
139 */
140int board_eth_init(bd_t *bis)
141{
142 int rc = 0;
143#ifdef CONFIG_SMC91111
144 rc = smc91111_initialize(0, CONFIG_SMC91111_BASE);
145#endif
146 return rc;
147}