boot_fit.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * (C) Copyright 2017
  3. * Texas Instruments, <www.ti.com>
  4. *
  5. * Franklin S Cooper Jr. <fcooper@ti.com>
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <boot_fit.h>
  10. #include <common.h>
  11. #include <errno.h>
  12. #include <image.h>
  13. #include <libfdt.h>
  14. int fdt_offset(void *fit)
  15. {
  16. int fdt_offset, fdt_len;
  17. int images;
  18. images = fdt_path_offset(fit, FIT_IMAGES_PATH);
  19. if (images < 0) {
  20. debug("%s: Cannot find /images node: %d\n", __func__, images);
  21. return -1;
  22. }
  23. /* Figure out which device tree the board wants to use */
  24. fdt_len = fit_select_fdt(fit, images, &fdt_offset);
  25. if (fdt_len < 0)
  26. return fdt_len;
  27. return fdt_offset;
  28. }
  29. void *locate_dtb_in_fit(void *fit)
  30. {
  31. struct image_header *header;
  32. int size;
  33. int ret;
  34. size = fdt_totalsize(fit);
  35. size = (size + 3) & ~3;
  36. header = (struct image_header *)fit;
  37. if (image_get_magic(header) != FDT_MAGIC) {
  38. debug("No FIT image appended to U-boot\n");
  39. return NULL;
  40. }
  41. ret = fdt_offset(fit);
  42. if (ret <= 0)
  43. return NULL;
  44. else
  45. return (void *)fit+size+ret;
  46. }