blob: 026d247e54ad8a36a1b5ebf53ab6a5539583b8b5 [file] [log] [blame]
wdenk507bbe32004-04-18 21:13:41 +00001/*
2 * (C) Copyright 2004 Atmark Techno, Inc.
3 *
4 * Yasushi SHOJI <yashi@atmark-techno.com>
5 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
23 */
24
25#include <common.h>
26#include <command.h>
27#include <malloc.h>
28#include <version.h>
wdenk7abf0c52004-04-18 21:45:42 +000029#include <watchdog.h>
wdenk507bbe32004-04-18 21:13:41 +000030
Wolfgang Denkd87080b2006-03-31 18:32:53 +020031DECLARE_GLOBAL_DATA_PTR;
32
wdenk507bbe32004-04-18 21:13:41 +000033const char version_string[] =
34 U_BOOT_VERSION" (" __DATE__ " - " __TIME__ ")";
35
36/*
37 * Begin and End of memory area for malloc(), and current "brk"
38 */
39static ulong mem_malloc_start;
40static ulong mem_malloc_end;
41static ulong mem_malloc_brk;
42
43
44void *sbrk (ptrdiff_t increment)
45{
46 ulong old = mem_malloc_brk;
47 ulong new = old + increment;
48
49 if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
50 return (NULL);
51 }
52 mem_malloc_brk = new;
53 return ((void *) old);
54}
55
56/*
57 * All attempts to come up with a "common" initialization sequence
58 * that works for all boards and architectures failed: some of the
59 * requirements are just _too_ different. To get rid of the resulting
60 * mess of board dependend #ifdef'ed code we now make the whole
61 * initialization sequence configurable to the user.
62 *
63 * The requirements for any new initalization function is simple: it
64 * receives a pointer to the "global data" structure as it's only
65 * argument, and returns an integer return code, where 0 means
66 * "continue" and != 0 means "fatal error, hang the system".
67 */
68typedef int (init_fnc_t) (void);
69
70init_fnc_t *init_sequence[] = {
71 serial_init, /* serial communications setup */
72 NULL,
73};
74
wdenk7abf0c52004-04-18 21:45:42 +000075void board_init(void)
76{
wdenk857cad32004-07-10 23:48:41 +000077 bd_t *bd;
wdenk7abf0c52004-04-18 21:45:42 +000078 init_fnc_t **init_fnc_ptr;
79
wdenk857cad32004-07-10 23:48:41 +000080 /* Pointer is writable since we allocated a register for it. */
81 gd = (gd_t *)CFG_GBL_DATA_OFFSET;
82 memset((void *)gd, 0, CFG_GBL_DATA_SIZE);
83
84 gd->bd = (bd_t *)(gd+1); /* At end of global data */
85 gd->baudrate = CONFIG_BAUDRATE;
86
87 bd = gd->bd;
88 bd->bi_baudrate = CONFIG_BAUDRATE;
89
wdenk7abf0c52004-04-18 21:45:42 +000090 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
91 WATCHDOG_RESET ();
92 if ((*init_fnc_ptr) () != 0) {
93 hang ();
94 }
95 }
96
97 /* main_loop */
98 for (;;) {
99 WATCHDOG_RESET ();
100 main_loop ();
101 }
102}
103
wdenk507bbe32004-04-18 21:13:41 +0000104void hang (void)
105{
106 puts ("### ERROR ### Please RESET the board ###\n");
107 for (;;);
108}