blob: 32d025a34237c89c443314035f58c3f6264105f3 [file] [log] [blame]
Daniel Hellstromc2f02da2008-03-28 09:47:00 +01001/* SPARC Board initialization
2 *
3 * (C) Copyright 2000-2006
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 *
6 * (C) Copyright 2007
7 * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com.
8 *
9 * See file CREDITS for list of people who contributed to this
10 * project.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * MA 02111-1307 USA
26 */
27
28#include <common.h>
29#include <command.h>
30#include <malloc.h>
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +020031#include <stdio_dev.h>
Daniel Hellstromc2f02da2008-03-28 09:47:00 +010032#include <config.h>
33#if defined(CONFIG_CMD_IDE)
34#include <ide.h>
35#endif
36#ifdef CONFIG_STATUS_LED
37#include <status_led.h>
38#endif
39#include <net.h>
40#include <serial.h>
41#include <version.h>
42#if defined(CONFIG_POST)
43#include <post.h>
44#endif
45#ifdef CONFIG_PS2KBD
46#include <keyboard.h>
47#endif
48#ifdef CONFIG_CMD_AMBAPP
49#include <ambapp.h>
50#endif
51
Luigi 'Comio' Mantellini310cecb2009-10-10 12:42:21 +020052#ifdef CONFIG_BITBANGMII
53#include <miiphy.h>
54#endif
55
Daniel Hellstromc2f02da2008-03-28 09:47:00 +010056DECLARE_GLOBAL_DATA_PTR;
57
58/* Debug options
59#define DEBUG_INIT_SEQUENCE
60#define DEBUG_MEM_LAYOUT
61#define DEBUG_COMMANDS
62*/
63
64extern void timer_interrupt_init(void);
Wolfgang Denk54841ab2010-06-28 22:00:46 +020065extern int do_ambapp_print(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]);
Daniel Hellstromc2f02da2008-03-28 09:47:00 +010066extern int prom_init(void);
67
68#if defined(CONFIG__CMD_DOC)
69void doc_init(void);
70#endif
71
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020072#if !defined(CONFIG_SYS_NO_FLASH)
Daniel Hellstromc2f02da2008-03-28 09:47:00 +010073static char *failed = "*** failed ***\n";
74#endif
75
76#include <environment.h>
77
78ulong monitor_flash_len;
79
Daniel Hellstromc2f02da2008-03-28 09:47:00 +010080/************************************************************************
Daniel Hellstromc2f02da2008-03-28 09:47:00 +010081 * Init Utilities *
82 ************************************************************************
83 * Some of this code should be moved into the core functions,
84 * but let's get it working (again) first...
85 */
86
87static int init_baudrate(void)
88{
Simon Glass74593742011-10-13 14:43:13 +000089 gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
90 return 0;
Daniel Hellstromc2f02da2008-03-28 09:47:00 +010091}
92
93/***********************************************************************/
94
95/*
96 * All attempts to come up with a "common" initialization sequence
97 * that works for all boards and architectures failed: some of the
98 * requirements are just _too_ different. To get rid of the resulting
99 * mess of board dependend #ifdef'ed code we now make the whole
100 * initialization sequence configurable to the user.
101 *
102 * The requirements for any new initalization function is simple: it
103 * receives a pointer to the "global data" structure as it's only
104 * argument, and returns an integer return code, where 0 means
105 * "continue" and != 0 means "fatal error, hang the system".
106 */
107typedef int (init_fnc_t) (void);
108
109#define WATCHDOG_RESET(x)
110
111/************************************************************************
112 * Initialization sequence *
113 ************************************************************************
114 */
115
116init_fnc_t *init_sequence[] = {
117
118#if defined(CONFIG_BOARD_EARLY_INIT_F)
119 board_early_init_f,
120#endif
121 serial_init,
122
123 init_timebase,
124
125#if defined(CONFIG_CMD_AMBAPP)
126 ambapp_init_reloc,
127#endif
128
129 env_init,
130
131 init_baudrate,
132
133 console_init_f,
134 display_options,
135
136 checkcpu,
137 checkboard,
138#if defined(CONFIG_MISC_INIT_F)
139 misc_init_f,
140#endif
141
142#ifdef CONFIG_POST
143 post_init_f,
144#endif
145
146 NULL, /* Terminate this list,
147 * beware: this list will be relocated
148 * which means that NULL will become
149 * NULL+RELOC_OFFSET. We simply make
150 * NULL be -RELOC_OFFSET instead.
151 */
152};
153
154/************************************************************************
155 *
156 * This is the SPARC board initialization routine, running from RAM.
157 *
158 ************************************************************************
159 */
160#ifdef DEBUG_INIT_SEQUENCE
161char *str_init_seq = "INIT_SEQ 00\n";
162char *str_init_seq_done = "\n\rInit sequence done...\r\n\r\n";
163#endif
164
165void board_init_f(ulong bootflag)
166{
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100167 bd_t *bd;
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100168 init_fnc_t **init_fnc_ptr;
169 int j;
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100170
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200171#ifndef CONFIG_SYS_NO_FLASH
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100172 ulong flash_size;
173#endif
174
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200175 gd = (gd_t *) (CONFIG_SYS_GBL_DATA_OFFSET);
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100176
177 /* Clear initial global data */
178 memset((void *)gd, 0, sizeof(gd_t));
179
180 gd->bd = (bd_t *) (gd + 1); /* At end of global data */
181 gd->baudrate = CONFIG_BAUDRATE;
182 gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
183
184 bd = gd->bd;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200185 bd->bi_memstart = CONFIG_SYS_RAM_BASE;
186 bd->bi_memsize = CONFIG_SYS_RAM_SIZE;
187 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
188#if defined(CONFIG_SYS_SRAM_BASE) && defined(CONFIG_SYS_SRAM_SIZE)
189 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE;
190 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE;
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100191#endif
192 bd->bi_baudrate = CONFIG_BAUDRATE;
193 bd->bi_bootflags = bootflag; /* boot / reboot flag (for LynxOS) */
194
195 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200196 gd->reloc_off = CONFIG_SYS_RELOC_MONITOR_BASE - CONFIG_SYS_MONITOR_BASE;
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100197
198 for (init_fnc_ptr = init_sequence, j = 0; *init_fnc_ptr;
199 ++init_fnc_ptr, j++) {
200#ifdef DEBUG_INIT_SEQUENCE
201 if (j > 9)
202 str_init_seq[9] = '0' + (j / 10);
203 str_init_seq[10] = '0' + (j - (j / 10) * 10);
204 serial_puts(str_init_seq);
205#endif
206 if ((*init_fnc_ptr + gd->reloc_off) () != 0) {
207 hang();
208 }
209 }
210#ifdef DEBUG_INIT_SEQUENCE
211 serial_puts(str_init_seq_done);
212#endif
213
214 /*
215 * Now that we have DRAM mapped and working, we can
216 * relocate the code and continue running from DRAM.
217 *
218 * Reserve memory at end of RAM for (top down in that order):
219 * - kernel log buffer
220 * - protected RAM
221 * - LCD framebuffer
222 * - monitor code
223 * - board info struct
224 */
225#ifdef DEBUG_MEM_LAYOUT
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200226 printf("CONFIG_SYS_MONITOR_BASE: 0x%lx\n", CONFIG_SYS_MONITOR_BASE);
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200227 printf("CONFIG_ENV_ADDR: 0x%lx\n", CONFIG_ENV_ADDR);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200228 printf("CONFIG_SYS_RELOC_MONITOR_BASE: 0x%lx (%d)\n", CONFIG_SYS_RELOC_MONITOR_BASE,
229 CONFIG_SYS_MONITOR_LEN);
230 printf("CONFIG_SYS_MALLOC_BASE: 0x%lx (%d)\n", CONFIG_SYS_MALLOC_BASE,
231 CONFIG_SYS_MALLOC_LEN);
232 printf("CONFIG_SYS_INIT_SP_OFFSET: 0x%lx (%d)\n", CONFIG_SYS_INIT_SP_OFFSET,
233 CONFIG_SYS_STACK_SIZE);
234 printf("CONFIG_SYS_PROM_OFFSET: 0x%lx (%d)\n", CONFIG_SYS_PROM_OFFSET,
235 CONFIG_SYS_PROM_SIZE);
236 printf("CONFIG_SYS_GBL_DATA_OFFSET: 0x%lx (%d)\n", CONFIG_SYS_GBL_DATA_OFFSET,
Wolfgang Denk25ddd1f2010-10-26 14:34:52 +0200237 GENERATED_GBL_DATA_SIZE);
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100238#endif
239
240#ifdef CONFIG_POST
241 post_bootmode_init();
242 post_run(NULL, POST_ROM | post_bootmode_get(0));
243#endif
244
Wolfgang Denk2e5167c2010-10-28 20:00:11 +0200245#if defined(CONFIG_NEEDS_MANUAL_RELOC)
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100246 /*
247 * We have to relocate the command table manually
248 */
Marek Vasut6c7c9462012-10-12 10:27:04 +0000249 fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd),
250 ll_entry_count(cmd_tbl_t, cmd));
Wolfgang Denk2e5167c2010-10-28 20:00:11 +0200251#endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100252
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200253#if defined(CONFIG_CMD_AMBAPP) && defined(CONFIG_SYS_AMBAPP_PRINT_ON_STARTUP)
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100254 puts("AMBA:\n");
255 do_ambapp_print(NULL, 0, 0, NULL);
256#endif
257
258 /* initialize higher level parts of CPU like time base and timers */
259 cpu_init_r();
260
261 /* start timer */
262 timer_interrupt_init();
263
264 /*
265 * Enable Interrupts before any calls to udelay,
266 * the flash driver may use udelay resulting in
267 * a hang if not timer0 IRQ is enabled.
268 */
269 interrupt_init();
270
Peter Tyserd4e8ada2009-08-21 23:05:21 -0500271 /* The Malloc area is immediately below the monitor copy in RAM */
Peter Tysera483a162009-08-21 23:05:20 -0500272 mem_malloc_init(CONFIG_SYS_MALLOC_BASE,
273 CONFIG_SYS_MALLOC_END - CONFIG_SYS_MALLOC_BASE);
Stefan Roesec790b042009-05-11 15:50:12 +0200274 malloc_bin_reloc();
275
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200276#if !defined(CONFIG_SYS_NO_FLASH)
Peter Tysereddf52b2010-12-28 18:12:05 -0600277 puts("Flash: ");
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100278
279 if ((flash_size = flash_init()) > 0) {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200280# ifdef CONFIG_SYS_FLASH_CHECKSUM
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100281 print_size(flash_size, "");
282 /*
283 * Compute and print flash CRC if flashchecksum is set to 'y'
284 *
285 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
286 */
287 s = getenv("flashchecksum");
288 if (s && (*s == 'y')) {
289 printf(" CRC: %08lX",
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200290 crc32(0, (const unsigned char *)CONFIG_SYS_FLASH_BASE,
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100291 flash_size)
292 );
293 }
294 putc('\n');
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200295# else /* !CONFIG_SYS_FLASH_CHECKSUM */
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100296 print_size(flash_size, "\n");
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200297# endif /* CONFIG_SYS_FLASH_CHECKSUM */
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100298 } else {
299 puts(failed);
300 hang();
301 }
302
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200303 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE; /* update start of FLASH memory */
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100304 bd->bi_flashsize = flash_size; /* size of FLASH memory (final value) */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200305#if CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100306 bd->bi_flashoffset = monitor_flash_len; /* reserved area for startup monitor */
307#else
308 bd->bi_flashoffset = 0;
309#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200310#else /* CONFIG_SYS_NO_FLASH */
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100311 bd->bi_flashsize = 0;
312 bd->bi_flashstart = 0;
313 bd->bi_flashoffset = 0;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200314#endif /* !CONFIG_SYS_NO_FLASH */
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100315
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100316#ifdef CONFIG_SPI
Jean-Christophe PLAGNIOL-VILLARDbb1f8b42008-09-05 09:19:30 +0200317# if !defined(CONFIG_ENV_IS_IN_EEPROM)
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100318 spi_init_f();
319# endif
320 spi_init_r();
321#endif
322
323 /* relocate environment function pointers etc. */
324 env_relocate();
325
326#if defined(CONFIG_BOARD_LATE_INIT)
327 board_late_init();
328#endif
329
Jean-Christophe PLAGNIOL-VILLARD32628c52008-08-30 23:54:58 +0200330#ifdef CONFIG_ID_EEPROM
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100331 mac_read_from_eeprom();
332#endif
333
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100334#if defined(CONFIG_PCI)
335 /*
336 * Do pci configuration
337 */
338 pci_init();
339#endif
340
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200341 /* Initialize stdio devices */
342 stdio_init();
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100343
344 /* Initialize the jump table for applications */
345 jumptable_init();
346
347 /* Initialize the console (after the relocation and devices init) */
348 console_init_r();
349
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100350#ifdef CONFIG_STATUS_LED
351 status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
352#endif
353
354 udelay(20);
355
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100356 /* Initialize from environment */
Simon Glass74593742011-10-13 14:43:13 +0000357 load_addr = getenv_ulong("loadaddr", 16, load_addr);
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100358
359 WATCHDOG_RESET();
360
361#if defined(CONFIG_CMD_DOC)
362 WATCHDOG_RESET();
363 puts("DOC: ");
364 doc_init();
365#endif
366
Luigi 'Comio' Mantellini310cecb2009-10-10 12:42:21 +0200367#ifdef CONFIG_BITBANGMII
368 bb_miiphy_init();
369#endif
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100370#if defined(CONFIG_CMD_NET)
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100371 WATCHDOG_RESET();
372 puts("Net: ");
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100373 eth_initialize(bd);
374#endif
375
376#if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
377 WATCHDOG_RESET();
378 debug("Reset Ethernet PHY\n");
379 reset_phy();
380#endif
381
382#ifdef CONFIG_POST
383 post_run(NULL, POST_RAM | post_bootmode_get(0));
384#endif
385
386#if defined(CONFIG_CMD_IDE)
387 WATCHDOG_RESET();
388 puts("IDE: ");
389 ide_init();
Stefan Roesef2302d42008-08-06 14:05:38 +0200390#endif /* CONFIG_CMD_IDE */
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100391
392#ifdef CONFIG_LAST_STAGE_INIT
393 WATCHDOG_RESET();
394 /*
395 * Some parts can be only initialized if all others (like
396 * Interrupts) are up and running (i.e. the PC-style ISA
397 * keyboard).
398 */
399 last_stage_init();
400#endif
401
402#ifdef CONFIG_PS2KBD
403 puts("PS/2: ");
404 kbd_init();
405#endif
406 prom_init();
407
408 /* main_loop */
409 for (;;) {
410 WATCHDOG_RESET();
411 main_loop();
412 }
413
414}
415
416void hang(void)
417{
418 puts("### ERROR ### Please RESET the board ###\n");
419#ifdef CONFIG_SHOW_BOOT_PROGRESS
Simon Glass770605e2012-02-13 13:51:18 +0000420 bootstage_error(BOOTSTAGE_ID_NEED_RESET);
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100421#endif
422 for (;;) ;
423}
424
425/************************************************************************/