mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: [PATCH 2/3] envfs: add command_abi_version support
Date: Mon, 22 Oct 2012 18:07:27 +0200	[thread overview]
Message-ID: <1350922048-25699-2-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <1350922048-25699-1-git-send-email-plagnioj@jcrosoft.com>

allow to store the command abi version
This will allow to detect incompatibility

Increase envfs minor to 1

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 commands/loadenv.c    |   11 ++++++++++-
 common/environment.c  |    7 ++++++-
 common/startup.c      |    4 ++--
 include/envfs.h       |    4 ++--
 include/environment.h |   13 ++++++++++++-
 scripts/bareboxenv.c  |    9 ++++++++-
 6 files changed, 40 insertions(+), 8 deletions(-)

diff --git a/commands/loadenv.c b/commands/loadenv.c
index 5bf1740..c52ee4b 100644
--- a/commands/loadenv.c
+++ b/commands/loadenv.c
@@ -26,6 +26,9 @@
 
 static int do_loadenv(int argc, char *argv[])
 {
+	int ret;
+	uint16_t command_abi_version;
+
 	char *filename, *dirname;
 
 	if (argc < 3)
@@ -37,7 +40,13 @@ static int do_loadenv(int argc, char *argv[])
 	else
 		filename = argv[1];
 	printf("loading environment from %s\n", filename);
-	return envfs_load(filename, dirname);
+	ret = envfs_load(filename, dirname, &command_abi_version);
+
+	if (command_abi_version < COMMAND_ABI_VERSION)
+		pr_warn("environment command_abi_verison (%u) < current version (%u)\n",
+			command_abi_version, COMMAND_ABI_VERSION);
+
+	return ret;
 }
 
 BAREBOX_CMD_HELP_START(loadenv)
diff --git a/common/environment.c b/common/environment.c
index 69c4c0a..e0207e9 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -162,6 +162,7 @@ int envfs_save(char *filename, char *dirname)
 
 	super = (struct envfs_super *)buf;
 	super->magic = ENVFS_32(ENVFS_MAGIC);
+	super->command_abi_version = ENVFS_16(COMMAND_ABI_VERSION);
 	super->major = ENVFS_MAJOR;
 	super->minor = ENVFS_MINOR;
 	super->size = ENVFS_32(size);
@@ -206,7 +207,7 @@ EXPORT_SYMBOL(envfs_save);
  * 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, uint16_t *command_abi_version)
 {
 	struct envfs_super super;
 	void *buf = NULL, *buf_free = NULL;
@@ -235,6 +236,7 @@ int envfs_load(char *filename, char *dir)
 		goto out;
 	}
 
+
 	if ( ENVFS_32(super.magic) != ENVFS_MAGIC) {
 		printf("envfs: wrong magic on %s\n", filename);
 		ret = -EIO;
@@ -248,6 +250,9 @@ int envfs_load(char *filename, char *dir)
 		goto out;
 	}
 
+	if (command_abi_version)
+		*command_abi_version = ENVFS_16(super.command_abi_version);
+
 	size = ENVFS_32(super.size);
 	buf = xmalloc(size);
 	buf_free = buf;
diff --git a/common/startup.c b/common/startup.c
index 78926c9..affb5a9 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -106,12 +106,12 @@ void start_barebox (void)
 	debug("initcalls done\n");
 
 #ifdef CONFIG_ENV_HANDLING
-	if (envfs_load(default_environment_path, "/env")) {
+	if (envfs_load(default_environment_path, "/env", NULL)) {
 #ifdef CONFIG_DEFAULT_ENVIRONMENT
 		printf("no valid environment found on %s. "
 			"Using default environment\n",
 			default_environment_path);
-		envfs_load("/dev/defaultenv", "/env");
+		envfs_load("/dev/defaultenv", "/env", NULL);
 #endif
 	}
 #endif
diff --git a/include/envfs.h b/include/envfs.h
index 3d14fcb..6503d22 100644
--- a/include/envfs.h
+++ b/include/envfs.h
@@ -6,7 +6,7 @@
 #endif
 
 #define ENVFS_MAJOR		1
-#define ENVFS_MINOR		0
+#define ENVFS_MINOR		1
 
 #define ENVFS_MAGIC		    0x798fba79	/* some random number */
 #define ENVFS_INODE_MAGIC	0x67a8c78d
@@ -40,7 +40,7 @@ struct envfs_super {
 	uint32_t size;			/* size of data */
 	uint8_t major;			/* major */
 	uint8_t minor;			/* minor */
-	uint16_t future;		/* reserved for future use */
+	uint16_t command_abi_version;	/* command abi version */
 	uint32_t flags;			/* feature flags */
 	uint32_t sb_crc;		/* crc for the superblock */
 };
diff --git a/include/environment.h b/include/environment.h
index 95e75e7..64de26f 100644
--- a/include/environment.h
+++ b/include/environment.h
@@ -74,8 +74,19 @@ int env_push_context(void);
 /* defaults to /dev/env0 */
 extern char *default_environment_path;
 
-int envfs_load(char *filename, char *dirname);
+#ifdef CONFIG_ENV_HANDLING
+int envfs_load(char *filename, char *dir, uint16_t *command_abi_version);
 int envfs_save(char *filename, char *dirname);
+#else
+static inline int envfs_load(char *filename, char *dir, uint16_t *command_abi_version)
+{
+	return -EINVAL;
+}
+static inline int envfs_save(char *filename, char *dirname)
+{
+	return -EINVAL;
+}
+#endif
 
 int export(const char *);
 
diff --git a/scripts/bareboxenv.c b/scripts/bareboxenv.c
index f44a1f8..6bd23e8 100644
--- a/scripts/bareboxenv.c
+++ b/scripts/bareboxenv.c
@@ -115,6 +115,7 @@ char *concat_subpath_file(const char *path, const char *f)
 }
 
 #include "../lib/recursive_action.c"
+#include "../include/command_abi.h"
 #include "../include/envfs.h"
 #include "../crypto/crc32.c"
 #include "../lib/make_directory.c"
@@ -189,14 +190,20 @@ int main(int argc, char *argv[])
 	}
 
 	if (load) {
+		uint16_t command_abi_version;
+
 		if (verbose)
 			printf("loading env from file %s to %s\n", filename, dirname);
-		envfs_load(filename, dirname);
+		envfs_load(filename, dirname, &command_abi_version);
+		if (verbose)
+			printf("with command_abi_version = %u\n", command_abi_version);
 	}
 	if (save) {
 		if (verbose)
 			printf("saving contents of %s to file %s\n", dirname, filename);
 		envfs_save(filename, dirname);
+		if (verbose)
+			printf("with command_abi_version = %u\n", COMMAND_ABI_VERSION);
 	}
 	exit(0);
 }
-- 
1.7.10.4


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

  reply	other threads:[~2012-10-22 16:09 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-22 16:03 [PATCH 0/3] introduce command abi version Jean-Christophe PLAGNIOL-VILLARD
2012-10-22 16:07 ` [PATCH 1/3] command: introduce " Jean-Christophe PLAGNIOL-VILLARD
2012-10-22 16:07   ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2012-10-23  8:59     ` [PATCH 2/3] envfs: add command_abi_version support Sascha Hauer
2012-10-23 10:20       ` Jean-Christophe PLAGNIOL-VILLARD
2012-10-23 12:56         ` Sascha Hauer
2012-10-23 13:27           ` Jean-Christophe PLAGNIOL-VILLARD
2012-10-22 16:07   ` [PATCH 3/3] environment: detect command_abi_version Jean-Christophe PLAGNIOL-VILLARD
2012-10-29  8:50   ` [PATCH 1/3] command: introduce abi version Sascha Hauer
2012-10-29  9:56     ` Johannes Stezenbach
2012-10-29 10:31       ` Sascha Hauer
2012-10-29 16:05       ` Jean-Christophe PLAGNIOL-VILLARD
2012-10-29 17:00         ` Johannes Stezenbach
2012-10-29 18:05           ` Jean-Christophe PLAGNIOL-VILLARD
2012-10-23  8:51 ` [PATCH 0/3] introduce command " Sascha Hauer
2012-10-23 10:28   ` Jean-Christophe PLAGNIOL-VILLARD

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=1350922048-25699-2-git-send-email-plagnioj@jcrosoft.com \
    --to=plagnioj@jcrosoft.com \
    --cc=barebox@lists.infradead.org \
    /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