summaryrefslogtreecommitdiffstats
path: root/common/startup.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2018-09-21 14:21:14 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2018-09-26 08:55:00 +0200
commitb234a6da331fa9ec656f2d278adafdeea45f9073 (patch)
tree9bd39a9df35d2da6c1be33339b54cf6c2ee56aca /common/startup.c
parentc6bdbf6e93a11227f91fbf15b7a36dceb60c526d (diff)
downloadbarebox-b234a6da331fa9ec656f2d278adafdeea45f9073.tar.gz
environment: Do not use environment when overlapping with other partitions
Environment partitions are usually specified with their hardcoded offset and size, either in the device tree or the board file. These partitions potentially overlap with other partitions read from the partition table. Overlapping partitions for sure have bad effects. Be more friendly to our users and warn them when such a situation occurs and stop using that partition for storing the environment. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/startup.c')
-rw-r--r--common/startup.c52
1 files changed, 51 insertions, 1 deletions
diff --git a/common/startup.c b/common/startup.c
index 8553849..832d326 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -73,16 +73,66 @@ fs_initcall(mount_root);
#endif
#ifdef CONFIG_ENV_HANDLING
+static int check_overlap(const char *path)
+{
+ struct cdev *cenv, *cdisk, *cpart;
+ const char *name;
+
+ name = devpath_to_name(path);
+
+ if (name == path)
+ /*
+ * no /dev/ in front, so *path is some file. No need to
+ * check further.
+ */
+ return 0;
+
+ cenv = cdev_by_name(name);
+ if (!cenv)
+ return -EINVAL;
+
+ cdisk = cenv->master;
+
+ if (!cdisk)
+ return 0;
+
+ list_for_each_entry(cpart, &cdisk->partitions, partition_entry) {
+ if (cpart == cenv)
+ continue;
+
+ if (lregion_overlap(cpart->offset, cpart->size,
+ cenv->offset, cenv->size))
+ goto conflict;
+ }
+
+ return 0;
+
+conflict:
+ pr_err("Environment partition (0x%08llx-0x%08llx) "
+ "overlaps with partition %s (0x%08llx-0x%08llx), not using it\n",
+ cenv->offset, cenv->offset + cenv->offset + cenv->size - 1,
+ cpart->name,
+ cpart->offset, cpart->offset + cpart->offset + cpart->size - 1);
+
+ return -EINVAL;
+}
+
static int load_environment(void)
{
const char *default_environment_path;
+ int ret;
default_environment_path = default_environment_path_get();
if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT))
defaultenv_load("/env", 0);
- envfs_load(default_environment_path, "/env", 0);
+ ret = check_overlap(default_environment_path);
+ if (ret)
+ default_environment_path_set(NULL);
+ else
+ envfs_load(default_environment_path, "/env", 0);
+
nvvar_load();
return 0;