common_fit.c 1.8 KB

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