* [RFC] Support multiple environments in barebox
@ 2011-03-09 15:17 Juergen Beisert
2011-03-09 15:17 ` [PATCH 1/5] Move environment handling out from the main routine Juergen Beisert
` (4 more replies)
0 siblings, 5 replies; 8+ messages in thread
From: Juergen Beisert @ 2011-03-09 15:17 UTC (permalink / raw)
To: barebox
This patch series adds handling routines for multiple environments. This
can be usefull if an environment partition gets destroyed by accident. In
this case barebox falls back to a second (or more) environment partition.
The board file just have to register env0, env1 and so on. When running the
saveenv command, barebox will store the new content to all environment
partitions it finds.
Comments are welcome, as this is a cleaned patch stack from one of March
last year. And untested, due to the lack of hardware.
jbe
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/5] Move environment handling out from the main routine
2011-03-09 15:17 [RFC] Support multiple environments in barebox Juergen Beisert
@ 2011-03-09 15:17 ` Juergen Beisert
2011-03-09 15:17 ` [PATCH 2/5] CRC value handling and dry run mode in 'envfs_load' Juergen Beisert
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Juergen Beisert @ 2011-03-09 15:17 UTC (permalink / raw)
To: barebox
This is for easier integration of multi environment handling.
Signed-off-by: Juergen Beisert <jbe@pengutronix.de>
---
common/startup.c | 29 ++++++++++++++++++++---------
1 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/common/startup.c b/common/startup.c
index aa76cb7..c39b08e 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -112,6 +112,26 @@ static int mount_root(void)
}
fs_initcall(mount_root);
+static void __maybe_unused load_default_environment(void)
+{
+#ifdef CONFIG_DEFAULT_ENVIRONMENT
+ printf("No valid environment found. Using default environment.\n");
+ envfs_load("/dev/defaultenv", "/env");
+#endif
+}
+
+static int __maybe_unused init_single_envfs_load(void)
+{
+ if (envfs_load("/dev/env0", "/env"))
+ load_default_environment();
+
+ return 0;
+}
+
+#ifdef CONFIG_ENV_HANDLING
+late_initcall(init_single_envfs_load);
+#endif
+
void start_barebox (void)
{
initcall_t *initcall;
@@ -139,15 +159,6 @@ void start_barebox (void)
display_meminfo();
-#ifdef CONFIG_ENV_HANDLING
- if (envfs_load("/dev/env0", "/env")) {
-#ifdef CONFIG_DEFAULT_ENVIRONMENT
- printf("no valid environment found on /dev/env0. "
- "Using default environment\n");
- envfs_load("/dev/defaultenv", "/env");
-#endif
- }
-#endif
printf("running /env/bin/init...\n");
if (!stat("/env/bin/init", &s)) {
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/5] CRC value handling and dry run mode in 'envfs_load'
2011-03-09 15:17 [RFC] Support multiple environments in barebox Juergen Beisert
2011-03-09 15:17 ` [PATCH 1/5] Move environment handling out from the main routine Juergen Beisert
@ 2011-03-09 15:17 ` Juergen Beisert
2011-03-09 15:17 ` [PATCH 3/5] Add generic routine for environment partition handling Juergen Beisert
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Juergen Beisert @ 2011-03-09 15:17 UTC (permalink / raw)
To: barebox; +Cc: Luotao Fu
From: Luotao Fu <l.fu@pengutronix.de>
In order to check if two environments contains the same content, extend the
'envfs_load' to support a crc sum. This change is required to add support
for multiple environments later on.
* envfs_load now accepts a parameter, where the crc value of the environment
partition can be stored.
* add a "dry run" mode to envfs_load. If the dirname is not set, 'envfs_load'
will now check only the crc values of the partition and returns without
writing to the file system.
Signed-off-by: Luotao Fu <l.fu@pengutronix.de>
Acked-by: Juergen Beisert <jbe@pengutronix.de>
---
commands/loadenv.c | 2 +-
common/environment.c | 13 +++++++++++--
common/startup.c | 4 ++--
include/environment.h | 2 +-
scripts/bareboxenv.c | 2 +-
5 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/commands/loadenv.c b/commands/loadenv.c
index c33c34f..5f4c195 100644
--- a/commands/loadenv.c
+++ b/commands/loadenv.c
@@ -40,7 +40,7 @@ static int do_loadenv(struct command *cmdtp, int argc, char *argv[])
else
filename = argv[1];
printf("loading environment from %s\n", filename);
- return envfs_load(filename, dirname);
+ return envfs_load(filename, dirname, NULL);
}
BAREBOX_CMD_HELP_START(loadenv)
diff --git a/common/environment.c b/common/environment.c
index e5f24ec..eb8278f 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -159,13 +159,15 @@ EXPORT_SYMBOL(envfs_save);
/**
* Restore the last environment into the current one
* @param[in] filename from where to restore
- * @param[in] dir where to store the last content
+ * @param[in] dir Where to store the last content. Function will return CRC
+ * value only if 'dir' == NULL.
+ * @param[in] crc Where to store the CRC
* @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_load(char *filename, char *dir)
+int envfs_load(char *filename, char *dir, int *crc)
{
struct envfs_super super;
void *buf = NULL, *buf_free = NULL;
@@ -219,6 +221,13 @@ int envfs_load(char *filename, char *dir)
goto out;
}
+ if (crc != NULL)
+ *crc = ENVFS_32(super.crc);
+
+ /* return CRC only if dir is not set */
+ if (!dir)
+ goto out;
+
while (size) {
struct envfs_inode *inode;
uint32_t inode_size, inode_namelen;
diff --git a/common/startup.c b/common/startup.c
index c39b08e..32a8aa0 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -116,13 +116,13 @@ static void __maybe_unused load_default_environment(void)
{
#ifdef CONFIG_DEFAULT_ENVIRONMENT
printf("No valid environment found. Using default environment.\n");
- envfs_load("/dev/defaultenv", "/env");
+ envfs_load("/dev/defaultenv", "/env", NULL);
#endif
}
static int __maybe_unused init_single_envfs_load(void)
{
- if (envfs_load("/dev/env0", "/env"))
+ if (envfs_load("/dev/env0", "/env", NULL))
load_default_environment();
return 0;
diff --git a/include/environment.h b/include/environment.h
index 21a7ffa..2b1f5d9 100644
--- a/include/environment.h
+++ b/include/environment.h
@@ -50,7 +50,7 @@ int setenv(const char *, const char *);
int env_pop_context(void);
int env_push_context(void);
-int envfs_load(char *filename, char *dirname);
+int envfs_load(char *filename, char *dirname, int *crc);
int envfs_save(char *filename, char *dirname);
int export(const char *);
diff --git a/scripts/bareboxenv.c b/scripts/bareboxenv.c
index 5c7f10e..af012e8 100644
--- a/scripts/bareboxenv.c
+++ b/scripts/bareboxenv.c
@@ -186,7 +186,7 @@ int main(int argc, char *argv[])
if (load) {
printf("loading env from file %s to %s\n", filename, dirname);
- envfs_load(filename, dirname);
+ envfs_load(filename, dirname, NULL);
}
if (save) {
printf("saving contents of %s to file %s\n", dirname, filename);
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 3/5] Add generic routine for environment partition handling
2011-03-09 15:17 [RFC] Support multiple environments in barebox Juergen Beisert
2011-03-09 15:17 ` [PATCH 1/5] Move environment handling out from the main routine Juergen Beisert
2011-03-09 15:17 ` [PATCH 2/5] CRC value handling and dry run mode in 'envfs_load' Juergen Beisert
@ 2011-03-09 15:17 ` Juergen Beisert
2011-03-09 15:17 ` [PATCH 4/5] Add multi environment support Juergen Beisert
2011-03-09 15:17 ` [PATCH 5/5] " Juergen Beisert
4 siblings, 0 replies; 8+ messages in thread
From: Juergen Beisert @ 2011-03-09 15:17 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Acked-by: Juergen Beisert <jbe@pengutronix.de>
---
common/environment.c | 34 ++++++++++++++++++++++++++++++++++
include/environment.h | 1 +
2 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/common/environment.c b/common/environment.c
index eb8278f..3270a08 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -93,6 +93,40 @@ out:
return 1;
}
+#ifdef __BAREBOX__
+int file_check_and_erase(char *filename)
+{
+ int fd;
+ int ret;
+
+ fd = open(filename, O_WRONLY | O_CREAT);
+ if (fd < 0) {
+ printf("could not open %s: %s\n", filename, errno_str());
+ return errno;
+ }
+
+ ret = protect(fd, ~0, 0, 0);
+
+ /* ENOSYS is no error here, many devices do not need it */
+ if (ret && errno != -ENOSYS) {
+ printf("could not unprotect %s: %s\n", filename, errno_str());
+ return errno;
+ }
+
+ ret = erase(fd, ~0, 0);
+
+ /* ENOSYS is no error here, many devices do not need it */
+ if (ret && errno != -ENOSYS) {
+ printf("could not erase %s: %s\n", filename, errno_str());
+ close(fd);
+ return errno;
+ }
+
+ close(fd);
+ return 0;
+}
+#endif /* __BAREBOX__ */
+
/**
* Make the current environment persistent
* @param[in] filename where to store
diff --git a/include/environment.h b/include/environment.h
index 2b1f5d9..b2b95e0 100644
--- a/include/environment.h
+++ b/include/environment.h
@@ -58,6 +58,7 @@ int export(const char *);
struct stat;
int file_size_action(const char *, struct stat *, void *, int);
int file_save_action(const char *, struct stat *, void *, int);
+int file_check_and_erase(char *filename);
#endif /* __BAREBOX__ */
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 4/5] Add multi environment support
2011-03-09 15:17 [RFC] Support multiple environments in barebox Juergen Beisert
` (2 preceding siblings ...)
2011-03-09 15:17 ` [PATCH 3/5] Add generic routine for environment partition handling Juergen Beisert
@ 2011-03-09 15:17 ` Juergen Beisert
2011-03-09 15:17 ` [PATCH 5/5] " Juergen Beisert
4 siblings, 0 replies; 8+ messages in thread
From: Juergen Beisert @ 2011-03-09 15:17 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Acked-by: Juergen Beisert <jbe@pengutronix.de>
---
commands/loadenv.c | 53 ++++++++++++++++++++++++-
commands/saveenv.c | 110 ++++++++++++++++++++++++++++++++-------------------
2 files changed, 120 insertions(+), 43 deletions(-)
diff --git a/commands/loadenv.c b/commands/loadenv.c
index 5f4c195..a6d93cd 100644
--- a/commands/loadenv.c
+++ b/commands/loadenv.c
@@ -26,8 +26,11 @@
#include <common.h>
#include <command.h>
#include <environment.h>
+#include <fs.h>
+#include <linux/stat.h>
-static int do_loadenv(struct command *cmdtp, int argc, char *argv[])
+static int __maybe_unused do_single_loadenv(struct command *cmdtp, int argc,
+ char *argv[])
{
char *filename, *dirname;
@@ -43,9 +46,51 @@ static int do_loadenv(struct command *cmdtp, int argc, char *argv[])
return envfs_load(filename, dirname, NULL);
}
+static int __maybe_unused do_multi_loadenv(struct command *cmdtp, int argc,
+ char *argv[])
+{
+ char *dirname;
+ int rc;
+ int i = 0;
+ char file[9 + 5]; /* '/dev/env.....' */
+ struct stat file_info;
+
+ if (argc < 3)
+ dirname = "/env";
+ else
+ dirname = argv[2];
+
+ if (argc > 1) {
+ rc = envfs_load(argv[1], dirname, NULL);
+ return rc ? 1 : 0;
+ }
+
+ rc = 1;
+
+ /* default filename, loop over all /dev/env[number] till one succeeds */
+ while (1) {
+ sprintf(file, "/dev/env%d", i);
+
+ if (stat(file, &file_info) != 0)
+ break;
+
+ rc = envfs_load(file, dirname, NULL);
+ if (!rc)
+ break;
+ i++;
+ }
+
+ return rc ? 1 : 0;
+}
+
BAREBOX_CMD_HELP_START(loadenv)
BAREBOX_CMD_HELP_USAGE("loadenv [ENVFS] [DIRECTORY]\n")
BAREBOX_CMD_HELP_SHORT("Load environment from ENVFS into DIRECTORY (default: /dev/env0 -> /env).\n")
+#ifdef CONFIG_MULTI_ENV_HANDLING
+BAREBOX_CMD_HELP_SHORT("If more than one environment backend storage is available, and the access to\n")
+BAREBOX_CMD_HELP_SHORT("the first storage fails, this command automatically uses the next available\n")
+BAREBOX_CMD_HELP_SHORT("environment backend storage (env0 -> env1).\n")
+#endif
BAREBOX_CMD_HELP_END
/**
@@ -58,7 +103,11 @@ ENVFS can only handle files, directories are skipped silently.
*/
BAREBOX_CMD_START(loadenv)
- .cmd = do_loadenv,
+#ifdef CONFIG_MULTI_ENV_HANDLING
+ .cmd = do_multi_loadenv,
+#else
+ .cmd = do_single_loadenv,
+#endif
.usage = "Load environment from ENVFS into DIRECTORY (default: /dev/env0 -> /env).",
BAREBOX_CMD_HELP(cmd_loadenv_help)
BAREBOX_CMD_END
diff --git a/commands/saveenv.c b/commands/saveenv.c
index 2f969fe..980ce7f 100644
--- a/commands/saveenv.c
+++ b/commands/saveenv.c
@@ -29,52 +29,22 @@
#include <fs.h>
#include <fcntl.h>
#include <environment.h>
+#include <linux/ctype.h>
+#include <linux/stat.h>
-static int do_saveenv(struct command *cmdtp, int argc, char *argv[])
+static int saveenv(char *filename, char *dirname)
{
- int ret, fd;
- char *filename, *dirname;
-
- printf("saving environment\n");
- if (argc < 3)
- dirname = "/env";
- else
- dirname = argv[2];
- if (argc < 2)
- filename = "/dev/env0";
- else
- filename = argv[1];
-
- fd = open(filename, O_WRONLY | O_CREAT);
- if (fd < 0) {
- printf("could not open %s: %s\n", filename, errno_str());
- return 1;
- }
+ int ret = 0;
+ int fd;
- ret = protect(fd, ~0, 0, 0);
-
- /* ENOSYS is no error here, many devices do not need it */
- if (ret && errno != -ENOSYS) {
- printf("could not unprotect %s: %s\n", filename, errno_str());
- close(fd);
+ ret = file_check_and_erase(filename);
+ if (ret)
return 1;
- }
-
- ret = erase(fd, ~0, 0);
-
- /* ENOSYS is no error here, many devices do not need it */
- if (ret && errno != -ENOSYS) {
- printf("could not erase %s: %s\n", filename, errno_str());
- close(fd);
- return 1;
- }
-
- close(fd);
ret = envfs_save(filename, dirname);
if (ret) {
printf("saveenv failed\n");
- goto out;
+ return 1;
}
fd = open(filename, O_WRONLY | O_CREAT);
@@ -88,19 +58,74 @@ static int do_saveenv(struct command *cmdtp, int argc, char *argv[])
return 1;
}
- ret = 0;
-out:
close(fd);
+
+ return 0;
+}
+
+static int __maybe_unused do_single_saveenv(struct command *cmdtp, int argc,
+ char *argv[])
+{
+ char *filename, *dirname;
+
+ printf("saving environment\n");
+ if (argc < 3)
+ dirname = "/env";
+ else
+ dirname = argv[2];
+ if (argc < 2)
+ filename = "/dev/env0";
+ else
+ filename = argv[1];
+
+ return saveenv(filename, dirname);
+}
+
+static int __maybe_unused do_multi_saveenv(struct command *cmdtp, int argc,
+ char *argv[])
+{
+ int ret = 0;
+ char *dirname;
+ int i = 0;
+ char file[9 + 5];
+ struct stat file_info;
+
+ printf("saving environment\n");
+ if (argc < 3)
+ dirname = "/env";
+ else
+ dirname = argv[2];
+
+ if (argc > 1)
+ return saveenv(argv[1], dirname);
+
+ /* default filename, save environment to all /dev/env[number] */
+ while (1) {
+ sprintf(file, "/dev/env%d", i);
+ if (stat(file, &file_info))
+ break;
+ ret |= saveenv(file, dirname);
+ i++;
+ }
+
return ret;
}
BAREBOX_CMD_HELP_START(saveenv)
BAREBOX_CMD_HELP_USAGE("saveenv [envfs] [directory]\n")
BAREBOX_CMD_HELP_SHORT("Save the files in <directory> to the persistent storage device <envfs>.\n")
+#ifdef CONFIG_MULTI_ENV_HANDLING
+BAREBOX_CMD_HELP_SHORT("If more than one environment backend storage is available it will get stored\n")
+BAREBOX_CMD_HELP_SHORT("in all of them in ascending order (env0 -> env1).\n")
+#endif
BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(saveenv)
- .cmd = do_saveenv,
+#ifdef CONFIG_MULTI_ENV_HANDLING
+ .cmd = do_multi_saveenv,
+#else
+ .cmd = do_single_saveenv,
+#endif
.usage = "save environment to persistent storage",
BAREBOX_CMD_HELP(cmd_saveenv_help)
BAREBOX_CMD_END
@@ -112,6 +137,9 @@ BAREBOX_CMD_END
ommitted, \<directory> defaults to /env and \<envfs> defaults to
/dev/env0. Note that envfs can only handle files, directories are being
skipped silently.</p>
+Only if CONFIG_MULTI_ENV_HANDLING is enabled:
+If more than one environment backend storage is available it will get stored
+in all of them in ascending order (env0 -> env1).
\todo What does 'block in flash' mean? Add example.
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 5/5] Add multi environment support
2011-03-09 15:17 [RFC] Support multiple environments in barebox Juergen Beisert
` (3 preceding siblings ...)
2011-03-09 15:17 ` [PATCH 4/5] Add multi environment support Juergen Beisert
@ 2011-03-09 15:17 ` Juergen Beisert
2011-08-14 6:09 ` Boaz Ben-David
2011-08-14 6:12 ` Boaz Ben-David
4 siblings, 2 replies; 8+ messages in thread
From: Juergen Beisert @ 2011-03-09 15:17 UTC (permalink / raw)
To: barebox; +Cc: Luotao Fu
From: Luotao Fu <l.fu@pengutronix.de>
We can deal with multiple environments now in our barebox. With this option
enabled barebox will scan all environment partions on start up and load the
environment from the first loadable environment partition it finds. Also it will
check the content of all environment parttions and autmotically synchronize
content of any outdated partition.
Signed-off-by: Luotao Fu <l.fu@pengutronix.de>
Acked-by: Juergen Beisert <jbe@pengutronix.de>
---
common/Kconfig | 11 +++++++++
common/startup.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 74 insertions(+), 0 deletions(-)
diff --git a/common/Kconfig b/common/Kconfig
index 02bc67e..272f146 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -53,6 +53,17 @@ config LOCALVERSION_AUTO
which is done within the script "scripts/setlocalversion".)
+config MULTI_ENV_HANDLING
+ select ENV_HANDLING
+ bool "Enable handling multiple environment partitions"
+ help
+ Barebox can handle multiple environments. With this option enabled,
+ barebox will scan all environment partions on start up and
+ load the environment from the first loadable environment partition
+ it finds. Also it will check if the content of all environment
+ partitions are synchronized and automatically synchronize content of
+ the outdated partition.
+
config BOARDINFO
string
diff --git a/common/startup.c b/common/startup.c
index 32a8aa0..759d694 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -128,8 +128,71 @@ static int __maybe_unused init_single_envfs_load(void)
return 0;
}
+static int __maybe_unused init_multi_envfs_load(void)
+{
+ char *dirname = "/env";
+ char file[9 + 5]; /* '/dev/env.....' */
+ int i = 0, j = 0, no_more_parts = 0;
+ int crc = 0, crc_ref = 0;
+ int rc;
+ struct stat file_info;
+
+ while (1) {
+ sprintf(file, "/dev/env%d", i);
+
+ if (stat(file, &file_info) != 0) {
+ no_more_parts = 1;
+ break;
+ }
+
+ /* first loadable environment is considered to be
+ * reference */
+ if (envfs_load(file, dirname, &crc_ref) == 0)
+ break;
+
+ i++;
+ }
+
+ /* no loadable environment partition found */
+ if (no_more_parts == 1) {
+ load_default_environment();
+ goto out;
+ }
+
+ /* Now try to restore, if any, the previous failed partitions */
+ for (j = 0; j < i; j++) {
+ sprintf(file, "/dev/env%d", j);
+ if (envfs_save(file, dirname))
+ printf("failed to sync environment on %s\n", file);
+ }
+
+ /* proceed to scan further env partitions */
+ while (1) {
+ i++;
+ sprintf(file, "/dev/env%d", i);
+
+ if (stat(file, &file_info) != 0)
+ break;
+
+ /* sync partition if loading failed or crc mismatch with
+ * the reference */
+ rc = envfs_load(file, NULL, &crc);
+ if (rc != 0 || crc != crc_ref) {
+ if (envfs_save(file, dirname))
+ printf("failed to sync environment on %s\n",
+ file);
+ }
+ }
+out:
+ return 0;
+}
+
#ifdef CONFIG_ENV_HANDLING
+# ifdef CONFIG_MULTI_ENV_HANDLING
+late_initcall(init_multi_envfs_load);
+# else
late_initcall(init_single_envfs_load);
+# endif
#endif
void start_barebox (void)
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 5/5] Add multi environment support
2011-03-09 15:17 ` [PATCH 5/5] " Juergen Beisert
@ 2011-08-14 6:09 ` Boaz Ben-David
2011-08-14 6:12 ` Boaz Ben-David
1 sibling, 0 replies; 8+ messages in thread
From: Boaz Ben-David @ 2011-08-14 6:09 UTC (permalink / raw)
To: Juergen Beisert; +Cc: barebox, Luotao Fu
[-- Attachment #1: Type: text/html, Size: 5173 bytes --]
[-- Attachment #2: Type: text/plain, Size: 149 bytes --]
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 5/5] Add multi environment support
2011-03-09 15:17 ` [PATCH 5/5] " Juergen Beisert
2011-08-14 6:09 ` Boaz Ben-David
@ 2011-08-14 6:12 ` Boaz Ben-David
1 sibling, 0 replies; 8+ messages in thread
From: Boaz Ben-David @ 2011-08-14 6:12 UTC (permalink / raw)
To: Juergen Beisert; +Cc: barebox, Luotao Fu
On 03/09/11 17:17, Juergen Beisert wrote:
> From: Luotao Fu<l.fu@pengutronix.de>
>
> We can deal with multiple environments now in our barebox. With this option
> enabled barebox will scan all environment partions on start up and load the
> environment from the first loadable environment partition it finds. Also it will
> check the content of all environment parttions and autmotically synchronize
> content of any outdated partition.
>
> Signed-off-by: Luotao Fu<l.fu@pengutronix.de>
> Acked-by: Juergen Beisert<jbe@pengutronix.de>
> ---
> common/Kconfig | 11 +++++++++
> common/startup.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 74 insertions(+), 0 deletions(-)
>
> diff --git a/common/Kconfig b/common/Kconfig
> index 02bc67e..272f146 100644
> --- a/common/Kconfig
> +++ b/common/Kconfig
> @@ -53,6 +53,17 @@ config LOCALVERSION_AUTO
>
> which is done within the script "scripts/setlocalversion".)
>
> +config MULTI_ENV_HANDLING
> + select ENV_HANDLING
> + bool "Enable handling multiple environment partitions"
> + help
> + Barebox can handle multiple environments. With this option enabled,
> + barebox will scan all environment partions on start up and
> + load the environment from the first loadable environment partition
> + it finds. Also it will check if the content of all environment
> + partitions are synchronized and automatically synchronize content of
> + the outdated partition.
> +
> config BOARDINFO
> string
>
> diff --git a/common/startup.c b/common/startup.c
> index 32a8aa0..759d694 100644
> --- a/common/startup.c
> +++ b/common/startup.c
> @@ -128,8 +128,71 @@ static int __maybe_unused init_single_envfs_load(void)
> return 0;
> }
>
> +static int __maybe_unused init_multi_envfs_load(void)
> +{
> + char *dirname = "/env";
> + char file[9 + 5]; /* '/dev/env.....' */
> + int i = 0, j = 0, no_more_parts = 0;
> + int crc = 0, crc_ref = 0;
> + int rc;
> + struct stat file_info;
> +
> + while (1) {
> + sprintf(file, "/dev/env%d", i);
> +
> + if (stat(file,&file_info) != 0) {
> + no_more_parts = 1;
> + break;
> + }
> +
> + /* first loadable environment is considered to be
> + * reference */
> + if (envfs_load(file, dirname,&crc_ref) == 0)
> + break;
> +
> + i++;
> + }
> +
> + /* no loadable environment partition found */
> + if (no_more_parts == 1) {
> + load_default_environment();
> + goto out;
> + }
> +
> + /* Now try to restore, if any, the previous failed partitions */
> + for (j = 0; j< i; j++) {
> + sprintf(file, "/dev/env%d", j);
> + if (envfs_save(file, dirname))
> + printf("failed to sync environment on %s\n", file);
> + }
> +
> + /* proceed to scan further env partitions */
> + while (1) {
> + i++;
> + sprintf(file, "/dev/env%d", i);
> +
> + if (stat(file,&file_info) != 0)
> + break;
> +
> + /* sync partition if loading failed or crc mismatch with
> + * the reference */
> + rc = envfs_load(file, NULL,&crc);
> + if (rc != 0 || crc != crc_ref) {
> + if (envfs_save(file, dirname))
> + printf("failed to sync environment on %s\n",
> + file);
> + }
> + }
> +out:
> + return 0;
> +}
> +
> #ifdef CONFIG_ENV_HANDLING
> +# ifdef CONFIG_MULTI_ENV_HANDLING
> +late_initcall(init_multi_envfs_load);
> +# else
> late_initcall(init_single_envfs_load);
> +# endif
> #endif
>
> void start_barebox (void)
Using this patch on a iMX35 variant I noticed a problem with the envs
recovery.
If on boot we have a broken env partition and we need to recover it from
a working one, don't we
have to first erase the partition?
As I was testing this I got I/O error from the partition after recovery
which went away when I added an erasure of the
partition before writing to it.
Boaz.
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2011-08-14 6:13 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-09 15:17 [RFC] Support multiple environments in barebox Juergen Beisert
2011-03-09 15:17 ` [PATCH 1/5] Move environment handling out from the main routine Juergen Beisert
2011-03-09 15:17 ` [PATCH 2/5] CRC value handling and dry run mode in 'envfs_load' Juergen Beisert
2011-03-09 15:17 ` [PATCH 3/5] Add generic routine for environment partition handling Juergen Beisert
2011-03-09 15:17 ` [PATCH 4/5] Add multi environment support Juergen Beisert
2011-03-09 15:17 ` [PATCH 5/5] " Juergen Beisert
2011-08-14 6:09 ` Boaz Ben-David
2011-08-14 6:12 ` Boaz Ben-David
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox