wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 1 | /* |
| 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 Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 12 | #include <stdio_dev.h> |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 13 | #include <watchdog.h> |
Peter Tyser | a78ded6 | 2009-08-21 23:05:19 -0500 | [diff] [blame] | 14 | #include <malloc.h> |
Thomas Chou | 232ce02 | 2010-04-22 17:27:16 +0800 | [diff] [blame] | 15 | #include <mmc.h> |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 16 | #include <net.h> |
| 17 | #ifdef CONFIG_STATUS_LED |
| 18 | #include <status_led.h> |
| 19 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 20 | #if defined(CONFIG_SYS_NIOS_EPCSBASE) |
Scott McNutt | 4fd37c0 | 2006-06-08 12:08:12 -0400 | [diff] [blame] | 21 | #include <nios2-epcs.h> |
| 22 | #endif |
Thomas Chou | 232ce02 | 2010-04-22 17:27:16 +0800 | [diff] [blame] | 23 | #ifdef CONFIG_CMD_NAND |
| 24 | #include <nand.h> /* cannot even include nand.h if it isnt configured */ |
| 25 | #endif |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 26 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 27 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 28 | |
| 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 | |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 43 | typedef int (init_fnc_t) (void); |
| 44 | |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 45 | |
| 46 | /************************************************************************ |
| 47 | * Initialization sequence * |
| 48 | ***********************************************************************/ |
| 49 | |
| 50 | init_fnc_t *init_sequence[] = { |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 51 | #if defined(CONFIG_BOARD_EARLY_INIT_F) |
| 52 | board_early_init_f, /* Call board-specific init code early.*/ |
| 53 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 54 | #if defined(CONFIG_SYS_NIOS_EPCSBASE) |
Scott McNutt | 4fd37c0 | 2006-06-08 12:08:12 -0400 | [diff] [blame] | 55 | epcs_reset, |
| 56 | #endif |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 57 | |
| 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ßmann | ed31d81 | 2013-04-18 22:48:47 +0000 | [diff] [blame] | 69 | void board_init(void) |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 70 | { |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 71 | bd_t *bd; |
| 72 | init_fnc_t **init_fnc_ptr; |
Thomas Chou | fe06c18 | 2012-04-23 10:55:02 +0800 | [diff] [blame] | 73 | static gd_t gd_data; |
| 74 | static bd_t bd_data; |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 75 | |
Thomas Chou | fe06c18 | 2012-04-23 10:55:02 +0800 | [diff] [blame] | 76 | /* Pointer is writable since we allocated a register for it. */ |
| 77 | gd = &gd_data; |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 78 | /* compiler optimization barrier needed for GCC >= 3.4 */ |
Andreas Bießmann | ed31d81 | 2013-04-18 22:48:47 +0000 | [diff] [blame] | 79 | __asm__ __volatile__("" : : : "memory"); |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 80 | |
Thomas Chou | fe06c18 | 2012-04-23 10:55:02 +0800 | [diff] [blame] | 81 | gd->bd = &bd_data; |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 82 | gd->baudrate = CONFIG_BAUDRATE; |
| 83 | gd->cpu_clk = CONFIG_SYS_CLK_FREQ; |
| 84 | |
| 85 | bd = gd->bd; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 86 | bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; |
| 87 | bd->bi_memsize = CONFIG_SYS_SDRAM_SIZE; |
Thomas Chou | 232ce02 | 2010-04-22 17:27:16 +0800 | [diff] [blame] | 88 | #ifndef CONFIG_SYS_NO_FLASH |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 89 | bd->bi_flashstart = CONFIG_SYS_FLASH_BASE; |
Thomas Chou | 232ce02 | 2010-04-22 17:27:16 +0800 | [diff] [blame] | 90 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 91 | #if defined(CONFIG_SYS_SRAM_BASE) && defined(CONFIG_SYS_SRAM_SIZE) |
Andreas Bießmann | ed31d81 | 2013-04-18 22:48:47 +0000 | [diff] [blame] | 92 | bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 93 | bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 94 | #endif |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 95 | |
| 96 | for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) { |
Andreas Bießmann | ed31d81 | 2013-04-18 22:48:47 +0000 | [diff] [blame] | 97 | WATCHDOG_RESET(); |
| 98 | if ((*init_fnc_ptr) () != 0) |
| 99 | hang(); |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Andreas Bießmann | ed31d81 | 2013-04-18 22:48:47 +0000 | [diff] [blame] | 102 | WATCHDOG_RESET(); |
Peter Tyser | 781c9b8 | 2009-08-21 23:05:21 -0500 | [diff] [blame] | 103 | |
| 104 | /* The Malloc area is immediately below the monitor copy in RAM */ |
Peter Tyser | ed52770 | 2009-08-21 23:05:20 -0500 | [diff] [blame] | 105 | mem_malloc_init(CONFIG_SYS_MALLOC_BASE, CONFIG_SYS_MALLOC_LEN); |
Stefan Roese | b81464e | 2009-05-11 15:50:12 +0200 | [diff] [blame] | 106 | |
Thomas Chou | 232ce02 | 2010-04-22 17:27:16 +0800 | [diff] [blame] | 107 | #ifndef CONFIG_SYS_NO_FLASH |
Andreas Bießmann | ed31d81 | 2013-04-18 22:48:47 +0000 | [diff] [blame] | 108 | WATCHDOG_RESET(); |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 109 | bd->bi_flashsize = flash_init(); |
Thomas Chou | 232ce02 | 2010-04-22 17:27:16 +0800 | [diff] [blame] | 110 | #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 |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 121 | |
Andreas Bießmann | ed31d81 | 2013-04-18 22:48:47 +0000 | [diff] [blame] | 122 | WATCHDOG_RESET(); |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 123 | env_relocate(); |
| 124 | |
Andreas Bießmann | ed31d81 | 2013-04-18 22:48:47 +0000 | [diff] [blame] | 125 | WATCHDOG_RESET(); |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 126 | stdio_init(); |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 127 | jumptable_init(); |
| 128 | console_init_r(); |
| 129 | |
Andreas Bießmann | ed31d81 | 2013-04-18 22:48:47 +0000 | [diff] [blame] | 130 | WATCHDOG_RESET(); |
| 131 | interrupt_init(); |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 132 | |
Scott McNutt | 4fd37c0 | 2006-06-08 12:08:12 -0400 | [diff] [blame] | 133 | #if defined(CONFIG_BOARD_LATE_INIT) |
Andreas Bießmann | ed31d81 | 2013-04-18 22:48:47 +0000 | [diff] [blame] | 134 | board_late_init(); |
Scott McNutt | 4fd37c0 | 2006-06-08 12:08:12 -0400 | [diff] [blame] | 135 | #endif |
| 136 | |
Scott McNutt | 5cfa9c0 | 2010-03-21 13:26:33 -0400 | [diff] [blame] | 137 | #if defined(CONFIG_CMD_NET) |
Andreas Bießmann | ed31d81 | 2013-04-18 22:48:47 +0000 | [diff] [blame] | 138 | puts("Net: "); |
| 139 | eth_initialize(bd); |
Scott McNutt | 5cfa9c0 | 2010-03-21 13:26:33 -0400 | [diff] [blame] | 140 | #endif |
| 141 | |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 142 | /* main_loop */ |
| 143 | for (;;) { |
Andreas Bießmann | ed31d81 | 2013-04-18 22:48:47 +0000 | [diff] [blame] | 144 | WATCHDOG_RESET(); |
| 145 | main_loop(); |
wdenk | ef3386f | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 146 | } |
| 147 | } |