summaryrefslogtreecommitdiffstats
path: root/scripts/dtc/fdtget.c
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/dtc/fdtget.c')
-rw-r--r--scripts/dtc/fdtget.c60
1 files changed, 33 insertions, 27 deletions
diff --git a/scripts/dtc/fdtget.c b/scripts/dtc/fdtget.c
index 4377419224..c2fbab2a54 100644
--- a/scripts/dtc/fdtget.c
+++ b/scripts/dtc/fdtget.c
@@ -277,33 +277,33 @@ static int do_fdtget(struct display_info *disp, const char *filename,
return 0;
}
-/* Usage related data. */
-static const char usage_synopsis[] =
- "read values from device tree\n"
+static const char *usage_msg =
+ "fdtget - read values from device tree\n"
+ "\n"
+ "Each value is printed on a new line.\n\n"
+ "Usage:\n"
" fdtget <options> <dt file> [<node> <property>]...\n"
" fdtget -p <options> <dt file> [<node> ]...\n"
- "\n"
- "Each value is printed on a new line.\n"
+ "Options:\n"
+ "\t-t <type>\tType of data\n"
+ "\t-p\t\tList properties for each node\n"
+ "\t-l\t\tList subnodes for each node\n"
+ "\t-d\t\tDefault value to display when the property is "
+ "missing\n"
+ "\t-h\t\tPrint this help\n\n"
USAGE_TYPE_MSG;
-static const char usage_short_opts[] = "t:pld:" USAGE_COMMON_SHORT_OPTS;
-static struct option const usage_long_opts[] = {
- {"type", a_argument, NULL, 't'},
- {"properties", no_argument, NULL, 'p'},
- {"list", no_argument, NULL, 'l'},
- {"default", a_argument, NULL, 'd'},
- USAGE_COMMON_LONG_OPTS,
-};
-static const char * const usage_opts_help[] = {
- "Type of data",
- "List properties for each node",
- "List subnodes for each node",
- "Default value to display when the property is missing",
- USAGE_COMMON_OPTS_HELP
-};
+
+static void usage(const char *msg)
+{
+ if (msg)
+ fprintf(stderr, "Error: %s\n\n", msg);
+
+ fprintf(stderr, "%s", usage_msg);
+ exit(2);
+}
int main(int argc, char *argv[])
{
- int opt;
char *filename = NULL;
struct display_info disp;
int args_per_step = 2;
@@ -312,14 +312,20 @@ int main(int argc, char *argv[])
memset(&disp, '\0', sizeof(disp));
disp.size = -1;
disp.mode = MODE_SHOW_VALUE;
- while ((opt = util_getopt_long()) != EOF) {
- switch (opt) {
- case_USAGE_COMMON_FLAGS
+ for (;;) {
+ int c = getopt(argc, argv, "d:hlpt:");
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'h':
+ case '?':
+ usage(NULL);
case 't':
if (utilfdt_decode_type(optarg, &disp.type,
&disp.size))
- usage("invalid type string");
+ usage("Invalid type string");
break;
case 'p':
@@ -341,7 +347,7 @@ int main(int argc, char *argv[])
if (optind < argc)
filename = argv[optind++];
if (!filename)
- usage("missing filename");
+ usage("Missing filename");
argv += optind;
argc -= optind;
@@ -352,7 +358,7 @@ int main(int argc, char *argv[])
/* Check for node, property arguments */
if (args_per_step == 2 && (argc % 2))
- usage("must have an even number of arguments");
+ usage("Must have an even number of arguments");
if (do_fdtget(&disp, filename, argv, argc, args_per_step))
return 1;