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 * SPDX-License-Identifier: GPL-2.0+
15 #include <stdio_dev.h>
17 #if defined(CONFIG_CMD_IDE)
20 #ifdef CONFIG_STATUS_LED
21 #include <status_led.h>
26 #if defined(CONFIG_POST)
32 #ifdef CONFIG_CMD_AMBAPP
36 #ifdef CONFIG_BITBANGMII
40 DECLARE_GLOBAL_DATA_PTR;
43 #define DEBUG_INIT_SEQUENCE
44 #define DEBUG_MEM_LAYOUT
45 #define DEBUG_COMMANDS
48 extern void timer_interrupt_init(void);
49 extern int do_ambapp_print(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]);
50 extern int prom_init(void);
52 #if defined(CONFIG__CMD_DOC)
56 #if !defined(CONFIG_SYS_NO_FLASH)
57 static char *failed = "*** failed ***\n";
60 #include <environment.h>
62 ulong monitor_flash_len;
64 /************************************************************************
66 ************************************************************************
67 * Some of this code should be moved into the core functions,
68 * but let's get it working (again) first...
71 static int init_baudrate(void)
73 gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
77 /***********************************************************************/
80 * All attempts to come up with a "common" initialization sequence
81 * that works for all boards and architectures failed: some of the
82 * requirements are just _too_ different. To get rid of the resulting
83 * mess of board dependend #ifdef'ed code we now make the whole
84 * initialization sequence configurable to the user.
86 * The requirements for any new initalization function is simple: it
87 * receives a pointer to the "global data" structure as it's only
88 * argument, and returns an integer return code, where 0 means
89 * "continue" and != 0 means "fatal error, hang the system".
91 typedef int (init_fnc_t) (void);
93 #define WATCHDOG_RESET(x)
95 /************************************************************************
96 * Initialization sequence *
97 ************************************************************************
100 init_fnc_t *init_sequence[] = {
102 #if defined(CONFIG_BOARD_EARLY_INIT_F)
109 #if defined(CONFIG_CMD_AMBAPP)
122 #if defined(CONFIG_MISC_INIT_F)
130 NULL, /* Terminate this list,
131 * beware: this list will be relocated
132 * which means that NULL will become
133 * NULL+RELOC_OFFSET. We simply make
134 * NULL be -RELOC_OFFSET instead.
138 /************************************************************************
140 * This is the SPARC board initialization routine, running from RAM.
142 ************************************************************************
144 #ifdef DEBUG_INIT_SEQUENCE
145 char *str_init_seq = "INIT_SEQ 00\n";
146 char *str_init_seq_done = "\n\rInit sequence done...\r\n\r\n";
149 void board_init_f(ulong bootflag)
152 init_fnc_t **init_fnc_ptr;
155 #ifndef CONFIG_SYS_NO_FLASH
159 gd = (gd_t *) (CONFIG_SYS_GBL_DATA_OFFSET);
161 /* Clear initial global data */
162 memset((void *)gd, 0, sizeof(gd_t));
164 gd->bd = (bd_t *) (gd + 1); /* At end of global data */
165 gd->baudrate = CONFIG_BAUDRATE;
166 gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
169 bd->bi_memstart = CONFIG_SYS_RAM_BASE;
170 bd->bi_memsize = CONFIG_SYS_RAM_SIZE;
171 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
172 #if defined(CONFIG_SYS_SRAM_BASE) && defined(CONFIG_SYS_SRAM_SIZE)
173 bd->bi_sramstart = CONFIG_SYS_SRAM_BASE;
174 bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE;
176 bd->bi_bootflags = bootflag; /* boot / reboot flag (for LynxOS) */
178 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
179 gd->reloc_off = CONFIG_SYS_RELOC_MONITOR_BASE - CONFIG_SYS_MONITOR_BASE;
181 for (init_fnc_ptr = init_sequence, j = 0; *init_fnc_ptr;
182 ++init_fnc_ptr, j++) {
183 #ifdef DEBUG_INIT_SEQUENCE
185 str_init_seq[9] = '0' + (j / 10);
186 str_init_seq[10] = '0' + (j - (j / 10) * 10);
187 serial_puts(str_init_seq);
189 if ((*init_fnc_ptr + gd->reloc_off) () != 0) {
193 #ifdef DEBUG_INIT_SEQUENCE
194 serial_puts(str_init_seq_done);
198 * Now that we have DRAM mapped and working, we can
199 * relocate the code and continue running from DRAM.
201 * Reserve memory at end of RAM for (top down in that order):
202 * - kernel log buffer
206 * - board info struct
208 #ifdef DEBUG_MEM_LAYOUT
209 printf("CONFIG_SYS_MONITOR_BASE: 0x%lx\n", CONFIG_SYS_MONITOR_BASE);
210 printf("CONFIG_ENV_ADDR: 0x%lx\n", CONFIG_ENV_ADDR);
211 printf("CONFIG_SYS_RELOC_MONITOR_BASE: 0x%lx (%d)\n", CONFIG_SYS_RELOC_MONITOR_BASE,
212 CONFIG_SYS_MONITOR_LEN);
213 printf("CONFIG_SYS_MALLOC_BASE: 0x%lx (%d)\n", CONFIG_SYS_MALLOC_BASE,
214 CONFIG_SYS_MALLOC_LEN);
215 printf("CONFIG_SYS_INIT_SP_OFFSET: 0x%lx (%d)\n", CONFIG_SYS_INIT_SP_OFFSET,
216 CONFIG_SYS_STACK_SIZE);
217 printf("CONFIG_SYS_PROM_OFFSET: 0x%lx (%d)\n", CONFIG_SYS_PROM_OFFSET,
218 CONFIG_SYS_PROM_SIZE);
219 printf("CONFIG_SYS_GBL_DATA_OFFSET: 0x%lx (%d)\n", CONFIG_SYS_GBL_DATA_OFFSET,
220 GENERATED_GBL_DATA_SIZE);
224 post_bootmode_init();
225 post_run(NULL, POST_ROM | post_bootmode_get(0));
228 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
230 * We have to relocate the command table manually
232 fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd),
233 ll_entry_count(cmd_tbl_t, cmd));
234 #endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */
236 #if defined(CONFIG_CMD_AMBAPP) && defined(CONFIG_SYS_AMBAPP_PRINT_ON_STARTUP)
238 do_ambapp_print(NULL, 0, 0, NULL);
241 /* initialize higher level parts of CPU like time base and timers */
245 timer_interrupt_init();
248 * Enable Interrupts before any calls to udelay,
249 * the flash driver may use udelay resulting in
250 * a hang if not timer0 IRQ is enabled.
254 /* The Malloc area is immediately below the monitor copy in RAM */
255 mem_malloc_init(CONFIG_SYS_MALLOC_BASE,
256 CONFIG_SYS_MALLOC_END - CONFIG_SYS_MALLOC_BASE);
258 #if !defined(CONFIG_SYS_NO_FLASH)
261 if ((flash_size = flash_init()) > 0) {
262 # ifdef CONFIG_SYS_FLASH_CHECKSUM
263 print_size(flash_size, "");
265 * Compute and print flash CRC if flashchecksum is set to 'y'
267 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
269 if (getenv_yesno("flashchecksum") == 1) {
270 printf(" CRC: %08lX",
271 crc32(0, (const unsigned char *)CONFIG_SYS_FLASH_BASE,
276 # else /* !CONFIG_SYS_FLASH_CHECKSUM */
277 print_size(flash_size, "\n");
278 # endif /* CONFIG_SYS_FLASH_CHECKSUM */
284 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE; /* update start of FLASH memory */
285 bd->bi_flashsize = flash_size; /* size of FLASH memory (final value) */
286 #if CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
287 bd->bi_flashoffset = monitor_flash_len; /* reserved area for startup monitor */
289 bd->bi_flashoffset = 0;
291 #else /* CONFIG_SYS_NO_FLASH */
292 bd->bi_flashsize = 0;
293 bd->bi_flashstart = 0;
294 bd->bi_flashoffset = 0;
295 #endif /* !CONFIG_SYS_NO_FLASH */
298 # if !defined(CONFIG_ENV_IS_IN_EEPROM)
304 /* relocate environment function pointers etc. */
307 #if defined(CONFIG_BOARD_LATE_INIT)
311 #ifdef CONFIG_ID_EEPROM
312 mac_read_from_eeprom();
315 #if defined(CONFIG_PCI)
317 * Do pci configuration
322 /* Initialize stdio devices */
325 /* Initialize the jump table for applications */
328 /* Initialize the console (after the relocation and devices init) */
331 #ifdef CONFIG_STATUS_LED
332 status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
337 /* Initialize from environment */
338 load_addr = getenv_ulong("loadaddr", 16, load_addr);
342 #if defined(CONFIG_CMD_DOC)
348 #ifdef CONFIG_BITBANGMII
351 #if defined(CONFIG_CMD_NET)
357 #if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
359 debug("Reset Ethernet PHY\n");
364 post_run(NULL, POST_RAM | post_bootmode_get(0));
367 #if defined(CONFIG_CMD_IDE)
371 #endif /* CONFIG_CMD_IDE */
373 #ifdef CONFIG_LAST_STAGE_INIT
376 * Some parts can be only initialized if all others (like
377 * Interrupts) are up and running (i.e. the PC-style ISA
397 /************************************************************************/