common_fit.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. conf = fdt_path_offset(fdt, FIT_CONFS_PATH);
  31. if (conf < 0) {
  32. debug("%s: Cannot find /configurations node: %d\n", __func__,
  33. conf);
  34. return -EINVAL;
  35. }
  36. for (node = fdt_first_subnode(fdt, conf);
  37. node >= 0;
  38. node = fdt_next_subnode(fdt, node)) {
  39. name = fdt_getprop(fdt, node, "description", &len);
  40. if (!name) {
  41. #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
  42. printf("%s: Missing FDT description in DTB\n",
  43. __func__);
  44. #endif
  45. return -EINVAL;
  46. }
  47. if (board_fit_config_name_match(name))
  48. continue;
  49. debug("Selecting config '%s'", name);
  50. return node;
  51. }
  52. return -ENOENT;
  53. }