diff options
author | Trent Piepho <tpiepho@kymetacorp.com> | 2015-12-17 00:52:49 +0000 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2016-01-08 08:30:55 +0100 |
commit | 3a0e9b49e7f167e1bec2257b44e4f0ca91497cc6 (patch) | |
tree | 482d0886065e124276592d7ade1dd5490325592e /drivers/of | |
parent | ab96ba298b55e0b3eef1c18fc8be506071634cdf (diff) | |
download | barebox-3a0e9b49e7f167e1bec2257b44e4f0ca91497cc6.tar.gz barebox-3a0e9b49e7f167e1bec2257b44e4f0ca91497cc6.tar.xz |
environment: Support env from file in a file-system via device tree
Current barebox,environment node only allows specifying a raw device or
partition to load an environment from. Some boards, like OMAP and
SoCFPGA, instead want to use a file located in a FAT filesystem.
Extend the device tree bindings with a new property 'file-path' that
will trigger this behavior.
This allows any board using this driver to get the env from a file or
from a raw device, instead of each machine type being either raw
device only or file only.
Signed-off-by: Trent Piepho <tpiepho@kymetacorp.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/of')
-rw-r--r-- | drivers/of/Kconfig | 7 | ||||
-rw-r--r-- | drivers/of/barebox.c | 47 |
2 files changed, 52 insertions, 2 deletions
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index 90475cfbca..d0a62bda91 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -43,3 +43,10 @@ config OF_BAREBOX_DRIVERS support for this feature. This currently allows to configure the environment path from devicetree and to partition devices. See Documentation/devicetree/bindings/barebox/ for more information. + +config OF_BAREBOX_ENV_IN_FS + depends on OF_BAREBOX_DRIVERS + bool "Allow environment to come from file" + help + Allow the devie tree configuration of the barebox environment path + to specify a file in filesystem, which will be mounted. diff --git a/drivers/of/barebox.c b/drivers/of/barebox.c index 1b3078eb47..125feef2cc 100644 --- a/drivers/of/barebox.c +++ b/drivers/of/barebox.c @@ -24,7 +24,46 @@ #include <malloc.h> #include <partition.h> #include <envfs.h> -#include <linux/mtd/mtd.h> +#include <fs.h> + +#define ENV_MNT_DIR "/boot" /* If env on filesystem, where to mount */ + +/* If dev describes a file on a fs, mount the fs and change devpath to + * point to the file's path. Otherwise leave devpath alone. Does + * nothing in env in a file support isn't enabled. */ +static int environment_check_mount(struct device_d *dev, char **devpath) +{ + const char *filepath; + int ret; + + if (!IS_ENABLED(CONFIG_OF_BAREBOX_ENV_IN_FS)) + return 0; + + ret = of_property_read_string(dev->device_node, "file-path", &filepath); + if (ret == -EINVAL) { + /* No file-path so just use device-path */ + return 0; + } else if (ret) { + /* file-path property exists, but has error */ + dev_err(dev, "Problem with file-path property\n"); + return ret; + } + + /* Get device env is on and mount it */ + mkdir(ENV_MNT_DIR, 0777); + ret = mount(*devpath, "fat", ENV_MNT_DIR, NULL); + if (ret) { + dev_err(dev, "Failed to load environment: mount %s failed (%d)\n", + *devpath, ret); + return ret; + } + + /* Set env to be in a file on the now mounted device */ + dev_dbg(dev, "Loading default env from %s on device %s\n", + filepath, *devpath); + *devpath = asprintf("%s/%s", ENV_MNT_DIR, filepath); + return 0; +} static int environment_probe(struct device_d *dev) { @@ -35,8 +74,12 @@ static int environment_probe(struct device_d *dev) if (ret) return ret; - dev_info(dev, "setting default environment path to %s\n", path); + /* Do we need to mount a fs and find env there? */ + ret = environment_check_mount(dev, &path); + if (ret) + return ret; + dev_dbg(dev, "Setting default environment path to %s\n", path); default_environment_path_set(path); return 0; |