3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 #include <stdio_dev.h>
30 #include <environment.h>
32 #include <onenand_uboot.h>
35 #ifdef CONFIG_BITBANGMII
39 DECLARE_GLOBAL_DATA_PTR;
41 extern int timer_init(void);
43 extern int incaip_set_cpuclk(void);
45 extern ulong uboot_end_data;
46 extern ulong uboot_end;
48 ulong monitor_flash_len;
50 static char *failed = "*** failed ***\n";
53 * mips_io_port_base is the begin of the address space to which x86 style
54 * I/O ports are mapped.
56 unsigned long mips_io_port_base = -1;
58 int __board_early_init_f(void)
61 * Nothing to do in this dummy implementation
65 int board_early_init_f(void)
66 __attribute__((weak, alias("__board_early_init_f")));
68 static int init_func_ram(void)
70 #ifdef CONFIG_BOARD_TYPES
71 int board_type = gd->board_type;
73 int board_type = 0; /* use dummy arg */
77 gd->ram_size = initdram(board_type);
78 if (gd->ram_size > 0) {
79 print_size(gd->ram_size, "\n");
86 static int display_banner(void)
89 printf("\n\n%s\n\n", version_string);
93 #ifndef CONFIG_SYS_NO_FLASH
94 static void display_flash_config(ulong size)
97 print_size(size, "\n");
101 static int init_baudrate(void)
103 gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
109 * Breath some life into the board...
111 * The first part of initialization is running from Flash memory;
112 * its main purpose is to initialize the RAM so that we
113 * can relocate the monitor code to RAM.
117 * All attempts to come up with a "common" initialization sequence
118 * that works for all boards and architectures failed: some of the
119 * requirements are just _too_ different. To get rid of the resulting
120 * mess of board dependend #ifdef'ed code we now make the whole
121 * initialization sequence configurable to the user.
123 * The requirements for any new initalization function is simple: it
124 * receives a pointer to the "global data" structure as it's only
125 * argument, and returns an integer return code, where 0 means
126 * "continue" and != 0 means "fatal error, hang the system".
128 typedef int (init_fnc_t)(void);
130 init_fnc_t *init_sequence[] = {
133 env_init, /* initialize environment */
134 #ifdef CONFIG_INCA_IP
135 incaip_set_cpuclk, /* set cpu clock according to env. variable */
137 init_baudrate, /* initialize baudrate settings */
138 serial_init, /* serial communications setup */
140 display_banner, /* say that we are here */
147 void board_init_f(ulong bootflag)
151 init_fnc_t **init_fnc_ptr;
152 ulong addr, addr_sp, len = (ulong)&uboot_end - CONFIG_SYS_MONITOR_BASE;
155 /* Pointer is writable since we allocated a register for it.
158 /* compiler optimization barrier needed for GCC >= 3.4 */
159 __asm__ __volatile__("" : : : "memory");
161 memset((void *)gd, 0, sizeof(gd_t));
163 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
164 if ((*init_fnc_ptr)() != 0)
169 * Now that we have DRAM mapped and working, we can
170 * relocate the code and continue running from DRAM.
172 addr = CONFIG_SYS_SDRAM_BASE + gd->ram_size;
174 /* We can reserve some RAM "on top" here.
177 /* round down to next 4 kB limit.
180 debug("Top of RAM usable for U-Boot at: %08lx\n", addr);
182 /* Reserve memory for U-Boot code, data & bss
183 * round down to next 16 kB limit
186 addr &= ~(16 * 1024 - 1);
188 debug("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
190 /* Reserve memory for malloc() arena.
192 addr_sp = addr - TOTAL_MALLOC_LEN;
193 debug("Reserving %dk for malloc() at: %08lx\n",
194 TOTAL_MALLOC_LEN >> 10, addr_sp);
197 * (permanently) allocate a Board Info struct
198 * and a permanent copy of the "global" data
200 addr_sp -= sizeof(bd_t);
201 bd = (bd_t *)addr_sp;
203 debug("Reserving %zu Bytes for Board Info at: %08lx\n",
204 sizeof(bd_t), addr_sp);
206 addr_sp -= sizeof(gd_t);
207 id = (gd_t *)addr_sp;
208 debug("Reserving %zu Bytes for Global Data at: %08lx\n",
209 sizeof(gd_t), addr_sp);
211 /* Reserve memory for boot params.
213 addr_sp -= CONFIG_SYS_BOOTPARAMS_LEN;
214 bd->bi_boot_params = addr_sp;
215 debug("Reserving %dk for boot params() at: %08lx\n",
216 CONFIG_SYS_BOOTPARAMS_LEN >> 10, addr_sp);
219 * Finally, we set up a new (bigger) stack.
221 * Leave some safety gap for SP, force alignment on 16 byte boundary
222 * Clear initial stack frame
226 s = (ulong *)addr_sp;
230 debug("Stack Pointer at: %08lx\n", addr_sp);
233 * Save local variables to board info struct
235 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; /* start of DRAM */
236 bd->bi_memsize = gd->ram_size; /* size of DRAM in bytes */
237 bd->bi_baudrate = gd->baudrate; /* Console Baudrate */
239 memcpy(id, (void *)gd, sizeof(gd_t));
241 relocate_code(addr_sp, id, addr);
243 /* NOTREACHED - relocate_code() does not return */
247 * This is the next part if the initialization sequence: we are now
248 * running from RAM and have a "normal" C environment, i. e. global
249 * data can be written, BSS has been cleared, the stack size in not
250 * that critical any more, etc.
253 void board_init_r(gd_t *id, ulong dest_addr)
255 #ifndef CONFIG_SYS_NO_FLASH
258 extern void malloc_bin_reloc(void);
259 #ifndef CONFIG_ENV_IS_NOWHERE
260 extern char *env_name_spec;
265 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
267 debug("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
269 gd->reloc_off = dest_addr - CONFIG_SYS_MONITOR_BASE;
271 monitor_flash_len = (ulong)&uboot_end_data - dest_addr;
273 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
275 * We have to relocate the command table manually
277 fixup_cmdtable(&__u_boot_cmd_start,
278 (ulong)(&__u_boot_cmd_end - &__u_boot_cmd_start));
279 #endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */
281 /* there are some other pointer constants we must deal with */
282 #ifndef CONFIG_ENV_IS_NOWHERE
283 env_name_spec += gd->reloc_off;
288 /* The Malloc area is immediately below the monitor copy in DRAM */
289 mem_malloc_init(CONFIG_SYS_MONITOR_BASE + gd->reloc_off -
290 TOTAL_MALLOC_LEN, TOTAL_MALLOC_LEN);
293 #ifndef CONFIG_SYS_NO_FLASH
294 /* configure available FLASH banks */
296 display_flash_config(size);
297 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
298 bd->bi_flashsize = size;
300 #if CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
301 bd->bi_flashoffset = monitor_flash_len; /* reserved area for U-Boot */
303 bd->bi_flashoffset = 0;
306 bd->bi_flashstart = 0;
307 bd->bi_flashsize = 0;
308 bd->bi_flashoffset = 0;
311 #ifdef CONFIG_CMD_NAND
313 nand_init(); /* go init the NAND */
316 #if defined(CONFIG_CMD_ONENAND)
320 /* relocate environment function pointers etc. */
323 #if defined(CONFIG_PCI)
325 * Do pci configuration
330 /** leave this here (after malloc(), environment and PCI are working) **/
331 /* Initialize stdio devices */
336 /* Initialize the console (after the relocation and devices init) */
338 /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **/
340 /* Initialize from environment */
341 load_addr = getenv_ulong("loadaddr", 16, load_addr);
342 #if defined(CONFIG_CMD_NET)
344 char *s = getenv("bootfile");
347 copy_filename(BootFile, s, sizeof(BootFile));
351 #ifdef CONFIG_CMD_SPI
353 spi_init(); /* go init the SPI */
357 #if defined(CONFIG_MISC_INIT_R)
358 /* miscellaneous platform dependent initialisations */
362 #ifdef CONFIG_BITBANGMII
365 #if defined(CONFIG_CMD_NET)
367 eth_initialize(gd->bd);
370 /* main_loop() can return to retry autoboot, if so just run it again. */
374 /* NOTREACHED - no way out of command loop except booting */
379 puts("### ERROR ### Please RESET the board ###\n");