/* These are the operations we support */ enum oper_type {
OPER_WRITE_PROP, /* Write a property in a node */
OPER_CREATE_NODE, /* Create a new node */
};
struct display_info { enum oper_type oper; /* operation to perform */ int type; /* data type (s/i/u/x or 0 for default) */ int size; /* data size (1/2/4) */ int verbose; /* verbose output */ int auto_path; /* automatically create all path components */
};
/** *Reportanerrorwithaparticularnode. * *@paramnameNodenametoreporterroron *@paramnamelenLengthofnodename,or-1touseentirestring *@paramerrErrornumbertoreport(-FDT_ERR_...)
*/ staticvoid report_error(constchar *name, int namelen, int err)
{ if (namelen == -1)
namelen = strlen(name);
fprintf(stderr, "Error at '%1.*s': %s\n", namelen, name,
fdt_strerror(err));
}
/** *Encodeaseriesofargumentsinapropertyvalue. * *@paramdispDisplayinformation/options *@paramargListofargumentsfromcommandline *@paramarg_countNumberofarguments(maybe0) *@paramvaluepReturnsbuffercontainingvalue *@param*value_lenReturnslengthofvalueencoded
*/ staticint encode_value(struct display_info *disp, char **arg, int arg_count, char **valuep, int *value_len)
{ char *value = NULL; /* holding area for value */ int value_size = 0; /* size of holding area */ char *ptr; /* pointer to current value position */ int len; /* length of this cell/string/byte */ int ival; int upto; /* the number of bytes we have written to buf */ char fmt[3];
upto = 0;
if (disp->verbose)
fprintf(stderr, "Decoding value:\n");
node = fdt_add_subnode(blob, node, p + 1); if (node < 0) {
report_error(p + 1, -1, node); return -1;
}
return0;
}
staticint do_fdtput(struct display_info *disp, constchar *filename, char **arg, int arg_count)
{ char *value; char *blob; int len, ret = 0;
blob = utilfdt_read(filename); if (!blob) return -1;
switch (disp->oper) { case OPER_WRITE_PROP: /* *Converttheargumentsintoasinglebinaryvalue,then *storethemintotheproperty.
*/
assert(arg_count >= 2); if (disp->auto_path && create_paths(blob, *arg)) return -1; if (encode_value(disp, arg + 2, arg_count - 2, &value, &len) ||
store_key_value(blob, *arg, arg[1], value, len))
ret = -1; break; case OPER_CREATE_NODE: for (; ret >= 0 && arg_count--; arg++) { if (disp->auto_path)
ret = create_paths(blob, *arg); else
ret = create_node(blob, *arg);
} break;
} if (ret >= 0)
ret = utilfdt_write(filename, blob);
free(blob); return ret;
}
staticconstchar *usage_msg = "fdtput - write a property value to a device tree\n" "\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 -c <options> <dt file> [<node>...]\n" "Options:\n" "\t-c\t\tCreate nodes if they don't already exist\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;
staticvoid usage(constchar *msg)
{ if (msg)
fprintf(stderr, "Error: %s\n\n", msg);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.