blob: f24218ff1c1f269fcba0cc8f63d24ca196b155f5 [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
wdenkef3386f2004-10-10 21:27:30 +000095
96 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
Andreas Bießmanned31d812013-04-18 22:48:47 +000097 WATCHDOG_RESET();
98 if ((*init_fnc_ptr) () != 0)
99 hang();
wdenkef3386f2004-10-10 21:27:30 +0000100 }
101
Andreas Bießmanned31d812013-04-18 22:48:47 +0000102 WATCHDOG_RESET();
Peter Tyser781c9b82009-08-21 23:05:21 -0500103
104 /* The Malloc area is immediately below the monitor copy in RAM */
Peter Tysered527702009-08-21 23:05:20 -0500105 mem_malloc_init(CONFIG_SYS_MALLOC_BASE, CONFIG_SYS_MALLOC_LEN);
Stefan Roeseb81464e2009-05-11 15:50:12 +0200106
Thomas Chou232ce022010-04-22 17:27:16 +0800107#ifndef CONFIG_SYS_NO_FLASH
Andreas Bießmanned31d812013-04-18 22:48:47 +0000108 WATCHDOG_RESET();
wdenkef3386f2004-10-10 21:27:30 +0000109 bd->bi_flashsize = flash_init();
Thomas Chou232ce022010-04-22 17:27:16 +0800110#endif
111
112#ifdef CONFIG_CMD_NAND
113 puts("NAND: ");
114 nand_init();
115#endif
116
117#ifdef CONFIG_GENERIC_MMC
118 puts("MMC: ");
119 mmc_initialize(bd);
120#endif
wdenkef3386f2004-10-10 21:27:30 +0000121
Andreas Bießmanned31d812013-04-18 22:48:47 +0000122 WATCHDOG_RESET();
wdenkef3386f2004-10-10 21:27:30 +0000123 env_relocate();
124
Andreas Bießmanned31d812013-04-18 22:48:47 +0000125 WATCHDOG_RESET();
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200126 stdio_init();
wdenkef3386f2004-10-10 21:27:30 +0000127 jumptable_init();
128 console_init_r();
129
Andreas Bießmanned31d812013-04-18 22:48:47 +0000130 WATCHDOG_RESET();
131 interrupt_init();
wdenkef3386f2004-10-10 21:27:30 +0000132
Scott McNutt4fd37c02006-06-08 12:08:12 -0400133#if defined(CONFIG_BOARD_LATE_INIT)
Andreas Bießmanned31d812013-04-18 22:48:47 +0000134 board_late_init();
Scott McNutt4fd37c02006-06-08 12:08:12 -0400135#endif
136
Scott McNutt5cfa9c02010-03-21 13:26:33 -0400137#if defined(CONFIG_CMD_NET)
Andreas Bießmanned31d812013-04-18 22:48:47 +0000138 puts("Net: ");
139 eth_initialize(bd);
Scott McNutt5cfa9c02010-03-21 13:26:33 -0400140#endif
141
wdenkef3386f2004-10-10 21:27:30 +0000142 /* main_loop */
143 for (;;) {
Andreas Bießmanned31d812013-04-18 22:48:47 +0000144 WATCHDOG_RESET();
145 main_loop();
wdenkef3386f2004-10-10 21:27:30 +0000146 }
147}