Commit 332ab0d54aaa5b8b27096996d10c8c6183c6972c

Authored by Simon Glass
Committed by Gerald Van Baren
1 parent 09258f1e8b

fdt: Add function to get a config string from device tree

Add a function to look up a configuration string such as board name
and returns its value. We look in the "/config" node for this.

Signed-off-by: Simon Glass <sjg@chromium.org>

Showing 2 changed files with 28 additions and 10 deletions Side-by-side Diff

... ... @@ -367,6 +367,16 @@
367 367 int fdtdec_get_config_int(const void *blob, const char *prop_name,
368 368 int default_val);
369 369  
  370 +/**
  371 + * Look in the FDT for a config item with the given name and return its value
  372 + * as a string.
  373 + *
  374 + * @param blob FDT blob
  375 + * @param prop_name property name to look up
  376 + * @returns property string, NULL on error.
  377 + */
  378 +char *fdtdec_get_config_string(const void *blob, const char *prop_name);
  379 +
370 380 /*
371 381 * Look up a property in a node and return its contents in a byte
372 382 * array of given length. The property must have at least enough data for
... ... @@ -513,16 +513,6 @@
513 513 return cell;
514 514 }
515 515  
516   -/**
517   - * Look in the FDT for a config item with the given name and return its value
518   - * as a 32-bit integer. The property must have at least 4 bytes of data. The
519   - * value of the first cell is returned.
520   - *
521   - * @param blob FDT blob to use
522   - * @param prop_name Node property name
523   - * @param default_val default value to return if the property is not found
524   - * @return integer value, if found, or default_val if not
525   - */
526 516 int fdtdec_get_config_int(const void *blob, const char *prop_name,
527 517 int default_val)
528 518 {
... ... @@ -533,5 +523,23 @@
533 523 if (config_node < 0)
534 524 return default_val;
535 525 return fdtdec_get_int(blob, config_node, prop_name, default_val);
  526 +}
  527 +
  528 +char *fdtdec_get_config_string(const void *blob, const char *prop_name)
  529 +{
  530 + const char *nodep;
  531 + int nodeoffset;
  532 + int len;
  533 +
  534 + debug("%s: %s\n", __func__, prop_name);
  535 + nodeoffset = fdt_path_offset(blob, "/config");
  536 + if (nodeoffset < 0)
  537 + return NULL;
  538 +
  539 + nodep = fdt_getprop(blob, nodeoffset, prop_name, &len);
  540 + if (!nodep)
  541 + return NULL;
  542 +
  543 + return (char *)nodep;
536 544 }