blob: bb1a8a7340724bf232f7ecbfc833451df8f1bbfc [file] [log] [blame]
wdenkef3386f2004-10-10 21:27:30 +00001/*
2 * (C) Copyright 2003, Psyent Corporation <www.psyent.com>
3 * Scott McNutt <smcnutt@psyent.com>
4 *
5 * (C) Copyright 2000-2002
6 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
wdenkef3386f2004-10-10 21:27:30 +00009 */
10
11#include <common.h>
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +020012#include <stdio_dev.h>
wdenkef3386f2004-10-10 21:27:30 +000013#include <watchdog.h>
Peter Tysera78ded62009-08-21 23:05:19 -050014#include <malloc.h>
Thomas Chou232ce022010-04-22 17:27:16 +080015#include <mmc.h>
wdenkef3386f2004-10-10 21:27:30 +000016#include <net.h>
17#ifdef CONFIG_STATUS_LED
18#include <status_led.h>
19#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020020#if defined(CONFIG_SYS_NIOS_EPCSBASE)
Scott McNutt4fd37c02006-06-08 12:08:12 -040021#include <nios2-epcs.h>
22#endif
Thomas Chou232ce022010-04-22 17:27:16 +080023#ifdef CONFIG_CMD_NAND
24#include <nand.h> /* cannot even include nand.h if it isnt configured */
25#endif
wdenkef3386f2004-10-10 21:27:30 +000026
Wolfgang Denk6405a152006-03-31 18:32:53 +020027DECLARE_GLOBAL_DATA_PTR;
wdenkef3386f2004-10-10 21:27:30 +000028
29/*
30 * All attempts to come up with a "common" initialization sequence
31 * that works for all boards and architectures failed: some of the
32 * requirements are just _too_ different. To get rid of the resulting
33 * mess of board dependend #ifdef'ed code we now make the whole
34 * initialization sequence configurable to the user.
35 *
36 * The requirements for any new initalization function is simple: it
37 * receives a pointer to the "global data" structure as it's only
38 * argument, and returns an integer return code, where 0 means
39 * "continue" and != 0 means "fatal error, hang the system".
40 */
41
42
wdenkef3386f2004-10-10 21:27:30 +000043typedef int (init_fnc_t) (void);
44
wdenkef3386f2004-10-10 21:27:30 +000045
46/************************************************************************
47 * Initialization sequence *
48 ***********************************************************************/
49
50init_fnc_t *init_sequence[] = {
wdenkef3386f2004-10-10 21:27:30 +000051#if defined(CONFIG_BOARD_EARLY_INIT_F)
52 board_early_init_f, /* Call board-specific init code early.*/
53#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020054#if defined(CONFIG_SYS_NIOS_EPCSBASE)
Scott McNutt4fd37c02006-06-08 12:08:12 -040055 epcs_reset,
56#endif
wdenkef3386f2004-10-10 21:27:30 +000057
58 env_init,
59 serial_init,
60 console_init_f,
61 display_options,
62 checkcpu,
63 checkboard,
64 NULL, /* Terminate this list */
65};
66
67
68/***********************************************************************/
Andreas Bießmanned31d812013-04-18 22:48:47 +000069void board_init(void)
wdenkef3386f2004-10-10 21:27:30 +000070{
wdenkef3386f2004-10-10 21:27:30 +000071 bd_t *bd;
72 init_fnc_t **init_fnc_ptr;
Thomas Choufe06c182012-04-23 10:55:02 +080073 static gd_t gd_data;
74 static bd_t bd_data;
wdenkef3386f2004-10-10 21:27:30 +000075
Thomas Choufe06c182012-04-23 10:55:02 +080076 /* Pointer is writable since we allocated a register for it. */
77 gd = &gd_data;
wdenkef3386f2004-10-10 21:27:30 +000078 /* compiler optimization barrier needed for GCC >= 3.4 */
Andreas Bießmanned31d812013-04-18 22:48:47 +000079 __asm__ __volatile__("" : : : "memory");
wdenkef3386f2004-10-10 21:27:30 +000080
Thomas Choufe06c182012-04-23 10:55:02 +080081 gd->bd = &bd_data;
wdenkef3386f2004-10-10 21:27:30 +000082 gd->baudrate = CONFIG_BAUDRATE;
83 gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
84
85 bd = gd->bd;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020086 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
87 bd->bi_memsize = CONFIG_SYS_SDRAM_SIZE;
Thomas Chou232ce022010-04-22 17:27:16 +080088#ifndef CONFIG_SYS_NO_FLASH
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020089 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
Thomas Chou232ce022010-04-22 17:27:16 +080090#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020091#if defined(CONFIG_SYS_SRAM_BASE) && defined(CONFIG_SYS_SRAM_SIZE)
Andreas Bießmanned31d812013-04-18 22:48:47 +000092 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020093 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE;
wdenkef3386f2004-10-10 21:27:30 +000094#endif
95 bd->bi_baudrate = CONFIG_BAUDRATE;
96
97 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
Andreas Bießmanned31d812013-04-18 22:48:47 +000098 WATCHDOG_RESET();
99 if ((*init_fnc_ptr) () != 0)
100 hang();
wdenkef3386f2004-10-10 21:27:30 +0000101 }
102
Andreas Bießmanned31d812013-04-18 22:48:47 +0000103 WATCHDOG_RESET();
Peter Tyser781c9b82009-08-21 23:05:21 -0500104
105 /* The Malloc area is immediately below the monitor copy in RAM */
Peter Tysered527702009-08-21 23:05:20 -0500106 mem_malloc_init(CONFIG_SYS_MALLOC_BASE, CONFIG_SYS_MALLOC_LEN);
Stefan Roeseb81464e2009-05-11 15:50:12 +0200107
Thomas Chou232ce022010-04-22 17:27:16 +0800108#ifndef CONFIG_SYS_NO_FLASH
Andreas Bießmanned31d812013-04-18 22:48:47 +0000109 WATCHDOG_RESET();
wdenkef3386f2004-10-10 21:27:30 +0000110 bd->bi_flashsize = flash_init();
Thomas Chou232ce022010-04-22 17:27:16 +0800111#endif
112
113#ifdef CONFIG_CMD_NAND
114 puts("NAND: ");
115 nand_init();
116#endif
117
118#ifdef CONFIG_GENERIC_MMC
119 puts("MMC: ");
120 mmc_initialize(bd);
121#endif
wdenkef3386f2004-10-10 21:27:30 +0000122
Andreas Bießmanned31d812013-04-18 22:48:47 +0000123 WATCHDOG_RESET();
wdenkef3386f2004-10-10 21:27:30 +0000124 env_relocate();
125
Andreas Bießmanned31d812013-04-18 22:48:47 +0000126 WATCHDOG_RESET();
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200127 stdio_init();
wdenkef3386f2004-10-10 21:27:30 +0000128 jumptable_init();
129 console_init_r();
130
Andreas Bießmanned31d812013-04-18 22:48:47 +0000131 WATCHDOG_RESET();
132 interrupt_init();
wdenkef3386f2004-10-10 21:27:30 +0000133
Scott McNutt4fd37c02006-06-08 12:08:12 -0400134#if defined(CONFIG_BOARD_LATE_INIT)
Andreas Bießmanned31d812013-04-18 22:48:47 +0000135 board_late_init();
Scott McNutt4fd37c02006-06-08 12:08:12 -0400136#endif
137
Scott McNutt5cfa9c02010-03-21 13:26:33 -0400138#if defined(CONFIG_CMD_NET)
Andreas Bießmanned31d812013-04-18 22:48:47 +0000139 puts("Net: ");
140 eth_initialize(bd);
Scott McNutt5cfa9c02010-03-21 13:26:33 -0400141#endif
142
wdenkef3386f2004-10-10 21:27:30 +0000143 /* main_loop */
144 for (;;) {
Andreas Bießmanned31d812013-04-18 22:48:47 +0000145 WATCHDOG_RESET();
146 main_loop();
wdenkef3386f2004-10-10 21:27:30 +0000147 }
148}