2007-07-05 16:01:14 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2002-2006
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*
|
|
|
|
* (C) Copyright 2002
|
|
|
|
* Sysgo Real-Time Solutions, GmbH <www.elinos.com>
|
|
|
|
* Marius Groeger <mgroeger@sysgo.de>
|
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-06-23 10:49:41 +00:00
|
|
|
#ifdef CONFIG_DEBUG_INITCALLS
|
|
|
|
#define DEBUG
|
|
|
|
#endif
|
|
|
|
|
2009-07-31 11:07:03 +00:00
|
|
|
/**
|
|
|
|
* @file
|
2009-12-15 08:11:09 +00:00
|
|
|
* @brief Main entry into the C part of barebox
|
2009-07-31 11:07:03 +00:00
|
|
|
*/
|
2007-07-05 16:01:14 +00:00
|
|
|
#include <common.h>
|
2007-07-05 16:01:24 +00:00
|
|
|
#include <init.h>
|
2007-07-05 16:01:14 +00:00
|
|
|
#include <command.h>
|
|
|
|
#include <malloc.h>
|
2007-07-05 16:01:29 +00:00
|
|
|
#include <debug_ll.h>
|
2007-07-05 16:01:52 +00:00
|
|
|
#include <fs.h>
|
2013-07-10 07:27:06 +00:00
|
|
|
#include <errno.h>
|
2007-07-05 16:01:52 +00:00
|
|
|
#include <linux/stat.h>
|
2013-01-20 12:16:28 +00:00
|
|
|
#include <envfs.h>
|
2011-01-17 09:59:42 +00:00
|
|
|
#include <asm/sections.h>
|
2013-01-20 14:54:08 +00:00
|
|
|
#include <uncompress.h>
|
2007-07-05 16:01:23 +00:00
|
|
|
|
2009-12-15 08:11:09 +00:00
|
|
|
extern initcall_t __barebox_initcalls_start[], __barebox_early_initcalls_end[],
|
|
|
|
__barebox_initcalls_end[];
|
2007-07-12 09:21:13 +00:00
|
|
|
|
2011-04-07 15:47:20 +00:00
|
|
|
#if defined CONFIG_FS_RAMFS && defined CONFIG_FS_DEVFS
|
2009-06-10 21:37:32 +00:00
|
|
|
static int mount_root(void)
|
2007-09-13 13:22:23 +00:00
|
|
|
{
|
2014-02-07 21:28:12 +00:00
|
|
|
mount("none", "ramfs", "/", NULL);
|
2009-06-10 21:37:32 +00:00
|
|
|
mkdir("/dev", 0);
|
2014-02-07 21:28:12 +00:00
|
|
|
mount("none", "devfs", "/dev", NULL);
|
2009-06-10 21:37:32 +00:00
|
|
|
return 0;
|
2007-09-13 13:22:23 +00:00
|
|
|
}
|
2009-06-10 21:37:32 +00:00
|
|
|
fs_initcall(mount_root);
|
2011-04-07 15:47:20 +00:00
|
|
|
#endif
|
2007-09-13 13:22:23 +00:00
|
|
|
|
2013-01-20 12:59:47 +00:00
|
|
|
int (*barebox_main)(void);
|
|
|
|
|
2013-01-20 12:36:20 +00:00
|
|
|
void __noreturn start_barebox(void)
|
2007-07-05 16:01:14 +00:00
|
|
|
{
|
2007-09-13 14:06:02 +00:00
|
|
|
initcall_t *initcall;
|
|
|
|
int result;
|
2007-07-05 16:01:52 +00:00
|
|
|
struct stat s;
|
2007-07-05 16:01:39 +00:00
|
|
|
|
2013-01-20 12:59:47 +00:00
|
|
|
if (!IS_ENABLED(CONFIG_SHELL_NONE))
|
|
|
|
barebox_main = run_shell;
|
|
|
|
|
2009-12-15 08:11:09 +00:00
|
|
|
for (initcall = __barebox_initcalls_start;
|
|
|
|
initcall < __barebox_initcalls_end; initcall++) {
|
2013-03-08 11:59:36 +00:00
|
|
|
pr_debug("initcall-> %pS\n", *initcall);
|
2007-09-13 14:06:02 +00:00
|
|
|
result = (*initcall)();
|
2012-10-07 11:34:46 +00:00
|
|
|
if (result)
|
|
|
|
pr_err("initcall %pS failed: %s\n", *initcall,
|
|
|
|
strerror(-result));
|
2007-09-13 14:06:02 +00:00
|
|
|
}
|
2007-07-05 16:01:24 +00:00
|
|
|
|
2013-03-08 11:59:36 +00:00
|
|
|
pr_debug("initcalls done\n");
|
2011-07-18 13:06:10 +00:00
|
|
|
|
2013-01-20 12:30:17 +00:00
|
|
|
if (IS_ENABLED(CONFIG_ENV_HANDLING)) {
|
|
|
|
int ret;
|
2014-01-23 12:58:49 +00:00
|
|
|
char *default_environment_path = default_environment_path_get();
|
2013-01-20 12:30:17 +00:00
|
|
|
|
|
|
|
ret = envfs_load(default_environment_path, "/env", 0);
|
|
|
|
|
|
|
|
if (ret && IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT)) {
|
2013-03-08 11:59:40 +00:00
|
|
|
pr_err("no valid environment found on %s. "
|
2013-01-20 12:30:17 +00:00
|
|
|
"Using default environment\n",
|
|
|
|
default_environment_path);
|
2014-02-18 09:25:13 +00:00
|
|
|
defaultenv_load("/env", 0);
|
2013-01-20 12:30:17 +00:00
|
|
|
}
|
2007-09-13 13:22:23 +00:00
|
|
|
}
|
2007-10-19 09:04:33 +00:00
|
|
|
|
2013-01-20 12:21:01 +00:00
|
|
|
if (IS_ENABLED(CONFIG_COMMAND_SUPPORT)) {
|
2013-03-08 11:59:40 +00:00
|
|
|
pr_info("running /env/bin/init...\n");
|
2013-01-20 12:21:01 +00:00
|
|
|
|
|
|
|
if (!stat("/env/bin/init", &s)) {
|
2014-02-27 11:23:29 +00:00
|
|
|
run_command("source /env/bin/init");
|
2013-01-20 12:21:01 +00:00
|
|
|
} else {
|
2013-03-08 11:59:40 +00:00
|
|
|
pr_err("/env/bin/init not found\n");
|
2013-09-16 17:49:58 +00:00
|
|
|
if (IS_ENABLED(CONFIG_CMD_LOGIN))
|
2014-02-27 11:23:29 +00:00
|
|
|
while(run_command("login -t 0"));
|
2013-01-20 12:21:01 +00:00
|
|
|
}
|
2007-07-05 16:01:52 +00:00
|
|
|
}
|
2013-01-20 12:59:47 +00:00
|
|
|
|
|
|
|
if (!barebox_main) {
|
2013-03-08 11:59:40 +00:00
|
|
|
pr_err("No main function! aborting.\n");
|
2013-01-20 12:59:47 +00:00
|
|
|
hang();
|
|
|
|
}
|
|
|
|
|
2007-09-13 14:06:02 +00:00
|
|
|
/* main_loop() can return to retry autoboot, if so just run it again. */
|
2007-09-13 13:22:23 +00:00
|
|
|
for (;;)
|
2013-01-20 12:59:47 +00:00
|
|
|
barebox_main();
|
2007-07-05 16:01:14 +00:00
|
|
|
|
|
|
|
/* NOTREACHED - no way out of command loop except booting */
|
|
|
|
}
|
|
|
|
|
2010-03-30 08:18:29 +00:00
|
|
|
void __noreturn hang (void)
|
2007-07-05 16:01:14 +00:00
|
|
|
{
|
|
|
|
puts ("### ERROR ### Please RESET the board ###\n");
|
|
|
|
for (;;);
|
|
|
|
}
|
2009-02-21 00:17:10 +00:00
|
|
|
|
2013-09-19 13:20:22 +00:00
|
|
|
void (*board_shutdown)(void);
|
|
|
|
|
2009-12-15 08:11:09 +00:00
|
|
|
/* Everything needed to cleanly shutdown barebox.
|
2009-02-21 00:17:10 +00:00
|
|
|
* Should be called before starting an OS to get
|
|
|
|
* the devices into a clean state
|
|
|
|
*/
|
2009-12-15 08:11:09 +00:00
|
|
|
void shutdown_barebox(void)
|
2009-02-21 00:17:10 +00:00
|
|
|
{
|
|
|
|
devices_shutdown();
|
2010-03-30 08:31:15 +00:00
|
|
|
#ifdef ARCH_SHUTDOWN
|
|
|
|
arch_shutdown();
|
|
|
|
#endif
|
2013-09-19 13:20:22 +00:00
|
|
|
if (board_shutdown)
|
|
|
|
board_shutdown();
|
2009-02-21 00:17:10 +00:00
|
|
|
}
|