common_fit.c 1.8 KB

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