]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/sparc/lib/board.c
dm: sparc: Fixup the compile warnings in sparc code
[karo-tx-uboot.git] / arch / sparc / lib / board.c
1 /* SPARC Board initialization
2  *
3  * (C) Copyright 2000-2006
4  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5  *
6  * (C) Copyright 2007
7  * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com.
8  *
9  * See file CREDITS for list of people who contributed to this
10  * project.
11  *
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.
16  *
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.
21  *
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,
25  * MA 02111-1307 USA
26  */
27
28 #include <common.h>
29 #include <command.h>
30 #include <malloc.h>
31 #include <stdio_dev.h>
32 #include <config.h>
33 #if defined(CONFIG_CMD_IDE)
34 #include <ide.h>
35 #endif
36 #ifdef CONFIG_STATUS_LED
37 #include <status_led.h>
38 #endif
39 #include <net.h>
40 #include <serial.h>
41 #include <version.h>
42 #if defined(CONFIG_POST)
43 #include <post.h>
44 #endif
45 #ifdef CONFIG_PS2KBD
46 #include <keyboard.h>
47 #endif
48 #ifdef CONFIG_CMD_AMBAPP
49 #include <ambapp.h>
50 #endif
51
52 #ifdef CONFIG_BITBANGMII
53 #include <miiphy.h>
54 #endif
55
56 DECLARE_GLOBAL_DATA_PTR;
57
58 /* Debug options
59 #define DEBUG_INIT_SEQUENCE
60 #define DEBUG_MEM_LAYOUT
61 #define DEBUG_COMMANDS
62 */
63
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 * const argv[]);
67 extern int prom_init(void);
68
69 #if defined(CONFIG__CMD_DOC)
70 void doc_init(void);
71 #endif
72
73 #if !defined(CONFIG_SYS_NO_FLASH)
74 static char *failed = "*** failed ***\n";
75 #endif
76
77 #include <environment.h>
78
79 ulong monitor_flash_len;
80
81 /************************************************************************
82  * Init Utilities                                                       *
83  ************************************************************************
84  * Some of this code should be moved into the core functions,
85  * but let's get it working (again) first...
86  */
87
88 static int init_baudrate(void)
89 {
90         gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
91         return 0;
92 }
93
94 /***********************************************************************/
95
96 /*
97  * All attempts to come up with a "common" initialization sequence
98  * that works for all boards and architectures failed: some of the
99  * requirements are just _too_ different. To get rid of the resulting
100  * mess of board dependend #ifdef'ed code we now make the whole
101  * initialization sequence configurable to the user.
102  *
103  * The requirements for any new initalization function is simple: it
104  * receives a pointer to the "global data" structure as it's only
105  * argument, and returns an integer return code, where 0 means
106  * "continue" and != 0 means "fatal error, hang the system".
107  */
108 typedef int (init_fnc_t) (void);
109
110 #define WATCHDOG_RESET(x)
111
112 /************************************************************************
113  * Initialization sequence                                              *
114  ************************************************************************
115  */
116
117 init_fnc_t *init_sequence[] = {
118
119 #if defined(CONFIG_BOARD_EARLY_INIT_F)
120         board_early_init_f,
121 #endif
122         serial_init,
123
124         init_timebase,
125
126 #if defined(CONFIG_CMD_AMBAPP)
127         ambapp_init_reloc,
128 #endif
129
130         env_init,
131
132         init_baudrate,
133
134         console_init_f,
135         display_options,
136
137         checkcpu,
138         checkboard,
139 #if defined(CONFIG_MISC_INIT_F)
140         misc_init_f,
141 #endif
142
143 #ifdef CONFIG_POST
144         post_init_f,
145 #endif
146
147         NULL,                   /* Terminate this list,
148                                  * beware: this list will be relocated
149                                  * which means that NULL will become
150                                  * NULL+RELOC_OFFSET. We simply make
151                                  * NULL be -RELOC_OFFSET instead.
152                                  */
153 };
154
155 /************************************************************************
156  *
157  * This is the SPARC board initialization routine, running from RAM.
158  *
159  ************************************************************************
160  */
161 #ifdef DEBUG_INIT_SEQUENCE
162 char *str_init_seq = "INIT_SEQ 00\n";
163 char *str_init_seq_done = "\n\rInit sequence done...\r\n\r\n";
164 #endif
165
166 void board_init_f(ulong bootflag)
167 {
168         bd_t *bd;
169         init_fnc_t **init_fnc_ptr;
170         int j;
171
172 #ifndef CONFIG_SYS_NO_FLASH
173         ulong flash_size;
174 #endif
175
176         gd = (gd_t *) (CONFIG_SYS_GBL_DATA_OFFSET);
177
178         /* Clear initial global data */
179         memset((void *)gd, 0, sizeof(gd_t));
180
181         gd->bd = (bd_t *) (gd + 1);     /* At end of global data */
182         gd->baudrate = CONFIG_BAUDRATE;
183         gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
184
185         bd = gd->bd;
186         bd->bi_memstart = CONFIG_SYS_RAM_BASE;
187         bd->bi_memsize = CONFIG_SYS_RAM_SIZE;
188         bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
189 #if     defined(CONFIG_SYS_SRAM_BASE) && defined(CONFIG_SYS_SRAM_SIZE)
190         bd->bi_sramstart = CONFIG_SYS_SRAM_BASE;
191         bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE;
192 #endif
193         bd->bi_baudrate = CONFIG_BAUDRATE;
194         bd->bi_bootflags = bootflag;    /* boot / reboot flag (for LynxOS)    */
195
196         gd->flags |= GD_FLG_RELOC;      /* tell others: relocation done */
197         gd->reloc_off = CONFIG_SYS_RELOC_MONITOR_BASE - CONFIG_SYS_MONITOR_BASE;
198
199         for (init_fnc_ptr = init_sequence, j = 0; *init_fnc_ptr;
200              ++init_fnc_ptr, j++) {
201 #ifdef DEBUG_INIT_SEQUENCE
202                 if (j > 9)
203                         str_init_seq[9] = '0' + (j / 10);
204                 str_init_seq[10] = '0' + (j - (j / 10) * 10);
205                 serial_puts(str_init_seq);
206 #endif
207                 if ((*init_fnc_ptr + gd->reloc_off) () != 0) {
208                         hang();
209                 }
210         }
211 #ifdef DEBUG_INIT_SEQUENCE
212         serial_puts(str_init_seq_done);
213 #endif
214
215         /*
216          * Now that we have DRAM mapped and working, we can
217          * relocate the code and continue running from DRAM.
218          *
219          * Reserve memory at end of RAM for (top down in that order):
220          *  - kernel log buffer
221          *  - protected RAM
222          *  - LCD framebuffer
223          *  - monitor code
224          *  - board info struct
225          */
226 #ifdef DEBUG_MEM_LAYOUT
227         printf("CONFIG_SYS_MONITOR_BASE:       0x%lx\n", CONFIG_SYS_MONITOR_BASE);
228         printf("CONFIG_ENV_ADDR:           0x%lx\n", CONFIG_ENV_ADDR);
229         printf("CONFIG_SYS_RELOC_MONITOR_BASE: 0x%lx (%d)\n", CONFIG_SYS_RELOC_MONITOR_BASE,
230                CONFIG_SYS_MONITOR_LEN);
231         printf("CONFIG_SYS_MALLOC_BASE:        0x%lx (%d)\n", CONFIG_SYS_MALLOC_BASE,
232                CONFIG_SYS_MALLOC_LEN);
233         printf("CONFIG_SYS_INIT_SP_OFFSET:     0x%lx (%d)\n", CONFIG_SYS_INIT_SP_OFFSET,
234                CONFIG_SYS_STACK_SIZE);
235         printf("CONFIG_SYS_PROM_OFFSET:        0x%lx (%d)\n", CONFIG_SYS_PROM_OFFSET,
236                CONFIG_SYS_PROM_SIZE);
237         printf("CONFIG_SYS_GBL_DATA_OFFSET:    0x%lx (%d)\n", CONFIG_SYS_GBL_DATA_OFFSET,
238                GENERATED_GBL_DATA_SIZE);
239 #endif
240
241 #ifdef CONFIG_POST
242         post_bootmode_init();
243         post_run(NULL, POST_ROM | post_bootmode_get(0));
244 #endif
245
246 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
247         /*
248          * We have to relocate the command table manually
249          */
250         fixup_cmdtable(&__u_boot_cmd_start,
251                 (ulong)(&__u_boot_cmd_end - &__u_boot_cmd_start));
252 #endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */
253
254 #if defined(CONFIG_CMD_AMBAPP) && defined(CONFIG_SYS_AMBAPP_PRINT_ON_STARTUP)
255         puts("AMBA:\n");
256         do_ambapp_print(NULL, 0, 0, NULL);
257 #endif
258
259         /* initialize higher level parts of CPU like time base and timers */
260         cpu_init_r();
261
262         /* start timer */
263         timer_interrupt_init();
264
265         /*
266          * Enable Interrupts before any calls to udelay,
267          * the flash driver may use udelay resulting in
268          * a hang if not timer0 IRQ is enabled.
269          */
270         interrupt_init();
271
272         /* The Malloc area is immediately below the monitor copy in RAM */
273         mem_malloc_init(CONFIG_SYS_MALLOC_BASE,
274                         CONFIG_SYS_MALLOC_END - CONFIG_SYS_MALLOC_BASE);
275         malloc_bin_reloc();
276
277 #if !defined(CONFIG_SYS_NO_FLASH)
278         puts("Flash: ");
279
280         if ((flash_size = flash_init()) > 0) {
281 # ifdef CONFIG_SYS_FLASH_CHECKSUM
282                 print_size(flash_size, "");
283                 /*
284                  * Compute and print flash CRC if flashchecksum is set to 'y'
285                  *
286                  * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
287                  */
288                 s = getenv("flashchecksum");
289                 if (s && (*s == 'y')) {
290                         printf("  CRC: %08lX",
291                                crc32(0, (const unsigned char *)CONFIG_SYS_FLASH_BASE,
292                                      flash_size)
293                             );
294                 }
295                 putc('\n');
296 # else                          /* !CONFIG_SYS_FLASH_CHECKSUM */
297                 print_size(flash_size, "\n");
298 # endif                         /* CONFIG_SYS_FLASH_CHECKSUM */
299         } else {
300                 puts(failed);
301                 hang();
302         }
303
304         bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;      /* update start of FLASH memory    */
305         bd->bi_flashsize = flash_size;  /* size of FLASH memory (final value) */
306 #if CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
307         bd->bi_flashoffset = monitor_flash_len; /* reserved area for startup monitor  */
308 #else
309         bd->bi_flashoffset = 0;
310 #endif
311 #else                           /* CONFIG_SYS_NO_FLASH */
312         bd->bi_flashsize = 0;
313         bd->bi_flashstart = 0;
314         bd->bi_flashoffset = 0;
315 #endif                          /* !CONFIG_SYS_NO_FLASH */
316
317 #ifdef CONFIG_SPI
318 # if !defined(CONFIG_ENV_IS_IN_EEPROM)
319         spi_init_f();
320 # endif
321         spi_init_r();
322 #endif
323
324         /* relocate environment function pointers etc. */
325         env_relocate();
326
327 #if defined(CONFIG_BOARD_LATE_INIT)
328         board_late_init();
329 #endif
330
331 #ifdef CONFIG_ID_EEPROM
332         mac_read_from_eeprom();
333 #endif
334
335 #if defined(CONFIG_PCI)
336         /*
337          * Do pci configuration
338          */
339         pci_init();
340 #endif
341
342         /* Initialize stdio devices */
343         stdio_init();
344
345         /* Initialize the jump table for applications */
346         jumptable_init();
347
348         /* Initialize the console (after the relocation and devices init) */
349         console_init_r();
350
351 #ifdef CONFIG_STATUS_LED
352         status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
353 #endif
354
355         udelay(20);
356
357         /* Initialize from environment */
358         load_addr = getenv_ulong("loadaddr", 16, load_addr);
359
360         WATCHDOG_RESET();
361
362 #if defined(CONFIG_CMD_DOC)
363         WATCHDOG_RESET();
364         puts("DOC:   ");
365         doc_init();
366 #endif
367
368 #ifdef CONFIG_BITBANGMII
369         bb_miiphy_init();
370 #endif
371 #if defined(CONFIG_CMD_NET)
372         WATCHDOG_RESET();
373         puts("Net:   ");
374         eth_initialize(bd);
375 #endif
376
377 #if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
378         WATCHDOG_RESET();
379         debug("Reset Ethernet PHY\n");
380         reset_phy();
381 #endif
382
383 #ifdef CONFIG_POST
384         post_run(NULL, POST_RAM | post_bootmode_get(0));
385 #endif
386
387 #if defined(CONFIG_CMD_IDE)
388         WATCHDOG_RESET();
389         puts("IDE:   ");
390         ide_init();
391 #endif /* CONFIG_CMD_IDE */
392
393 #ifdef CONFIG_LAST_STAGE_INIT
394         WATCHDOG_RESET();
395         /*
396          * Some parts can be only initialized if all others (like
397          * Interrupts) are up and running (i.e. the PC-style ISA
398          * keyboard).
399          */
400         last_stage_init();
401 #endif
402
403 #ifdef CONFIG_PS2KBD
404         puts("PS/2:  ");
405         kbd_init();
406 #endif
407         prom_init();
408
409         /* main_loop */
410         for (;;) {
411                 WATCHDOG_RESET();
412                 main_loop();
413         }
414
415 }
416
417 void hang(void)
418 {
419         puts("### ERROR ### Please RESET the board ###\n");
420 #ifdef CONFIG_SHOW_BOOT_PROGRESS
421         bootstage_error(BOOTSTAGE_ID_NEED_RESET);
422 #endif
423         for (;;) ;
424 }
425
426 /************************************************************************/