]>
git.ipfire.org Git - people/ms/u-boot.git/blob - lib_m68k/board.c
3 * Josef Baumgartner <josef.baumgartner@telex.de>
5 * (C) Copyright 2000-2002
6 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
8 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
34 #include <asm/immap_5272.h>
37 #if (CONFIG_COMMANDS & CFG_CMD_IDE)
40 #if (CONFIG_COMMANDS & CFG_CMD_SCSI)
43 #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
46 #ifdef CONFIG_STATUS_LED
47 #include <status_led.h>
50 #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
51 #include <cmd_bedbug.h>
53 #ifdef CFG_ALLOC_DPRAM
58 static char *failed
= "*** failed ***\n";
61 extern flash_info_t flash_info
[];
64 #include <environment.h>
66 #if ( ((CFG_ENV_ADDR+CFG_ENV_SIZE) < CFG_MONITOR_BASE) || \
67 (CFG_ENV_ADDR >= (CFG_MONITOR_BASE + CFG_MONITOR_LEN)) ) || \
68 defined(CFG_ENV_IS_IN_NVRAM)
69 #define TOTAL_MALLOC_LEN (CFG_MALLOC_LEN + CFG_ENV_SIZE)
71 #define TOTAL_MALLOC_LEN CFG_MALLOC_LEN
74 extern ulong __init_end
;
77 extern void timer_init(void);
79 #if defined(CONFIG_WATCHDOG)
80 # define INIT_FUNC_WATCHDOG_INIT watchdog_init,
81 # define WATCHDOG_DISABLE watchdog_disable
83 extern int watchdog_init(void);
84 extern int watchdog_disable(void);
86 # define INIT_FUNC_WATCHDOG_INIT /* undef */
87 # define WATCHDOG_DISABLE /* undef */
88 #endif /* CONFIG_WATCHDOG */
90 ulong monitor_flash_len
;
93 * Begin and End of memory area for malloc(), and current "brk"
95 static ulong mem_malloc_start
= 0;
96 static ulong mem_malloc_end
= 0;
97 static ulong mem_malloc_brk
= 0;
99 /************************************************************************
101 ************************************************************************
105 * The Malloc area is immediately below the monitor copy in DRAM
107 static void mem_malloc_init (void)
109 DECLARE_GLOBAL_DATA_PTR
;
111 ulong dest_addr
= CFG_MONITOR_BASE
+ gd
->reloc_off
;
113 mem_malloc_end
= dest_addr
;
114 mem_malloc_start
= dest_addr
- TOTAL_MALLOC_LEN
;
115 mem_malloc_brk
= mem_malloc_start
;
117 memset ((void *) mem_malloc_start
,
119 mem_malloc_end
- mem_malloc_start
);
122 void *sbrk (ptrdiff_t increment
)
124 ulong old
= mem_malloc_brk
;
125 ulong
new = old
+ increment
;
127 if ((new < mem_malloc_start
) ||
128 (new > mem_malloc_end
) ) {
131 mem_malloc_brk
= new;
132 return ((void *)old
);
135 char *strmhz(char *buf
, long hz
)
142 l
= sprintf (buf
, "%ld", n
);
144 m
= (hz
% 1000000L) / 1000L;
147 sprintf (buf
+l
, ".%03ld", m
);
153 * All attempts to come up with a "common" initialization sequence
154 * that works for all boards and architectures failed: some of the
155 * requirements are just _too_ different. To get rid of the resulting
156 * mess of board dependend #ifdef'ed code we now make the whole
157 * initialization sequence configurable to the user.
159 * The requirements for any new initalization function is simple: it
160 * receives a pointer to the "global data" structure as it's only
161 * argument, and returns an integer return code, where 0 means
162 * "continue" and != 0 means "fatal error, hang the system".
164 typedef int (init_fnc_t
) (void);
166 /************************************************************************
168 ************************************************************************
169 * Some of this code should be moved into the core functions,
170 * but let's get it working (again) first...
173 static int init_baudrate (void)
175 DECLARE_GLOBAL_DATA_PTR
;
177 uchar tmp
[64]; /* long enough for environment variables */
178 int i
= getenv_r ("baudrate", tmp
, sizeof (tmp
));
180 gd
->baudrate
= (i
> 0)
181 ? (int) simple_strtoul (tmp
, NULL
, 10)
186 /***********************************************************************/
188 static int init_func_ram (void)
190 DECLARE_GLOBAL_DATA_PTR
;
192 int board_type
= 0; /* use dummy arg */
195 if ((gd
->ram_size
= initdram (board_type
)) > 0) {
196 print_size (gd
->ram_size
, "\n");
203 /***********************************************************************/
205 /************************************************************************
206 * Initialization sequence *
207 ************************************************************************
210 init_fnc_t
*init_sequence
[] = {
219 #if defined(CFG_DRAM_TEST)
221 #endif /* CFG_DRAM_TEST */
222 INIT_FUNC_WATCHDOG_INIT
223 NULL
, /* Terminate this list */
227 /************************************************************************
229 * This is the first part of the initialization sequence that is
230 * implemented in C, but still running from ROM.
232 * The main purpose is to provide a (serial) console interface as
233 * soon as possible (so we can see any error messages), and to
234 * initialize the RAM so that we can relocate the monitor code to
237 * Be aware of the restrictions: global data is read-only, BSS is not
238 * initialized, and stack space is limited to a few kB.
240 ************************************************************************
244 board_init_f (ulong bootflag
)
246 DECLARE_GLOBAL_DATA_PTR
;
249 ulong len
, addr
, addr_sp
;
251 init_fnc_t
**init_fnc_ptr
;
255 uchar tmp
[64]; /* long enough for environment variables */
258 /* Pointer is writable since we allocated a register for it */
259 gd
= (gd_t
*) (CFG_INIT_RAM_ADDR
+ CFG_GBL_DATA_OFFSET
);
260 /* compiler optimization barrier needed for GCC >= 3.4 */
261 __asm__
__volatile__("": : :"memory");
263 /* Clear initial global data */
264 memset ((void *) gd
, 0, sizeof (gd_t
));
266 for (init_fnc_ptr
= init_sequence
; *init_fnc_ptr
; ++init_fnc_ptr
) {
267 if ((*init_fnc_ptr
)() != 0) {
273 * Now that we have DRAM mapped and working, we can
274 * relocate the code and continue running from DRAM.
276 * Reserve memory at end of RAM for (top down in that order):
280 * - board info struct
282 len
= (ulong
)&_end
- CFG_MONITOR_BASE
;
284 addr
= CFG_SDRAM_BASE
+ gd
->ram_size
;
286 #ifdef CONFIG_LOGBUFFER
287 /* reserve kernel log buffer */
288 addr
-= (LOGBUFF_RESERVE
);
289 debug ("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN
, addr
);
294 * reserve protected RAM
296 i
= getenv_r ("pram", tmp
, sizeof (tmp
));
297 reg
= (i
> 0) ? simple_strtoul (tmp
, NULL
, 10) : CONFIG_PRAM
;
298 addr
-= (reg
<< 10); /* size is in kB */
299 debug ("Reserving %ldk for protected RAM at %08lx\n", reg
, addr
);
300 #endif /* CONFIG_PRAM */
303 * reserve memory for U-Boot code, data & bss
304 * round down to next 4 kB limit
309 debug ("Reserving %ldk for U-Boot at: %08lx\n", len
>> 10, addr
);
312 * reserve memory for malloc() arena
314 addr_sp
= addr
- TOTAL_MALLOC_LEN
;
315 debug ("Reserving %dk for malloc() at: %08lx\n",
316 TOTAL_MALLOC_LEN
>> 10, addr_sp
);
319 * (permanently) allocate a Board Info struct
320 * and a permanent copy of the "global" data
322 addr_sp
-= sizeof (bd_t
);
323 bd
= (bd_t
*) addr_sp
;
325 debug ("Reserving %d Bytes for Board Info at: %08lx\n",
326 sizeof (bd_t
), addr_sp
);
327 addr_sp
-= sizeof (gd_t
);
328 id
= (gd_t
*) addr_sp
;
329 debug ("Reserving %d Bytes for Global Data at: %08lx\n",
330 sizeof (gd_t
), addr_sp
);
332 /* Reserve memory for boot params. */
333 addr_sp
-= CFG_BOOTPARAMS_LEN
;
334 bd
->bi_boot_params
= addr_sp
;
335 debug ("Reserving %dk for boot parameters at: %08lx\n",
336 CFG_BOOTPARAMS_LEN
>> 10, addr_sp
);
339 * Finally, we set up a new (bigger) stack.
341 * Leave some safety gap for SP, force alignment on 16 byte boundary
342 * Clear initial stack frame
346 *((ulong
*) addr_sp
)-- = 0;
347 *((ulong
*) addr_sp
)-- = 0;
348 debug ("Stack Pointer at: %08lx\n", addr_sp
);
351 * Save local variables to board info struct
353 bd
->bi_memstart
= CFG_SDRAM_BASE
; /* start of DRAM memory */
354 bd
->bi_memsize
= gd
->ram_size
; /* size of DRAM memory in bytes */
355 bd
->bi_mbar_base
= CFG_MBAR
; /* base of internal registers */
357 bd
->bi_bootflags
= bootflag
; /* boot / reboot flag (for LynxOS) */
360 bd
->bi_intfreq
= gd
->cpu_clk
; /* Internal Freq, in Hz */
361 bd
->bi_busfreq
= gd
->bus_clk
; /* Bus Freq, in Hz */
362 bd
->bi_baudrate
= gd
->baudrate
; /* Console Baudrate */
365 strncpy (bd
->bi_s_version
, "1.2", sizeof (bd
->bi_s_version
));
366 strncpy (bd
->bi_r_version
, U_BOOT_VERSION
, sizeof (bd
->bi_r_version
));
372 post_bootmode_init();
373 post_run (NULL
, POST_ROM
| post_bootmode_get(0));
378 memcpy (id
, (void *)gd
, sizeof (gd_t
));
380 debug ("Start relocate of code from %08x to %08lx\n", CFG_MONITOR_BASE
, addr
);
381 relocate_code (addr_sp
, id
, addr
);
383 /* NOTREACHED - jump_to_ram() does not return */
386 /************************************************************************
388 * This is the next part if the initialization sequence: we are now
389 * running from RAM and have a "normal" C environment, i. e. global
390 * data can be written, BSS has been cleared, the stack size in not
391 * that critical any more, etc.
393 ************************************************************************
395 void board_init_r (gd_t
*id
, ulong dest_addr
)
397 DECLARE_GLOBAL_DATA_PTR
;
402 extern void malloc_bin_reloc (void);
404 #ifndef CFG_ENV_IS_NOWHERE
405 extern char * env_name_spec
;
410 gd
= id
; /* initialize RAM version of global data */
413 gd
->flags
|= GD_FLG_RELOC
; /* tell others: relocation done */
415 debug ("Now running in RAM - U-Boot at: %08lx\n", dest_addr
);
419 gd
->reloc_off
= dest_addr
- CFG_MONITOR_BASE
;
421 monitor_flash_len
= (ulong
)&__init_end
- dest_addr
;
424 * We have to relocate the command table manually
426 for (cmdtp
= &__u_boot_cmd_start
; cmdtp
!= &__u_boot_cmd_end
; cmdtp
++) {
428 addr
= (ulong
) (cmdtp
->cmd
) + gd
->reloc_off
;
430 printf ("Command \"%s\": 0x%08lx => 0x%08lx\n",
431 cmdtp
->name
, (ulong
) (cmdtp
->cmd
), addr
);
434 (int (*)(struct cmd_tbl_s
*, int, int, char *[]))addr
;
436 addr
= (ulong
)(cmdtp
->name
) + gd
->reloc_off
;
437 cmdtp
->name
= (char *)addr
;
440 addr
= (ulong
)(cmdtp
->usage
) + gd
->reloc_off
;
441 cmdtp
->usage
= (char *)addr
;
445 addr
= (ulong
)(cmdtp
->help
) + gd
->reloc_off
;
446 cmdtp
->help
= (char *)addr
;
450 /* there are some other pointer constants we must deal with */
451 #ifndef CFG_ENV_IS_NOWHERE
452 env_name_spec
+= gd
->reloc_off
;
457 #ifdef CONFIG_LOGBUFFER
458 logbuff_init_ptrs ();
461 post_output_backlog ();
467 /* instruction cache enabled in cpu_init_f() for faster relocation */
468 icache_enable (); /* it's time to enable the instruction cache */
472 * Setup trap handlers
476 #if !defined(CFG_NO_FLASH)
479 if ((flash_size
= flash_init ()) > 0) {
480 # ifdef CFG_FLASH_CHECKSUM
481 print_size (flash_size
, "");
483 * Compute and print flash CRC if flashchecksum is set to 'y'
485 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
487 s
= getenv ("flashchecksum");
488 if (s
&& (*s
== 'y')) {
489 printf (" CRC: %08lX",
491 (const unsigned char *) CFG_FLASH_BASE
,
496 # else /* !CFG_FLASH_CHECKSUM */
497 print_size (flash_size
, "\n");
498 # endif /* CFG_FLASH_CHECKSUM */
504 bd
->bi_flashstart
= CFG_FLASH_BASE
; /* update start of FLASH memory */
505 bd
->bi_flashsize
= flash_size
; /* size of FLASH memory (final value) */
506 bd
->bi_flashoffset
= 0;
507 #else /* CFG_NO_FLASH */
508 bd
->bi_flashsize
= 0;
509 bd
->bi_flashstart
= 0;
510 bd
->bi_flashoffset
= 0;
511 #endif /* !CFG_NO_FLASH */
515 /* initialize higher level parts of CPU like time base and timers */
520 /* initialize malloc() area */
525 # if !defined(CFG_ENV_IS_IN_EEPROM)
531 /* relocate environment function pointers etc. */
535 * Fill in missing fields of bd_info.
536 * We do this here, where we have "normal" access to the
537 * environment; we used to do this still running from ROM,
538 * where had to use getenv_r(), which can be pretty slow when
539 * the environment is in EEPROM.
541 s
= getenv ("ethaddr");
542 for (i
= 0; i
< 6; ++i
) {
543 bd
->bi_enetaddr
[i
] = s
? simple_strtoul (s
, &e
, 16) : 0;
545 s
= (*e
) ? e
+ 1 : e
;
549 bd
->bi_ip_addr
= getenv_IPaddr ("ipaddr");
554 /** leave this here (after malloc(), environment and PCI are working) **/
555 /* Initialize devices */
558 /* Initialize the jump table for applications */
561 /* Initialize the console (after the relocation and devices init) */
564 #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
570 debug ("U-Boot relocated to %08lx\n", dest_addr
);
577 /* Must happen after interrupts are initialized since
578 * an irq handler gets installed
582 #ifdef CONFIG_SERIAL_SOFTWARE_FIFO
583 serial_buffered_init();
586 #ifdef CONFIG_STATUS_LED
587 status_led_set (STATUS_LED_BOOT
, STATUS_LED_BLINKING
);
594 /* Insert function pointers now that we have relocated the code */
596 /* Initialize from environment */
597 if ((s
= getenv ("loadaddr")) != NULL
) {
598 load_addr
= simple_strtoul (s
, NULL
, 16);
600 #if (CONFIG_COMMANDS & CFG_CMD_NET)
601 if ((s
= getenv ("bootfile")) != NULL
) {
602 copy_filename (BootFile
, s
, sizeof (BootFile
));
604 #endif /* CFG_CMD_NET */
608 #if (CONFIG_COMMANDS & CFG_CMD_DOC)
614 #if (CONFIG_COMMANDS & CFG_CMD_NAND)
617 nand_init(); /* go init the NAND */
620 #if (CONFIG_COMMANDS & CFG_CMD_NET) && defined(FEC_ENET)
626 post_run (NULL
, POST_RAM
| post_bootmode_get(0));
629 #ifdef CONFIG_LAST_STAGE_INIT
632 * Some parts can be only initialized if all others (like
633 * Interrupts) are up and running (i.e. the PC-style ISA
639 #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
644 #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
646 * Export available size of memory for Linux,
647 * taking into account the protected RAM at top of memory
655 if ((s
= getenv ("pram")) != NULL
) {
656 pram
= simple_strtoul (s
, NULL
, 10);
663 #ifdef CONFIG_LOGBUFFER
664 /* Also take the logbuffer into account (pram is in kB) */
665 pram
+= (LOGBUFF_LEN
+LOGBUFF_OVERHEAD
)/1024;
667 sprintf (memsz
, "%ldk", (bd
->bi_memsize
/ 1024) - pram
);
668 setenv ("mem", memsz
);
672 #ifdef CONFIG_MODEM_SUPPORT
674 extern int do_mdm_init
;
675 do_mdm_init
= gd
->do_mdm_init
;
679 #ifdef CONFIG_WATCHDOG
680 /* disable watchdog if environment is set */
681 if ((s
= getenv ("watchdog")) != NULL
) {
682 if (strncmp (s
, "off", 3) == 0) {
686 #endif /* CONFIG_WATCHDOG*/
689 /* Initialization complete - start the monitor */
691 /* main_loop() can return to retry autoboot, if so just run it again. */
697 /* NOTREACHED - no way out of command loop except booting */
703 puts ("### ERROR ### Please RESET the board ###\n");