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 int do_ambapp_print(cmd_tbl_t
* cmdtp
, int flag
, int argc
, char * const argv
[]);
66 extern int prom_init(void);
68 #if defined(CONFIG__CMD_DOC)
72 #if !defined(CONFIG_SYS_NO_FLASH)
73 static char *failed
= "*** failed ***\n";
76 #include <environment.h>
78 ulong monitor_flash_len
;
80 /************************************************************************
82 ************************************************************************
83 * Some of this code should be moved into the core functions,
84 * but let's get it working (again) first...
87 static int init_baudrate(void)
89 gd
->baudrate
= getenv_ulong("baudrate", 10, CONFIG_BAUDRATE
);
93 /***********************************************************************/
96 * All attempts to come up with a "common" initialization sequence
97 * that works for all boards and architectures failed: some of the
98 * requirements are just _too_ different. To get rid of the resulting
99 * mess of board dependend #ifdef'ed code we now make the whole
100 * initialization sequence configurable to the user.
102 * The requirements for any new initalization function is simple: it
103 * receives a pointer to the "global data" structure as it's only
104 * argument, and returns an integer return code, where 0 means
105 * "continue" and != 0 means "fatal error, hang the system".
107 typedef int (init_fnc_t
) (void);
109 #define WATCHDOG_RESET(x)
111 /************************************************************************
112 * Initialization sequence *
113 ************************************************************************
116 init_fnc_t
*init_sequence
[] = {
118 #if defined(CONFIG_BOARD_EARLY_INIT_F)
125 #if defined(CONFIG_CMD_AMBAPP)
138 #if defined(CONFIG_MISC_INIT_F)
146 NULL
, /* Terminate this list,
147 * beware: this list will be relocated
148 * which means that NULL will become
149 * NULL+RELOC_OFFSET. We simply make
150 * NULL be -RELOC_OFFSET instead.
154 /************************************************************************
156 * This is the SPARC board initialization routine, running from RAM.
158 ************************************************************************
160 #ifdef DEBUG_INIT_SEQUENCE
161 char *str_init_seq
= "INIT_SEQ 00\n";
162 char *str_init_seq_done
= "\n\rInit sequence done...\r\n\r\n";
165 void board_init_f(ulong bootflag
)
168 init_fnc_t
**init_fnc_ptr
;
171 #ifndef CONFIG_SYS_NO_FLASH
175 gd
= (gd_t
*) (CONFIG_SYS_GBL_DATA_OFFSET
);
177 /* Clear initial global data */
178 memset((void *)gd
, 0, sizeof(gd_t
));
180 gd
->bd
= (bd_t
*) (gd
+ 1); /* At end of global data */
181 gd
->baudrate
= CONFIG_BAUDRATE
;
182 gd
->cpu_clk
= CONFIG_SYS_CLK_FREQ
;
185 bd
->bi_memstart
= CONFIG_SYS_RAM_BASE
;
186 bd
->bi_memsize
= CONFIG_SYS_RAM_SIZE
;
187 bd
->bi_flashstart
= CONFIG_SYS_FLASH_BASE
;
188 #if defined(CONFIG_SYS_SRAM_BASE) && defined(CONFIG_SYS_SRAM_SIZE)
189 bd
->bi_sramstart
= CONFIG_SYS_SRAM_BASE
;
190 bd
->bi_sramsize
= CONFIG_SYS_SRAM_SIZE
;
192 bd
->bi_baudrate
= CONFIG_BAUDRATE
;
193 bd
->bi_bootflags
= bootflag
; /* boot / reboot flag (for LynxOS) */
195 gd
->flags
|= GD_FLG_RELOC
; /* tell others: relocation done */
196 gd
->reloc_off
= CONFIG_SYS_RELOC_MONITOR_BASE
- CONFIG_SYS_MONITOR_BASE
;
198 for (init_fnc_ptr
= init_sequence
, j
= 0; *init_fnc_ptr
;
199 ++init_fnc_ptr
, j
++) {
200 #ifdef DEBUG_INIT_SEQUENCE
202 str_init_seq
[9] = '0' + (j
/ 10);
203 str_init_seq
[10] = '0' + (j
- (j
/ 10) * 10);
204 serial_puts(str_init_seq
);
206 if ((*init_fnc_ptr
+ gd
->reloc_off
) () != 0) {
210 #ifdef DEBUG_INIT_SEQUENCE
211 serial_puts(str_init_seq_done
);
215 * Now that we have DRAM mapped and working, we can
216 * relocate the code and continue running from DRAM.
218 * Reserve memory at end of RAM for (top down in that order):
219 * - kernel log buffer
223 * - board info struct
225 #ifdef DEBUG_MEM_LAYOUT
226 printf("CONFIG_SYS_MONITOR_BASE: 0x%lx\n", CONFIG_SYS_MONITOR_BASE
);
227 printf("CONFIG_ENV_ADDR: 0x%lx\n", CONFIG_ENV_ADDR
);
228 printf("CONFIG_SYS_RELOC_MONITOR_BASE: 0x%lx (%d)\n", CONFIG_SYS_RELOC_MONITOR_BASE
,
229 CONFIG_SYS_MONITOR_LEN
);
230 printf("CONFIG_SYS_MALLOC_BASE: 0x%lx (%d)\n", CONFIG_SYS_MALLOC_BASE
,
231 CONFIG_SYS_MALLOC_LEN
);
232 printf("CONFIG_SYS_INIT_SP_OFFSET: 0x%lx (%d)\n", CONFIG_SYS_INIT_SP_OFFSET
,
233 CONFIG_SYS_STACK_SIZE
);
234 printf("CONFIG_SYS_PROM_OFFSET: 0x%lx (%d)\n", CONFIG_SYS_PROM_OFFSET
,
235 CONFIG_SYS_PROM_SIZE
);
236 printf("CONFIG_SYS_GBL_DATA_OFFSET: 0x%lx (%d)\n", CONFIG_SYS_GBL_DATA_OFFSET
,
237 GENERATED_GBL_DATA_SIZE
);
241 post_bootmode_init();
242 post_run(NULL
, POST_ROM
| post_bootmode_get(0));
245 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
247 * We have to relocate the command table manually
249 fixup_cmdtable(ll_entry_start(cmd_tbl_t
, cmd
),
250 ll_entry_count(cmd_tbl_t
, cmd
));
251 #endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */
253 #if defined(CONFIG_CMD_AMBAPP) && defined(CONFIG_SYS_AMBAPP_PRINT_ON_STARTUP)
255 do_ambapp_print(NULL
, 0, 0, NULL
);
258 /* initialize higher level parts of CPU like time base and timers */
262 timer_interrupt_init();
265 * Enable Interrupts before any calls to udelay,
266 * the flash driver may use udelay resulting in
267 * a hang if not timer0 IRQ is enabled.
271 /* The Malloc area is immediately below the monitor copy in RAM */
272 mem_malloc_init(CONFIG_SYS_MALLOC_BASE
,
273 CONFIG_SYS_MALLOC_END
- CONFIG_SYS_MALLOC_BASE
);
275 #if !defined(CONFIG_SYS_NO_FLASH)
278 if ((flash_size
= flash_init()) > 0) {
279 # ifdef CONFIG_SYS_FLASH_CHECKSUM
280 print_size(flash_size
, "");
282 * Compute and print flash CRC if flashchecksum is set to 'y'
284 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
286 if (getenv_yesno("flashchecksum") == 1) {
287 printf(" CRC: %08lX",
288 crc32(0, (const unsigned char *)CONFIG_SYS_FLASH_BASE
,
293 # else /* !CONFIG_SYS_FLASH_CHECKSUM */
294 print_size(flash_size
, "\n");
295 # endif /* CONFIG_SYS_FLASH_CHECKSUM */
301 bd
->bi_flashstart
= CONFIG_SYS_FLASH_BASE
; /* update start of FLASH memory */
302 bd
->bi_flashsize
= flash_size
; /* size of FLASH memory (final value) */
303 #if CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
304 bd
->bi_flashoffset
= monitor_flash_len
; /* reserved area for startup monitor */
306 bd
->bi_flashoffset
= 0;
308 #else /* CONFIG_SYS_NO_FLASH */
309 bd
->bi_flashsize
= 0;
310 bd
->bi_flashstart
= 0;
311 bd
->bi_flashoffset
= 0;
312 #endif /* !CONFIG_SYS_NO_FLASH */
315 # if !defined(CONFIG_ENV_IS_IN_EEPROM)
321 /* relocate environment function pointers etc. */
324 #if defined(CONFIG_BOARD_LATE_INIT)
328 #ifdef CONFIG_ID_EEPROM
329 mac_read_from_eeprom();
332 #if defined(CONFIG_PCI)
334 * Do pci configuration
339 /* Initialize stdio devices */
342 /* Initialize the jump table for applications */
345 /* Initialize the console (after the relocation and devices init) */
348 #ifdef CONFIG_STATUS_LED
349 status_led_set(STATUS_LED_BOOT
, STATUS_LED_BLINKING
);
354 /* Initialize from environment */
355 load_addr
= getenv_ulong("loadaddr", 16, load_addr
);
359 #if defined(CONFIG_CMD_DOC)
365 #ifdef CONFIG_BITBANGMII
368 #if defined(CONFIG_CMD_NET)
374 #if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
376 debug("Reset Ethernet PHY\n");
381 post_run(NULL
, POST_RAM
| post_bootmode_get(0));
384 #if defined(CONFIG_CMD_IDE)
388 #endif /* CONFIG_CMD_IDE */
390 #ifdef CONFIG_LAST_STAGE_INIT
393 * Some parts can be only initialized if all others (like
394 * Interrupts) are up and running (i.e. the PC-style ISA
414 /************************************************************************/