spl_nand.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (C) 2011
  3. * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <config.h>
  9. #include <spl.h>
  10. #include <asm/io.h>
  11. #include <nand.h>
  12. void spl_nand_load_image(void)
  13. {
  14. struct image_header *header;
  15. int *src __attribute__((unused));
  16. int *dst __attribute__((unused));
  17. debug("spl: nand - using hw ecc\n");
  18. nand_init();
  19. /*use CONFIG_SYS_TEXT_BASE as temporary storage area */
  20. header = (struct image_header *)(CONFIG_SYS_TEXT_BASE);
  21. #ifdef CONFIG_SPL_OS_BOOT
  22. if (!spl_start_uboot()) {
  23. /*
  24. * load parameter image
  25. * load to temp position since nand_spl_load_image reads
  26. * a whole block which is typically larger than
  27. * CONFIG_CMD_SPL_WRITE_SIZE therefore may overwrite
  28. * following sections like BSS
  29. */
  30. nand_spl_load_image(CONFIG_CMD_SPL_NAND_OFS,
  31. CONFIG_CMD_SPL_WRITE_SIZE,
  32. (void *)CONFIG_SYS_TEXT_BASE);
  33. /* copy to destintion */
  34. for (dst = (int *)CONFIG_SYS_SPL_ARGS_ADDR,
  35. src = (int *)CONFIG_SYS_TEXT_BASE;
  36. src < (int *)(CONFIG_SYS_TEXT_BASE +
  37. CONFIG_CMD_SPL_WRITE_SIZE);
  38. src++, dst++) {
  39. writel(readl(src), dst);
  40. }
  41. /* load linux */
  42. nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
  43. sizeof(*header), (void *)header);
  44. spl_parse_image_header(header);
  45. if (header->ih_os == IH_OS_LINUX) {
  46. /* happy - was a linux */
  47. nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
  48. spl_image.size, (void *)spl_image.load_addr);
  49. nand_deselect();
  50. return;
  51. } else {
  52. puts("The Expected Linux image was not "
  53. "found. Please check your NAND "
  54. "configuration.\n");
  55. puts("Trying to start u-boot now...\n");
  56. }
  57. }
  58. #endif
  59. #ifdef CONFIG_NAND_ENV_DST
  60. nand_spl_load_image(CONFIG_ENV_OFFSET,
  61. sizeof(*header), (void *)header);
  62. spl_parse_image_header(header);
  63. nand_spl_load_image(CONFIG_ENV_OFFSET, spl_image.size,
  64. (void *)spl_image.load_addr);
  65. #ifdef CONFIG_ENV_OFFSET_REDUND
  66. nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND,
  67. sizeof(*header), (void *)header);
  68. spl_parse_image_header(header);
  69. nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND, spl_image.size,
  70. (void *)spl_image.load_addr);
  71. #endif
  72. #endif
  73. /* Load u-boot */
  74. nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
  75. sizeof(*header), (void *)header);
  76. spl_parse_image_header(header);
  77. nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
  78. spl_image.size, (void *)spl_image.load_addr);
  79. nand_deselect();
  80. }