aboutsummaryrefslogtreecommitdiffstats
path: root/package/network/utils/layerscape/restool/patches/0002-dprc-add-full-path-option-to-dprc-list-command.patch
blob: 0e39ef7245108861b961ae2140611795289ac303 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
From 6039bd1b7e5e71a0a171406cf980d2d61a6e79d4 Mon Sep 17 00:00:00 2001
From: Ioana Ciornei <ioana.ciornei@nxp.com>
Date: Tue, 24 Oct 2017 16:29:37 +0000
Subject: [PATCH 02/12] dprc: add --full-path option to dprc list command

Instead of printing an indented dprc list, activating
the --full-path option restool will print the entire path
of the dprc.
Example:

root@rodos:~# restool dprc list --full-path
dprc.1
dprc.1/dprc.3
dprc.1/dprc.2
dprc.1/dprc.2/dprc.4

Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
---
 dprc_commands.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 50 insertions(+), 11 deletions(-)

diff --git a/dprc_commands.c b/dprc_commands.c
index e1a8f16..8de2f0e 100644
--- a/dprc_commands.c
+++ b/dprc_commands.c
@@ -76,13 +76,16 @@ C_ASSERT(ARRAY_SIZE(dprc_sync_options) <= MAX_NUM_CMD_LINE_OPTIONS + 1);
  */
 enum dprc_list_options {
 	LIST_OPT_HELP = 0,
+	LIST_OPT_FULL_PATH,
 };
 
 static struct option dprc_list_options[] = {
 	[LIST_OPT_HELP] = {
 		.name = "help",
 	},
-
+	[LIST_OPT_FULL_PATH] = {
+		.name = "full-path",
+	},
 	{ 0 },
 };
 
@@ -421,17 +424,33 @@ static int cmd_dprc_sync(void)
  * Lists nested DPRCs inside a given DPRC, recursively
  */
 static int list_dprc(uint32_t dprc_id, uint16_t dprc_handle,
-		     int nesting_level, bool show_non_dprc_objects)
+		     int nesting_level, bool show_non_dprc_objects,
+		     char *full_path)
 {
+	char *updated_full_path = NULL;
 	int num_child_devices;
 	int error = 0;
+	int full_path_len;
 
 	assert(nesting_level <= MAX_DPRC_NESTING);
 
-	for (int i = 0; i < nesting_level; i++)
-		printf("  ");
-
-	printf("dprc.%u\n", dprc_id);
+	if (full_path) {
+		full_path_len = strlen(full_path);
+		updated_full_path = malloc(full_path_len + 10);
+		if (!updated_full_path) {
+			ERROR_PRINTF("Could not alloc memory for full-path!\n");
+			return -ENOMEM;
+		}
+		if (full_path_len != 0)
+			sprintf(updated_full_path, "%s/dprc.%d", full_path, dprc_id);
+		else
+			sprintf(updated_full_path, "dprc.%d", dprc_id);
+		printf("%s\n", updated_full_path);
+	} else {
+		for (int i = 0; i < nesting_level; i++)
+			printf("  ");
+		printf("dprc.%u\n", dprc_id);
+	}
 
 	error = dprc_get_obj_count(&restool.mc_io, 0,
 				   dprc_handle,
@@ -475,8 +494,11 @@ static int list_dprc(uint32_t dprc_id, uint16_t dprc_handle,
 		if (error < 0)
 			goto out;
 
-		error = list_dprc(obj_desc.id, child_dprc_handle,
-				  nesting_level + 1, show_non_dprc_objects);
+		error = list_dprc(obj_desc.id,
+				  child_dprc_handle,
+				  nesting_level + 1,
+				  show_non_dprc_objects,
+				  updated_full_path);
 
 		error2 = dprc_close(&restool.mc_io, 0, child_dprc_handle);
 		if (error2 < 0) {
@@ -491,6 +513,9 @@ static int list_dprc(uint32_t dprc_id, uint16_t dprc_handle,
 	}
 
 out:
+	if (full_path)
+		free(updated_full_path);
+
 	return error;
 }
 
@@ -498,8 +523,14 @@ static int cmd_dprc_list(void)
 {
 	static const char usage_msg[] =
 		"\n"
-		"Usage: restool dprc list\n"
+		"Usage: restool dprc list [OPTIONS]\n"
+		"\n"
+		"OPTIONS:\n"
+		"--full-path\n"
+		"   prints the dprc list in a full-path\n"
+		"   format like: dprc.1/dprc.2\n"
 		"\n";
+	bool full_path = false;
 
 	if (restool.cmd_option_mask & ONE_BIT_MASK(LIST_OPT_HELP)) {
 		puts(usage_msg);
@@ -507,6 +538,12 @@ static int cmd_dprc_list(void)
 		return 0;
 	}
 
+
+	if (restool.cmd_option_mask & ONE_BIT_MASK(LIST_OPT_FULL_PATH)) {
+		restool.cmd_option_mask &= ~ONE_BIT_MASK(LIST_OPT_FULL_PATH);
+		full_path = true;
+	}
+
 	if (restool.obj_name != NULL) {
 		ERROR_PRINTF(
 			"Unexpected argument: \'%s\'\n\n", restool.obj_name);
@@ -514,8 +551,10 @@ static int cmd_dprc_list(void)
 		return -EINVAL;
 	}
 
-	return list_dprc(
-		restool.root_dprc_id, restool.root_dprc_handle, 0, false);
+	return list_dprc(restool.root_dprc_id,
+			 restool.root_dprc_handle,
+			 0, false,
+			 full_path ? "" : NULL);
 }
 
 static int show_one_resource_type(uint16_t dprc_handle,
-- 
2.14.1