Commit 3912b791 authored by Frank Rowand's avatar Frank Rowand Committed by Rob Herring

of: overlay: simplify applying symbols from an overlay

The code to apply symbols from an overlay to the live device tree
was implemented with the intent to be minimally intrusive on the
existing code.  After recent restructuring of the overlay apply
code, it is easier to disintangle the code that applies the
symbols, and to make the overlay changeset creation code more
straight forward and understandable.

Remove the extra complexity, and make the code more obvious.
Signed-off-by: default avatarFrank Rowand <frank.rowand@sony.com>
Signed-off-by: default avatarRob Herring <robh@kernel.org>
parent f948d6d8
...@@ -32,14 +32,14 @@ ...@@ -32,14 +32,14 @@
struct fragment { struct fragment {
struct device_node *target; struct device_node *target;
struct device_node *overlay; struct device_node *overlay;
bool is_symbols_node;
}; };
/** /**
* struct overlay_changeset * struct overlay_changeset
* @ovcs_list: list on which we are located * @ovcs_list: list on which we are located
* @count: count of @fragments structures * @count: count of fragment structures
* @fragments: info about fragment nodes in overlay expanded device tree * @fragments: fragment nodes in the overlay expanded device tree
* @symbols_fragment: last element of @fragments[] is the __symbols__ node
* @cset: changeset to apply fragments to live device tree * @cset: changeset to apply fragments to live device tree
*/ */
struct overlay_changeset { struct overlay_changeset {
...@@ -47,6 +47,7 @@ struct overlay_changeset { ...@@ -47,6 +47,7 @@ struct overlay_changeset {
struct list_head ovcs_list; struct list_head ovcs_list;
int count; int count;
struct fragment *fragments; struct fragment *fragments;
bool symbols_fragment;
struct of_changeset cset; struct of_changeset cset;
}; };
...@@ -68,8 +69,7 @@ static int devicetree_corrupt(void) ...@@ -68,8 +69,7 @@ static int devicetree_corrupt(void)
static int build_changeset_next_level(struct overlay_changeset *ovcs, static int build_changeset_next_level(struct overlay_changeset *ovcs,
struct device_node *target_node, struct device_node *target_node,
const struct device_node *overlay_node, const struct device_node *overlay_node);
bool is_symbols_node);
/* /*
* of_resolve_phandles() finds the largest phandle in the live tree. * of_resolve_phandles() finds the largest phandle in the live tree.
...@@ -221,7 +221,7 @@ static struct property *dup_and_fixup_symbol_prop( ...@@ -221,7 +221,7 @@ static struct property *dup_and_fixup_symbol_prop(
* @ovcs: overlay changeset * @ovcs: overlay changeset
* @target_node: where to place @overlay_prop in live tree * @target_node: where to place @overlay_prop in live tree
* @overlay_prop: property to add or update, from overlay tree * @overlay_prop: property to add or update, from overlay tree
* is_symbols_node: 1 if @target_node is "/__symbols__" * @is_symbols_prop: 1 if @overlay_prop is from node "/__symbols__"
* *
* If @overlay_prop does not already exist in @target_node, add changeset entry * If @overlay_prop does not already exist in @target_node, add changeset entry
* to add @overlay_prop in @target_node, else add changeset entry to update * to add @overlay_prop in @target_node, else add changeset entry to update
...@@ -237,7 +237,7 @@ static struct property *dup_and_fixup_symbol_prop( ...@@ -237,7 +237,7 @@ static struct property *dup_and_fixup_symbol_prop(
static int add_changeset_property(struct overlay_changeset *ovcs, static int add_changeset_property(struct overlay_changeset *ovcs,
struct device_node *target_node, struct device_node *target_node,
struct property *overlay_prop, struct property *overlay_prop,
bool is_symbols_node) bool is_symbols_prop)
{ {
struct property *new_prop = NULL, *prop; struct property *new_prop = NULL, *prop;
int ret = 0; int ret = 0;
...@@ -249,7 +249,7 @@ static int add_changeset_property(struct overlay_changeset *ovcs, ...@@ -249,7 +249,7 @@ static int add_changeset_property(struct overlay_changeset *ovcs,
!of_prop_cmp(overlay_prop->name, "linux,phandle")) !of_prop_cmp(overlay_prop->name, "linux,phandle"))
return 0; return 0;
if (is_symbols_node) { if (is_symbols_prop) {
if (prop) if (prop)
return -EINVAL; return -EINVAL;
new_prop = dup_and_fixup_symbol_prop(ovcs, overlay_prop); new_prop = dup_and_fixup_symbol_prop(ovcs, overlay_prop);
...@@ -330,13 +330,13 @@ static int add_changeset_node(struct overlay_changeset *ovcs, ...@@ -330,13 +330,13 @@ static int add_changeset_node(struct overlay_changeset *ovcs,
if (ret) if (ret)
return ret; return ret;
return build_changeset_next_level(ovcs, tchild, node, 0); return build_changeset_next_level(ovcs, tchild, node);
} }
if (node->phandle && tchild->phandle) if (node->phandle && tchild->phandle)
ret = -EINVAL; ret = -EINVAL;
else else
ret = build_changeset_next_level(ovcs, tchild, node, 0); ret = build_changeset_next_level(ovcs, tchild, node);
of_node_put(tchild); of_node_put(tchild);
return ret; return ret;
...@@ -347,7 +347,6 @@ static int add_changeset_node(struct overlay_changeset *ovcs, ...@@ -347,7 +347,6 @@ static int add_changeset_node(struct overlay_changeset *ovcs,
* @ovcs: overlay changeset * @ovcs: overlay changeset
* @target_node: where to place @overlay_node in live tree * @target_node: where to place @overlay_node in live tree
* @overlay_node: node from within an overlay device tree fragment * @overlay_node: node from within an overlay device tree fragment
* @is_symbols_node: @overlay_node is node "/__symbols__"
* *
* Add the properties (if any) and nodes (if any) from @overlay_node to the * Add the properties (if any) and nodes (if any) from @overlay_node to the
* @ovcs->cset changeset. If an added node has child nodes, they will * @ovcs->cset changeset. If an added node has child nodes, they will
...@@ -360,16 +359,14 @@ static int add_changeset_node(struct overlay_changeset *ovcs, ...@@ -360,16 +359,14 @@ static int add_changeset_node(struct overlay_changeset *ovcs,
*/ */
static int build_changeset_next_level(struct overlay_changeset *ovcs, static int build_changeset_next_level(struct overlay_changeset *ovcs,
struct device_node *target_node, struct device_node *target_node,
const struct device_node *overlay_node, const struct device_node *overlay_node)
bool is_symbols_node)
{ {
struct device_node *child; struct device_node *child;
struct property *prop; struct property *prop;
int ret; int ret;
for_each_property_of_node(overlay_node, prop) { for_each_property_of_node(overlay_node, prop) {
ret = add_changeset_property(ovcs, target_node, prop, ret = add_changeset_property(ovcs, target_node, prop, 0);
is_symbols_node);
if (ret) { if (ret) {
pr_debug("Failed to apply prop @%pOF/%s, err=%d\n", pr_debug("Failed to apply prop @%pOF/%s, err=%d\n",
target_node, prop->name, ret); target_node, prop->name, ret);
...@@ -377,9 +374,6 @@ static int build_changeset_next_level(struct overlay_changeset *ovcs, ...@@ -377,9 +374,6 @@ static int build_changeset_next_level(struct overlay_changeset *ovcs,
} }
} }
if (is_symbols_node)
return 0;
for_each_child_of_node(overlay_node, child) { for_each_child_of_node(overlay_node, child) {
ret = add_changeset_node(ovcs, target_node, child); ret = add_changeset_node(ovcs, target_node, child);
if (ret) { if (ret) {
...@@ -393,6 +387,28 @@ static int build_changeset_next_level(struct overlay_changeset *ovcs, ...@@ -393,6 +387,28 @@ static int build_changeset_next_level(struct overlay_changeset *ovcs,
return 0; return 0;
} }
/*
* Add the properties from __overlay__ node to the @ovcs->cset changeset.
*/
static int build_changeset_symbols_node(struct overlay_changeset *ovcs,
struct device_node *target_node,
const struct device_node *overlay_symbols_node)
{
struct property *prop;
int ret;
for_each_property_of_node(overlay_symbols_node, prop) {
ret = add_changeset_property(ovcs, target_node, prop, 1);
if (ret) {
pr_debug("Failed to apply prop @%pOF/%s, err=%d\n",
target_node, prop->name, ret);
return ret;
}
}
return 0;
}
/** /**
* build_changeset() - populate overlay changeset in @ovcs from @ovcs->fragments * build_changeset() - populate overlay changeset in @ovcs from @ovcs->fragments
* @ovcs: Overlay changeset * @ovcs: Overlay changeset
...@@ -407,14 +423,33 @@ static int build_changeset_next_level(struct overlay_changeset *ovcs, ...@@ -407,14 +423,33 @@ static int build_changeset_next_level(struct overlay_changeset *ovcs,
*/ */
static int build_changeset(struct overlay_changeset *ovcs) static int build_changeset(struct overlay_changeset *ovcs)
{ {
int i, ret; struct fragment *fragment;
int fragments_count, i, ret;
for (i = 0; i < ovcs->count; i++) { /*
struct fragment *fragment = &ovcs->fragments[i]; * if there is a symbols fragment in ovcs->fragments[i] it is
* the final element in the array
*/
if (ovcs->symbols_fragment)
fragments_count = ovcs->count - 1;
else
fragments_count = ovcs->count;
for (i = 0; i < fragments_count; i++) {
fragment = &ovcs->fragments[i];
ret = build_changeset_next_level(ovcs, fragment->target, ret = build_changeset_next_level(ovcs, fragment->target,
fragment->overlay, fragment->overlay);
fragment->is_symbols_node); if (ret) {
pr_debug("apply failed '%pOF'\n", fragment->target);
return ret;
}
}
if (ovcs->symbols_fragment) {
fragment = &ovcs->fragments[ovcs->count - 1];
ret = build_changeset_symbols_node(ovcs, fragment->target,
fragment->overlay);
if (ret) { if (ret) {
pr_debug("apply failed '%pOF'\n", fragment->target); pr_debug("apply failed '%pOF'\n", fragment->target);
return ret; return ret;
...@@ -531,12 +566,16 @@ static int init_overlay_changeset(struct overlay_changeset *ovcs, ...@@ -531,12 +566,16 @@ static int init_overlay_changeset(struct overlay_changeset *ovcs,
} }
} }
/*
* if there is a symbols fragment in ovcs->fragments[i] it is
* the final element in the array
*/
node = of_get_child_by_name(tree, "__symbols__"); node = of_get_child_by_name(tree, "__symbols__");
if (node) { if (node) {
ovcs->symbols_fragment = 1;
fragment = &fragments[cnt]; fragment = &fragments[cnt];
fragment->overlay = node; fragment->overlay = node;
fragment->target = of_find_node_by_path("/__symbols__"); fragment->target = of_find_node_by_path("/__symbols__");
fragment->is_symbols_node = 1;
if (!fragment->target) { if (!fragment->target) {
pr_err("no symbols in root of device tree.\n"); pr_err("no symbols in root of device tree.\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment