2 * Copyright (c) 2011 The Chromium OS Authors.
3 * (C) Copyright 2002-2006
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
8 * Marius Groeger <mgroeger@sysgo.de>
10 * See file CREDITS for list of people who contributed to this
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of
16 * the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 #ifdef CONFIG_HAS_DATAFLASH
31 #include <dataflash.h>
33 #include <environment.h>
40 #include <onenand_uboot.h>
42 #include <stdio_dev.h>
43 #include <asm/sections.h>
45 DECLARE_GLOBAL_DATA_PTR;
47 ulong monitor_flash_len;
50 static int initr_reloc(void)
52 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
53 bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r");
60 * Some of these functions are needed purely because the functions they
61 * call return void. If we change them to return 0, these stubs can go away.
63 static int initr_caches(void)
71 static int initr_reloc_global_data(void)
73 #ifdef CONFIG_SYS_SYM_OFFSETS
74 monitor_flash_len = _end_ofs;
76 monitor_flash_len = (ulong)&__init_end - gd->dest_addr;
80 static int initr_serial(void)
86 #ifdef CONFIG_LOGBUFFER
87 unsigned long logbuffer_base(void)
89 return gd->ram_top - LOGBUFF_LEN;
92 static int initr_logbuffer(void)
100 static int initr_post_backlog(void)
102 post_output_backlog();
107 static int initr_malloc(void)
111 /* The malloc area is immediately below the monitor copy in DRAM */
112 malloc_start = gd->dest_addr - TOTAL_MALLOC_LEN;
113 mem_malloc_init(malloc_start, TOTAL_MALLOC_LEN);
117 __weak int power_init_board(void)
122 static int initr_announce(void)
124 debug("Now running in RAM - U-Boot at: %08lx\n", gd->dest_addr);
128 #if !defined(CONFIG_SYS_NO_FLASH)
129 static int initr_flash(void)
135 flash_size = flash_init();
136 if (flash_size <= 0) {
137 puts("*** failed ***\n");
140 print_size(flash_size, "");
141 #ifdef CONFIG_SYS_FLASH_CHECKSUM
143 * Compute and print flash CRC if flashchecksum is set to 'y'
145 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
147 if (getenv_yesno("flashchecksum") == 1) {
148 printf(" CRC: %08X", crc32(0,
149 (const unsigned char *) CONFIG_SYS_FLASH_BASE,
152 #endif /* CONFIG_SYS_FLASH_CHECKSUM */
159 #ifdef CONFIG_CMD_NAND
160 /* go init the NAND */
169 #if defined(CONFIG_CMD_ONENAND)
170 /* go init the NAND */
171 int initr_onenand(void)
179 #ifdef CONFIG_GENERIC_MMC
183 mmc_initialize(gd->bd);
188 #ifdef CONFIG_HAS_DATAFLASH
189 int initr_dataflash(void)
191 AT91F_DataflashInit();
192 dataflash_print_info();
198 * Tell if it's OK to load the environment early in boot.
200 * If CONFIG_OF_CONFIG is defined, we'll check with the FDT to see
201 * if this is OK (defaulting to saying it's OK).
203 * NOTE: Loading the environment early can be a bad idea if security is
204 * important, since no verification is done on the environment.
206 * @return 0 if environment should not be loaded, !=0 if it is ok to load
208 static int should_load_env(void)
210 #ifdef CONFIG_OF_CONTROL
211 return fdtdec_get_config_int(gd->fdt_blob, "load-environment", 1);
212 #elif defined CONFIG_DELAY_ENVIRONMENT
219 static int initr_env(void)
221 /* initialize environment */
222 if (should_load_env())
225 set_default_env(NULL);
227 /* Initialize from environment */
228 load_addr = getenv_ulong("loadaddr", 16, load_addr);
232 static int initr_jumptable(void)
238 #if defined(CONFIG_API)
239 static int initr_api(void)
247 #ifdef CONFIG_DISPLAY_BOARDINFO_LATE
248 static int show_model_r(void)
250 /* Put this here so it appears on the LCD, now it is ready */
251 # ifdef CONFIG_OF_CONTROL
254 model = (char *)fdt_getprop(gd->fdt_blob, 0, "model", NULL);
255 printf("Model: %s\n", model ? model : "<unknown>");
262 /* enable exceptions */
263 static int initr_enable_interrupts(void)
269 #ifdef CONFIG_CMD_NET
270 static int initr_ethaddr(void)
275 #endif /* CONFIG_CMD_NET */
277 #ifdef CONFIG_BITBANGMII
278 static int initr_bbmii(void)
285 #ifdef CONFIG_CMD_NET
286 static int initr_net(void)
289 eth_initialize(gd->bd);
290 #if defined(CONFIG_RESET_PHY_R)
291 debug("Reset Ethernet PHY\n");
299 static int initr_post(void)
301 post_run(NULL, POST_RAM | post_bootmode_get(0));
306 #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
308 * Export available size of memory for Linux, taking into account the
309 * protected RAM at top of memory
317 pram = getenv_ulong("pram", 10, CONFIG_PRAM);
319 # if defined(CONFIG_LOGBUFFER) && !defined(CONFIG_ALT_LB_ADDR)
320 /* Also take the logbuffer into account (pram is in kB) */
321 pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024;
323 sprintf(memsz, "%ldk", (gd->ram_size / 1024) - pram);
324 setenv("mem", memsz);
328 static int run_main_loop(void)
330 /* main_loop() can return to retry autoboot, if so just run it again */
337 * Over time we hope to remove these functions with code fragments and
338 * stub funtcions, and instead call the relevant function directly.
340 * We also hope to remove most of the driver-related init and do it if/when
341 * the driver is later used.
343 init_fnc_t init_sequence_r[] = {
347 board_init, /* Setup chipselects */
349 initr_reloc_global_data,
352 #ifdef CONFIG_LOGBUFFER
359 #ifdef CONFIG_ARCH_EARLY_INIT_R
363 #ifndef CONFIG_SYS_NO_FLASH
366 #ifdef CONFIG_CMD_NAND
369 #ifdef CONFIG_CMD_ONENAND
372 #ifdef CONFIG_GENERIC_MMC
375 #ifdef CONFIG_HAS_DATAFLASH
384 console_init_r, /* fully init console as a device */
385 #ifdef CONFIG_DISPLAY_BOARDINFO_LATE
388 #ifdef CONFIG_ARCH_MISC_INIT
389 arch_misc_init, /* miscellaneous arch-dependent init */
391 #ifdef CONFIG_MISC_INIT_R
392 misc_init_r, /* miscellaneous platform-dependent init */
395 initr_enable_interrupts,
396 #ifdef CONFIG_CMD_NET
399 #ifdef CONFIG_BOARD_LATE_INIT
402 #ifdef CONFIG_BITBANGMII
405 #ifdef CONFIG_CMD_NET
414 void board_init_r(gd_t *new_gd, ulong dest_addr)
417 if (initcall_run_list(init_sequence_r))
420 /* NOTREACHED - run_main_loop() does not return */