1 /* SPARC Board initialization
3 * (C) Copyright 2000-2006
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7 * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com.
9 * See file CREDITS for list of people who contributed to this
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 #include <stdio_dev.h>
33 #if defined(CONFIG_CMD_IDE)
36 #ifdef CONFIG_STATUS_LED
37 #include <status_led.h>
42 #if defined(CONFIG_POST)
48 #ifdef CONFIG_CMD_AMBAPP
52 #ifdef CONFIG_BITBANGMII
56 DECLARE_GLOBAL_DATA_PTR;
59 #define DEBUG_INIT_SEQUENCE
60 #define DEBUG_MEM_LAYOUT
61 #define DEBUG_COMMANDS
64 extern void timer_interrupt_init(void);
65 extern void malloc_bin_reloc(void);
66 extern int do_ambapp_print(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]);
67 extern int prom_init(void);
69 #if defined(CONFIG__CMD_DOC)
73 #if !defined(CONFIG_SYS_NO_FLASH)
74 static char *failed = "*** failed ***\n";
77 #include <environment.h>
79 ulong monitor_flash_len;
81 /************************************************************************
83 ************************************************************************
84 * Some of this code should be moved into the core functions,
85 * but let's get it working (again) first...
88 static int init_baudrate(void)
90 char tmp[64]; /* long enough for environment variables */
91 int i = getenv_r("baudrate", tmp, sizeof(tmp));
93 gd->baudrate = (i > 0)
94 ? (int)simple_strtoul(tmp, NULL, 10)
99 /***********************************************************************/
102 * All attempts to come up with a "common" initialization sequence
103 * that works for all boards and architectures failed: some of the
104 * requirements are just _too_ different. To get rid of the resulting
105 * mess of board dependend #ifdef'ed code we now make the whole
106 * initialization sequence configurable to the user.
108 * The requirements for any new initalization function is simple: it
109 * receives a pointer to the "global data" structure as it's only
110 * argument, and returns an integer return code, where 0 means
111 * "continue" and != 0 means "fatal error, hang the system".
113 typedef int (init_fnc_t) (void);
115 #define WATCHDOG_RESET(x)
117 /************************************************************************
118 * Initialization sequence *
119 ************************************************************************
122 init_fnc_t *init_sequence[] = {
124 #if defined(CONFIG_BOARD_EARLY_INIT_F)
131 #if defined(CONFIG_CMD_AMBAPP)
144 #if defined(CONFIG_MISC_INIT_F)
152 NULL, /* Terminate this list,
153 * beware: this list will be relocated
154 * which means that NULL will become
155 * NULL+RELOC_OFFSET. We simply make
156 * NULL be -RELOC_OFFSET instead.
160 /************************************************************************
162 * This is the SPARC board initialization routine, running from RAM.
164 ************************************************************************
166 #ifdef DEBUG_INIT_SEQUENCE
167 char *str_init_seq = "INIT_SEQ 00\n";
168 char *str_init_seq_done = "\n\rInit sequence done...\r\n\r\n";
171 void board_init_f(ulong bootflag)
176 init_fnc_t **init_fnc_ptr;
181 #ifndef CONFIG_SYS_NO_FLASH
185 gd = (gd_t *) (CONFIG_SYS_GBL_DATA_OFFSET);
187 /* Clear initial global data */
188 memset((void *)gd, 0, sizeof(gd_t));
190 gd->bd = (bd_t *) (gd + 1); /* At end of global data */
191 gd->baudrate = CONFIG_BAUDRATE;
192 gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
195 bd->bi_memstart = CONFIG_SYS_RAM_BASE;
196 bd->bi_memsize = CONFIG_SYS_RAM_SIZE;
197 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
198 #if defined(CONFIG_SYS_SRAM_BASE) && defined(CONFIG_SYS_SRAM_SIZE)
199 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE;
200 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE;
202 bd->bi_baudrate = CONFIG_BAUDRATE;
203 bd->bi_bootflags = bootflag; /* boot / reboot flag (for LynxOS) */
205 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
206 gd->reloc_off = CONFIG_SYS_RELOC_MONITOR_BASE - CONFIG_SYS_MONITOR_BASE;
208 for (init_fnc_ptr = init_sequence, j = 0; *init_fnc_ptr;
209 ++init_fnc_ptr, j++) {
210 #ifdef DEBUG_INIT_SEQUENCE
212 str_init_seq[9] = '0' + (j / 10);
213 str_init_seq[10] = '0' + (j - (j / 10) * 10);
214 serial_puts(str_init_seq);
216 if ((*init_fnc_ptr + gd->reloc_off) () != 0) {
220 #ifdef DEBUG_INIT_SEQUENCE
221 serial_puts(str_init_seq_done);
225 * Now that we have DRAM mapped and working, we can
226 * relocate the code and continue running from DRAM.
228 * Reserve memory at end of RAM for (top down in that order):
229 * - kernel log buffer
233 * - board info struct
235 #ifdef DEBUG_MEM_LAYOUT
236 printf("CONFIG_SYS_MONITOR_BASE: 0x%lx\n", CONFIG_SYS_MONITOR_BASE);
237 printf("CONFIG_ENV_ADDR: 0x%lx\n", CONFIG_ENV_ADDR);
238 printf("CONFIG_SYS_RELOC_MONITOR_BASE: 0x%lx (%d)\n", CONFIG_SYS_RELOC_MONITOR_BASE,
239 CONFIG_SYS_MONITOR_LEN);
240 printf("CONFIG_SYS_MALLOC_BASE: 0x%lx (%d)\n", CONFIG_SYS_MALLOC_BASE,
241 CONFIG_SYS_MALLOC_LEN);
242 printf("CONFIG_SYS_INIT_SP_OFFSET: 0x%lx (%d)\n", CONFIG_SYS_INIT_SP_OFFSET,
243 CONFIG_SYS_STACK_SIZE);
244 printf("CONFIG_SYS_PROM_OFFSET: 0x%lx (%d)\n", CONFIG_SYS_PROM_OFFSET,
245 CONFIG_SYS_PROM_SIZE);
246 printf("CONFIG_SYS_GBL_DATA_OFFSET: 0x%lx (%d)\n", CONFIG_SYS_GBL_DATA_OFFSET,
247 CONFIG_SYS_GBL_DATA_SIZE);
251 post_bootmode_init();
252 post_run(NULL, POST_ROM | post_bootmode_get(0));
256 * We have to relocate the command table manually
258 for (cmdtp = &__u_boot_cmd_start; cmdtp != &__u_boot_cmd_end; cmdtp++) {
260 addr = (ulong) (cmdtp->cmd) + gd->reloc_off;
262 printf("Command \"%s\": 0x%08lx => 0x%08lx\n",
263 cmdtp->name, (ulong) (cmdtp->cmd), addr);
266 (int (*)(struct cmd_tbl_s *, int, int, char *[]))addr;
268 addr = (ulong) (cmdtp->name) + gd->reloc_off;
269 cmdtp->name = (char *)addr;
272 addr = (ulong) (cmdtp->usage) + gd->reloc_off;
273 cmdtp->usage = (char *)addr;
275 #ifdef CONFIG_SYS_LONGHELP
277 addr = (ulong) (cmdtp->help) + gd->reloc_off;
278 cmdtp->help = (char *)addr;
283 #if defined(CONFIG_CMD_AMBAPP) && defined(CONFIG_SYS_AMBAPP_PRINT_ON_STARTUP)
285 do_ambapp_print(NULL, 0, 0, NULL);
288 /* initialize higher level parts of CPU like time base and timers */
292 timer_interrupt_init();
295 * Enable Interrupts before any calls to udelay,
296 * the flash driver may use udelay resulting in
297 * a hang if not timer0 IRQ is enabled.
301 /* The Malloc area is immediately below the monitor copy in RAM */
302 mem_malloc_init(CONFIG_SYS_MALLOC_BASE,
303 CONFIG_SYS_MALLOC_END - CONFIG_SYS_MALLOC_BASE);
306 #if !defined(CONFIG_SYS_NO_FLASH)
309 if ((flash_size = flash_init()) > 0) {
310 # ifdef CONFIG_SYS_FLASH_CHECKSUM
311 print_size(flash_size, "");
313 * Compute and print flash CRC if flashchecksum is set to 'y'
315 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
317 s = getenv("flashchecksum");
318 if (s && (*s == 'y')) {
319 printf(" CRC: %08lX",
320 crc32(0, (const unsigned char *)CONFIG_SYS_FLASH_BASE,
325 # else /* !CONFIG_SYS_FLASH_CHECKSUM */
326 print_size(flash_size, "\n");
327 # endif /* CONFIG_SYS_FLASH_CHECKSUM */
333 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE; /* update start of FLASH memory */
334 bd->bi_flashsize = flash_size; /* size of FLASH memory (final value) */
335 #if CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
336 bd->bi_flashoffset = monitor_flash_len; /* reserved area for startup monitor */
338 bd->bi_flashoffset = 0;
340 #else /* CONFIG_SYS_NO_FLASH */
341 bd->bi_flashsize = 0;
342 bd->bi_flashstart = 0;
343 bd->bi_flashoffset = 0;
344 #endif /* !CONFIG_SYS_NO_FLASH */
347 # if !defined(CONFIG_ENV_IS_IN_EEPROM)
353 /* relocate environment function pointers etc. */
356 #if defined(CONFIG_BOARD_LATE_INIT)
360 #ifdef CONFIG_ID_EEPROM
361 mac_read_from_eeprom();
365 bd->bi_ip_addr = getenv_IPaddr("ipaddr");
366 #if defined(CONFIG_PCI)
368 * Do pci configuration
373 /* Initialize stdio devices */
376 /* Initialize the jump table for applications */
379 /* Initialize the console (after the relocation and devices init) */
382 #ifdef CONFIG_SERIAL_SOFTWARE_FIFO
383 serial_buffered_init();
386 #ifdef CONFIG_STATUS_LED
387 status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
394 /* Initialize from environment */
395 if ((s = getenv("loadaddr")) != NULL) {
396 load_addr = simple_strtoul(s, NULL, 16);
398 #if defined(CONFIG_CMD_NET)
399 if ((s = getenv("bootfile")) != NULL) {
400 copy_filename(BootFile, s, sizeof(BootFile));
402 #endif /* CONFIG_CMD_NET */
406 #if defined(CONFIG_CMD_DOC)
412 #ifdef CONFIG_BITBANGMII
415 #if defined(CONFIG_CMD_NET)
416 #if defined(CONFIG_NET_MULTI)
423 #if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
425 debug("Reset Ethernet PHY\n");
430 post_run(NULL, POST_RAM | post_bootmode_get(0));
433 #if defined(CONFIG_CMD_IDE)
437 #endif /* CONFIG_CMD_IDE */
439 #ifdef CONFIG_LAST_STAGE_INIT
442 * Some parts can be only initialized if all others (like
443 * Interrupts) are up and running (i.e. the PC-style ISA
465 puts("### ERROR ### Please RESET the board ###\n");
466 #ifdef CONFIG_SHOW_BOOT_PROGRESS
467 show_boot_progress(-30);
472 /************************************************************************/