nand_base: We have to ignore the -EUCLEAN error
[barebox-mini2440.git] / common / startup.c
blobe40759d2c69d3b056c757963dc32bc7614d0c2ca
1 /*
2 * (C) Copyright 2002-2006
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * (C) Copyright 2002
6 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
7 * Marius Groeger <mgroeger@sysgo.de>
9 * See file CREDITS for list of people who contributed to this
10 * project.
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * MA 02111-1307 USA
28 /**
29 * @file
30 * @brief Main entry into the C part of U-Boot-v2
32 #include <common.h>
33 #include <init.h>
34 #include <command.h>
35 #include <malloc.h>
36 #include <mem_malloc.h>
37 #include <debug_ll.h>
38 #include <fs.h>
39 #include <linux/stat.h>
40 #include <environment.h>
41 #include <reloc.h>
42 #include <asm-generic/memory_layout.h>
44 extern initcall_t __u_boot_initcalls_start[], __u_boot_early_initcalls_end[],
45 __u_boot_initcalls_end[];
47 static void display_meminfo(void)
49 ulong mstart = mem_malloc_start();
50 ulong mend = mem_malloc_end();
51 ulong msize = mend - mstart + 1;
53 debug("U-Boot code : 0x%08lX -> 0x%08lX BSS: -> 0x%08lX\n",
54 _u_boot_start, _bss_start, _bss_end);
55 printf("Malloc space: 0x%08lx -> 0x%08lx (size %s)\n",
56 mstart, mend, size_human_readable(msize));
57 #ifdef CONFIG_ARM
58 printf("Stack space : 0x%08lx -> 0x%08lx (size %s)\n",
59 STACK_BASE, STACK_BASE + STACK_SIZE,
60 size_human_readable(STACK_SIZE));
61 #endif
64 #ifdef CONFIG_HAS_EARLY_INIT
66 #define EARLY_INITDATA (CFG_INIT_RAM_ADDR + CFG_INIT_RAM_SIZE \
67 - CONFIG_EARLY_INITDATA_SIZE)
69 void *init_data_ptr = (void *)EARLY_INITDATA;
71 void early_init (void)
73 /* copy the early initdata segment to early init RAM */
74 memcpy((void *)EARLY_INITDATA, RELOC(&__early_init_data_begin),
75 (ulong)&__early_init_data_end -
76 (ulong)&__early_init_data_begin);
79 #endif /* CONFIG_HAS_EARLY_INIT */
81 #ifdef CONFIG_DEFAULT_ENVIRONMENT
82 #include <uboot_default_env.h>
84 static struct memory_platform_data default_env_platform_data = {
85 .name = "defaultenv",
88 static struct device_d default_env_dev = {
89 .name = "mem",
90 .platform_data = &default_env_platform_data,
93 static int register_default_env(void)
95 default_env_dev.map_base = (unsigned long)default_environment;
96 default_env_dev.size = sizeof(default_environment);
97 register_device(&default_env_dev);
98 return 0;
101 device_initcall(register_default_env);
102 #endif
104 static int mount_root(void)
106 mount("none", "ramfs", "/");
107 mkdir("/dev", 0);
108 mount("none", "devfs", "/dev");
109 return 0;
111 fs_initcall(mount_root);
113 void start_uboot (void)
115 initcall_t *initcall;
116 int result;
117 struct stat s;
119 #ifdef CONFIG_HAS_EARLY_INIT
120 /* We are running from RAM now, copy early initdata from
121 * early RAM to RAM
123 memcpy(&__early_init_data_begin, init_data_ptr,
124 (ulong)&__early_init_data_end -
125 (ulong)&__early_init_data_begin);
126 init_data_ptr = &__early_init_data_begin;
127 #endif /* CONFIG_HAS_EARLY_INIT */
129 for (initcall = __u_boot_initcalls_start;
130 initcall < __u_boot_initcalls_end; initcall++) {
131 PUTHEX_LL(*initcall);
132 PUTC_LL('\n');
133 result = (*initcall)();
134 if (result)
135 hang();
138 display_meminfo();
140 #ifdef CONFIG_ENV_HANDLING
141 if (envfs_load("/dev/env0", "/env")) {
142 #ifdef CONFIG_DEFAULT_ENVIRONMENT
143 printf("no valid environment found on /dev/env0. "
144 "Using default environment\n");
145 envfs_load("/dev/defaultenv", "/env");
146 #endif
148 #endif
149 printf("running /env/bin/init...\n");
151 if (!stat("/env/bin/init", &s)) {
152 run_command("source /env/bin/init", 0);
153 } else {
154 printf("not found\n");
157 /* main_loop() can return to retry autoboot, if so just run it again. */
158 for (;;)
159 run_shell();
161 /* NOTREACHED - no way out of command loop except booting */
164 void hang (void)
166 puts ("### ERROR ### Please RESET the board ###\n");
167 for (;;);
170 /* Everything needed to cleanly shutdown U-Boot.
171 * Should be called before starting an OS to get
172 * the devices into a clean state
174 void shutdown_uboot(void)
176 devices_shutdown();