51 static void report_error(
const char *where,
int err)
80 is_string = (disp->
type) ==
's' ||
83 if (data[len - 1] !=
'\0') {
84 fprintf(stderr,
"Unterminated string\n");
87 for (s = data; s - data < len; s +=
strlen(s) + 1) {
90 printf(
"%s", (
const char *)s);
96 size = (len % 4) == 0 ? 4 : 1;
97 }
else if (len % size) {
98 fprintf(stderr,
"Property length must be a multiple of "
99 "selected data size\n");
103 fmt[1] = disp->
type ? disp->
type :
'd';
105 for (i = 0; i < len; i +=
size, p +=
size) {
109 size == 2 ? (*p << 8) | p[1] : *p;
122 static int list_properties(
const void *
blob,
int node)
150 static int list_subnodes(
const void *blob,
int node)
163 if (level <= depth) {
165 pathp =
"/* NULL pointer error */";
173 printf(
"Nested too deep, aborting.\n");
188 printf(
"Unknown tag 0x%08X\n", tag);
206 static int show_data_for_item(
const void *blob,
struct display_info *disp,
209 const void *value =
NULL;
212 switch (disp->
mode) {
214 err = list_properties(blob, node);
218 err = list_subnodes(blob, node);
225 if (show_data(disp, value, len))
232 report_error(property, len);
251 char **
arg,
int arg_count,
int args_per_step)
261 for (i = 0; i + args_per_step <= arg_count; i += args_per_step) {
268 report_error(arg[i], node);
272 prop = args_per_step == 1 ?
NULL : arg[i + 1];
274 if (show_data_for_item(blob, disp, node, prop))
280 static const char *usage_msg =
281 "fdtget - read values from device tree\n"
283 "Each value is printed on a new line.\n\n"
285 " fdtget <options> <dt file> [<node> <property>]...\n"
286 " fdtget -p <options> <dt file> [<node> ]...\n"
288 "\t-t <type>\tType of data\n"
289 "\t-p\t\tList properties for each node\n"
290 "\t-l\t\tList subnodes for each node\n"
291 "\t-d\t\tDefault value to display when the property is "
293 "\t-h\t\tPrint this help\n\n"
299 fprintf(stderr,
"Error: %s\n\n", msg);
301 fprintf(stderr,
"%s", usage_msg);
307 char *filename =
NULL;
309 int args_per_step = 2;
312 memset(&disp,
'\0',
sizeof(disp));
316 int c = getopt(argc, argv,
"d:hlpt:");
328 usage(
"Invalid type string");
348 filename = argv[optind++];
350 usage(
"Missing filename");
360 if (args_per_step == 2 && (argc % 2))
361 usage(
"Must have an even number of arguments");
363 if (do_fdtget(&disp, filename, argv, argc, args_per_step))