mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Juergen Beisert <jbe@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Luotao Fu <l.fu@pengutronix.de>
Subject: [PATCH 2/5] CRC value handling and dry run mode in 'envfs_load'
Date: Wed,  9 Mar 2011 16:17:23 +0100	[thread overview]
Message-ID: <1299683846-20616-3-git-send-email-jbe@pengutronix.de> (raw)
In-Reply-To: <1299683846-20616-1-git-send-email-jbe@pengutronix.de>

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

  parent reply	other threads:[~2011-03-09 15:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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=1299683846-20616-3-git-send-email-jbe@pengutronix.de \
    --to=jbe@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=l.fu@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