common_fit.c 1.8 KB

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