spl_nand.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (C) 2011
  3. * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <asm/u-boot.h>
  25. #include <asm/utils.h>
  26. #include <asm/arch/sys_proto.h>
  27. #include <asm/io.h>
  28. #include <nand.h>
  29. #include <version.h>
  30. #include <asm/omap_common.h>
  31. void spl_nand_load_image(void)
  32. {
  33. struct image_header *header;
  34. int *src __attribute__((unused));
  35. int *dst __attribute__((unused));
  36. switch (omap_boot_mode()) {
  37. case NAND_MODE_HW_ECC:
  38. debug("spl: nand - using hw ecc\n");
  39. gpmc_init();
  40. nand_init();
  41. break;
  42. default:
  43. puts("spl: ERROR: This bootmode is not implemented - hanging");
  44. hang();
  45. }
  46. /*use CONFIG_SYS_TEXT_BASE as temporary storage area */
  47. header = (struct image_header *)(CONFIG_SYS_TEXT_BASE);
  48. #ifdef CONFIG_SPL_OS_BOOT
  49. if (!spl_start_uboot()) {
  50. /*
  51. * load parameter image
  52. * load to temp position since nand_spl_load_image reads
  53. * a whole block which is typically larger than
  54. * CONFIG_CMD_SAVEBP_WRITE_SIZE therefore may overwrite
  55. * following sections like BSS
  56. */
  57. nand_spl_load_image(CONFIG_CMD_SPL_NAND_OFS,
  58. CONFIG_CMD_SPL_WRITE_SIZE,
  59. (void *)CONFIG_SYS_TEXT_BASE);
  60. /* copy to destintion */
  61. for (dst = (int *)CONFIG_SYS_SPL_ARGS_ADDR,
  62. src = (int *)CONFIG_SYS_TEXT_BASE;
  63. src < (int *)(CONFIG_SYS_TEXT_BASE +
  64. CONFIG_CMD_SPL_WRITE_SIZE);
  65. src++, dst++) {
  66. writel(readl(src), dst);
  67. }
  68. /* load linux */
  69. nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
  70. CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
  71. spl_parse_image_header(header);
  72. if (header->ih_os == IH_OS_LINUX) {
  73. /* happy - was a linux */
  74. nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
  75. spl_image.size, (void *)spl_image.load_addr);
  76. nand_deselect();
  77. return;
  78. } else {
  79. printf("The Expected Linux image was not"
  80. "found. Please check your NAND"
  81. "configuration.\n");
  82. printf("Trying to start u-boot now...\n");
  83. }
  84. }
  85. #endif
  86. #ifdef CONFIG_NAND_ENV_DST
  87. nand_spl_load_image(CONFIG_ENV_OFFSET,
  88. CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
  89. spl_parse_image_header(header);
  90. nand_spl_load_image(CONFIG_ENV_OFFSET, spl_image.size,
  91. (void *)spl_image.load_addr);
  92. #ifdef CONFIG_ENV_OFFSET_REDUND
  93. nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND,
  94. CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
  95. spl_parse_image_header(header);
  96. nand_spl_load_image(CONFIG_ENV_OFFSET_REDUND, spl_image.size,
  97. (void *)spl_image.load_addr);
  98. #endif
  99. #endif
  100. /* Load u-boot */
  101. nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
  102. CONFIG_SYS_NAND_PAGE_SIZE, (void *)header);
  103. spl_parse_image_header(header);
  104. nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
  105. spl_image.size, (void *)spl_image.load_addr);
  106. nand_deselect();
  107. }