blob: bb1a8a7340724bf232f7ecbfc833451df8f1bbfc [file] [log] [blame]
wdenk5c952cf2004-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 Denk1a459662013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
wdenk5c952cf2004-10-10 21:27:30 +00009 */
10
11#include <common.h>
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +020012#include <stdio_dev.h>
wdenk5c952cf2004-10-10 21:27:30 +000013#include <watchdog.h>
Peter Tyser5e93bd12009-08-21 23:05:19 -050014#include <malloc.h>
Thomas Chou441cac12010-04-22 17:27:16 +080015#include <mmc.h>
wdenk5c952cf2004-10-10 21:27:30 +000016#include <net.h>
17#ifdef CONFIG_STATUS_LED
18#include <status_led.h>
19#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020020#if defined(CONFIG_SYS_NIOS_EPCSBASE)
Scott McNutt1f6ce8f2006-06-08 12:08:12 -040021#include <nios2-epcs.h>
22#endif
Thomas Chou441cac12010-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
wdenk5c952cf2004-10-10 21:27:30 +000026
Wolfgang Denkd87080b2006-03-31 18:32:53 +020027DECLARE_GLOBAL_DATA_PTR;
wdenk5c952cf2004-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
wdenk5c952cf2004-10-10 21:27:30 +000043typedef int (init_fnc_t) (void);
44
wdenk5c952cf2004-10-10 21:27:30 +000045
46/************************************************************************
47 * Initialization sequence *
48 ***********************************************************************/
49
50init_fnc_t *init_sequence[] = {
wdenk5c952cf2004-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-VILLARD6d0f6bc2008-10-16 15:01:15 +020054#if defined(CONFIG_SYS_NIOS_EPCSBASE)
Scott McNutt1f6ce8f2006-06-08 12:08:12 -040055 epcs_reset,
56#endif
wdenk5c952cf2004-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ßmann63495ad2013-04-18 22:48:47 +000069void board_init(void)
wdenk5c952cf2004-10-10 21:27:30 +000070{
wdenk5c952cf2004-10-10 21:27:30 +000071 bd_t *bd;
72 init_fnc_t **init_fnc_ptr;
Thomas Chou7dfb0602012-04-23 10:55:02 +080073 static gd_t gd_data;
74 static bd_t bd_data;
wdenk5c952cf2004-10-10 21:27:30 +000075
Thomas Chou7dfb0602012-04-23 10:55:02 +080076 /* Pointer is writable since we allocated a register for it. */
77 gd = &gd_data;
wdenk5c952cf2004-10-10 21:27:30 +000078 /* compiler optimization barrier needed for GCC >= 3.4 */
Andreas Bießmann63495ad2013-04-18 22:48:47 +000079 __asm__ __volatile__("" : : : "memory");
wdenk5c952cf2004-10-10 21:27:30 +000080
Thomas Chou7dfb0602012-04-23 10:55:02 +080081 gd->bd = &bd_data;
wdenk5c952cf2004-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-VILLARD6d0f6bc2008-10-16 15:01:15 +020086 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
87 bd->bi_memsize = CONFIG_SYS_SDRAM_SIZE;
Thomas Chou441cac12010-04-22 17:27:16 +080088#ifndef CONFIG_SYS_NO_FLASH
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020089 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
Thomas Chou441cac12010-04-22 17:27:16 +080090#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020091#if defined(CONFIG_SYS_SRAM_BASE) && defined(CONFIG_SYS_SRAM_SIZE)
Andreas Bießmann63495ad2013-04-18 22:48:47 +000092 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020093 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE;
wdenk5c952cf2004-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ßmann63495ad2013-04-18 22:48:47 +000098 WATCHDOG_RESET();
99 if ((*init_fnc_ptr) () != 0)
100 hang();
wdenk5c952cf2004-10-10 21:27:30 +0000101 }
102
Andreas Bießmann63495ad2013-04-18 22:48:47 +0000103 WATCHDOG_RESET();
Peter Tyserd4e8ada2009-08-21 23:05:21 -0500104
105 /* The Malloc area is immediately below the monitor copy in RAM */
Peter Tysera483a162009-08-21 23:05:20 -0500106 mem_malloc_init(CONFIG_SYS_MALLOC_BASE, CONFIG_SYS_MALLOC_LEN);
Stefan Roesec790b042009-05-11 15:50:12 +0200107
Thomas Chou441cac12010-04-22 17:27:16 +0800108#ifndef CONFIG_SYS_NO_FLASH
Andreas Bießmann63495ad2013-04-18 22:48:47 +0000109 WATCHDOG_RESET();
wdenk5c952cf2004-10-10 21:27:30 +0000110 bd->bi_flashsize = flash_init();
Thomas Chou441cac12010-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
wdenk5c952cf2004-10-10 21:27:30 +0000122
Andreas Bießmann63495ad2013-04-18 22:48:47 +0000123 WATCHDOG_RESET();
wdenk5c952cf2004-10-10 21:27:30 +0000124 env_relocate();
125
Andreas Bießmann63495ad2013-04-18 22:48:47 +0000126 WATCHDOG_RESET();
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200127 stdio_init();
wdenk5c952cf2004-10-10 21:27:30 +0000128 jumptable_init();
129 console_init_r();
130
Andreas Bießmann63495ad2013-04-18 22:48:47 +0000131 WATCHDOG_RESET();
132 interrupt_init();
wdenk5c952cf2004-10-10 21:27:30 +0000133
Scott McNutt1f6ce8f2006-06-08 12:08:12 -0400134#if defined(CONFIG_BOARD_LATE_INIT)
Andreas Bießmann63495ad2013-04-18 22:48:47 +0000135 board_late_init();
Scott McNutt1f6ce8f2006-06-08 12:08:12 -0400136#endif
137
Scott McNutt3fd2a1f2010-03-21 13:26:33 -0400138#if defined(CONFIG_CMD_NET)
Andreas Bießmann63495ad2013-04-18 22:48:47 +0000139 puts("Net: ");
140 eth_initialize(bd);
Scott McNutt3fd2a1f2010-03-21 13:26:33 -0400141#endif
142
wdenk5c952cf2004-10-10 21:27:30 +0000143 /* main_loop */
144 for (;;) {
Andreas Bießmann63495ad2013-04-18 22:48:47 +0000145 WATCHDOG_RESET();
146 main_loop();
wdenk5c952cf2004-10-10 21:27:30 +0000147 }
148}