diff --git a/src/barebox-state.c b/src/barebox-state.c index f10b7c6..f8b8df6 100644 --- a/src/barebox-state.c +++ b/src/barebox-state.c @@ -310,15 +310,12 @@ struct state *state_get(const char *name, bool readonly, bool auth) { - struct device_node *root, *node, *partition_node; + struct device_node *root, *node; char *path; struct state *state; int ret; const char *backend_type = NULL; struct state_variable *v; - char *devpath; - off_t offset; - size_t size; root = of_read_proc_devicetree(); if (IS_ERR(root)) { @@ -349,19 +346,7 @@ if (pr_level_get() > 6) of_print_nodes(node, 0); - partition_node = of_parse_phandle(node, "backend", 0); - if (!partition_node) { - pr_err("cannot find backend node in %s\n", node->full_name); - exit (1); - } - - ret = of_get_devicepath(partition_node, &devpath, &offset, &size); - if (ret) { - pr_err("Cannot find backend path in %s\n", node->full_name); - return ERR_PTR(ret); - } - - state = state_new_from_node(node, devpath, offset, size, readonly); + state = state_new_from_node(node, readonly); if (IS_ERR(state)) { pr_err("unable to initialize state: %s\n", strerror(PTR_ERR(state))); diff --git a/src/barebox-state/state.c b/src/barebox-state/state.c index 6e483df..d6ab464 100644 --- a/src/barebox-state/state.c +++ b/src/barebox-state/state.c @@ -566,17 +566,10 @@ /* * state_new_from_node - create a new state instance from a device_node * - * @node The device_node describing the new state instance - * @path Path to the backend device. If NULL the path is constructed - * using the path in the backend property of the DT. - * @offset Offset in the device path. May be 0 to start at the beginning. - * @max_size Maximum size of the area used. This may be 0 to use the full - * size. * @readonly This is a read-only state. Note that with this option set, * there are no repairs done. */ -struct state *state_new_from_node(struct device_node *node, char *path, - off_t offset, size_t max_size, bool readonly) +struct state *state_new_from_node(struct device_node *node, bool readonly) { struct state *state; int ret = 0; @@ -584,6 +577,9 @@ const char *storage_type = NULL; const char *alias; uint32_t stridesize; + struct device_node *partition_node; + off_t offset = 0; + size_t size = 0; alias = of_alias_get(node); if (!alias) { @@ -595,26 +591,24 @@ if (IS_ERR(state)) return state; - if (!path) { - struct device_node *partition_node; - - partition_node = of_parse_phandle(node, "backend", 0); - if (!partition_node) { - dev_err(&state->dev, "Cannot resolve \"backend\" phandle\n"); - ret = -EINVAL; - goto out_release_state; - } - - ret = of_find_path_by_node(partition_node, &path, 0); - if (ret) { - if (ret != -EPROBE_DEFER) - dev_err(&state->dev, "state failed to parse path to backend: %s\n", - strerror(-ret)); - goto out_release_state; - } + partition_node = of_parse_phandle(node, "backend", 0); + if (!partition_node) { + dev_err(&state->dev, "Cannot resolve \"backend\" phandle\n"); + ret = -EINVAL; + goto out_release_state; } - state->backend_path = xstrdup(path); +#ifdef __BAREBOX__ + ret = of_find_path_by_node(partition_node, &state->backend_path, 0); +#else + ret = of_get_devicepath(partition_node, &state->backend_path, &offset, &size); +#endif + if (ret) { + if (ret != -EPROBE_DEFER) + dev_err(&state->dev, "state failed to parse path to backend: %s\n", + strerror(-ret)); + goto out_release_state; + } ret = of_property_read_string(node, "backend-type", &backend_type); if (ret) { @@ -634,8 +628,8 @@ if (ret) goto out_release_state; - ret = state_storage_init(state, path, offset, - max_size, stridesize, storage_type); + ret = state_storage_init(state, state->backend_path, offset, + size, stridesize, storage_type); if (ret) goto out_release_state; diff --git a/src/dt/dt.h b/src/dt/dt.h index 6d71a71..10fe162 100644 --- a/src/dt/dt.h +++ b/src/dt/dt.h @@ -370,12 +370,6 @@ struct device_node *of_read_proc_devicetree(void); -static inline int of_find_path_by_node(struct device_node *node, char **outpath, - unsigned flags) -{ - return -ENOSYS; -} - static inline struct device_node *of_find_node_by_devpath(struct device_node *root, const char *path) { diff --git a/src/state.h b/src/state.h index 888b491..132c0c3 100644 --- a/src/state.h +++ b/src/state.h @@ -10,8 +10,7 @@ int state_backend_raw_file(struct state *state, const char *of_path, const char *path, off_t offset, size_t size); -struct state *state_new_from_node(struct device_node *node, char *path, - off_t offset, size_t max_size, bool readonly); +struct state *state_new_from_node(struct device_node *node, bool readonly); void state_release(struct state *state); struct state *state_by_name(const char *name);