[PATCH 1/3] env: add register_persistent_environment

Eric Bénard eric at eukrea.com
Thu Feb 14 06:56:49 EST 2013


- heavily copied from register_persistant_environment which was
Signed-off-by: Juergen Beisert <jbe at pengutronix.de>

Signed-off-by: Eric Bénard <eric at eukrea.com>
---
 common/environment.c  | 40 ++++++++++++++++++++++++++++++++++++++++
 include/environment.h |  1 +
 2 files changed, 41 insertions(+)

diff --git a/common/environment.c b/common/environment.c
index e8d623f..55befd9 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -363,3 +363,43 @@ out:
 		free(buf_free);
 	return ret;
 }
+
+#ifdef __BAREBOX__
+/**
+ * Try to register an environment storage on a device's partition
+ * @return 0 on success
+ *
+ * We rely on the existence of a usable storage device, already attached to
+ * our system, to get something like a persistent memory for our environment.
+ * We need to specify the partition number to use on this device.
+ * @param[in] devname Name of the device
+ * @param[in] partnr Partition number
+ * @return 0 on success, anything else in case of failure
+ */
+
+int register_persistent_environment(const char *devname, unsigned int partnr)
+{
+	struct cdev *cdev;
+	char *partname;
+
+	if (!devname)
+		return -EINVAL;
+
+	cdev = cdev_by_name(devname);
+	if (cdev == NULL) {
+		pr_err("No %s present\n", devname);
+		return -ENODEV;
+	}
+	partname = asprintf("%s.%d", devname, partnr);
+	cdev = cdev_by_name(partname);
+	if (cdev == NULL) {
+		pr_err("No %s partition available\n", partname);
+		pr_info("Please create the partition %s to store the env\n", partname);
+		return -ENODEV;
+	}
+
+	return devfs_add_partition(partname, 0, cdev->size,
+						DEVFS_PARTITION_FIXED, "env0");
+}
+EXPORT_SYMBOL(register_persistent_environment);
+#endif
diff --git a/include/environment.h b/include/environment.h
index 7bdd213..d172f8f 100644
--- a/include/environment.h
+++ b/include/environment.h
@@ -71,6 +71,7 @@ int env_pop_context(void);
 int env_push_context(void);
 
 int export(const char *);
+int register_persistent_environment(const char *devname, unsigned int partnr);
 
 #endif	/* _ENVIRONMENT_H_ */
 
-- 
1.7.11.7




More information about the barebox mailing list