summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2018-02-08 09:03:46 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2018-02-08 09:03:46 +0100
commit490a3c496454cea131dbd5edadbe7d7cfce4cfa8 (patch)
tree5222ffde63801a98ce90168d6be2247cc39bcfa7 /common
parentb84f8a712ffe04def5f3d402ef9be990d485ecce (diff)
parent5316da0098c913b1e548801a57b7d5d9fd5a4d6d (diff)
downloadbarebox-490a3c496454cea131dbd5edadbe7d7cfce4cfa8.tar.gz
barebox-490a3c496454cea131dbd5edadbe7d7cfce4cfa8.tar.xz
Merge branch 'for-next/misc'
Diffstat (limited to 'common')
-rw-r--r--common/Kconfig1
-rw-r--r--common/boot.c2
-rw-r--r--common/bootargs.c6
-rw-r--r--common/env.c2
-rw-r--r--common/filetype.c10
-rw-r--r--common/startup.c6
-rw-r--r--common/state/state.c14
-rw-r--r--common/state/state.h2
8 files changed, 32 insertions, 11 deletions
diff --git a/common/Kconfig b/common/Kconfig
index 57418cadc6..93b1d89274 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -947,7 +947,6 @@ config STATE_BACKWARD_COMPATIBLE
config BOOTCHOOSER
bool "bootchooser infrastructure"
- depends on !SHELL_NONE
select BOOT
select BOOTM
select ENVIRONMENT_VARIABLES
diff --git a/common/boot.c b/common/boot.c
index cef3d5e514..41bf1ce64b 100644
--- a/common/boot.c
+++ b/common/boot.c
@@ -289,7 +289,7 @@ int bootentry_create_from_name(struct bootentries *bootentries,
found += ret;
}
- if (!found) {
+ if (IS_ENABLED(CONFIG_COMMAND_SUPPORT) && !found) {
char *path;
if (*name != '/')
diff --git a/common/bootargs.c b/common/bootargs.c
index a89f23a3f2..f0ab689158 100644
--- a/common/bootargs.c
+++ b/common/bootargs.c
@@ -56,19 +56,21 @@ const char *linux_bootargs_get(void)
bootargs = basprintf("%s mtdparts=%s", linux_bootargs,
parts);
free(linux_bootargs);
- free(parts);
linux_bootargs = bootargs;
}
+ free(parts);
+
parts = globalvar_get_match("linux.blkdevparts.", ";");
if (strlen(parts)) {
bootargs = basprintf("%s blkdevparts=%s", linux_bootargs,
parts);
free(linux_bootargs);
- free(parts);
linux_bootargs = bootargs;
}
+ free(parts);
+
return linux_bootargs;
}
diff --git a/common/env.c b/common/env.c
index 80d3f7ab50..323a82223e 100644
--- a/common/env.c
+++ b/common/env.c
@@ -266,7 +266,7 @@ int setenv(const char *_name, const char *value)
if (strchr(name, '.')) {
ret = dev_setenv(name, value);
if (ret)
- eprintf("Cannot set parameter: %s\n", strerror(-ret));
+ eprintf("Cannot set parameter %s: %s\n", name, strerror(-ret));
goto out;
}
diff --git a/common/filetype.c b/common/filetype.c
index f9c034ff2a..71691fd813 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -21,6 +21,7 @@
#include <asm/unaligned.h>
#include <fcntl.h>
#include <fs.h>
+#include <libfile.h>
#include <malloc.h>
#include <errno.h>
#include <envfs.h>
@@ -343,13 +344,13 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
return filetype_unknown;
}
-enum filetype file_name_detect_type(const char *filename)
+enum filetype file_name_detect_type_offset(const char *filename, loff_t pos)
{
int fd, ret;
void *buf;
enum filetype type = filetype_unknown;
- fd = open(filename, O_RDONLY);
+ fd = open_and_lseek(filename, O_RDONLY, pos);
if (fd < 0)
return fd;
@@ -368,6 +369,11 @@ err_out:
return type;
}
+enum filetype file_name_detect_type(const char *filename)
+{
+ return file_name_detect_type_offset(filename, 0);
+}
+
enum filetype cdev_detect_type(const char *name)
{
enum filetype type = filetype_unknown;
diff --git a/common/startup.c b/common/startup.c
index 432be67cd6..8b075422dd 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -66,6 +66,9 @@ static int mount_root(void)
mount("none", "pstore", "/pstore", NULL);
}
+ if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT))
+ defaultenv_load("/env", 0);
+
return 0;
}
fs_initcall(mount_root);
@@ -78,9 +81,6 @@ static int load_environment(void)
default_environment_path = default_environment_path_get();
- if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT))
- defaultenv_load("/env", 0);
-
envfs_load(default_environment_path, "/env", 0);
nvvar_load();
diff --git a/common/state/state.c b/common/state/state.c
index 6399bd3736..cb979328c1 100644
--- a/common/state/state.c
+++ b/common/state/state.c
@@ -99,6 +99,7 @@ static int state_do_load(struct state *state, enum state_flags flags)
goto out;
}
+ state->init_from_defaults = 0;
state->dirty = 0;
out:
@@ -153,6 +154,11 @@ void state_backend_set_readonly(struct state *state)
state_storage_set_readonly(&state->storage);
}
+static int state_set_deny(struct param_d *p, void *priv)
+{
+ return -EROFS;
+}
+
static struct state *state_new(const char *name)
{
struct state *state;
@@ -172,12 +178,16 @@ static struct state *state_new(const char *name)
}
state->dirty = 1;
- dev_add_param_bool(&state->dev, "dirty", NULL, NULL, &state->dirty,
+ dev_add_param_bool(&state->dev, "dirty", state_set_deny, NULL, &state->dirty,
NULL);
+
state->save_on_shutdown = 1;
dev_add_param_bool(&state->dev, "save_on_shutdown", NULL, NULL,
&state->save_on_shutdown, NULL);
+ dev_add_param_bool(&state->dev, "init_from_defaults", state_set_deny, NULL,
+ &state->init_from_defaults, NULL);
+
list_add_tail(&state->list, &state_list);
return state;
@@ -638,6 +648,8 @@ struct state *state_new_from_node(struct device_node *node, char *path,
goto out_release_state;
}
+ state->init_from_defaults = 1;
+
ret = of_register_fixup(of_state_fixup, state);
if (ret) {
goto out_release_state;
diff --git a/common/state/state.h b/common/state/state.h
index fcc6b9f5cd..da1c6acaeb 100644
--- a/common/state/state.h
+++ b/common/state/state.h
@@ -107,7 +107,9 @@ struct state {
uint32_t magic;
struct list_head variables; /* Sorted list of variables */
+
unsigned int dirty;
+ unsigned int init_from_defaults;
unsigned int save_on_shutdown;
struct state_backend_format *format;