spl_nor.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2012 Stefan Roese <sr@denx.de>
  4. */
  5. #include <common.h>
  6. #include <spl.h>
  7. static int spl_nor_load_image(struct spl_image_info *spl_image,
  8. struct spl_boot_device *bootdev)
  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(spl_image, 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. spl_image->arg = (void *)CONFIG_SYS_FDT_BASE;
  34. return 0;
  35. } else {
  36. puts("The Expected Linux image was not found.\n"
  37. "Please check your NOR configuration.\n"
  38. "Trying to start u-boot now...\n");
  39. }
  40. }
  41. #endif
  42. /*
  43. * Load real U-Boot from its location in NOR flash to its
  44. * defined location in SDRAM
  45. */
  46. ret = spl_parse_image_header(spl_image,
  47. (const struct image_header *)CONFIG_SYS_UBOOT_BASE);
  48. if (ret)
  49. return ret;
  50. memcpy((void *)(unsigned long)spl_image->load_addr,
  51. (void *)(CONFIG_SYS_UBOOT_BASE + sizeof(struct image_header)),
  52. spl_image->size);
  53. return 0;
  54. }
  55. SPL_LOAD_IMAGE_METHOD("NOR", 0, BOOT_DEVICE_NOR, spl_nor_load_image);