summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/Kconfig9
-rw-r--r--common/environment.c11
-rw-r--r--common/filetype.c12
-rw-r--r--common/startup.c95
4 files changed, 72 insertions, 55 deletions
diff --git a/common/Kconfig b/common/Kconfig
index b60b78bb89..df67382191 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -37,9 +37,6 @@ config BLOCK
config BLOCK_WRITE
bool
-config HAVE_NOSHELL
- bool
-
config FILETYPE
bool
@@ -352,12 +349,11 @@ choice
simple shell. No if/then, no return values from commands, no loops
config SHELL_NONE
- depends on HAVE_NOSHELL
bool "no shell (noninteractive build)"
help
No shell at all. This means no shell is started and your board has
- to provide a run_shell() function which is started at the end of
- the barebox startup process.
+ to overwrite the barebox_main function pointer which is then called
+ at the end of the barebox startup process.
endchoice
config GLOB
@@ -407,7 +403,6 @@ config AUTO_COMPLETE
config MENU
bool
prompt "Menu Framework"
- depends on PROCESS_ESCAPE_SEQUENCE
help
a menu framework that allow us to create list menu to simplify
barebox and make it more user-frendly
diff --git a/common/environment.c b/common/environment.c
index e11cd9dd47..eebccce100 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -41,9 +41,16 @@
#define EXPORT_SYMBOL(x)
#endif
+struct action_data {
+ int fd;
+ const char *base;
+ void *writep;
+};
+#define PAD4(x) ((x + 3) & ~3)
+
char *default_environment_path = "/dev/env0";
-int file_size_action(const char *filename, struct stat *statbuf,
+static int file_size_action(const char *filename, struct stat *statbuf,
void *userdata, int depth)
{
struct action_data *data = userdata;
@@ -68,7 +75,7 @@ int file_size_action(const char *filename, struct stat *statbuf,
return 1;
}
-int file_save_action(const char *filename, struct stat *statbuf,
+static int file_save_action(const char *filename, struct stat *statbuf,
void *userdata, int depth)
{
struct action_data *data = userdata;
diff --git a/common/filetype.c b/common/filetype.c
index 748e364e65..22fc621a14 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -106,12 +106,12 @@ enum filetype is_fat_or_mbr(const unsigned char *sector, unsigned long *bootsec)
return filetype_mbr;
}
-enum filetype file_detect_type(void *_buf, size_t bufsize)
+enum filetype file_detect_type(const void *_buf, size_t bufsize)
{
- u32 *buf = _buf;
- u64 *buf64 = _buf;
- u8 *buf8 = _buf;
- u16 *buf16 = _buf;
+ const u32 *buf = _buf;
+ const u64 *buf64 = _buf;
+ const u8 *buf8 = _buf;
+ const u16 *buf16 = _buf;
enum filetype type;
if (bufsize < 9)
@@ -145,7 +145,7 @@ enum filetype file_detect_type(void *_buf, size_t bufsize)
return filetype_aimage;
if (buf64[0] == le64_to_cpu(0x0a1a0a0d474e5089ull))
return filetype_png;
- if (strncmp(buf8 + 0x10, "barebox", 7) == 0)
+ if (is_barebox_mips_head(_buf))
return filetype_mips_barebox;
if (bufsize < 64)
diff --git a/common/startup.c b/common/startup.c
index 14409a217d..52a8996cdf 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -32,8 +32,9 @@
#include <debug_ll.h>
#include <fs.h>
#include <linux/stat.h>
-#include <environment.h>
+#include <envfs.h>
#include <asm/sections.h>
+#include <uncompress.h>
extern initcall_t __barebox_initcalls_start[], __barebox_early_initcalls_end[],
__barebox_initcalls_end[];
@@ -41,32 +42,35 @@ extern initcall_t __barebox_initcalls_start[], __barebox_early_initcalls_end[],
#ifdef CONFIG_DEFAULT_ENVIRONMENT
#include "barebox_default_env.h"
-#ifdef CONFIG_DEFAULT_ENVIRONMENT_COMPRESSED
-#include <uncompress.h>
-void *defaultenv;
-#else
-#define defaultenv default_environment
-#endif
-
static int register_default_env(void)
{
-#ifdef CONFIG_DEFAULT_ENVIRONMENT_COMPRESSED
int ret;
- void *tmp;
+ void *defaultenv;
- tmp = xzalloc(default_environment_size);
- memcpy(tmp, default_environment, default_environment_size);
+ if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT_COMPRESSED)) {
+ void *tmp = malloc(default_environment_size);
- defaultenv = xzalloc(default_environment_uncompress_size);
+ if (!tmp)
+ return -ENOMEM;
- ret = uncompress(tmp, default_environment_size, NULL, NULL,
- defaultenv, NULL, uncompress_err_stdout);
+ memcpy(tmp, default_environment, default_environment_size);
- free(tmp);
+ defaultenv = xzalloc(default_environment_uncompress_size);
+
+ ret = uncompress(tmp, default_environment_size,
+ NULL, NULL,
+ defaultenv, NULL, uncompress_err_stdout);
+
+ free(tmp);
+
+ if (ret) {
+ free(defaultenv);
+ return ret;
+ }
+ } else {
+ defaultenv = (void *)default_environment;
+ }
- if (ret)
- return ret;
-#endif
add_mem_device("defaultenv", (unsigned long)defaultenv,
default_environment_uncompress_size,
@@ -88,13 +92,16 @@ static int mount_root(void)
fs_initcall(mount_root);
#endif
-void start_barebox (void)
+int (*barebox_main)(void);
+
+void __noreturn start_barebox(void)
{
initcall_t *initcall;
int result;
-#ifdef CONFIG_COMMAND_SUPPORT
struct stat s;
-#endif
+
+ if (!IS_ENABLED(CONFIG_SHELL_NONE))
+ barebox_main = run_shell;
for (initcall = __barebox_initcalls_start;
initcall < __barebox_initcalls_end; initcall++) {
@@ -107,28 +114,37 @@ void start_barebox (void)
debug("initcalls done\n");
-#ifdef CONFIG_ENV_HANDLING
- if (envfs_load(default_environment_path, "/env", 0)) {
-#ifdef CONFIG_DEFAULT_ENVIRONMENT
- printf("no valid environment found on %s. "
- "Using default environment\n",
- default_environment_path);
- envfs_load("/dev/defaultenv", "/env", 0);
-#endif
+ if (IS_ENABLED(CONFIG_ENV_HANDLING)) {
+ int ret;
+
+ ret = envfs_load(default_environment_path, "/env", 0);
+
+ if (ret && IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT)) {
+ printf("no valid environment found on %s. "
+ "Using default environment\n",
+ default_environment_path);
+ envfs_load("/dev/defaultenv", "/env", 0);
+ }
}
-#endif
-#ifdef CONFIG_COMMAND_SUPPORT
- printf("running /env/bin/init...\n");
- if (!stat("/env/bin/init", &s)) {
- run_command("source /env/bin/init", 0);
- } else {
- printf("not found\n");
+ if (IS_ENABLED(CONFIG_COMMAND_SUPPORT)) {
+ printf("running /env/bin/init...\n");
+
+ if (!stat("/env/bin/init", &s)) {
+ run_command("source /env/bin/init", 0);
+ } else {
+ printf("not found\n");
+ }
}
-#endif
+
+ if (!barebox_main) {
+ printf("No main function! aborting.\n");
+ hang();
+ }
+
/* main_loop() can return to retry autoboot, if so just run it again. */
for (;;)
- run_shell();
+ barebox_main();
/* NOTREACHED - no way out of command loop except booting */
}
@@ -150,4 +166,3 @@ void shutdown_barebox(void)
arch_shutdown();
#endif
}
-