57 fprintf(stderr,
"Error at '%1.*s': %s\n", namelen, name,
70 static int encode_value(
struct display_info *disp,
char **
arg,
int arg_count,
84 fprintf(stderr,
"Decoding value:\n");
87 fmt[1] = disp->
type ? disp->
type :
'd';
89 for (; arg_count > 0; arg++, arg_count--, upto += len) {
91 if (disp->
type ==
's')
94 len = disp->
size == -1 ? 4 : disp->
size;
97 if (upto + len > value_size) {
98 value_size = (upto + len) + 500;
99 value = realloc(value, value_size);
101 fprintf(stderr,
"Out of mmory: cannot alloc "
102 "%d bytes\n", value_size);
108 if (disp->
type ==
's') {
111 fprintf(stderr,
"\tstring: '%s'\n", ptr);
113 int *iptr = (
int *)ptr;
121 disp->
size == 1 ?
"byte" :
122 disp->
size == 2 ?
"short" :
"int",
130 fprintf(stderr,
"Value size %d\n", upto);
134 static int store_key_value(
void *
blob,
const char *
node_name,
142 report_error(node_name, -1, node);
148 report_error(property, -1, err);
164 static int create_paths(
void *blob,
const char *in_path)
166 const char *
path = in_path;
174 for (sep = path; *sep; path = sep + 1, offset =
node) {
178 sep = path +
strlen(path);
187 report_error(path, sep - path, node);
206 static int create_node(
void *blob,
const char *node_name)
221 report_error(node_name, -1, node);
228 report_error(p + 1, -1, node);
236 char **arg,
int arg_count)
246 switch (disp->
oper) {
253 if (disp->
auto_path && create_paths(blob, *arg))
255 if (encode_value(disp, arg + 2, arg_count - 2, &value, &len) ||
256 store_key_value(blob, *arg, arg[1], value, len))
260 for (; ret >= 0 && arg_count--; arg++) {
262 ret = create_paths(blob, *arg);
264 ret = create_node(blob, *arg);
275 static const char *usage_msg =
276 "fdtput - write a property value to a device tree\n"
278 "The command line arguments are joined together into a single value.\n"
281 " fdtput <options> <dt file> <node> <property> [<value>...]\n"
282 " fdtput -c <options> <dt file> [<node>...]\n"
284 "\t-c\t\tCreate nodes if they don't already exist\n"
285 "\t-p\t\tAutomatically create nodes as needed for the node path\n"
286 "\t-t <type>\tType of data\n"
287 "\t-v\t\tVerbose: display each value decoded from command line\n"
288 "\t-h\t\tPrint this help\n\n"
294 fprintf(stderr,
"Error: %s\n\n", msg);
296 fprintf(stderr,
"%s", usage_msg);
303 char *filename =
NULL;
305 memset(&disp,
'\0',
sizeof(disp));
309 int c = getopt(argc, argv,
"chpt:v");
335 usage(
"Invalid type string");
345 filename = argv[optind++];
347 usage(
"Missing filename");
354 usage(
"Missing node");
356 usage(
"Missing property");
359 if (do_fdtput(&disp, filename, argv, argc))