diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2012-09-09 23:07:28 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2012-09-14 11:47:42 +0200 |
commit | ca77bd8f034d0f20edad7b04990b1ddf2e442e5b (patch) | |
tree | f0e6601bb5a61c446e521fc784d9cfd3f0c111ef /drivers/of/partition.c | |
parent | f4eb95053584b1bd79c02024018e19b7f8813b06 (diff) | |
download | barebox-ca77bd8f034d0f20edad7b04990b1ddf2e442e5b.tar.gz barebox-ca77bd8f034d0f20edad7b04990b1ddf2e442e5b.tar.xz |
of: Add devicetree partition parsing
Helper code to probe mtd partitions from the devicetree.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/of/partition.c')
-rw-r--r-- | drivers/of/partition.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/drivers/of/partition.c b/drivers/of/partition.c new file mode 100644 index 0000000000..6a57a6036e --- /dev/null +++ b/drivers/of/partition.c @@ -0,0 +1,64 @@ +/* + * partition.c - devicetree partition parsing + * + * Copyright (c) 2012 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix + * + * based on Linux devicetree support + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ +#include <common.h> +#include <of.h> +#include <malloc.h> +#include <linux/mtd/mtd.h> + +int of_parse_partitions(const char *cdevname, + struct device_node *node) +{ + struct device_node *n; + const char *partname; + char *filename; + + device_node_for_nach_child(node, n) { + const __be32 *reg; + unsigned long offset, size; + const char *name; + int len; + unsigned long flags = 0; + + reg = of_get_property(n, "reg", &len); + if (!reg) + continue; + + offset = be32_to_cpu(reg[0]); + size = be32_to_cpu(reg[1]); + + partname = of_get_property(n, "label", &len); + if (!partname) + partname = of_get_property(n, "name", &len); + name = (char *)partname; + + debug("add partition: %s.%s 0x%08lx 0x%08lx\n", cdevname, partname, offset, size); + + if (of_get_property(n, "read-only", &len)) + flags = DEVFS_PARTITION_READONLY; + + filename = asprintf("%s.%s", cdevname, partname); + + devfs_add_partition(cdevname, offset, size, flags, filename); + + free(filename); + } + + return 0; +} |