spl_nor.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. /*
  35. * Copy DT blob (fdt) to SDRAM. Passing pointer to
  36. * flash doesn't work
  37. */
  38. memcpy((void *)CONFIG_SYS_SPL_ARGS_ADDR,
  39. (void *)(CONFIG_SYS_FDT_BASE),
  40. CONFIG_SYS_FDT_SIZE);
  41. return 0;
  42. } else {
  43. puts("The Expected Linux image was not found.\n"
  44. "Please check your NOR configuration.\n"
  45. "Trying to start u-boot now...\n");
  46. }
  47. }
  48. #endif
  49. /*
  50. * Load real U-Boot from its location in NOR flash to its
  51. * defined location in SDRAM
  52. */
  53. ret = spl_parse_image_header(spl_image,
  54. (const struct image_header *)CONFIG_SYS_UBOOT_BASE);
  55. if (ret)
  56. return ret;
  57. memcpy((void *)(unsigned long)spl_image->load_addr,
  58. (void *)(CONFIG_SYS_UBOOT_BASE + sizeof(struct image_header)),
  59. spl_image->size);
  60. return 0;
  61. }
  62. SPL_LOAD_IMAGE_METHOD("NOR", 0, BOOT_DEVICE_NOR, spl_nor_load_image);