1 From 6039bd1b7e5e71a0a171406cf980d2d61a6e79d4 Mon Sep 17 00:00:00 2001
2 From: Ioana Ciornei <ioana.ciornei@nxp.com>
3 Date: Tue, 24 Oct 2017 16:29:37 +0000
4 Subject: [PATCH 02/12] dprc: add --full-path option to dprc list command
6 Instead of printing an indented dprc list, activating
7 the --full-path option restool will print the entire path
11 root@rodos:~# restool dprc list --full-path
17 Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
19 dprc_commands.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++-----------
20 1 file changed, 50 insertions(+), 11 deletions(-)
22 diff --git a/dprc_commands.c b/dprc_commands.c
23 index e1a8f16..8de2f0e 100644
26 @@ -76,13 +76,16 @@ C_ASSERT(ARRAY_SIZE(dprc_sync_options) <= MAX_NUM_CMD_LINE_OPTIONS + 1);
28 enum dprc_list_options {
33 static struct option dprc_list_options[] = {
38 + [LIST_OPT_FULL_PATH] = {
39 + .name = "full-path",
44 @@ -421,17 +424,33 @@ static int cmd_dprc_sync(void)
45 * Lists nested DPRCs inside a given DPRC, recursively
47 static int list_dprc(uint32_t dprc_id, uint16_t dprc_handle,
48 - int nesting_level, bool show_non_dprc_objects)
49 + int nesting_level, bool show_non_dprc_objects,
52 + char *updated_full_path = NULL;
53 int num_child_devices;
57 assert(nesting_level <= MAX_DPRC_NESTING);
59 - for (int i = 0; i < nesting_level; i++)
62 - printf("dprc.%u\n", dprc_id);
64 + full_path_len = strlen(full_path);
65 + updated_full_path = malloc(full_path_len + 10);
66 + if (!updated_full_path) {
67 + ERROR_PRINTF("Could not alloc memory for full-path!\n");
70 + if (full_path_len != 0)
71 + sprintf(updated_full_path, "%s/dprc.%d", full_path, dprc_id);
73 + sprintf(updated_full_path, "dprc.%d", dprc_id);
74 + printf("%s\n", updated_full_path);
76 + for (int i = 0; i < nesting_level; i++)
78 + printf("dprc.%u\n", dprc_id);
81 error = dprc_get_obj_count(&restool.mc_io, 0,
83 @@ -475,8 +494,11 @@ static int list_dprc(uint32_t dprc_id, uint16_t dprc_handle,
87 - error = list_dprc(obj_desc.id, child_dprc_handle,
88 - nesting_level + 1, show_non_dprc_objects);
89 + error = list_dprc(obj_desc.id,
92 + show_non_dprc_objects,
95 error2 = dprc_close(&restool.mc_io, 0, child_dprc_handle);
97 @@ -491,6 +513,9 @@ static int list_dprc(uint32_t dprc_id, uint16_t dprc_handle,
102 + free(updated_full_path);
107 @@ -498,8 +523,14 @@ static int cmd_dprc_list(void)
109 static const char usage_msg[] =
111 - "Usage: restool dprc list\n"
112 + "Usage: restool dprc list [OPTIONS]\n"
116 + " prints the dprc list in a full-path\n"
117 + " format like: dprc.1/dprc.2\n"
119 + bool full_path = false;
121 if (restool.cmd_option_mask & ONE_BIT_MASK(LIST_OPT_HELP)) {
123 @@ -507,6 +538,12 @@ static int cmd_dprc_list(void)
128 + if (restool.cmd_option_mask & ONE_BIT_MASK(LIST_OPT_FULL_PATH)) {
129 + restool.cmd_option_mask &= ~ONE_BIT_MASK(LIST_OPT_FULL_PATH);
133 if (restool.obj_name != NULL) {
135 "Unexpected argument: \'%s\'\n\n", restool.obj_name);
136 @@ -514,8 +551,10 @@ static int cmd_dprc_list(void)
141 - restool.root_dprc_id, restool.root_dprc_handle, 0, false);
142 + return list_dprc(restool.root_dprc_id,
143 + restool.root_dprc_handle,
145 + full_path ? "" : NULL);
148 static int show_one_resource_type(uint16_t dprc_handle,