]>
Commit | Line | Data |
---|---|---|
463d47f6 ML |
1 | /* |
2 | * (C) Copyright 2002-2006 | |
3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. | |
4 | * | |
5 | * Copyright (C) 2011 Andes Technology Corporation | |
6 | * Shawn Lin, Andes Technology Corporation <nobuhiro@andestech.com> | |
7 | * Macpaul Lin, Andes Technology Corporation <macpaul@andestech.com> | |
8 | * | |
1a459660 | 9 | * SPDX-License-Identifier: GPL-2.0+ |
463d47f6 ML |
10 | */ |
11 | ||
12 | #include <common.h> | |
13 | #include <command.h> | |
14 | #include <malloc.h> | |
15 | #include <stdio_dev.h> | |
16 | #include <timestamp.h> | |
17 | #include <version.h> | |
18 | #include <net.h> | |
19 | #include <serial.h> | |
20 | #include <nand.h> | |
21 | #include <onenand_uboot.h> | |
22 | #include <mmc.h> | |
fe8e4dba | 23 | #include <asm/sections.h> |
463d47f6 ML |
24 | |
25 | DECLARE_GLOBAL_DATA_PTR; | |
26 | ||
27 | ulong monitor_flash_len; | |
28 | ||
29 | /* | |
30 | * Init Utilities | |
31 | */ | |
32 | ||
33 | #if !defined(CONFIG_BAUDRATE) | |
34 | #define CONFIG_BAUDRATE 38400 | |
35 | #endif | |
36 | static int init_baudrate(void) | |
37 | { | |
569bc625 | 38 | gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE); |
463d47f6 ML |
39 | return 0; |
40 | } | |
41 | ||
42 | /* | |
43 | * WARNING: this code looks "cleaner" than the PowerPC version, but | |
44 | * has the disadvantage that you either get nothing, or everything. | |
45 | * On PowerPC, you might see "DRAM: " before the system hangs - which | |
46 | * gives a simple yet clear indication which part of the | |
47 | * initialization if failing. | |
48 | */ | |
49 | static int display_dram_config(void) | |
50 | { | |
51 | int i; | |
52 | ||
53 | #ifdef DEBUG | |
54 | puts("RAM Configuration:\n"); | |
55 | ||
56 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { | |
57 | printf("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start); | |
58 | print_size(gd->bd->bi_dram[i].size, "\n"); | |
59 | } | |
60 | #else | |
61 | ulong size = 0; | |
62 | ||
63 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) | |
64 | size += gd->bd->bi_dram[i].size; | |
65 | ||
66 | puts("DRAM: "); | |
67 | print_size(size, "\n"); | |
68 | #endif | |
69 | ||
70 | return 0; | |
71 | } | |
72 | ||
73 | #ifndef CONFIG_SYS_NO_FLASH | |
74 | static void display_flash_config(ulong size) | |
75 | { | |
76 | puts("Flash: "); | |
77 | print_size(size, "\n"); | |
78 | } | |
79 | #endif /* CONFIG_SYS_NO_FLASH */ | |
80 | ||
81 | #if defined(CONFIG_CMD_PCI) || defined(CONFIG_PCI) | |
82 | #include <pci.h> | |
83 | static int nds32_pci_init(void) | |
84 | { | |
85 | pci_init(); | |
86 | return 0; | |
87 | } | |
88 | #endif /* CONFIG_CMD_PCI || CONFIG_PCI */ | |
89 | ||
90 | #if defined(CONFIG_PMU) || defined(CONFIG_PCU) | |
11a05fbd | 91 | #ifndef CONFIG_SKIP_LOWLEVEL_INIT |
463d47f6 ML |
92 | static int pmu_init(void) |
93 | { | |
94 | #if defined(CONFIG_FTPMU010_POWER) | |
95 | #ifdef __NDS32_N1213_43U1H__ /* AG101: internal definition in toolchain */ | |
96 | ftpmu010_sdram_clk_disable(CONFIG_SYS_FTPMU010_PDLLCR0_HCLKOUTDIS); | |
97 | ftpmu010_mfpsr_select_dev(FTPMU010_MFPSR_AC97CLKSEL); | |
98 | ftpmu010_sdramhtc_set(CONFIG_SYS_FTPMU010_SDRAMHTC); | |
99 | #endif /* __NDS32_N1213_43U1H__ */ | |
100 | #endif | |
101 | return 0; | |
102 | } | |
103 | #endif | |
11a05fbd | 104 | #endif |
463d47f6 ML |
105 | |
106 | /* | |
107 | * Breathe some life into the board... | |
108 | * | |
109 | * Initialize a serial port as console, and carry out some hardware | |
110 | * tests. | |
111 | * | |
112 | * The first part of initialization is running from Flash memory; | |
113 | * its main purpose is to initialize the RAM so that we | |
114 | * can relocate the monitor code to RAM. | |
115 | */ | |
116 | ||
117 | /* | |
118 | * All attempts to come up with a "common" initialization sequence | |
119 | * that works for all boards and architectures failed: some of the | |
120 | * requirements are just _too_ different. To get rid of the resulting | |
121 | * mess of board dependent #ifdef'ed code we now make the whole | |
122 | * initialization sequence configurable to the user. | |
123 | * | |
124 | * The requirements for any new initalization function is simple: it | |
125 | * receives a pointer to the "global data" structure as it's only | |
126 | * argument, and returns an integer return code, where 0 means | |
127 | * "continue" and != 0 means "fatal error, hang the system". | |
128 | */ | |
129 | typedef int (init_fnc_t)(void); | |
130 | ||
131 | void __dram_init_banksize(void) | |
132 | { | |
133 | gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE; | |
134 | gd->bd->bi_dram[0].size = gd->ram_size; | |
135 | } | |
136 | void dram_init_banksize(void) | |
137 | __attribute__((weak, alias("__dram_init_banksize"))); | |
138 | ||
139 | init_fnc_t *init_sequence[] = { | |
140 | #if defined(CONFIG_ARCH_CPU_INIT) | |
141 | arch_cpu_init, /* basic arch cpu dependent setup */ | |
142 | #endif | |
143 | #if defined(CONFIG_PMU) || defined(CONFIG_PCU) | |
144 | #ifndef CONFIG_SKIP_LOWLEVEL_INIT | |
145 | pmu_init, | |
146 | #endif | |
147 | #endif | |
148 | board_init, /* basic board dependent setup */ | |
149 | #if defined(CONFIG_USE_IRQ) | |
150 | interrupt_init, /* set up exceptions */ | |
151 | #endif | |
152 | timer_init, /* initialize timer */ | |
153 | env_init, /* initialize environment */ | |
154 | init_baudrate, /* initialze baudrate settings */ | |
155 | serial_init, /* serial communications setup */ | |
156 | console_init_f, /* stage 1 init of console */ | |
157 | #if defined(CONFIG_DISPLAY_BOARDINFO) | |
158 | checkboard, /* display board info */ | |
159 | #endif | |
160 | #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) | |
161 | init_func_i2c, | |
162 | #endif | |
163 | dram_init, /* configure available RAM banks */ | |
164 | display_dram_config, | |
165 | NULL, | |
166 | }; | |
167 | ||
168 | void board_init_f(ulong bootflag) | |
169 | { | |
170 | bd_t *bd; | |
171 | init_fnc_t **init_fnc_ptr; | |
172 | gd_t *id; | |
173 | ulong addr, addr_sp; | |
174 | ||
175 | /* Pointer is writable since we allocated a register for it */ | |
176 | gd = (gd_t *) ((CONFIG_SYS_INIT_SP_ADDR) & ~0x07); | |
177 | ||
178 | memset((void *)gd, 0, GENERATED_GBL_DATA_SIZE); | |
179 | ||
3929fb0a | 180 | gd->mon_len = (unsigned int)(&__bss_end) - (unsigned int)(&_start); |
463d47f6 ML |
181 | |
182 | for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) { | |
183 | if ((*init_fnc_ptr)() != 0) | |
184 | hang(); | |
185 | } | |
186 | ||
187 | debug("monitor len: %08lX\n", gd->mon_len); | |
188 | /* | |
189 | * Ram is setup, size stored in gd !! | |
190 | */ | |
191 | debug("ramsize: %08lX\n", gd->ram_size); | |
192 | ||
193 | addr = CONFIG_SYS_SDRAM_BASE + gd->ram_size; | |
194 | ||
463d47f6 ML |
195 | /* round down to next 4 kB limit */ |
196 | addr &= ~(4096 - 1); | |
197 | debug("Top of RAM usable for U-Boot at: %08lx\n", addr); | |
198 | ||
199 | #ifdef CONFIG_LCD | |
200 | #ifdef CONFIG_FB_ADDR | |
201 | gd->fb_base = CONFIG_FB_ADDR; | |
202 | #else | |
203 | /* reserve memory for LCD display (always full pages) */ | |
204 | addr = lcd_setmem(addr); | |
205 | gd->fb_base = addr; | |
206 | #endif /* CONFIG_FB_ADDR */ | |
207 | #endif /* CONFIG_LCD */ | |
208 | ||
209 | /* | |
210 | * reserve memory for U-Boot code, data & bss | |
211 | * round down to next 4 kB limit | |
212 | */ | |
213 | addr -= gd->mon_len; | |
214 | addr &= ~(4096 - 1); | |
215 | ||
216 | debug("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10, addr); | |
217 | ||
218 | /* | |
219 | * reserve memory for malloc() arena | |
220 | */ | |
221 | addr_sp = addr - TOTAL_MALLOC_LEN; | |
222 | debug("Reserving %dk for malloc() at: %08lx\n", | |
223 | TOTAL_MALLOC_LEN >> 10, addr_sp); | |
224 | /* | |
225 | * (permanently) allocate a Board Info struct | |
226 | * and a permanent copy of the "global" data | |
227 | */ | |
228 | addr_sp -= GENERATED_BD_INFO_SIZE; | |
229 | bd = (bd_t *) addr_sp; | |
230 | gd->bd = bd; | |
231 | memset((void *)bd, 0, GENERATED_BD_INFO_SIZE); | |
232 | debug("Reserving %zu Bytes for Board Info at: %08lx\n", | |
233 | GENERATED_BD_INFO_SIZE, addr_sp); | |
234 | ||
235 | addr_sp -= GENERATED_GBL_DATA_SIZE; | |
236 | id = (gd_t *) addr_sp; | |
237 | debug("Reserving %zu Bytes for Global Data at: %08lx\n", | |
238 | GENERATED_GBL_DATA_SIZE, addr_sp); | |
239 | ||
240 | /* setup stackpointer for exeptions */ | |
241 | gd->irq_sp = addr_sp; | |
242 | #ifdef CONFIG_USE_IRQ | |
243 | addr_sp -= (CONFIG_STACKSIZE_IRQ + CONFIG_STACKSIZE_FIQ); | |
244 | debug("Reserving %zu Bytes for IRQ stack at: %08lx\n", | |
245 | CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ, addr_sp); | |
246 | #endif | |
247 | /* leave 3 words for abort-stack */ | |
248 | addr_sp -= 12; | |
249 | ||
250 | /* 8-byte alignment for ABI compliance */ | |
251 | addr_sp &= ~0x07; | |
252 | debug("New Stack Pointer is: %08lx\n", addr_sp); | |
253 | ||
254 | gd->bd->bi_baudrate = gd->baudrate; | |
255 | /* Ram isn't board specific, so move it to board code ... */ | |
256 | dram_init_banksize(); | |
257 | display_dram_config(); /* and display it */ | |
258 | ||
259 | gd->relocaddr = addr; | |
260 | gd->start_addr_sp = addr_sp; | |
261 | ||
262 | gd->reloc_off = addr - _TEXT_BASE; | |
263 | ||
264 | debug("relocation Offset is: %08lx\n", gd->reloc_off); | |
265 | memcpy(id, (void *)gd, GENERATED_GBL_DATA_SIZE); | |
266 | ||
267 | relocate_code(addr_sp, id, addr); | |
268 | ||
269 | /* NOTREACHED - relocate_code() does not return */ | |
270 | } | |
271 | ||
272 | /* | |
273 | * This is the next part if the initialization sequence: we are now | |
274 | * running from RAM and have a "normal" C environment, i. e. global | |
275 | * data can be written, BSS has been cleared, the stack size in not | |
276 | * that critical any more, etc. | |
277 | */ | |
278 | void board_init_r(gd_t *id, ulong dest_addr) | |
279 | { | |
463d47f6 ML |
280 | bd_t *bd; |
281 | ulong malloc_start; | |
282 | ||
463d47f6 ML |
283 | gd = id; |
284 | bd = gd->bd; | |
285 | ||
286 | gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */ | |
287 | ||
fe8e4dba | 288 | monitor_flash_len = (ulong)&_end - (ulong)&_start; |
463d47f6 ML |
289 | debug("monitor flash len: %08lX\n", monitor_flash_len); |
290 | ||
291 | board_init(); /* Setup chipselects */ | |
292 | ||
293 | #if defined(CONFIG_NEEDS_MANUAL_RELOC) | |
294 | /* | |
295 | * We have to relocate the command table manually | |
296 | */ | |
6c7c946c MV |
297 | fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd), |
298 | ll_entry_count(cmd_tbl_t, cmd)); | |
463d47f6 ML |
299 | #endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */ |
300 | ||
463d47f6 | 301 | serial_initialize(); |
463d47f6 ML |
302 | |
303 | debug("Now running in RAM - U-Boot at: %08lx\n", dest_addr); | |
304 | ||
305 | /* The Malloc area is immediately below the monitor copy in DRAM */ | |
306 | malloc_start = dest_addr - TOTAL_MALLOC_LEN; | |
307 | mem_malloc_init(malloc_start, TOTAL_MALLOC_LEN); | |
463d47f6 ML |
308 | |
309 | #ifndef CONFIG_SYS_NO_FLASH | |
310 | /* configure available FLASH banks */ | |
311 | gd->bd->bi_flashstart = CONFIG_SYS_FLASH_BASE; | |
312 | gd->bd->bi_flashsize = flash_init(); | |
313 | gd->bd->bi_flashoffset = CONFIG_SYS_FLASH_BASE + gd->bd->bi_flashsize; | |
314 | ||
315 | if (gd->bd->bi_flashsize) | |
316 | display_flash_config(gd->bd->bi_flashsize); | |
317 | #endif /* CONFIG_SYS_NO_FLASH */ | |
318 | ||
319 | #if defined(CONFIG_CMD_NAND) | |
320 | puts("NAND: "); | |
321 | nand_init(); /* go init the NAND */ | |
322 | #endif | |
323 | ||
a2308547 ML |
324 | #if defined(CONFIG_CMD_IDE) |
325 | puts("IDE: "); | |
326 | ide_init(); | |
327 | #endif | |
328 | ||
463d47f6 ML |
329 | #ifdef CONFIG_GENERIC_MMC |
330 | puts("MMC: "); | |
331 | mmc_initialize(gd->bd); | |
332 | #endif | |
333 | ||
334 | /* initialize environment */ | |
335 | env_relocate(); | |
336 | ||
337 | #if defined(CONFIG_CMD_PCI) || defined(CONFIG_PCI) | |
4ef80679 | 338 | puts("PCI: "); |
463d47f6 ML |
339 | nds32_pci_init(); |
340 | #endif | |
341 | ||
463d47f6 ML |
342 | stdio_init(); /* get the devices list going. */ |
343 | ||
344 | jumptable_init(); | |
345 | ||
346 | #if defined(CONFIG_API) | |
347 | /* Initialize API */ | |
348 | api_init(); | |
349 | #endif | |
350 | ||
351 | console_init_r(); /* fully init console as a device */ | |
352 | ||
353 | #if defined(CONFIG_ARCH_MISC_INIT) | |
354 | /* miscellaneous arch dependent initialisations */ | |
355 | arch_misc_init(); | |
356 | #endif | |
357 | #if defined(CONFIG_MISC_INIT_R) | |
358 | /* miscellaneous platform dependent initialisations */ | |
359 | misc_init_r(); | |
360 | #endif | |
361 | ||
362 | #if defined(CONFIG_USE_IRQ) | |
363 | /* set up exceptions */ | |
364 | interrupt_init(); | |
365 | /* enable exceptions */ | |
366 | enable_interrupts(); | |
367 | #endif | |
368 | ||
369 | /* Initialize from environment */ | |
569bc625 | 370 | load_addr = getenv_ulong("loadaddr", 16, load_addr); |
463d47f6 | 371 | |
6abcf2d5 | 372 | #ifdef CONFIG_BOARD_LATE_INIT |
463d47f6 ML |
373 | board_late_init(); |
374 | #endif | |
375 | ||
376 | #if defined(CONFIG_CMD_NET) | |
377 | puts("Net: "); | |
378 | ||
379 | eth_initialize(gd->bd); | |
380 | #if defined(CONFIG_RESET_PHY_R) | |
381 | debug("Reset Ethernet PHY\n"); | |
382 | reset_phy(); | |
383 | #endif | |
384 | #endif | |
385 | ||
386 | /* main_loop() can return to retry autoboot, if so just run it again. */ | |
387 | for (;;) | |
388 | main_loop(); | |
389 | ||
390 | /* NOTREACHED - no way out of command loop except booting */ | |
391 | } |