Thread (1 message) 1 message, 1 author, 2011-09-04

Re: [PATCH 6/9] Add new dtput utility to write values to fdt

From: Simon Glass <hidden>
Date: 2011-09-04 03:23:15

Hi Grant,

On Wed, Jul 6, 2011 at 11:46 AM, Grant Likely [off-list ref] wrote:
On Tue, Jul 05, 2011 at 12:02:54PM -0700, Simon Glass wrote:
quoted
This simple utility allows writing of values into a device tree from the
command line.

Signed-off-by: Simon Glass <redacted>
---
[snip]
quoted
+static void usage(const char *msg)
+{
+     if (msg)
+             fprintf(stderr, "Error: %s\n\n", msg);
+     fprintf(stderr, "dtput - write a property value to a device tree\n\n");
+     fprintf(stderr, "Usage: dtput <options> <dt file> <key> "
+             "[<value>...]\n");
+     fprintf(stderr, "Options:\n");
+     fprintf(stderr, "\t-f, --format <fmt>\tScanf format string to use "
+             "for value\n");
+     fprintf(stderr, "\t-t, --type <typechar>\tForce type to be string "
+             "(s), byte(b) or int(i)\n");
+     fprintf(stderr, "\t-h, --help\t\tPrint this help\n\n");
+     fprintf(stderr, "\t<key> is <node>/<property>, for example "
+             "/lcd/width for the width\n");
+     fprintf(stderr, "\tproperty in the LCD node\n");
Can you make this text a single string and only call fprintf once?  It
will be easier to reqd that way.
OK will do, thanks.
It would be useful to have a mode for removing or renaming properties/nodes.
Yes, perhaps a -d flag to delete something (either a property or
node). I will look at this if my v2 patches pass muster.

Regards,
Simon
quoted
+     exit(2);
+}
+
+int main(int argc, char *argv[])
+{
+     int c;
+     int ret;
+     char *format = NULL;
+     int type = 0;
+     char *filename = NULL;
+     static struct option long_options[] = {
+             {"format", 1, 0, 'f'},
+             {"help", 1, 0, 'h'},
+             {"type", 1, 0, 't'},
+             {"verbose", 1, 0, 'v'},
+             {0, 0, 0, 0}
+     };
+
+     for (;;) {
+             c = getopt_long(argc, argv, "f:ht:v", long_options, NULL);
+             if (c == -1)
+                     break;
+
+             switch (c) {
+             case 'h':
+             case '?':
+                     usage(NULL);
+
+             case 'f':
+                     format = optarg;
+                     break;
+
+             case 't':
+                     type = *optarg;
+                     break;
+
+             case 'v':
+                     verbose = 1;
+                     break;
+             }
+     }
+
+     if (optind < argc)
+             filename = argv[optind++];
+     if (!filename)
+             usage("Missing filename");
+     if (optind == argc)
+             usage("Missing key(s)");
+
+     ret = do_dtput(filename, format, type, argv + optind, argc - optind);
+     return ret;
+}
--
1.7.3.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help