2 * (C) Copyright 2002-2006
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
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
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,
30 * @brief Main entry into the C part of U-Boot-v2
36 #include <mem_malloc.h>
39 #include <linux/stat.h>
40 #include <environment.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
));
58 printf("Stack space : 0x%08lx -> 0x%08lx (size %s)\n",
59 STACK_BASE
, STACK_BASE
+ STACK_SIZE
,
60 size_human_readable(STACK_SIZE
));
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
= {
88 static struct device_d default_env_dev
= {
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
);
101 device_initcall(register_default_env
);
104 static int mount_root(void)
106 mount("none", "ramfs", "/");
108 mount("none", "devfs", "/dev");
111 fs_initcall(mount_root
);
113 void start_uboot (void)
115 initcall_t
*initcall
;
119 #ifdef CONFIG_HAS_EARLY_INIT
120 /* We are running from RAM now, copy early initdata from
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
);
133 result
= (*initcall
)();
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");
149 printf("running /env/bin/init...\n");
151 if (!stat("/env/bin/init", &s
)) {
152 run_command("source /env/bin/init", 0);
154 printf("not found\n");
157 /* main_loop() can return to retry autoboot, if so just run it again. */
161 /* NOTREACHED - no way out of command loop except booting */
166 puts ("### ERROR ### Please RESET the board ###\n");
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)