common_fit.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (C) 2016 Google, Inc
  3. * Written by Simon Glass <sjg@chromium.org>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <errno.h>
  9. #include <image.h>
  10. #include <libfdt.h>
  11. #include <spl.h>
  12. ulong fdt_getprop_u32(const void *fdt, int node, const char *prop)
  13. {
  14. const u32 *cell;
  15. int len;
  16. cell = fdt_getprop(fdt, node, prop, &len);
  17. if (!cell || len != sizeof(*cell))
  18. return FDT_ERROR;
  19. return fdt32_to_cpu(*cell);
  20. }
  21. /*
  22. * Iterate over all /configurations subnodes and call a platform specific
  23. * function to find the matching configuration.
  24. * Returns the node offset or a negative error number.
  25. */
  26. int fit_find_config_node(const void *fdt)
  27. {
  28. const char *name;
  29. int conf, node, len;
  30. const char *dflt_conf_name;
  31. const char *dflt_conf_desc = NULL;
  32. int dflt_conf_node = -ENOENT;
  33. conf = fdt_path_offset(fdt, FIT_CONFS_PATH);
  34. if (conf < 0) {
  35. debug("%s: Cannot find /configurations node: %d\n", __func__,
  36. conf);
  37. return -EINVAL;
  38. }
  39. dflt_conf_name = fdt_getprop(fdt, conf, "default", &len);
  40. for (node = fdt_first_subnode(fdt, conf);
  41. node >= 0;
  42. node = fdt_next_subnode(fdt, node)) {
  43. name = fdt_getprop(fdt, node, "description", &len);
  44. if (!name) {
  45. #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
  46. printf("%s: Missing FDT description in DTB\n",
  47. __func__);
  48. #endif
  49. return -EINVAL;
  50. }
  51. if (dflt_conf_name) {
  52. const char *node_name = fdt_get_name(fdt, node, NULL);
  53. if (strcmp(dflt_conf_name, node_name) == 0) {
  54. dflt_conf_node = node;
  55. dflt_conf_desc = name;
  56. }
  57. }
  58. if (board_fit_config_name_match(name))
  59. continue;
  60. debug("Selecting config '%s'", name);
  61. return node;
  62. }
  63. if (dflt_conf_node != -ENOENT) {
  64. debug("Selecting default config '%s'", dflt_conf_desc);
  65. return dflt_conf_node;
  66. }
  67. return -ENOENT;
  68. }