mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Luotao Fu <l.fu@pengutronix.de>
To: s.hauer@pengutronix.de
Cc: barebox@lists.infradead.org, Luotao Fu <l.fu@pengutronix.de>
Subject: [PATCH V2 2/4] add multi environment support
Date: Mon,  5 Jul 2010 15:57:38 +0200	[thread overview]
Message-ID: <1278338260-29454-3-git-send-email-l.fu@pengutronix.de> (raw)
In-Reply-To: <1278338260-29454-1-git-send-email-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>
---
V2 Changes:
* fix envfs_load call if the multienv support is disabled

 common/Kconfig   |   11 ++++++
 common/startup.c |   90 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 92 insertions(+), 9 deletions(-)

diff --git a/common/Kconfig b/common/Kconfig
index a58f242..c33cf14 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -40,6 +40,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
+	  We can have multiple environments 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 if the content of all environment
+	  parttions are synchronized and autmotically synchronize content of
+	  the outdated partition.
+
 config BOARDINFO
 	string
 
diff --git a/common/startup.c b/common/startup.c
index 2190159..b57a712 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -110,6 +110,87 @@ static int mount_root(void)
 }
 fs_initcall(mount_root);
 
+#ifdef CONFIG_ENV_HANDLING
+#ifdef CONFIG_MULTI_ENV_HANDLING
+static int init_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) {
+#ifdef CONFIG_DEFAULT_ENVIRONMENT
+		printf("no valid environment found. "
+			"Using default environment\n");
+		envfs_load("/dev/defaultenv", "/env", &crc_ref);
+#endif
+		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;
+}
+#else /* MULTI_ENV_HANDLING */
+static int init_envfs_load(void)
+{
+	if (envfs_load("/dev/env0", "/env", NULL)) {
+#ifdef CONFIG_DEFAULT_ENVIRONMENT
+		printf("no valid environment found. "
+			"Using default environment\n");
+		envfs_load("/dev/defaultenv", "/env", NULL);
+#endif
+	}
+
+	return 0;
+}
+#endif /* MULTI_ENV_HANDLING */
+late_initcall(init_envfs_load);
+#endif /* CONFIG_ENV_HANDLING */
+
 void start_barebox (void)
 {
 	initcall_t *initcall;
@@ -137,15 +218,6 @@ void start_barebox (void)
 
 	display_meminfo();
 
-#ifdef CONFIG_ENV_HANDLING
-	if (envfs_load("/dev/env0", "/env", NULL)) {
-#ifdef CONFIG_DEFAULT_ENVIRONMENT
-		printf("no valid environment found on /dev/env0. "
-			"Using default environment\n");
-		envfs_load("/dev/defaultenv", "/env", NULL);
-#endif
-	}
-#endif
 	printf("running /env/bin/init...\n");
 
 	if (!stat("/env/bin/init", &s)) {
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2010-07-05 13:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-05 13:57 reworked multiple " Luotao Fu
2010-07-05 13:57 ` [PATCH V2 1/4] crc value handling and dry run mode in envfs_load Luotao Fu
2010-07-05 13:57 ` Luotao Fu [this message]
2010-07-05 13:57 ` [PATCH V2 3/4] Add multi env support to saveenv and loadenv commands Luotao Fu
2010-07-05 13:57 ` [PATCH V2 4/4] add general check_and_erase callback to environment handling Luotao Fu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1278338260-29454-3-git-send-email-l.fu@pengutronix.de \
    --to=l.fu@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox