diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2017-05-05 11:31:46 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2017-05-05 11:31:46 +0200 |
commit | 587afe8133b0218cde15750947e82f199d9ed6aa (patch) | |
tree | 317d15f5ddd90cd15ab2a49a6dda4d8c2f5a4531 | |
parent | 5485383d60cd62f1306c5ba6b781e684ba5c2ec3 (diff) | |
parent | 70ea799f6b6ddcd92b94420a2d352a73f0f9ff08 (diff) | |
download | barebox-587afe8133b0218cde15750947e82f199d9ed6aa.tar.gz barebox-587afe8133b0218cde15750947e82f199d9ed6aa.tar.xz |
Merge branch 'for-next/state'
-rw-r--r-- | Documentation/devicetree/bindings/barebox/barebox,state.rst | 8 | ||||
-rw-r--r-- | common/state/state.c | 28 |
2 files changed, 32 insertions, 4 deletions
diff --git a/Documentation/devicetree/bindings/barebox/barebox,state.rst b/Documentation/devicetree/bindings/barebox/barebox,state.rst index 00fb592614..06a0d100c8 100644 --- a/Documentation/devicetree/bindings/barebox/barebox,state.rst +++ b/Documentation/devicetree/bindings/barebox/barebox,state.rst @@ -32,6 +32,8 @@ Required properties: * ``backend``: contains a phandle to the device/partition which holds the actual state data. * ``backend-type``: should be ``raw`` or ``dtb``. +* additionally a state node must have an alias in the /aliases/ node pointing + to it. Optional properties: @@ -74,7 +76,11 @@ Optional properties: Example:: - state: state@0 { + /aliases { + state = &state; + }; + + state: state { magic = <0x27031977>; compatible = "barebox,state"; backend-type = "raw"; diff --git a/common/state/state.c b/common/state/state.c index 6db77f2c18..b4a634fa99 100644 --- a/common/state/state.c +++ b/common/state/state.c @@ -407,7 +407,7 @@ static int of_state_fixup(struct device_node *root, void *ctx) { struct state *state = ctx; const char *compatible = "barebox,state"; - struct device_node *new_node, *node, *parent, *backend_node; + struct device_node *new_node, *node, *parent, *backend_node, *aliases; struct property *p; int ret; phandle phandle; @@ -416,6 +416,15 @@ static int of_state_fixup(struct device_node *root, void *ctx) if (node) { /* replace existing node - it will be deleted later */ parent = node->parent; + + /* + * barebox replaces the state node in the device tree it starts the + * kernel with, so a state node that already exists in the device tree + * will be overwritten. Warn about this so people do not wonder why + * changes in the kernels state node do not have any effect. + */ + if (root != of_get_root_node()) + dev_warn(&state->dev, "Warning: Kernel devicetree contains state node, replacing it\n"); } else { char *of_path, *c; @@ -511,6 +520,17 @@ static int of_state_fixup(struct device_node *root, void *ctx) if (ret) goto out; + aliases = of_create_node(root, "/aliases"); + if (!aliases) { + ret = -ENOMEM; + goto out; + } + + ret = of_set_property(aliases, state->name, new_node->full_name, + strlen(new_node->full_name) + 1, 1); + if (ret) + goto out; + /* delete existing node */ if (node) of_delete_node(node); @@ -558,8 +578,10 @@ struct state *state_new_from_node(struct device_node *node, char *path, uint32_t stridesize; alias = of_alias_get(node); - if (!alias) - alias = node->name; + if (!alias) { + pr_err("State node %s does not have an alias in the /aliases/ node\n", node->full_name); + return ERR_PTR(-EINVAL); + } state = state_new(alias); if (IS_ERR(state)) |