blob: 85aa1899be02776f602772610a579270eaa37526 [file] [log] [blame]
Stefan Kristianssone0f1fd42011-11-26 19:04:52 +00001/*
2 * (C) Copyright 2011
3 * Julius Baxter, julius@opencores.org
4 *
5 * (C) Copyright 2003, Psyent Corporation <www.psyent.com>
6 * Scott McNutt <smcnutt@psyent.com>
7 *
8 * (C) Copyright 2000-2002
9 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
10 *
11 *
12 * See file CREDITS for list of people who contributed to this
13 * project.
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 * MA 02111-1307 USA
29 */
30
31#include <common.h>
32#include <stdio_dev.h>
33#include <watchdog.h>
34#include <malloc.h>
35#include <mmc.h>
36#include <net.h>
37#ifdef CONFIG_STATUS_LED
38#include <status_led.h>
39#endif
40#ifdef CONFIG_CMD_NAND
41#include <nand.h> /* cannot even include nand.h if it isnt configured */
42#endif
43
44#include <timestamp.h>
45#include <version.h>
46
47DECLARE_GLOBAL_DATA_PTR;
48
49/*
50 * All attempts to come up with a "common" initialization sequence
51 * that works for all boards and architectures failed: some of the
52 * requirements are just _too_ different. To get rid of the resulting
53 * mess of board dependend #ifdef'ed code we now make the whole
54 * initialization sequence configurable to the user.
55 *
56 * The requirements for any new initalization function is simple: it
57 * receives a pointer to the "global data" structure as it's only
58 * argument, and returns an integer return code, where 0 means
59 * "continue" and != 0 means "fatal error, hang the system".
60 */
61
62extern int cache_init(void);
63
64/*
65 * Initialization sequence
66 */
67static int (* const init_sequence[])(void) = {
68 cache_init,
69 timer_init, /* initialize timer */
70 env_init,
71 serial_init,
72 console_init_f,
73 display_options,
74 checkcpu,
75 checkboard,
76};
77
78
79/***********************************************************************/
80void board_init(void)
81{
82 bd_t *bd;
83 int i;
84
85 gd = (gd_t *)CONFIG_SYS_GBL_DATA_ADDR;
86
87 memset((void *)gd, 0, GENERATED_GBL_DATA_SIZE);
88
89 gd->bd = (bd_t *)(gd+1); /* At end of global data */
90 gd->baudrate = CONFIG_BAUDRATE;
91 gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
92
93 bd = gd->bd;
94 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
95 bd->bi_memsize = CONFIG_SYS_SDRAM_SIZE;
96#ifndef CONFIG_SYS_NO_FLASH
97 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
98#endif
99#if defined(CONFIG_SYS_SRAM_BASE) && defined(CONFIG_SYS_SRAM_SIZE)
100 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE;
101 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE;
102#endif
103 bd->bi_baudrate = CONFIG_BAUDRATE;
104
105 for (i = 0; i < ARRAY_SIZE(init_sequence); i++) {
106 WATCHDOG_RESET();
107 if (init_sequence[i]())
108 hang();
109 }
110
111 WATCHDOG_RESET();
112
113 /* The Malloc area is immediately below the monitor copy in RAM */
114 mem_malloc_init(CONFIG_SYS_MALLOC_BASE, CONFIG_SYS_MALLOC_LEN);
115
116#ifndef CONFIG_SYS_NO_FLASH
117 WATCHDOG_RESET();
118 bd->bi_flashsize = flash_init();
119#endif
120
121#ifdef CONFIG_CMD_NAND
122 puts("NAND: ");
123 nand_init();
124#endif
125
126#ifdef CONFIG_GENERIC_MMC
127 puts("MMC: ");
128 mmc_initialize(bd);
129#endif
130
131 WATCHDOG_RESET();
132 env_relocate();
133
134 WATCHDOG_RESET();
135 stdio_init();
136 jumptable_init();
137 console_init_r();
138
139 WATCHDOG_RESET();
140 interrupt_init();
141
142#if defined(CONFIG_BOARD_LATE_INIT)
143 board_late_init();
144#endif
145
146#if defined(CONFIG_CMD_NET)
147 puts("NET: ");
148 eth_initialize(bd);
149#endif
150
151 /* main_loop */
152 for (;;) {
153 WATCHDOG_RESET();
154 main_loop();
155 }
156}
157
158
159/***********************************************************************/
160
161void hang(void)
162{
163 disable_interrupts();
164 puts("### ERROR ### Please reset board ###\n");
165
166 for (;;)
167 ;
168}