spl_nor.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. static int spl_nor_load_image(struct spl_image_info *spl_image,
  9. struct spl_boot_device *bootdev)
  10. {
  11. int ret;
  12. /*
  13. * Loading of the payload to SDRAM is done with skipping of
  14. * the mkimage header in this SPL NOR driver
  15. */
  16. spl_image->flags |= SPL_COPY_PAYLOAD_ONLY;
  17. #ifdef CONFIG_SPL_OS_BOOT
  18. if (!spl_start_uboot()) {
  19. const struct image_header *header;
  20. /*
  21. * Load Linux from its location in NOR flash to its defined
  22. * location in SDRAM
  23. */
  24. header = (const struct image_header *)CONFIG_SYS_OS_BASE;
  25. if (image_get_os(header) == IH_OS_LINUX) {
  26. /* happy - was a Linux */
  27. ret = spl_parse_image_header(spl_image, header);
  28. if (ret)
  29. return ret;
  30. memcpy((void *)spl_image->load_addr,
  31. (void *)(CONFIG_SYS_OS_BASE +
  32. sizeof(struct image_header)),
  33. spl_image->size);
  34. spl_image->arg = (void *)CONFIG_SYS_FDT_BASE;
  35. return 0;
  36. } else {
  37. puts("The Expected Linux image was not found.\n"
  38. "Please check your NOR configuration.\n"
  39. "Trying to start u-boot now...\n");
  40. }
  41. }
  42. #endif
  43. /*
  44. * Load real U-Boot from its location in NOR flash to its
  45. * defined location in SDRAM
  46. */
  47. ret = spl_parse_image_header(spl_image,
  48. (const struct image_header *)CONFIG_SYS_UBOOT_BASE);
  49. if (ret)
  50. return ret;
  51. memcpy((void *)(unsigned long)spl_image->load_addr,
  52. (void *)(CONFIG_SYS_UBOOT_BASE + sizeof(struct image_header)),
  53. spl_image->size);
  54. return 0;
  55. }
  56. SPL_LOAD_IMAGE_METHOD("NOR", 0, BOOT_DEVICE_NOR, spl_nor_load_image);