0020-MIPS-lantiq-add-NAND-SPL-support.patch 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. From e17398316e82d8b28217232b4fd6030c65138e74 Mon Sep 17 00:00:00 2001
  2. From: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
  3. Date: Mon, 12 Aug 2013 01:18:00 +0200
  4. Subject: MIPS: lantiq: add NAND SPL support
  5. Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
  6. --- a/arch/mips/cpu/mips32/lantiq-common/spl.c
  7. +++ b/arch/mips/cpu/mips32/lantiq-common/spl.c
  8. @@ -8,6 +8,7 @@
  9. #include <image.h>
  10. #include <version.h>
  11. #include <spi_flash.h>
  12. +#include <nand.h>
  13. #include <linux/compiler.h>
  14. #include <lzma/LzmaDec.h>
  15. #include <linux/lzo.h>
  16. @@ -63,6 +64,18 @@
  17. #define spl_boot_nor_flash 0
  18. #endif
  19. +#if defined(CONFIG_LTQ_SUPPORT_SPL_NAND_FLASH) && defined(CONFIG_SYS_BOOT_NANDSPL)
  20. +#define spl_boot_nand_flash 1
  21. +#else
  22. +#define spl_boot_nand_flash 0
  23. +#ifndef CONFIG_SYS_NAND_U_BOOT_OFFS
  24. +#define CONFIG_SYS_NAND_U_BOOT_OFFS 0
  25. +#endif
  26. +#ifndef CONFIG_SYS_NAND_PAGE_SIZE
  27. +#define CONFIG_SYS_NAND_PAGE_SIZE 0
  28. +#endif
  29. +#endif
  30. +
  31. #define spl_sync() __asm__ __volatile__("sync");
  32. struct spl_image {
  33. @@ -337,6 +350,58 @@ static int spl_load_nor_flash(struct spl
  34. return ret;
  35. }
  36. +static int spl_load_nand_flash(struct spl_image *spl)
  37. +{
  38. + image_header_t *hdr;
  39. + int ret;
  40. + unsigned long loadaddr;
  41. +
  42. + /*
  43. + * Image format:
  44. + *
  45. + * - 12 byte non-volatile bootstrap header
  46. + * - SPL binary
  47. + * - 12 byte non-volatile bootstrap header
  48. + * - padding bytes up to CONFIG_SYS_NAND_U_BOOT_OFFS
  49. + * - 64 byte U-Boot mkimage header
  50. + * - U-Boot binary
  51. + */
  52. + spl->data_addr = CONFIG_SYS_NAND_U_BOOT_OFFS;
  53. +
  54. + spl_puts("SPL: initializing NAND flash\n");
  55. + nand_init();
  56. +
  57. + spl_debug("SPL: reading image header at page offset %lx\n",
  58. + spl->data_addr);
  59. +
  60. + hdr = (image_header_t *) CONFIG_LOADADDR;
  61. + ret = nand_spl_load_image(spl->data_addr,
  62. + CONFIG_SYS_NAND_PAGE_SIZE, hdr);
  63. + if (ret)
  64. + return ret;
  65. +
  66. + spl_debug("SPL: checking image header at address %p\n", hdr);
  67. +
  68. + ret = spl_parse_image(hdr, spl);
  69. + if (ret)
  70. + return ret;
  71. +
  72. + if (spl_is_compressed(spl))
  73. + loadaddr = CONFIG_LOADADDR;
  74. + else
  75. + loadaddr = spl->entry_addr;
  76. +
  77. + spl_puts("SPL: loading U-Boot to RAM\n");
  78. +
  79. + ret = nand_spl_load_image(spl->data_addr, spl->data_size,
  80. + (void *) loadaddr);
  81. +
  82. + if (spl_is_compressed(spl))
  83. + ret = spl_uncompress(spl, loadaddr);
  84. +
  85. + return ret;
  86. +}
  87. +
  88. static int spl_load(struct spl_image *spl)
  89. {
  90. int ret;
  91. @@ -345,6 +410,8 @@ static int spl_load(struct spl_image *sp
  92. ret = spl_load_spi_flash(spl);
  93. else if (spl_boot_nor_flash)
  94. ret = spl_load_nor_flash(spl);
  95. + else if (spl_boot_nand_flash)
  96. + ret = spl_load_nand_flash(spl);
  97. else
  98. ret = 1;
  99. --- a/arch/mips/include/asm/lantiq/config.h
  100. +++ b/arch/mips/include/asm/lantiq/config.h
  101. @@ -40,6 +40,26 @@
  102. #define CONFIG_SPI_SPL_SIMPLE
  103. #endif
  104. +/*
  105. + * NAND flash SPL
  106. + * BOOT CFG 06 only (address cycle based probing, 2KB or 512B page size)
  107. + */
  108. +#if defined(CONFIG_LTQ_SUPPORT_SPL_NAND_FLASH) && defined(CONFIG_SYS_BOOT_NANDSPL)
  109. +#define CONFIG_SPL
  110. +#define CONFIG_SPL_NAND_SUPPORT
  111. +#define CONFIG_SPL_NAND_DRIVERS
  112. +#define CONFIG_SPL_NAND_SIMPLE
  113. +#define CONFIG_SPL_NAND_ECC
  114. +
  115. +/* use software ECC until driver supports HW ECC */
  116. +#define CONFIG_SPL_NAND_SOFTECC
  117. +#define CONFIG_SYS_NAND_ECCSIZE 256
  118. +#define CONFIG_SYS_NAND_ECCBYTES 3
  119. +#define CONFIG_SYS_NAND_ECCPOS {40, 41, 42, 43, 44, 45, 46, 47, \
  120. + 48, 49, 50, 51, 52, 53, 54, 55, \
  121. + 56, 57, 58, 59, 60, 61, 62, 63}
  122. +#endif
  123. +
  124. #if defined(CONFIG_LTQ_SUPPORT_SPL_NOR_FLASH) && defined(CONFIG_SYS_BOOT_NORSPL)
  125. #define CONFIG_SPL
  126. #endif
  127. @@ -148,6 +168,21 @@
  128. #define CONFIG_ENV_LOAD_UBOOT_SF
  129. #endif
  130. +#if defined(CONFIG_LTQ_SUPPORT_NAND_FLASH)
  131. +#define CONFIG_ENV_WRITE_UBOOT_NAND \
  132. + "write-uboot-nand=" \
  133. + "nand erase 0 $filesize && " \
  134. + "nand write $fileaddr 0 $filesize\0"
  135. +
  136. +#define CONFIG_ENV_LOAD_UBOOT_NAND \
  137. + "load-uboot-nandspl=tftpboot u-boot.ltq.nandspl\0" \
  138. + "load-uboot-nandspl-lzo=tftpboot u-boot.ltq.lzo.nandspl\0" \
  139. + "load-uboot-nandspl-lzma=tftpboot u-boot.ltq.lzma.nandspl\0"
  140. +#else
  141. +#define CONFIG_ENV_WRITE_UBOOT_NAND
  142. +#define CONFIG_ENV_LOAD_UBOOT_NAND
  143. +#endif
  144. +
  145. #define CONFIG_ENV_LANTIQ_DEFAULTS \
  146. CONFIG_ENV_CONSOLEDEV \
  147. CONFIG_ENV_ADDCONSOLE \
  148. @@ -159,6 +194,8 @@
  149. CONFIG_ENV_LOAD_UBOOT_NOR \
  150. CONFIG_ENV_SF_PROBE \
  151. CONFIG_ENV_WRITE_UBOOT_SF \
  152. - CONFIG_ENV_LOAD_UBOOT_SF
  153. + CONFIG_ENV_LOAD_UBOOT_SF \
  154. + CONFIG_ENV_WRITE_UBOOT_NAND \
  155. + CONFIG_ENV_LOAD_UBOOT_NAND
  156. #endif /* __LANTIQ_CONFIG_H__ */