diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2014-05-19 13:55:48 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2014-05-19 22:23:56 +0200 |
commit | e275b2653f87dc6969b3c0baf6f0e7460c62a8db (patch) | |
tree | 59a870d2c340091d3a8546475992282d57ec306a /common/complete.c | |
parent | e5c59c386784d9c52505823ee293c94f633a8744 (diff) | |
download | barebox-e275b2653f87dc6969b3c0baf6f0e7460c62a8db.tar.gz |
complete: Add devicetree completion
The of_* commands take devicetree nodes as parameters. Add a
devicetree completion function to ease passing nodes to these
commands.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/complete.c')
-rw-r--r-- | common/complete.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/common/complete.c b/common/complete.c index 368321f921..5b71f03cf8 100644 --- a/common/complete.c +++ b/common/complete.c @@ -204,6 +204,77 @@ int command_var_complete(struct string_list *sl, char *instr) } EXPORT_SYMBOL(command_var_complete); +int devicetree_alias_complete(struct string_list *sl, char *instr) +{ + struct device_node *aliases; + struct property *p; + + aliases = of_find_node_by_path("/aliases"); + if (!aliases) + return 0; + + list_for_each_entry(p, &aliases->properties, list) { + if (strncmp(instr, p->name, strlen(instr))) + continue; + + string_list_add_asprintf(sl, "%s ", p->name); + } + + return 0; +} +EXPORT_SYMBOL(devicetree_alias_complete); + +int devicetree_nodepath_complete(struct string_list *sl, char *instr) +{ + struct device_node *node, *child; + char *dirn, *base; + char *path = strdup(instr); + + if (*instr == '/') { + dirn = dirname(path); + base = basename(instr); + node = of_find_node_by_path(dirn); + if (!node) + goto out; + } else if (!*instr) { + node = of_get_root_node(); + if (!node) + goto out; + base = ""; + } else { + goto out; + } + + for_each_child_of_node(node, child) { + if (strncmp(base, child->name, strlen(base))) + continue; + string_list_add_asprintf(sl, "%s/", child->full_name); + } +out: + free(path); + + return 0; +} +EXPORT_SYMBOL(devicetree_nodepath_complete); + +int devicetree_complete(struct string_list *sl, char *instr) +{ + devicetree_nodepath_complete(sl, instr); + devicetree_alias_complete(sl, instr); + + return 0; +} +EXPORT_SYMBOL(devicetree_complete); + +int devicetree_file_complete(struct string_list *sl, char *instr) +{ + devicetree_complete(sl, instr); + file_complete(sl, instr, 0); + + return 0; +} +EXPORT_SYMBOL(devicetree_file_complete); + static int env_param_complete(struct string_list *sl, char *instr, int eval) { struct device_d *dev; |