spl_nor.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (C) 2012 Stefan Roese <sr@denx.de>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <spl.h>
  8. int spl_nor_load_image(void)
  9. {
  10. int ret;
  11. /*
  12. * Loading of the payload to SDRAM is done with skipping of
  13. * the mkimage header in this SPL NOR driver
  14. */
  15. spl_image.flags |= SPL_COPY_PAYLOAD_ONLY;
  16. #ifdef CONFIG_SPL_OS_BOOT
  17. if (!spl_start_uboot()) {
  18. const struct image_header *header;
  19. /*
  20. * Load Linux from its location in NOR flash to its defined
  21. * location in SDRAM
  22. */
  23. header = (const struct image_header *)CONFIG_SYS_OS_BASE;
  24. if (image_get_os(header) == IH_OS_LINUX) {
  25. /* happy - was a Linux */
  26. ret = spl_parse_image_header(header);
  27. if (ret)
  28. return ret;
  29. memcpy((void *)spl_image.load_addr,
  30. (void *)(CONFIG_SYS_OS_BASE +
  31. sizeof(struct image_header)),
  32. spl_image.size);
  33. /*
  34. * Copy DT blob (fdt) to SDRAM. Passing pointer to
  35. * flash doesn't work
  36. */
  37. memcpy((void *)CONFIG_SYS_SPL_ARGS_ADDR,
  38. (void *)(CONFIG_SYS_FDT_BASE),
  39. CONFIG_SYS_FDT_SIZE);
  40. return 0;
  41. } else {
  42. puts("The Expected Linux image was not found.\n"
  43. "Please check your NOR configuration.\n"
  44. "Trying to start u-boot now...\n");
  45. }
  46. }
  47. #endif
  48. /*
  49. * Load real U-Boot from its location in NOR flash to its
  50. * defined location in SDRAM
  51. */
  52. ret = spl_parse_image_header(
  53. (const struct image_header *)CONFIG_SYS_UBOOT_BASE);
  54. if (ret)
  55. return ret;
  56. memcpy((void *)(unsigned long)spl_image.load_addr,
  57. (void *)(CONFIG_SYS_UBOOT_BASE + sizeof(struct image_header)),
  58. spl_image.size);
  59. return 0;
  60. }