summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2014-08-07 06:14:58 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2014-08-07 06:14:58 +0200
commit50d10b224edf190c5b1f7e8d64140265d19c7bbb (patch)
tree34628949c4cb1fdb4c7fc7395c8a9d0bf765875d /common
parent8a11a59b379b641423a6ed655aae36ec00404403 (diff)
parent95bd1a07a3f28bf9f5ad79219e83685e95d01605 (diff)
downloadbarebox-50d10b224edf190c5b1f7e8d64140265d19c7bbb.tar.gz
barebox-50d10b224edf190c5b1f7e8d64140265d19c7bbb.tar.xz
Merge branch 'for-next/env'
Diffstat (limited to 'common')
-rw-r--r--common/environment.c33
1 files changed, 25 insertions, 8 deletions
diff --git a/common/environment.c b/common/environment.c
index 2d1edf8381..e55c7b7417 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -167,12 +167,13 @@ out:
* Make the current environment persistent
* @param[in] filename where to store
* @param[in] dirname what to store (all files in this dir)
+ * @param[in] flags superblock flags (refer ENVFS_FLAGS_* macros)
* @return 0 on success, anything else in case of failure
*
* Note: This function will also be used on the host! See note in the header
* of this file.
*/
-int envfs_save(const char *filename, const char *dirname)
+int envfs_save(const char *filename, const char *dirname, unsigned flags)
{
struct envfs_super *super;
int envfd, size, ret;
@@ -182,11 +183,15 @@ int envfs_save(const char *filename, const char *dirname)
data.writep = NULL;
data.base = dirname;
- /* first pass: calculate size */
- recursive_action(dirname, ACTION_RECURSE, file_size_action,
- NULL, &data, 0);
+ if (flags & ENVFS_FLAGS_FORCE_BUILT_IN) {
+ size = 0; /* force no content */
+ } else {
+ /* first pass: calculate size */
+ recursive_action(dirname, ACTION_RECURSE, file_size_action,
+ NULL, &data, 0);
- size = (unsigned long)data.writep;
+ size = (unsigned long)data.writep;
+ }
buf = xzalloc(size + sizeof(struct envfs_super));
data.writep = buf + sizeof(struct envfs_super);
@@ -196,10 +201,13 @@ int envfs_save(const char *filename, const char *dirname)
super->major = ENVFS_MAJOR;
super->minor = ENVFS_MINOR;
super->size = ENVFS_32(size);
+ super->flags = ENVFS_32(flags);
- /* second pass: copy files to buffer */
- recursive_action(dirname, ACTION_RECURSE, file_save_action,
- NULL, &data, 0);
+ if (!(flags & ENVFS_FLAGS_FORCE_BUILT_IN)) {
+ /* second pass: copy files to buffer */
+ recursive_action(dirname, ACTION_RECURSE, file_save_action,
+ NULL, &data, 0);
+ }
super->crc = ENVFS_32(crc32(0, buf + sizeof(struct envfs_super), size));
super->sb_crc = ENVFS_32(crc32(0, buf, sizeof(struct envfs_super) - 4));
@@ -447,6 +455,15 @@ int envfs_load(const char *filename, const char *dir, unsigned flags)
if (ret)
goto out;
+ if (super.flags & ENVFS_FLAGS_FORCE_BUILT_IN) {
+ printf("found force-builtin environment, using defaultenv\n");
+ ret = defaultenv_load(dir, 0);
+ if (ret)
+ printf("failed to load default environment: %s\n",
+ strerror(-ret));
+ goto out;
+ }
+
buf = xmalloc(size);
rbuf = buf;