aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lepore <ian@FreeBSD.org>2019-02-27 04:58:18 +0000
committerIan Lepore <ian@FreeBSD.org>2019-02-27 04:58:18 +0000
commita6bcabcd06f9bb6c525b426afb9685033a0351af (patch)
treebd67f85dc337f9a0bdd294f8c283d1ebece7a334
parent85f55a2a97a0e7335870697397b6023a12521a78 (diff)
downloadsrc-a6bcabcd06f9bb6c525b426afb9685033a0351af.tar.gz
src-a6bcabcd06f9bb6c525b426afb9685033a0351af.zip
Add support to fdt_slicer for the new style partition data documented in
devicetree/bindings/mtd/partition.txt. In the old style, all the children of the device node which did not have a compatible property were the partitions. In the new style, there is a child node of the device which has a compatible string of "fixed-partitions", and its children are the individual partitions. Also, support the read-only property by setting the corresponding slice flag.
Notes
Notes: svn path=/head/; revision=344616
-rw-r--r--sys/dev/fdt/fdt_slicer.c65
1 files changed, 44 insertions, 21 deletions
diff --git a/sys/dev/fdt/fdt_slicer.c b/sys/dev/fdt/fdt_slicer.c
index 61ae3e5e9276..ebbfa45e2ece 100644
--- a/sys/dev/fdt/fdt_slicer.c
+++ b/sys/dev/fdt/fdt_slicer.c
@@ -51,27 +51,17 @@ static int fill_slices(device_t dev, const char *provider,
static void fdt_slicer_init(void);
static int
-fill_slices(device_t dev, const char *provider __unused,
- struct flash_slice *slices, int *slices_num)
+fill_slices_from_node(phandle_t node, struct flash_slice *slices, int *count)
{
- char *slice_name;
- phandle_t node, child;
+ char *label;
+ phandle_t child;
u_long base, size;
- int i;
+ int flags, i;
ssize_t nmlen;
- /*
- * We assume the caller provides buffer for FLASH_SLICES_MAX_NUM
- * flash_slice structures.
- */
- if (slices == NULL) {
- *slices_num = 0;
- return (ENOMEM);
- }
-
i = 0;
- node = ofw_bus_get_node(dev);
for (child = OF_child(node); child != 0; child = OF_peer(child)) {
+ flags = FLASH_SLICES_FLAG_NONE;
/* Nodes with a compatible property are not slices. */
if (OF_hasprop(child, "compatible"))
@@ -95,28 +85,61 @@ fill_slices(device_t dev, const char *provider __unused,
}
/* Retrieve label. */
- nmlen = OF_getprop_alloc(child, "label", (void **)&slice_name);
+ nmlen = OF_getprop_alloc(child, "label", (void **)&label);
if (nmlen <= 0) {
/* Use node name if no label defined */
- nmlen = OF_getprop_alloc(child, "name",
- (void **)&slice_name);
+ nmlen = OF_getprop_alloc(child, "name", (void **)&label);
if (nmlen <= 0) {
debugf("slice i=%d with no name\n", i);
- slice_name = NULL;
+ label = NULL;
}
}
+ if (OF_hasprop(child, "read-only"))
+ flags |= FLASH_SLICES_FLAG_RO;
+
/* Fill slice entry data. */
slices[i].base = base;
slices[i].size = size;
- slices[i].label = slice_name;
+ slices[i].label = label;
+ slices[i].flags = flags;
i++;
}
- *slices_num = i;
+ *count = i;
return (0);
}
+static int
+fill_slices(device_t dev, const char *provider __unused,
+ struct flash_slice *slices, int *slices_num)
+{
+ phandle_t child, node;
+
+ /*
+ * We assume the caller provides buffer for FLASH_SLICES_MAX_NUM
+ * flash_slice structures.
+ */
+ if (slices == NULL) {
+ *slices_num = 0;
+ return (ENOMEM);
+ }
+
+ node = ofw_bus_get_node(dev);
+
+ /*
+ * If there is a child node whose compatible is "fixed-partitions" then
+ * we have new-style data where all partitions are the children of that
+ * node. Otherwise we have old-style data where all the children of the
+ * device node are the partitions.
+ */
+ child = fdt_find_compatible(node, "fixed-partitions", false);
+ if (child == 0)
+ return fill_slices_from_node(node, slices, slices_num);
+ else
+ return fill_slices_from_node(child, slices, slices_num);
+}
+
static void
fdt_slicer_init(void)
{