Wolfgang Denk | 83c1585 | 2006-10-24 14:21:16 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2006 Atmel Corporation |
| 3 | * |
| 4 | * See file CREDITS for list of people who contributed to this |
| 5 | * project. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation; either version 2 of |
| 10 | * the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 20 | * MA 02111-1307 USA |
| 21 | */ |
| 22 | #include <common.h> |
| 23 | #include <command.h> |
| 24 | #include <malloc.h> |
| 25 | #include <devices.h> |
| 26 | #include <version.h> |
| 27 | #include <net.h> |
| 28 | |
| 29 | #include <asm/initcalls.h> |
| 30 | #include <asm/sections.h> |
| 31 | |
| 32 | #ifndef CONFIG_IDENT_STRING |
| 33 | #define CONFIG_IDENT_STRING "" |
| 34 | #endif |
| 35 | |
| 36 | DECLARE_GLOBAL_DATA_PTR; |
| 37 | |
| 38 | const char version_string[] = |
| 39 | U_BOOT_VERSION " (" __DATE__ " - " __TIME__ ") " CONFIG_IDENT_STRING; |
| 40 | |
| 41 | unsigned long monitor_flash_len; |
| 42 | |
| 43 | /* |
| 44 | * Begin and end of memory area for malloc(), and current "brk" |
| 45 | */ |
| 46 | static unsigned long mem_malloc_start = 0; |
| 47 | static unsigned long mem_malloc_end = 0; |
| 48 | static unsigned long mem_malloc_brk = 0; |
| 49 | |
| 50 | /* The malloc area is wherever the board wants it to be */ |
| 51 | static void mem_malloc_init(void) |
| 52 | { |
| 53 | mem_malloc_start = CFG_MALLOC_START; |
| 54 | mem_malloc_end = CFG_MALLOC_END; |
| 55 | mem_malloc_brk = mem_malloc_start; |
| 56 | |
| 57 | printf("malloc: Using memory from 0x%08lx to 0x%08lx\n", |
| 58 | mem_malloc_start, mem_malloc_end); |
| 59 | |
| 60 | memset ((void *)mem_malloc_start, 0, |
| 61 | mem_malloc_end - mem_malloc_start); |
| 62 | } |
| 63 | |
| 64 | void *sbrk(ptrdiff_t increment) |
| 65 | { |
| 66 | unsigned long old = mem_malloc_brk; |
| 67 | unsigned long new = old + increment; |
| 68 | |
| 69 | if ((new < mem_malloc_start) || (new > mem_malloc_end)) |
| 70 | return NULL; |
| 71 | |
| 72 | mem_malloc_brk = new; |
| 73 | return ((void *)old); |
| 74 | } |
| 75 | |
| 76 | static int init_baudrate(void) |
| 77 | { |
| 78 | char tmp[64]; |
| 79 | int i; |
| 80 | |
| 81 | i = getenv_r("baudrate", tmp, sizeof(tmp)); |
| 82 | if (i > 0) { |
| 83 | gd->baudrate = simple_strtoul(tmp, NULL, 10); |
| 84 | } else { |
| 85 | gd->baudrate = CONFIG_BAUDRATE; |
| 86 | } |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | |
| 91 | static int display_banner (void) |
| 92 | { |
| 93 | printf ("\n\n%s\n\n", version_string); |
| 94 | printf ("U-Boot code: %p -> %p data: %p -> %p\n", |
| 95 | _text, _etext, _data, _end); |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | void hang(void) |
| 100 | { |
| 101 | for (;;) ; |
| 102 | } |
| 103 | |
| 104 | static int display_dram_config (void) |
| 105 | { |
| 106 | int i; |
| 107 | |
| 108 | puts ("DRAM Configuration:\n"); |
| 109 | |
| 110 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
| 111 | printf ("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start); |
| 112 | print_size (gd->bd->bi_dram[i].size, "\n"); |
| 113 | } |
| 114 | |
| 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | static void display_flash_config (void) |
| 119 | { |
| 120 | puts ("Flash: "); |
| 121 | print_size(gd->bd->bi_flashsize, " "); |
| 122 | printf("at address 0x%08lx\n", gd->bd->bi_flashstart); |
| 123 | } |
| 124 | |
Haavard Skinnemoen | 4707f0f | 2006-11-18 17:15:30 +0100 | [diff] [blame] | 125 | void board_init_f(ulong unused) |
Wolfgang Denk | 83c1585 | 2006-10-24 14:21:16 +0200 | [diff] [blame] | 126 | { |
| 127 | gd_t gd_data; |
| 128 | |
| 129 | /* Initialize the global data pointer */ |
| 130 | memset(&gd_data, 0, sizeof(gd_data)); |
| 131 | gd = &gd_data; |
| 132 | |
Wolfgang Denk | 83c1585 | 2006-10-24 14:21:16 +0200 | [diff] [blame] | 133 | /* Perform initialization sequence */ |
Haavard Skinnemoen | 0a2743f | 2006-11-19 18:06:53 +0100 | [diff] [blame^] | 134 | board_early_init_f(); |
Wolfgang Denk | 83c1585 | 2006-10-24 14:21:16 +0200 | [diff] [blame] | 135 | cpu_init(); |
| 136 | timer_init(); |
| 137 | env_init(); |
| 138 | init_baudrate(); |
| 139 | serial_init(); |
| 140 | console_init_f(); |
| 141 | display_banner(); |
Wolfgang Denk | 83c1585 | 2006-10-24 14:21:16 +0200 | [diff] [blame] | 142 | board_init_memories(); |
Haavard Skinnemoen | 4707f0f | 2006-11-18 17:15:30 +0100 | [diff] [blame] | 143 | |
| 144 | board_init_r(gd, CFG_MONITOR_BASE); |
| 145 | } |
Wolfgang Denk | 83c1585 | 2006-10-24 14:21:16 +0200 | [diff] [blame] | 146 | |
Haavard Skinnemoen | 4707f0f | 2006-11-18 17:15:30 +0100 | [diff] [blame] | 147 | void board_init_r(gd_t *new_gd, ulong dest_addr) |
| 148 | { |
| 149 | gd = new_gd; |
| 150 | |
| 151 | monitor_flash_len = _edata - _text; |
| 152 | |
| 153 | mem_malloc_init(); |
Wolfgang Denk | 83c1585 | 2006-10-24 14:21:16 +0200 | [diff] [blame] | 154 | gd->bd = malloc(sizeof(bd_t)); |
| 155 | memset(gd->bd, 0, sizeof(bd_t)); |
| 156 | gd->bd->bi_baudrate = gd->baudrate; |
| 157 | gd->bd->bi_dram[0].start = CFG_SDRAM_BASE; |
| 158 | gd->bd->bi_dram[0].size = gd->sdram_size; |
| 159 | |
| 160 | board_init_info(); |
| 161 | flash_init(); |
| 162 | |
| 163 | if (gd->bd->bi_flashsize) |
| 164 | display_flash_config(); |
| 165 | if (gd->bd->bi_dram[0].size) |
| 166 | display_dram_config(); |
| 167 | |
| 168 | gd->bd->bi_boot_params = malloc(CFG_BOOTPARAMS_LEN); |
| 169 | if (!gd->bd->bi_boot_params) |
| 170 | puts("WARNING: Cannot allocate space for boot parameters\n"); |
| 171 | |
| 172 | /* initialize environment */ |
| 173 | env_relocate(); |
| 174 | |
| 175 | devices_init(); |
| 176 | jumptable_init(); |
| 177 | console_init_r(); |
| 178 | |
| 179 | for (;;) { |
| 180 | main_loop(); |
| 181 | } |
| 182 | } |