Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 1 | /* |
Yusuke Goda | 1a2334a | 2008-03-05 14:30:02 +0900 | [diff] [blame] | 2 | * Copyright (C) 2007,2008 |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 3 | * Nobuhiro Iwamatsu <iwamatsu@nigauri.org> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
| 7 | * published by the Free Software Foundation; either version 2 of |
| 8 | * the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 18 | * MA 02111-1307 USA |
| 19 | */ |
| 20 | |
| 21 | #include <common.h> |
| 22 | #include <command.h> |
| 23 | #include <malloc.h> |
| 24 | #include <devices.h> |
| 25 | #include <version.h> |
| 26 | #include <net.h> |
| 27 | #include <environment.h> |
| 28 | |
| 29 | extern void malloc_bin_reloc (void); |
| 30 | extern int cpu_init(void); |
| 31 | extern int board_init(void); |
| 32 | extern int dram_init(void); |
| 33 | extern int watchdog_init(void); |
| 34 | extern int timer_init(void); |
| 35 | |
| 36 | const char version_string[] = U_BOOT_VERSION" (" __DATE__ " - " __TIME__ ")"; |
| 37 | |
| 38 | unsigned long monitor_flash_len = CFG_MONITOR_LEN; |
| 39 | |
| 40 | static unsigned long mem_malloc_start; |
| 41 | static unsigned long mem_malloc_end; |
| 42 | static unsigned long mem_malloc_brk; |
| 43 | |
| 44 | static void mem_malloc_init (void) |
| 45 | { |
| 46 | |
| 47 | mem_malloc_start = (TEXT_BASE - CFG_GBL_DATA_SIZE - CFG_MALLOC_LEN); |
| 48 | mem_malloc_end = (mem_malloc_start + CFG_MALLOC_LEN - 16); |
| 49 | mem_malloc_brk = mem_malloc_start; |
Wolfgang Denk | 61fb15c5 | 2007-12-27 01:52:50 +0100 | [diff] [blame] | 50 | memset ((void *) mem_malloc_start, 0, |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 51 | (mem_malloc_end - mem_malloc_start)); |
| 52 | } |
| 53 | |
| 54 | void *sbrk (ptrdiff_t increment) |
| 55 | { |
| 56 | unsigned long old = mem_malloc_brk; |
| 57 | unsigned long new = old + increment; |
| 58 | |
| 59 | if ((new < mem_malloc_start) || |
| 60 | (new > mem_malloc_end)) { |
| 61 | return NULL; |
| 62 | } |
| 63 | |
| 64 | mem_malloc_brk = new; |
| 65 | return (void *) old; |
| 66 | } |
| 67 | |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 68 | static int sh_flash_init(void) |
| 69 | { |
| 70 | DECLARE_GLOBAL_DATA_PTR; |
| 71 | |
| 72 | gd->bd->bi_flashsize = flash_init(); |
| 73 | printf("FLASH: %dMB\n", gd->bd->bi_flashsize / (1024*1024)); |
| 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | #if defined(CONFIG_CMD_NAND) |
Scott Wood | d6ac2ed | 2008-05-22 10:49:46 -0500 | [diff] [blame] | 79 | #include <nand.h> |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 80 | static int sh_nand_init(void) |
| 81 | { |
| 82 | printf("NAND: "); |
| 83 | nand_init(); /* go init the NAND */ |
| 84 | return 0; |
| 85 | } |
| 86 | #endif /* CONFIG_CMD_NAND */ |
| 87 | |
| 88 | #if defined(CONFIG_CMD_IDE) |
| 89 | #include <ide.h> |
| 90 | static int sh_marubun_init(void) |
| 91 | { |
| 92 | puts ("IDE: "); |
| 93 | ide_init(); |
| 94 | return 0; |
| 95 | } |
| 96 | #endif /* (CONFIG_CMD_IDE) */ |
| 97 | |
Yusuke Goda | 1a2334a | 2008-03-05 14:30:02 +0900 | [diff] [blame] | 98 | #if defined(CONFIG_PCI) |
| 99 | static int sh_pci_init(void) |
| 100 | { |
| 101 | pci_init(); |
| 102 | return 0; |
| 103 | } |
| 104 | #endif /* CONFIG_PCI */ |
| 105 | |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 106 | static int sh_mem_env_init(void) |
| 107 | { |
| 108 | mem_malloc_init(); |
| 109 | malloc_bin_reloc(); |
| 110 | env_relocate(); |
| 111 | jumptable_init(); |
| 112 | return 0; |
| 113 | } |
| 114 | |
Nobuhiro Iwamatsu | 9e23fe0 | 2008-07-08 12:03:24 +0900 | [diff] [blame^] | 115 | #if defined(CONFIG_CMD_NET) |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 116 | static int sh_net_init(void) |
| 117 | { |
| 118 | DECLARE_GLOBAL_DATA_PTR; |
| 119 | char *s, *e; |
| 120 | int i; |
| 121 | |
| 122 | gd->bd->bi_ip_addr = getenv_IPaddr("ipaddr"); |
| 123 | s = getenv("ethaddr"); |
| 124 | for (i = 0; i < 6; ++i) { |
| 125 | gd->bd->bi_enetaddr[i] = s ? simple_strtoul(s, &e, 16) : 0; |
| 126 | if (s) s = (*e) ? e + 1 : e; |
| 127 | } |
| 128 | |
| 129 | return 0; |
| 130 | } |
Nobuhiro Iwamatsu | 9e23fe0 | 2008-07-08 12:03:24 +0900 | [diff] [blame^] | 131 | #endif |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 132 | |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 133 | typedef int (init_fnc_t) (void); |
| 134 | |
| 135 | init_fnc_t *init_sequence[] = |
| 136 | { |
| 137 | cpu_init, /* basic cpu dependent setup */ |
| 138 | board_init, /* basic board dependent setup */ |
| 139 | interrupt_init, /* set up exceptions */ |
| 140 | env_init, /* event init */ |
| 141 | serial_init, /* SCIF init */ |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 142 | watchdog_init, /* watchdog init */ |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 143 | console_init_f, |
| 144 | display_options, |
| 145 | checkcpu, |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 146 | checkboard, /* Check support board */ |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 147 | dram_init, /* SDRAM init */ |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 148 | timer_init, /* SuperH Timer (TCNT0 only) init */ |
| 149 | sh_flash_init, /* Flash memory(NOR) init*/ |
| 150 | sh_mem_env_init, |
| 151 | #if defined(CONFIG_CMD_NAND) |
| 152 | sh_nand_init, /* Flash memory (NAND) init */ |
| 153 | #endif |
Yusuke Goda | 1a2334a | 2008-03-05 14:30:02 +0900 | [diff] [blame] | 154 | #if defined(CONFIG_PCI) |
| 155 | sh_pci_init, /* PCI Init */ |
| 156 | #endif |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 157 | devices_init, |
| 158 | console_init_r, |
| 159 | interrupt_init, |
| 160 | #ifdef BOARD_LATE_INIT |
| 161 | board_late_init, |
| 162 | #endif |
| 163 | #if defined(CONFIG_CMD_NET) |
| 164 | sh_net_init, /* SH specific eth init */ |
| 165 | #endif |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 166 | NULL /* Terminate this list */ |
| 167 | }; |
| 168 | |
| 169 | void sh_generic_init (void) |
| 170 | { |
| 171 | DECLARE_GLOBAL_DATA_PTR; |
| 172 | |
| 173 | bd_t *bd; |
| 174 | init_fnc_t **init_fnc_ptr; |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 175 | int i; |
Nobuhiro Iwamatsu | 9e23fe0 | 2008-07-08 12:03:24 +0900 | [diff] [blame^] | 176 | char *s; |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 177 | |
| 178 | memset (gd, 0, CFG_GBL_DATA_SIZE); |
| 179 | |
| 180 | gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */ |
| 181 | |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 182 | gd->bd = (bd_t *) (gd + 1); /* At end of global data */ |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 183 | gd->baudrate = CONFIG_BAUDRATE; |
| 184 | |
| 185 | gd->cpu_clk = CONFIG_SYS_CLK_FREQ; |
| 186 | |
| 187 | bd = gd->bd; |
| 188 | bd->bi_memstart = CFG_SDRAM_BASE; |
| 189 | bd->bi_memsize = CFG_SDRAM_SIZE; |
| 190 | bd->bi_flashstart = CFG_FLASH_BASE; |
| 191 | #if defined(CFG_SRAM_BASE) && defined(CFG_SRAM_SIZE) |
| 192 | bd->bi_sramstart= CFG_SRAM_BASE; |
| 193 | bd->bi_sramsize = CFG_SRAM_SIZE; |
| 194 | #endif |
| 195 | bd->bi_baudrate = CONFIG_BAUDRATE; |
| 196 | |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 197 | for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr , i++) { |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 198 | if ((*init_fnc_ptr) () != 0) { |
| 199 | hang(); |
| 200 | } |
| 201 | } |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 202 | |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 203 | #if defined(CONFIG_CMD_NET) |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 204 | puts ("Net: "); |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 205 | eth_initialize(gd->bd); |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 206 | |
Wolfgang Denk | 61fb15c5 | 2007-12-27 01:52:50 +0100 | [diff] [blame] | 207 | if ((s = getenv ("bootfile")) != NULL) { |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 208 | copy_filename (BootFile, s, sizeof (BootFile)); |
| 209 | } |
| 210 | #endif /* CONFIG_CMD_NET */ |
| 211 | |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 212 | while (1) { |
| 213 | main_loop(); |
| 214 | } |
| 215 | } |
| 216 | |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 217 | /***********************************************************************/ |
| 218 | |
| 219 | void hang (void) |
| 220 | { |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 221 | puts ("Board ERROR\n"); |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 222 | for (;;); |
| 223 | } |