+ } else if (argv[1][0] == 'g') {
+ char *subcmd; /* sub-command */
+ char *pathp; /* path */
+ char *prop; /* property */
+ char *var; /* variable to store result */
+ int nodeoffset; /* node offset from libfdt */
+ const void *nodep; /* property node pointer */
+ int len = 0; /* new length of the property */
+
+ /*
+ * Parameters: Node path, property, optional value.
+ */
+ if (argc < 5)
+ return CMD_RET_USAGE;
+
+ subcmd = argv[2];
+
+ if (argc < 6 && subcmd[0] != 's')
+ return CMD_RET_USAGE;
+
+ var = argv[3];
+ pathp = argv[4];
+ prop = argv[5];
+
+ nodeoffset = fdt_path_offset(working_fdt, pathp);
+ if (nodeoffset < 0) {
+ /*
+ * Not found or something else bad happened.
+ */
+ printf("libfdt fdt_path_offset() returned %s\n",
+ fdt_strerror(nodeoffset));
+ return 1;
+ }
+
+ if (subcmd[0] == 'n' || (subcmd[0] == 's' && argc == 5)) {
+ int reqIndex = -1;
+ int startDepth = fdt_node_depth(
+ working_fdt, nodeoffset);
+ int curDepth = startDepth;
+ int curIndex = -1;
+ int nextNodeOffset = fdt_next_node(
+ working_fdt, nodeoffset, &curDepth);
+
+ if (subcmd[0] == 'n')
+ reqIndex = simple_strtoul(argv[5], NULL, 16);
+
+ while (curDepth > startDepth) {
+ if (curDepth == startDepth + 1)
+ curIndex++;
+ if (subcmd[0] == 'n' && curIndex == reqIndex) {
+ const char *nodeName = fdt_get_name(
+ working_fdt, nextNodeOffset, NULL);
+
+ setenv(var, (char *)nodeName);
+ return 0;
+ }
+ nextNodeOffset = fdt_next_node(
+ working_fdt, nextNodeOffset, &curDepth);
+ if (nextNodeOffset < 0)
+ break;
+ }
+ if (subcmd[0] == 's') {
+ /* get the num nodes at this level */
+ char buf[11];
+
+ sprintf(buf, "%d", curIndex + 1);
+ setenv(var, buf);
+ } else {
+ /* node index not found */
+ printf("libfdt node not found\n");
+ return 1;
+ }
+ } else {
+ nodep = fdt_getprop(
+ working_fdt, nodeoffset, prop, &len);
+ if (len == 0) {
+ /* no property value */
+ setenv(var, "");
+ return 0;
+ } else if (len > 0) {
+ if (subcmd[0] == 'v') {
+ int ret;
+
+ ret = fdt_value_setenv(nodep, len, var);
+ if (ret != 0)
+ return ret;
+ } else if (subcmd[0] == 'a') {
+ /* Get address */
+ char buf[11];
+
+ sprintf(buf, "0x%p", nodep);
+ setenv(var, buf);
+ } else if (subcmd[0] == 's') {
+ /* Get size */
+ char buf[11];
+
+ sprintf(buf, "0x%08X", len);
+ setenv(var, buf);
+ } else
+ return CMD_RET_USAGE;
+ return 0;
+ } else {
+ printf("libfdt fdt_getprop(): %s\n",
+ fdt_strerror(len));
+ return 1;
+ }
+ }
+
+ /*
+ * Print (recursive) / List (single level)
+ */