Browse Source

dtc/fdt{get, put}/convert-dtsv0-lexer: convert to new usage helpers

This helps standardize the flag processing and the usage screens.

Only lightly tested; would be great if someone who uses these utils
could double check.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
main
Mike Frysinger 12 years ago committed by David Gibson
parent
commit
03449b84c8
  1. 22
      convert-dtsv0-lexer.l
  2. 111
      dtc.c
  3. 60
      fdtget.c
  4. 63
      fdtput.c
  5. 2
      util.h

22
convert-dtsv0-lexer.l

@ -194,11 +194,15 @@ const struct {
} }


%% %%
static void usage(void) /* Usage related data. */
{ static const char usage_synopsis[] = "convert-dtsv0 [options] <v0 dts file>...";
fprintf(stderr, "convert-dtsv0 <v0 dts file>...\n"); static const char usage_short_opts[] = "" USAGE_COMMON_SHORT_OPTS;
exit(3); static struct option const usage_long_opts[] = {
} USAGE_COMMON_LONG_OPTS
};
static const char * const usage_opts_help[] = {
USAGE_COMMON_OPTS_HELP
};


static void convert_file(const char *fname) static void convert_file(const char *fname)
{ {
@ -226,10 +230,16 @@ static void convert_file(const char *fname)


int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int opt;
int i; int i;


while ((opt = util_getopt_long()) != EOF) {
switch (opt) {
case_USAGE_COMMON_FLAGS
}
}
if (argc < 2) if (argc < 2)
usage(); long_usage("missing filename");


for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
fprintf(stderr, "Converting %s from dts v0 to dts v1\n", argv[i]); fprintf(stderr, "Converting %s from dts v0 to dts v1\n", argv[i]);

111
dtc.c

@ -47,55 +47,60 @@ static void fill_fullpaths(struct node *tree, const char *prefix)
fill_fullpaths(child, tree->fullpath); fill_fullpaths(child, tree->fullpath);
} }


static void __attribute__ ((noreturn)) usage(void) /* Usage related data. */
{ static const char usage_synopsis[] = "dtc [options] <input file>";
fprintf(stderr, "Usage:\n"); static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:fb:i:H:sW:E:hv";
fprintf(stderr, "\tdtc [options] <input file>\n"); static struct option const usage_long_opts[] = {
fprintf(stderr, "\nOptions:\n"); {"quiet", no_argument, NULL, 'q'},
fprintf(stderr, "\t-h\n"); {"in-format", a_argument, NULL, 'I'},
fprintf(stderr, "\t\tThis help text\n"); {"out", a_argument, NULL, 'o'},
fprintf(stderr, "\t-q\n"); {"out-format", a_argument, NULL, 'O'},
fprintf(stderr, "\t\tQuiet: -q suppress warnings, -qq errors, -qqq all\n"); {"out-version", a_argument, NULL, 'V'},
fprintf(stderr, "\t-I <input format>\n"); {"out-dependency", a_argument, NULL, 'd'},
fprintf(stderr, "\t\tInput formats are:\n"); {"reserve", a_argument, NULL, 'R'},
fprintf(stderr, "\t\t\tdts - device tree source text\n"); {"space", a_argument, NULL, 'S'},
fprintf(stderr, "\t\t\tdtb - device tree blob\n"); {"pad", a_argument, NULL, 'p'},
fprintf(stderr, "\t\t\tfs - /proc/device-tree style directory\n"); {"boot-cpu", a_argument, NULL, 'b'},
fprintf(stderr, "\t-o <output file>\n"); {"force", no_argument, NULL, 'f'},
fprintf(stderr, "\t-O <output format>\n"); {"include", a_argument, NULL, 'i'},
fprintf(stderr, "\t\tOutput formats are:\n"); {"sort", no_argument, NULL, 's'},
fprintf(stderr, "\t\t\tdts - device tree source text\n"); {"phandle", a_argument, NULL, 'H'},
fprintf(stderr, "\t\t\tdtb - device tree blob\n"); {"warning", a_argument, NULL, 'W'},
fprintf(stderr, "\t\t\tasm - assembler source\n"); {"error", a_argument, NULL, 'E'},
fprintf(stderr, "\t-V <output version>\n"); {"help", no_argument, NULL, 'h'},
fprintf(stderr, "\t\tBlob version to produce, defaults to %d (relevant for dtb\n\t\tand asm output only)\n", DEFAULT_FDT_VERSION); {"version", no_argument, NULL, 'v'},
fprintf(stderr, "\t-d <output dependency file>\n"); {NULL, no_argument, NULL, 0x0},
fprintf(stderr, "\t-R <number>\n"); };
fprintf(stderr, "\t\tMake space for <number> reserve map entries (relevant for \n\t\tdtb and asm output only)\n"); static const char * const usage_opts_help[] = {
fprintf(stderr, "\t-S <bytes>\n"); "\n\tQuiet: -q suppress warnings, -qq errors, -qqq all",
fprintf(stderr, "\t\tMake the blob at least <bytes> long (extra space)\n"); "\n\tInput formats are:\n"
fprintf(stderr, "\t-p <bytes>\n"); "\t\tdts - device tree source text\n"
fprintf(stderr, "\t\tAdd padding to the blob of <bytes> long (extra space)\n"); "\t\tdtb - device tree blob\n"
fprintf(stderr, "\t-b <number>\n"); "\t\tfs - /proc/device-tree style directory",
fprintf(stderr, "\t\tSet the physical boot cpu\n"); "\n\tOutput file",
fprintf(stderr, "\t-f\n"); "\n\tOutput formats are:\n"
fprintf(stderr, "\t\tForce - try to produce output even if the input tree has errors\n"); "\t\tdts - device tree source text\n"
fprintf(stderr, "\t-i\n"); "\t\tdtb - device tree blob\n"
fprintf(stderr, "\t\tAdd a path to search for include files\n"); "\t\tasm - assembler source",
fprintf(stderr, "\t-s\n"); "\n\tBlob version to produce, defaults to %d (for dtb and asm output)", //, DEFAULT_FDT_VERSION);
fprintf(stderr, "\t\tSort nodes and properties before outputting (only useful for\n\t\tcomparing trees)\n"); "\n\tOutput dependency file",
fprintf(stderr, "\t-v\n"); "\n\ttMake space for <number> reserve map entries (for dtb and asm output)",
fprintf(stderr, "\t\tPrint DTC version and exit\n"); "\n\tMake the blob at least <bytes> long (extra space)",
fprintf(stderr, "\t-H <phandle format>\n"); "\n\tAdd padding to the blob of <bytes> long (extra space)",
fprintf(stderr, "\t\tphandle formats are:\n"); "\n\tSet the physical boot cpu",
fprintf(stderr, "\t\t\tlegacy - \"linux,phandle\" properties only\n"); "\n\tTry to produce output even if the input tree has errors",
fprintf(stderr, "\t\t\tepapr - \"phandle\" properties only\n"); "\n\tAdd a path to search for include files",
fprintf(stderr, "\t\t\tboth - Both \"linux,phandle\" and \"phandle\" properties\n"); "\n\tSort nodes and properties before outputting (useful for comparing trees)",
fprintf(stderr, "\t-W [no-]<checkname>\n"); "\n\tValid phandle formats are:\n"
fprintf(stderr, "\t-E [no-]<checkname>\n"); "\t\tlegacy - \"linux,phandle\" properties only\n"
fprintf(stderr, "\t\t\tenable or disable warnings and errors\n"); "\t\tepapr - \"phandle\" properties only\n"
exit(3); "\t\tboth - Both \"linux,phandle\" and \"phandle\" properties",
} "\n\tEnable/disable warnings (prefix with \"no-\")",
"\n\tEnable/disable errors (prefix with \"no-\")",
"\n\tPrint this help and exit",
"\n\tPrint version and exit",
NULL,
};


int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@ -116,8 +121,7 @@ int main(int argc, char *argv[])
minsize = 0; minsize = 0;
padsize = 0; padsize = 0;


while ((opt = getopt(argc, argv, "hI:O:o:V:d:R:S:p:fqb:i:vH:sW:E:")) while ((opt = util_getopt_long()) != EOF) {
!= EOF) {
switch (opt) { switch (opt) {
case 'I': case 'I':
inform = optarg; inform = optarg;
@ -182,13 +186,14 @@ int main(int argc, char *argv[])
break; break;


case 'h': case 'h':
long_usage(NULL);
default: default:
usage(); long_usage("unknown option");
} }
} }


if (argc > (optind+1)) if (argc > (optind+1))
usage(); long_usage("missing files");
else if (argc < (optind+1)) else if (argc < (optind+1))
arg = "-"; arg = "-";
else else

60
fdtget.c

@ -277,33 +277,33 @@ static int do_fdtget(struct display_info *disp, const char *filename,
return 0; return 0;
} }


static const char *usage_msg = /* Usage related data. */
"fdtget - read values from device tree\n" static const char usage_synopsis[] =
"\n" "read values from device tree\n"
"Each value is printed on a new line.\n\n"
"Usage:\n"
" fdtget <options> <dt file> [<node> <property>]...\n" " fdtget <options> <dt file> [<node> <property>]...\n"
" fdtget -p <options> <dt file> [<node> ]...\n" " fdtget -p <options> <dt file> [<node> ]...\n"
"Options:\n" "\n"
"\t-t <type>\tType of data\n" "Each value is printed on a new line.\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; USAGE_TYPE_MSG;

static const char usage_short_opts[] = "t:pld:" USAGE_COMMON_SHORT_OPTS;
static void usage(const char *msg) static struct option const usage_long_opts[] = {
{ {"type", a_argument, NULL, 't'},
if (msg) {"properties", no_argument, NULL, 'p'},
fprintf(stderr, "Error: %s\n\n", msg); {"list", no_argument, NULL, 'l'},

{"default", a_argument, NULL, 'd'},
fprintf(stderr, "%s", usage_msg); USAGE_COMMON_LONG_OPTS,
exit(2); };
} 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
};


int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int opt;
char *filename = NULL; char *filename = NULL;
struct display_info disp; struct display_info disp;
int args_per_step = 2; int args_per_step = 2;
@ -312,20 +312,14 @@ int main(int argc, char *argv[])
memset(&disp, '\0', sizeof(disp)); memset(&disp, '\0', sizeof(disp));
disp.size = -1; disp.size = -1;
disp.mode = MODE_SHOW_VALUE; disp.mode = MODE_SHOW_VALUE;
for (;;) { while ((opt = util_getopt_long()) != EOF) {
int c = getopt(argc, argv, "d:hlpt:"); switch (opt) {
if (c == -1) case_USAGE_COMMON_FLAGS
break;

switch (c) {
case 'h':
case '?':
usage(NULL);


case 't': case 't':
if (utilfdt_decode_type(optarg, &disp.type, if (utilfdt_decode_type(optarg, &disp.type,
&disp.size)) &disp.size))
usage("Invalid type string"); long_usage("invalid type string");
break; break;


case 'p': case 'p':
@ -347,7 +341,7 @@ int main(int argc, char *argv[])
if (optind < argc) if (optind < argc)
filename = argv[optind++]; filename = argv[optind++];
if (!filename) if (!filename)
usage("Missing filename"); long_usage("missing filename");


argv += optind; argv += optind;
argc -= optind; argc -= optind;
@ -358,7 +352,7 @@ int main(int argc, char *argv[])


/* Check for node, property arguments */ /* Check for node, property arguments */
if (args_per_step == 2 && (argc % 2)) if (args_per_step == 2 && (argc % 2))
usage("Must have an even number of arguments"); long_usage("must have an even number of arguments");


if (do_fdtget(&disp, filename, argv, argc, args_per_step)) if (do_fdtget(&disp, filename, argv, argc, args_per_step))
return 1; return 1;

63
fdtput.c

@ -272,44 +272,40 @@ static int do_fdtput(struct display_info *disp, const char *filename,
return ret; return ret;
} }


static const char *usage_msg = /* Usage related data. */
"fdtput - write a property value to a device tree\n" static const char usage_synopsis[] =
"\n" "write a property value to a device tree\n"
"The command line arguments are joined together into a single value.\n"
"\n"
"Usage:\n"
" fdtput <options> <dt file> <node> <property> [<value>...]\n" " fdtput <options> <dt file> <node> <property> [<value>...]\n"
" fdtput -c <options> <dt file> [<node>...]\n" " fdtput -c <options> <dt file> [<node>...]\n"
"Options:\n" "\n"
"\t-c\t\tCreate nodes if they don't already exist\n" "The command line arguments are joined together into a single value.\n"
"\t-p\t\tAutomatically create nodes as needed for the node path\n"
"\t-t <type>\tType of data\n"
"\t-v\t\tVerbose: display each value decoded from command line\n"
"\t-h\t\tPrint this help\n\n"
USAGE_TYPE_MSG; USAGE_TYPE_MSG;

static const char usage_short_opts[] = "cpt:v" USAGE_COMMON_SHORT_OPTS;
static void usage(const char *msg) static struct option const usage_long_opts[] = {
{ {"create", no_argument, NULL, 'c'},
if (msg) {"auto-path", no_argument, NULL, 'p'},
fprintf(stderr, "Error: %s\n\n", msg); {"type", a_argument, NULL, 't'},

{"verbose", no_argument, NULL, 'v'},
fprintf(stderr, "%s", usage_msg); USAGE_COMMON_LONG_OPTS,
exit(2); };
} static const char * const usage_opts_help[] = {
"Create nodes if they don't already exist",
"Automatically create nodes as needed for the node path",
"Type of data",
"Display each value decoded from command line",
USAGE_COMMON_OPTS_HELP
};


int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int opt;
struct display_info disp; struct display_info disp;
char *filename = NULL; char *filename = NULL;


memset(&disp, '\0', sizeof(disp)); memset(&disp, '\0', sizeof(disp));
disp.size = -1; disp.size = -1;
disp.oper = OPER_WRITE_PROP; disp.oper = OPER_WRITE_PROP;
for (;;) { while ((opt = util_getopt_long()) != EOF) {
int c = getopt(argc, argv, "chpt:v");
if (c == -1)
break;

/* /*
* TODO: add options to: * TODO: add options to:
* - delete property * - delete property
@ -319,20 +315,19 @@ int main(int argc, char *argv[])
* - set amount of free space when writing * - set amount of free space when writing
* - expand fdt if value doesn't fit * - expand fdt if value doesn't fit
*/ */
switch (c) { switch (opt) {
case_USAGE_COMMON_FLAGS

case 'c': case 'c':
disp.oper = OPER_CREATE_NODE; disp.oper = OPER_CREATE_NODE;
break; break;
case 'h':
case '?':
usage(NULL);
case 'p': case 'p':
disp.auto_path = 1; disp.auto_path = 1;
break; break;
case 't': case 't':
if (utilfdt_decode_type(optarg, &disp.type, if (utilfdt_decode_type(optarg, &disp.type,
&disp.size)) &disp.size))
usage("Invalid type string"); long_usage("Invalid type string");
break; break;


case 'v': case 'v':
@ -344,16 +339,16 @@ int main(int argc, char *argv[])
if (optind < argc) if (optind < argc)
filename = argv[optind++]; filename = argv[optind++];
if (!filename) if (!filename)
usage("Missing filename"); long_usage("missing filename");


argv += optind; argv += optind;
argc -= optind; argc -= optind;


if (disp.oper == OPER_WRITE_PROP) { if (disp.oper == OPER_WRITE_PROP) {
if (argc < 1) if (argc < 1)
usage("Missing node"); long_usage("missing node");
if (argc < 2) if (argc < 2)
usage("Missing property"); long_usage("missing property");
} }


if (do_fdtput(&disp, filename, argv, argc)) if (do_fdtput(&disp, filename, argv, argc))

2
util.h

@ -164,7 +164,7 @@ int utilfdt_decode_type(const char *fmt, int *type, int *size);
#define USAGE_TYPE_MSG \ #define USAGE_TYPE_MSG \
"<type>\ts=string, i=int, u=unsigned, x=hex\n" \ "<type>\ts=string, i=int, u=unsigned, x=hex\n" \
"\tOptional modifier prefix:\n" \ "\tOptional modifier prefix:\n" \
"\t\thh or b=byte, h=2 byte, l=4 byte (default)\n"; "\t\thh or b=byte, h=2 byte, l=4 byte (default)";


/** /**
* Print property data in a readable format to stdout * Print property data in a readable format to stdout

Loading…
Cancel
Save